Skip to content

perf(cuda): keep graphs whole across the audited expert-stack kernel reads - #3496

Merged
inureyes merged 5 commits into
lablup:mainfrom
Jaeyeong-CHOI:perf/3387-cuda-graph-commit-audit
Nov 28, 2026
Merged

inureyes merged 5 commits into
lablup:mainfrom
Jaeyeong-CHOI:perf/3387-cuda-graph-commit-audit

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Summary

Closes #3387.

The audit the issue asks for, on GB10, and the one fix it led to.

Of the three candidate paths in the issue, none has a custom kernel left to exempt on CUDA: paged sparse decode is already covered by the #3406 name match, the pool gather is a builtin, and the MLA absorbed-decode kernels have no CUDA port. Going through every cuda_kernel registration found the two kernels that do pay: moe_gateup_kernel_cu and moe_down_kernel_cu, the fused decode-MoE pair. They take a layer's whole expert stacks and read the experts their index names, 8 of 128 on Qwen3-30B-A3B, so on DGX Spark each of the two launches cut the graph in every layer. This PR charges a stack for the experts the index names.

Graph launches per decode step at B=1 on GB10: Qwen3-30B-A3B-4bit 147.0 to 62.1 (60.1 with MLX_MAX_MB_PER_BUFFER=1000), LFM2-8B-A1B-4bit 48.0 to 30.0 (29.0 raised). Decode rate against main: Qwen3-30B-A3B +10.2% and +17.7% at a 256-token prompt and +4.5% and +6.0% at 8192 tokens (two runs, three rounds each with a null arm), LFM2-8B-A1B +0.8% and +0.5% (inside the null), reply text byte-identical everywhere.

The pool gather and gather_qmm are affected builtins and are written up in #3495 instead of being changed here, as the issue asks. The full table is in the issue comment and in docs/benchmark_results/cuda-graph-commit-audit-gb10-2026-11-27.md.

What changed

  • src/lib/mlxcelverse/overlays/cuda/mlx/backend/cuda/custom_kernel.cpp: rows_read_of_inputs(name, inputs) replaces the single name test. For moe_gateup_kernel_cu (inputs {x, indices, gate_w, gate_s, gate_b, up_w, up_s, up_b}) and moe_down_kernel_cu ({indices, down_w, down_s, down_b, act_g, scores}) each three-dimensional stack input is charged for indices.size() of its shape(0) experts. x, indices, act_g and scores are read whole and counted whole. The mlxcel_paged_attention* kernels keep what perf(cache): reduce paged attention execution overhead #3406 gave them, every input left out. The comment above the function says, per kernel, why the bytes read are bounded by the index.
  • src/lib/mlxcelverse/overlays/cuda/mlx/backend/cuda/device.cpp: set_input_rows_read(rows_read, rows) and counted_input_elements(data_size, rows_read, rows). set_input_array adds counted_input_elements(arr.data_size(), ...); set_input_bytes_uncounted(bool) is now set_input_rows_read(uncounted ? 0 : 1, 1), so its one caller behaves as before. Two test hooks: graph_launch_count(), an atomic counter bumped at both cudaGraphLaunch sites of commit_impl, and default_graph_limits().
  • src/lib/mlxcel-core: the bridge functions cuda_graph_commit_stats and cuda_graph_counted_input_elements (cpp/mlx_cxx_ext.cpp, cpp/mlx_cxx_bridge.h, src/lib.rs), CudaGraphCommitStats in src/cuda_graph_budget.rs, and the tests in src/cuda_graph_commit_tests.rs.
  • scripts/nsys_cuda_graph_launches.py: graphs per decode step, and the kernels held by the graphs that were cut short, from an exported --cuda-graph-trace=node trace.
  • docs/benchmark_results/cuda-graph-commit-audit-gb10-2026-11-27.md with its rows, the overlay README, docs/benchmark_results/README.md and CHANGELOG.md.

Why the two kernels read only the rows their index names

Both bodies are in src/lib/mlxcel-core/cpp/mlx_cxx_kernels.cpp (MOE_GATEUP_CUDA_SOURCE, MOE_DOWN_CUDA_SOURCE). The grid's z axis is the expert slot, eslot = blockIdx.z < K, and the only way either body forms an address into a stack is

uint32_t e   = indices[eslot];
uint32_t row = e * Dff + f;            // gate/up; `e * Din + h` in the down kernel
const uint32_t* gwr = gate_w + row * Din_p;
const T*        gsr = gate_s + row * G;

followed by reads at gwr[p] with p < Din_p and gsr[grp] with grp < G. So a launch touches K whole expert slices of each stack and nothing else of it: K * Dff * Din_p of E * Dff * Din_p packed words, and the same share of the scale and bias stacks. The launcher (run_fused_moe_two_kernel) passes indices with K entries and sizes the grid's z axis to K.

Where this differs from the issue text

  • The stacks are charged for the experts read, not left out. The issue's proposal is to add the kernel to the name match, which takes every input out of the count. Here a stack counts data_size / E * K. With 8 of 128 experts that is under the budget and the graph is no longer cut, which is the effect the issue wants. With an index that names every expert the launch reads the stacks whole and is charged whole, so the rule cannot hide a launch that reads its whole input, and an index that names enough experts to be over the budget on its own still cuts the graph. The paged-attention kernels keep the all-or-nothing form perf(cache): reduce paged attention execution overhead #3406 measured. Charging them by share would, by the same arithmetic, bring the cuts back at long context (four 8K requests name half of a 134M-element pair of slabs), which is a different decision from the one perf(cache): reduce paged attention execution overhead #3406 made and measured.
  • The exempted kernels are not among the issue's candidates. They come from the sweep over every cuda_kernel registration. The three candidates turned out as: already exempt (sparse decode), a builtin (the gather), and not launched on CUDA at all (MLA).
  • Not every path has a B=4 cell. The fused MoE kernel takes one token, so B=4 is the gather_qmm builtin. The sparse path could only be launched through the synthetic bench at batch 1. Prompt-lookup verification at B=4 has no window in which all four rows stream; that cell is reported as a whole-cell total.
  • The Gemma 3 figure in the issue (54 against 29) could not be re-run. It is from the sliding-window branch of feat(cache): paged sliding-window KV with prefix reuse at any block boundary #3334; on main Gemma 3 is not pool-backed. The known case was reproduced on Qwen3-0.6B instead, against the profile perf(cache): reduce paged attention execution overhead #3406 committed.
  • The tests use an encoder hook the issue only allowed for. There was none, so this PR adds the graph-launch counter.

Verification

Spark2: NVIDIA GB10 (sm_121), driver 580.178.04, CUDA 13.0.88, Ubuntu 24.04.5, Linux 7.0.0 aarch64, rustc 1.97.1 (the pinned toolchain), --features cuda. Base 944dbfc2ddd6ccab2b051dadc995e99d9d796c83. Tested tree eb5058712ed25f7f084adebf176df11258da7dfe, the tree of the commit.

  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-targets --features cuda -- -D warnings
  • python3 scripts/ci/check_used_by.py, bash scripts/ci/check_used_by_test.sh, python3 scripts/insert_apache_header.py --check, and the other scripts/ci checks (check_env_var_docs.py, check_kernel_dtype_keys.py and its test, check_cross_repo_refs.py, check_benchmark_raw_logs.py and its test, check_benchmark_csv_schema.py, check_kernel_port_dispatch.py, check_native_env_writes.py, check_binary_assets.py, check_windows_reserved_paths.py, check_crate_versions.py): all exit 0.
  • cargo test --locked -p mlxcel-core --profile test-fast --features cuda --lib <filter> -- --test-threads=1: cuda_graph_commit 3 passed, fused_moe 6 passed, paged 268 passed and 1 ignored, cuda_graph_budget 8 passed.
  • make verify-test-cuda with a private 0700 TMPDIR: 17,409 passed, 5 failed, 517 ignored over 199 test result lines. The five failures are all in the mlxcel library target and all Raon: models::raon1_mini::speculative::tests::{a_steered_verify_block_applies_the_alpha_exactly_as_decode_does, a_verify_block_equals_the_decode_chain_byte_for_byte, rollback_after_a_partial_accept_equals_a_fresh_decode_of_the_accepted_tokens, the_exactness_probe_passes_on_the_tiny_model} and models::raon_mhc::tests::compiled_site_equals_the_eager_site_bit_for_bit. This PR does not touch Raon; the same five fail with the same messages on unmodified main in the gate runs of our other open PRs on this host (fix(vision): build the DeepSeek-OCR prompt as the reference does #3482, fix: keep the boundary snapshot when a prompt-cache warm-up extends it #3492), and fix(models): keep Raon DFlash2 verify blocks byte-exact on CUDA #3476 is open for the speculative ones. The tree was eb5058712 before and after the gate.

Tests

New file src/lib/mlxcel-core/src/cuda_graph_commit_tests.rs, compiled with --features cuda. The launch tests need a device whose byte budget the test stacks exceed, which is DGX Spark at MLX's default; elsewhere they skip with a message naming MLX_MAX_MB_PER_BUFFER=25.

  • a_partly_read_input_is_charged_for_the_rows_read: the encoder's own counted_input_elements, through the bridge, with no launch. A 33,554,432-element stack with 0, 1, 8, 127, 128, 129 and u64::MAX of 128 rows read; 1 of 1 and 0 of 1 (the two forms the paged kernels use); rows == 0; an empty input and an input smaller than its row count; u64::MAX in each argument; and a sweep that holds the result to never exceed the input, never decrease in the rows read, and stay within rows_read of the exact share.
  • moe_expert_stacks_over_the_byte_budget_do_not_cut_the_graph: stacks of 128 experts, Din 2048, Dff 1024, 4-bit, tiled from 16 random quantized experts, so each weight stack is 33.5M elements, over the budget on its own. For both launchers (SwiGLU fused_moe_expert_kernel, GeGLU fused_moe_geglu_kernel) and for an index of 1 and of 8 experts, one eval of one fused call, which is the gate/up launch followed by the down launch, launches exactly one graph, and its output is byte-for-byte the output of the same experts taken from the 16-expert stack, which is under the budget.
  • an_index_over_the_byte_budget_still_cuts_the_graph: with all 128 experts named the same eval launches at least 3 graphs, and with 64 named at least 2 (the gate and up stacks are then charged 41.9M elements).

Every graph count is the minimum over five repetitions with the stream drained before each, so graphs launched by another test thread can only make a test fail, not pass.

Before and after, cargo test --locked -p mlxcel-core --profile test-fast --features cuda --lib cuda_graph_commit -- --test-threads=1:

Tree Result
The commit 3 passed
The commit with custom_kernel.cpp of main (hook and tests only, the state before the change) 2 passed, 1 failed: moe_expert_stacks_over_the_byte_budget_do_not_cut_the_graph, swiglu, 1 of 128 experts: the two launches must share one graph, left: 3, right: 1
The commit, down stacks counted whole again (the moe_down_kernel_cu branch removed) 1 failed: the same test, left: 2
The commit, gate/up stacks counted whole again (the moe_gateup_kernel_cu branch removed) 1 failed: the same test, left: 2
The commit, stacks left out whole whatever the index (the issue's name-match form) 1 failed: an_index_over_the_byte_budget_still_cuts_the_graph
The commit, counted_input_elements without the rows_read >= rows clamp 1 failed: a_partly_read_input_is_charged_for_the_rows_read, left: 33816576, right: 33554432

The six existing fused_moe tests (parity against the f32 reference and gather_qmm, determinism, SGY invariance), which now run through the new accounting, pass on the commit.

The four review lessons

  1. Boundary inputs. The new arithmetic takes a size, a count and a ratio, so a_partly_read_input_is_charged_for_the_rows_read pins it at 0, 1, the last row before all, all, one past all, rows == 0, an empty input, an input smaller than its row count, and u64::MAX in each position. Writing those cases is what removed my first form, data_size / rows * rows_read + data_size % rows * rows_read / rows: its second product wraps once rows passes 2^32. The shipped form takes the quotient first and cannot wrap; it is short of the exact share by less than rows_read elements, against a budget counted in units of 2^20. On the launch side the index is tested at 1, 8, 64 and all 128 experts. An index naming no expert is charged nothing by the arithmetic test, and is not a launch the kernels support: the launcher sizes the grid's depth to K, and a probe on the commit's tree showed fused_moe_expert_kernel returning a lazy [Din] array for an empty index whose eval aborts the process in cuGraphAddKernelNode (invalid argument). That is the launcher's existing behaviour, no model passes top_k = 0, and this PR does not change it.
  2. Time on large inputs. The encoder gains three substring searches on the kernel name and one vector of inputs.size() entries per custom-kernel launch, none of which grows with a tensor, and one atomic increment per graph. A decode step runs about a hundred custom-kernel launches. scripts/nsys_cuda_graph_launches.py is one pass over the kernels with a bisect per kernel: 1.0 s and 184 MB on the largest export of the audit (1.02M kernels, 2.68M API calls, 1.1 GB). The test stacks are built once per test; the arithmetic sweep is about 30,000 bridge calls.
  3. Every other caller. set_input_bytes_uncounted has one caller, the paged-attention branch of custom_kernel.cpp, and it now goes through rows_read_of_inputs with {0, 1}: traces of the change give 26 / 42 / 55 / 68 graph launches per step at B = 1 to 4 on Qwen3-0.6B, the same as main, with identical text. CommandEncoder::set_input_array is called from 93 sites of the CUDA overlay and the rest of the backend; they see the thread-local at 1 of 1, which returns data_size unchanged, and eval_gpu resets it after its loop as before. The two MoE kernels are reached from fused_moe_expert_kernel (SwitchGLU families, qwen3_next), fused_moe_geglu_kernel (gemma4) and, for the down kernel only, fused_moe_forward's squared-ReLU branch, which has no CUDA fc1 port and so does not run on CUDA; all pass the stacks in the registered order. Every other cuda_kernel registration is listed in the issue comment with why it stays counted. The same count exists in the ROCm overlay (rocm/device.cpp:591, fixed budget 200, no exemption for any kernel) and is not changed here: no ROCm host.
  4. cargo fmt --all -- --check on the committed tree: passes.

Measurements

All on GB10, release builds copied aside with their sha256, one server at a time under a memory watchdog, no build or test beside a measurement. Method and every row: docs/benchmark_results/cuda-graph-commit-audit-gb10-2026-11-27.md and the two CSVs beside it.

The known case. With the #3406 name match turned off, Qwen3-0.6B-4bit fused paged decode at 8,193 tokens costs 29 / 57 / 57 / 85 graph launches per step at B = 1 to 4; main costs 26 / 42 / 55 / 68, and so do both binaries under the raised budget. The #3385 profile (47.8 before, 37.6 after) was taken over a window of varying batch size; its own kernel counts give the mix (33% of steps at B=1, mean batch 1.74), and weighting the rows above by it gives 47.8 to 48.7 and 37.6.

Graph launches per decode step, main, default budget against MLX_MAX_MB_PER_BUFFER=1000.

Path Model Context B Default Raised
Fused paged decode Qwen3-0.6B-4bit 8,193 1 / 4 26.0 / 68.0 26.0 / 68.0
Paged sparse decode (synthetic bench) MiniMax-M3 geometry 65,536 1 1.00 1.00
Pool gather, decode under the v2 floor Qwen3-0.6B-4bit 3,073 / 257 1 / 4 58.0 / 281.0 27.0 / 90.0
Pool gather, MLXCEL_PAGED_ATTENTION_NATIVE=0 Qwen3-0.6B-4bit 8,193 1 / 4 58.0 / 309.0 27.0 / 97.0
Pool gather, prompt-lookup verify, per token Qwen3-0.6B-4bit 3,073 1 10.6 5.5
MLA absorbed decode (composed; cut by gather_qmm) Kimi-VL-A3B-Thinking-4bit 9,217 1 / 4 134.0 / 215.0 76.1 / 155.1
Fused decode-MoE kernels Qwen3-30B-A3B-4bit 8,193 1 147.0 60.1
Fused decode-MoE kernels LFM2-8B-A1B-4bit 9,218 1 48.0 29.0
MoE at B > 1 (gather_qmm) Qwen3-30B-A3B-4bit / LFM2-8B-A1B-4bit 8,193 / 9,218 4 290.0 / 66.0 169.6 / 56.0

With the change, default budget. Qwen3-30B-A3B at B=1: 62.1 (96 of main's 99 short graphs per step held one of the two MoE kernels; 3 short graphs remain). LFM2-8B-A1B at B=1: 30.0. Qwen3-0.6B paged decode: 26 / 42 / 55 / 68 at B = 1 to 4, as main. Qwen3-30B-A3B at B=4 (gather_qmm, not touched): 290.0, as main. Reply text is identical to main in each of these cells.

Decode rate, main against the change (bench_decode.py of the #3385 record; arms main-a / change / main-b rotated per round; three rounds, two samples per cell and round, four in run 2; tok/s medians):

Model P B main-a main-b change main range change range null change vs main per round
Qwen3-30B-A3B-4bit 256 1 66.44 63.95 73.06 57.83 to 71.19 72.57 to 73.79 3.8% +10.2% +18.9%, +11.9%, +10.0%
Qwen3-30B-A3B-4bit 8192 1 53.72 53.59 56.12 52.07 to 57.97 55.66 to 56.60 0.3% +4.5% +6.4%, -1.8%, +4.1%
Qwen3-30B-A3B-4bit, run 2 256 1 62.09 62.08 73.07 57.07 to 68.78 63.67 to 74.98 0.0% +17.7% +17.7%, +22.0%, +13.2%
Qwen3-30B-A3B-4bit, run 2 8192 1 53.33 53.31 56.53 52.33 to 56.56 55.39 to 58.55 0.0% +6.0% +6.0%, +5.8%, +7.9%
LFM2-8B-A1B-4bit 256 (290 tokens) 1 123.21 122.36 123.95 121.77 to 123.88 122.45 to 124.65 0.7% +0.8% +1.2%, -0.0%, +0.8%
LFM2-8B-A1B-4bit 8192 (9,218 tokens) 1 109.52 109.37 109.92 108.41 to 111.51 109.56 to 110.87 0.1% +0.5% +0.1%, +0.4%, +1.1%
gemma-4-26b-a4b-it-4bit (graph capture off) 256 1 43.30 43.09 43.22 42.97 to 43.74 41.79 to 43.84 0.5% +0.2% -1.3%, +0.7%, +0.0%
gemma-4-26b-a4b-it-4bit (graph capture off) 8192 1 39.56 39.35 39.39 39.11 to 39.61 39.25 to 39.49 0.5% -0.1% -0.2%, +0.0%, -0.2%
Qwen3-0.6B-4bit (paged, control) 8192 1 108.73 107.36 107.49 105.92 to 115.92 106.06 to 113.10 1.3% -0.1% -0.2%, -0.3%, +0.8%
Qwen3-0.6B-4bit (paged, control) 8192 4 136.85 136.38 135.81 135.22 to 138.90 135.30 to 136.59 0.3% -0.6% -0.1%, -1.2%, -0.7%

The reply text is byte-identical across the three arms in every sample of every cell.

  • Qwen3-30B-A3B is faster in both runs. In the first run one of the three rounds at the 8192-token prompt was behind main (-1.8%): both main arms of that round started 3 to 4 tok/s above the other rounds. main moves between server starts on this model (57 to 71 tok/s at the short prompt); I did not find out why. The second run has four samples per cell and round and all three rounds ahead.
  • LFM2-8B-A1B is unchanged within the null. Its tokenizer splits the prompt's words (290 and 9,218 tokens), so I ran it (and Gemma 4, which did not need it) with a copy of the driver whose 5% prompt-length check can be switched off by an environment variable; the rows record the real lengths.
  • Gemma 4 26B-A4B launches no CUDA graph in any arm (the loader turns capture off for Gemma 4, bug(gemma4/cuda): decode collapses to <pad> after 1-3 tokens (single-query maskless attention + quantized GEMV); mlx_lm decodes coherently #688), so it is a second control: +0.2% and -0.1% against nulls of 0.5%.
  • The paged control reads -0.6% at B=4 with a null of 0.3%: the change range is inside the main range, but all three rounds are at or below zero. The graphs are the same as main's and the added work is one small vector and three substring searches per custom-kernel launch, so I do not have a mechanism for it and did not repeat the cell. It is listed under doubts in the limits below.

Verification limits

  • One host, one backend. GB10 only. Metal and ROCm were not built or run. The byte budget this PR touches exists only in the CUDA overlay; the ROCm overlay has its own copy of the count (rocm/device.cpp:591) under a fixed budget of 200 and was not changed.
  • Families measured for the fix: two. qwen3_moe (Qwen3-30B-A3B) and lfm2_moe (LFM2-8B-A1B). The same kernels serve the other SwitchGLU families and qwen3_next at B=1 (afmoe, bailing_moe, cohere2_moe, dbrx, dots.llm1, granitemoehybrid, klear, kolibri1, laguna, mellum, minimax, olmoe, phimoe, qwen2_moe, qwen3_vl_moe, the qwen3_omni_moe thinker and talker); none of those was run. perf(cuda): evaluate raising the MLX graph ops budget on GB10 (sm_121) #1798 found that raising both budgets for everything has a different sign per family. This change is narrower (two kernels' inputs, op budget unchanged at 20), but that is an argument, not a measurement, for the families I did not run.
  • Gemma 4 is not affected either way. The loader turns CUDA graph capture off for Gemma 4 (bug(gemma4/cuda): decode collapses to <pad> after 1-3 tokens (single-query maskless attention + quantized GEMV); mlx_lm decodes coherently #688), and the 26B-A4B checkpoint launches no graph at all in any arm (0 cudaGraphLaunch, 1,041 direct kernel launches per step). The GeGLU form of the gate/up kernel is therefore covered by the commit test only, on synthetic stacks.
  • Only B=1 changes. SwitchGLU::forward_fused_kernel takes one token; batched decode runs gather_qmm and is untouched (290.0 graph launches per step at B=4 before and after).
  • The paged exemption after the refactor is held by traces, not by a test. set_input_bytes_uncounted now goes through set_input_rows_read; the evidence that the paged kernels are still left out is the 26 / 42 / 55 / 68 trace and identical text, not a commit test over a pool slab.
  • The sparse path was launched only through the synthetic bench at batch 1, and prompt lookup was the only drafter traced; MTP and full-model draft verification were not.
  • Prefill and B=4 verify are whole-cell totals, not per-step windows, and a B > 1 prefill count is mixed with the decode steps of the rows already streaming, so only B=1 prefill totals are reported.
  • The short-graph attribution is a heuristic. "A graph of at most 20 nodes was cut by the byte budget or the end of an eval" is the reading; a captured child graph is one node however many kernels it runs. Every "cut by" statement above also rests on the raised-budget arm removing those graphs.
  • nsys reported "Not all CUDA events might have been collected" on the traces. Within each window the per-layer kernels come out at whole numbers per step and the counts repeat exactly from step to step, which is what I relied on.
  • Measured binary and committed tree. The decode A/B and the post-fix traces were taken with a release server built from the fix tree before the final commit; a release server rebuilt from the committed tree has the same sha256 (4612ee77…2516674), so those measurements apply to the commit as is.
  • Doubts. The -0.6% on the paged control at B=4 (above). The reason main's Qwen3-30B-A3B rate varies between server starts. An index that names no expert aborts in the launcher today; I left it alone.

…reads

Issue lablup#3387 asks which kernels, besides the fused paged-attention ones of lablup#3406, are handed a whole preallocated buffer while reading part of it. On DGX Spark (sm_121) the CUDA encoder counts such an input at its full `data_size()` and commits the graph once the count passes 25 << 20 elements, so the launch cuts the graph on its own.

An nsys audit on GB10 (`--cuda-graph-trace=node`, default budget against `MLX_MAX_MB_PER_BUFFER=1000`) found no custom kernel left to exempt among the issue's three candidates: paged sparse decode is covered by the lablup#3406 name match, the pool gather is the builtin `take`, and the MLA absorbed-decode kernels have no CUDA port. The kernels that do pay are the fused decode-MoE pair, `moe_gateup_kernel_cu` and `moe_down_kernel_cu`. They take a layer's expert stacks and read the experts their index names, 8 of 128 on Qwen3-30B-A3B, and each launch cut the graph in every layer.

The `custom_kernel.cpp` overlay now charges each expert stack for the experts the index names, through `set_input_rows_read` in the `device.cpp` overlay. An index that names every expert reads the stacks whole and is charged whole, as before, and the paged-attention kernels keep the form lablup#3406 measured. The issue proposed leaving the inputs out by name; charging the rows read gives the same result at 8 of 128 and cannot hide a launch that reads its whole input.

- Graph launches per decode step at B=1 on GB10: Qwen3-30B-A3B-4bit 147.0 to 62.1 (60.1 with the raised budget), LFM2-8B-A1B-4bit 48.0 to 30.0 (29.0). Qwen3-0.6B-4bit on the paged path is unchanged at 26 / 42 / 55 / 68 for B = 1 to 4.
- Decode rate against `main` with a null arm, three rounds: Qwen3-30B-A3B +10.2% and +17.7% at a 256-token prompt, +4.5% and +6.0% at 8192 (two runs); LFM2-8B-A1B +0.8% and +0.5%, inside the null; Gemma 4 26B-A4B, which runs with graph capture off (lablup#688), +0.2% and -0.1%; the paged control -0.1% at B=1 and -0.6% at B=4 inside the main range. Reply text is byte-identical in every cell.
- `cuda_graph_commit_tests` reads a graph-launch counter added to the encoder: over-budget stacks with a small index launch one graph for the gate/up and down launches (three before the change), and an index naming every expert still cuts it. The byte-budget arithmetic is tested at its boundaries.
- `scripts/nsys_cuda_graph_launches.py` counts graphs per decode step and the kernels in the graphs cut short. The record is `docs/benchmark_results/cuda-graph-commit-audit-gb10-2026-11-27.md`.
- The pool gather and `gather_qmm` are affected builtins (58 against 27 graph launches per step on a short Qwen3 chat, 281 against 90 at B=4) and are left to a follow-up issue, as lablup#3387 asks.

Closes lablup#3387
The merge of origin/main put the entry under v0.9.0-beta.3, which was already tagged at 25b82c0 without it. It now sits in a new Unreleased section above the release.
# Conflicts:
#	src/lib/mlxcel-core/cpp/mlx_cxx_bridge.h
#	src/lib/mlxcel-core/src/lib.rs
#	src/lib/mlxcelverse/overlays/cuda/README.md
@inureyes

Copy link
Copy Markdown
Member

Hardening review

Reviewed against #3387. Keeping graphs whole is safe: MOE_GATEUP_CUDA_SOURCE and MOE_DOWN_CUDA_SOURCE read only device buffers, every stack address is indices[eslot]-based with eslot < K, so a launch touches only K expert slices (6-bit path included) and no host-visible state is baked into a captured graph. The byte budget changes only where MLX cuts graphs. Fallbacks hold: a mismatched input count (not 8 or 6) is charged whole, an index naming every expert is charged whole, rows_read >= rows clamps to data_size, and the thread-local counter resets to 1 of 1 after each launch while paged attention keeps {0,1}.

Pushed (8e159250)

Validation (GB10, --features cuda, --profile test-fast, --test-threads=1)

  • cuda_graph_commit 3/3 (launch tests not skipped), fused_moe 6/6, cuda_graph_budget 8/8, paged 268 passed, 1 ignored; clippy -p mlxcel-core --features cuda --lib --tests -D warnings and fmt clean.
  • Revert experiment: with main's custom_kernel.cpp, moe_expert_stacks_over_the_byte_budget_do_not_cut_the_graph fails (swiglu, 1 of 128 experts: 3 graphs instead of 1).
  • Real models, greedy with MLXCEL_SDPA_DETERMINISTIC=1: Qwen3-30B-A3B-4bit 128-token text hash 32e4e446008c4300 before and after across alternating rounds; LFM2-8B-A1B-4bit byte-identical before and after. Throughput showed no regression, but the box was loaded by other builds, so the PR's committed measurements stand as the performance record.

Not run: the full make verify-test-cuda gate.

@inureyes
inureyes merged commit e50c93a into lablup:main Nov 28, 2026
33 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 28, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:low Low priority status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Audit other pool-slab kernels for per-launch CUDA graph commits

2 participants