Repository navigation
fix(xla): split ragged load timing, restore decode-only tok/s (#2961) - #2976
Merged
Merged
Conversation
5 tasks done
Split the ragged load span into module load and weight upload through the existing MLXCEL_XLA_LOAD_TIMING reporter. The parts line now carries the uploaded tensor count, bytes, host dequantize time, f16 pack time and device copy time. A capacity bucket reports zero upload because it shares the base context's views. No new labels are printed when the variable is unset. Add test-support counters for xla_llama_upload_weight and an ignored root device test that asserts one upload per declared weight spec and none for a capacity bucket. xla_batch_bench loads the engine before its timed window again. #2936 (311ad93) moved the load under t_run while replacing the pump loop with drive, which is what dropped the f16 B=4 reading from the control's 63.4 tok/s to 20.8 and made the #2933 targets look unverifiable. The pre-#2933 control (fd2a65e) loads the same span in 4.9 s on the same checkpoint, host, IREE distribution and capacity, so the 0.7 s figure in the issue does not reproduce. The f16 ragged load is the host dequantize, f16 pack and 3.0 GB device copy, unchanged from the control, and flat across capacity 256 and 1024. Measured on gfx1151, medians of three runs: f16 ragged load 5.62 s at B=4 and 5.03 s at B=8, native 1.17 s and 1.15 s. Decode-only medians are 64.0 and 60.4 tok/s for f16 and 61.7 and 75.8 for native at B=4 and B=8.
inureyes
force-pushed
the
fix/issue-2961-f16-ragged-load-timing
branch
from
November 11, 2026 16:35
9a6e3ab to
1ae8eb8
Compare
inureyes
marked this pull request as ready for review
November 11, 2026 16:39
9 of 18 tasks
inureyes
pushed a commit
that referenced
this pull request
Nov 15, 2026
## Summary Follow-up to #2976. That change split the OpenXLA load span and showed the f16 weight upload is host-bound: on gfx1151 about 3.8 of 5 s is affine dequantization and f16 packing, both single-threaded. This threads those conversions. On a DGX Spark GB10 the batch engine's load goes from 5.8 to 5.9 s to 2.0 to 2.1 s with bit-identical weights. ## Related issues Refs #2961, #2976 ## Type of change - [ ] `feat` — new user-visible feature - [ ] `fix` — bug fix - [x] `perf` — performance improvement (include before/after numbers in the PR body) - [ ] `refactor` — internal restructuring without behavior change - [ ] `chore` — build, CI, dependencies, release infrastructure - [ ] `docs` — documentation only - [ ] `test` — tests only ## What changed One file, `src/lib/mlxcel-xla/src/weights.rs`: - `fill_rows_parallel` fills an output slice in bands of whole rows, one `std::thread::scope` thread per band. `dequantize_affine` (through `dequantize_affine_with_metadata`), `pack_f16` and `transpose_projection` use it. - `conversion_threads` picks the thread count: one below 2^20 elements, otherwise `available_parallelism` capped at 16. - `f16_to_f32` builds its 65536-entry table once per process (`OnceLock`) instead of once per call. A quantized checkpoint called it twice per projection. Each element is written by exactly one thread with the arithmetic the serial loop used, so the output does not depend on the thread count. No new dependency, no new environment variable, no change to the loader or the graphs. ## Measurements DGX Spark GB10 (20 cores, sm_121, CUDA 13.0, driver 580.178.04), IREE 3.12.0rc20260721, `mlx-community/Llama-3.2-1B-Instruct-4bit`, `--device cuda`, `MLXCEL_XLA_QUANT` unset, release build with `--features cuda,xla-iree`. Base `955335a3`. `xla_batch_bench` with `MLXCEL_XLA_LOAD_TIMING=1`, main and patched binaries interleaved, three runs each at B=4 and at B=8. The load does not depend on B, so the ranges below cover all six runs per binary. Batch engine (146 tensors, 2,997,100,544 bytes): | | main | this PR | |---|---|---| | `ragged-context-and-upload` | 5.81 to 5.92 s | 2.01 to 2.08 s | | `language-weight-upload` | 5.61 to 5.74 s | 1.83 to 1.90 s | | `dequantize_ms` | 2505 to 2567 | 340 to 347 | | `pack_ms` | 1900 to 1924 | 254 to 261 | | `copy_ms` | 996 to 1048 | 934 to 997 | | `language-module-load` | 0.18 to 0.20 s | 0.18 to 0.19 s | Single-sequence reference engine (147 tensors, 3,522,437,120 bytes): | | main | this PR | |---|---|---| | `language-total` | 9.56 to 9.81 s | 3.37 to 3.47 s | | `language-weight-upload` | 9.29 to 9.52 s | 3.11 to 3.20 s | | `dequantize_ms` | 2575 to 2628 | 356 to 360 | | `pack_ms` | 2531 to 2557 | 317 to 324 | The single-sequence engine also transposes each projection; that pass is not in `pack_ms` but is in the upload total, which is why its total falls by more than the two listed parts. Decode is untouched: 22.6 to 23.1 tok/s on main against 23.0 to 23.3 at B=4, and 31.9 to 32.5 against 32.6 to 32.9 at B=8. Scaling of the batch engine upload with the affinity mask (`taskset`, fastest cores first, two runs each): | cores | upload | dequantize | pack | |---|---|---|---| | 1 | 5.70 to 5.72 s | 2582 to 2586 ms | 1955 to 1959 ms | | 2 | 3.52 to 3.53 s | 1351 to 1368 | 990 to 999 | | 4 | 2.47 s | 742 to 746 | 507 to 513 | | 8 | 1.86 to 1.94 s | 423 to 427 | 282 to 287 | | 10 | 1.84 s | 368 to 369 | 239 to 241 | | 16 | 1.78 to 1.80 s | 334 to 342 | 249 to 257 | | 20 | 1.82 to 1.87 s | 344 | 256 | One core reproduces main, and the gain is spent by 8 to 10 cores. That is where the cap of 16 comes from. What remains is the device copy, about 1 s for 3 GB, which this PR does not touch. ## Correctness - `threaded_conversions_are_bit_identical_to_the_serial_reference`: on a 1024 x 1088 tensor, which takes the threaded path, `dequantize_affine`, `pack_f16` and `transpose_projection` equal an element-by-element serial reference bit for bit. - `fill_rows_parallel_matches_the_serial_fill_for_every_thread_count`: 1 to 64 threads over 37 rows, which none of the tested counts above 1 divides. - `conversion_threads_is_serial_below_the_threshold_and_capped_above`. - Twelve 128-token greedy trajectories (`xla_traj_dump`, six prompts each on llama-3.2-1b-instruct-4bit and the untied Qwen2.5-7B-Instruct-4bit) are identical id for id between the main and the patched binary. - `xla_batch_bench` on `cuda`: `REFERENCE-EXACT PASS` in all twelve interleaved runs (main and patched, B=4 and B=8) and in all fourteen scaling runs. ## Test plan - [x] `cargo fmt --all -- --check` - [ ] `cargo clippy --workspace --all-targets --features metal,accelerate -- -D warnings` (not run; Linux host). `cargo clippy -p mlxcel-xla --all-targets --features iree -- -D warnings` is clean. - [ ] `cargo test --workspace --profile test-fast --features metal,accelerate --no-fail-fast -- --test-threads=1` (not run; Linux host) - [ ] `cargo deny check` (not run; no dependency change) - [x] Validated with real checkpoints: `mlx-community/Llama-3.2-1B-Instruct-4bit`, `mlx-community/Qwen2.5-7B-Instruct-4bit` - [x] Before/after numbers and environment are in the PR body Also on the GB10 host: `cargo test --release -p mlxcel-xla --lib` (410 passed, 19 ignored, no IREE environment), `cargo test --release -p mlxcel-xla --features iree --lib` (435 passed, 22 ignored), and `RUSTFLAGS="-D warnings" cargo check -p mlxcel-xla --all-targets`. ## Notes for reviewers - **Only one host.** The cap and the curve come from a 20-core big.LITTLE machine on `cuda`. I could not run `hip`; from the #2976 table (dequantize 1.9 s, pack 1.9 s on gfx1151) I would expect a similar saving there, but that is an expectation, not a measurement. - **Threads are spawned per large tensor**, about 150 times per load, not kept in a pool. The one-core row above equals main to within noise, so the spawn cost is not visible. - **Not threaded:** `dequantize_affine_stacked` (the MoE expert bank), the two BF16 carrier variants Gemma3n uses, and the unquantized `bf16_to_f32` / `f32_le_to_f32` widening. They are not on the path measured here. - **Memory.** The conversion output buffers have the same sizes. Peak RSS was not measured; per-thread stacks and the process-lifetime conversion table add overhead. ## Checklist - [x] PR title uses a Conventional Commits prefix (`feat:`, `fix:`, etc.) - [x] One logical change per PR (split unrelated changes) - [x] Updated `docs/` if user-facing behavior or supported models changed (no user-facing change) - [x] Updated `// Used by: ...` comments on any shared function I modified (see `docs/code-guidelines.md`) (none carry one) - [x] No secrets, credentials, or `.env` files committed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
iree.rs: the opaque load span is reported in parts through the existingreport_load_timinggate.language-module-loadcoversxla_llama_create(instance, device, session, vmfb module load),language-weight-uploadcoversupload_weights_with_sink, andlanguage-weight-upload-partsappendstensors,uploaded_bytes,dequantize_ms,pack_msandcopy_ms. A capacity bucket prints the parts line with zero counters because it shares the base context's views. No line is printed whenMLXCEL_XLA_LOAD_TIMINGis unset.xla_llama_upload_weightcalls and bytes underMLXCEL_XLA_TEST_SUPPORT, andIreeRaggedLlama::weight_count()exposes the declared spec count. The ignored root testbase_load_uploads_each_weight_once_and_a_bucket_uploads_noneasserts one upload per spec and zero for a bucket.examples/xla_batch_bench.rs: the engine is loaded beforet_run, and the phase 1 and phase 2 load times print separately, soBENCHreports decode-only tok/s, the convention indocs/benchmarks.md.docs/environment-variables.mdandCHANGELOG.mddescribe the new fields and the window fix.Root cause of the throughput drop
#2936 (
311ad935) replaced the inline pump loop withdrive(...)and, in that move, constructed the engine afterlet t_run = Instant::now();. The pre-#2936 harness started the clock after the engine load. With the f16 ragged load at 4.9 to 5.6 s, that one-time cost landed in the denominator, which is the whole difference between the 60 to 65 tok/s the harness used to report and the 20.6 to 22.5 tok/s the issue recorded. With the load excluded, the same runs decode at a median of 64.0 tok/s at B=4, and the pre-#2933 control harness, which already excluded the load, reports 63.4.The load itself
Medians of three measured runs, capacity 256 unless stated. Load is
ragged-context-and-uploadon HEAD and the innerlanguage-vmfb-and-device-uploadon the control, which is the same span in both.fd2a65ea) loads the same span in 4.89 s at B=4 and 4.93 s at B=8 on the same checkpoint, host, IREE distribution and capacity. The 0.7 s figure in the issue does not reproduce: the control is the same ~5 s, HEAD is 0.7 s slower at B=4 and 0.1 s slower at B=8, and both differences are inside the copy-time spread. There is no 7x load regression to revert.hip. Since decode throughput, not load time, is the perf(xla): run the ragged engine through the native 4-bit GEMV #2933 gate and the f16-resident path is unchanged from the control, this issue keeps f16-resident weights and records the trade-off instead.IreeLlama, 147 tensors, 3.52 GB, about 12.6 s upload), phase 2 is the ragged batch engine (IreeRaggedLlama, 146 tensors, 3.0 GB).ragged-context-and-uploadexists only on the phase-2 ragged load, and the control prints only the inner label, which is the comparable number.#2933 absolute targets, decode-only
Reference exactness: every native run and every f16 B=8 run prints
REFERENCE-EXACT PASS. The f16 B=4 arm diverges at request 2, token 3, in all three HEAD runs and in all three runs of the pre-#2933 control with the same prompt artifact, so the divergence is a near-tie in the f16 ragged path that predates this change and is not caused by it. A repeat of the B=4 f16 target with a natural-text prompt artifact of the same shape printsREFERENCE-EXACT PASSat 63.1 tok/s, so the divergence is prompt-specific and not a path regression.Measurement protocol
ce6855bcplus this change; control built fromfd2a65ea(the parent of the perf(xla): run the ragged engine through the native 4-bit GEMV #2933 commit) in a separate tree fromgit archive, with an identicalCargo.lockand the same IREE ROCm3.12.0rc20260721tree.gfx1151, every run underscripts/rocm_gpu_guard.sh --hold, one process per run,MLXCEL_XLA_DEVICE=hip,MLXCEL_XLA_QUANTunset for the f16 arm,MLXCEL_XLA_CONTEXT_CAPACITY256 unless stated, warm checkpoint page cache, one warmup per arm, then three measured runs interleaved so host drift hits every arm alike; medians are reported.spike/openxla/artifacts/prompt_ids.jsonis not in the checkout. I generated a 63-id natural-text artifact from the checkpoint's tokenizer; the harness derives the same request lengths (20 to 62) and the same caps as perf(xla): run the ragged engine through the native 4-bit GEMV #2933, and the runs generate 170 tokens at B=4 and 420 at B=8, which matches the perf(xla): run the ragged engine through the native 4-bit GEMV #2933 workload and its 46 and 69 pump steps.Verification
make verify-fmt: pass.cargo clippy -p mlxcel-xla --features iree --lib --tests -- -D warnings: pass.cargo test -p mlxcel-xla --lib: 407 passed, 19 ignored.cargo test --release -p mlxcel-xla --lib --features iree load_timing_accounting_tests: 3 passed (byte accounting, detail formatting, line shape with and without detail).cargo test --test llama_compat_manifest: 4 passed.make verify-env-var-docs: 15 checks pass.cargo test --release --features xla-iree,test-utils --test xla_ragged_hardening base_load_uploads_each_weight_once_and_a_bucket_uploads_none -- --ignored: 1 passed, asserting one upload per declared spec on the base load and zero calls and bytes for the capacity bucket.Closes #2961.