Skip to content

cuda: the expert plan as a shared module (cuda/grouped.zig); Nemotron routes through it - #558

Merged
ashhart merged 1 commit into
ashhart:mainfrom
jschmied:cuda-grouped-plan
Oct 10, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
jschmied:cuda-grouped-plan

Conversation

@jschmied

@jschmied jschmied commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Draft for #548's second step, as a concrete example of the shape it proposes: the expert plan that groups routed pairs by expert (experts.route on experts.cu's plan kernels) moves out of families/nemotron into zig/src/cuda/grouped.zig, and Nemotron routes through it. Behaviour doesn't change: same kernels, same grids, same arguments.

  • cuda/grouped.zig: maxItems, Plan (the scratch the plan writes) and Router (resolve from the loaded experts module, route = the one-block plan up to 1,024 pairs, else rank, offsets and scatter).
  • families/nemotron/cuda_kernels.zig: Plan and maxItems become aliases, Kernels holds a Router instead of four plan functions, and Ops.plan delegates. No caller changes. The family is 42 lines shorter.
  • tf-cuda-test grouped-plan <dir> with oracle/grouped_plan.py: members, items and counts against experts.route (python-0.6) for one-block and wide plans at tiles 16 and 64 (1 to 2,048 rows, 7 and 9 slots, 33 and 385 experts).

Every MoE port needs this plan: Kolibri's FP8 experts (#481), Flash Next's NVFP4 experts (#472) and GLM's EXL3 experts (#509). With it here, the per-format expert kernels can share one plan instead of each carrying its own.

Receipts so far: zig build test passes on GB10 (Linux aarch64), the CUDA kernels build for sm_121, and lean_check is clean for the touched files.

Receipts on GB10 (DGX Spark, sm_121, CUDA 13.0):

  • tf-cuda-test grouped-plan: members, items and counts equal experts.route's bytes in all 5 cases: one-block plans at 1 and 3 rows, wide plans at 300 rows (tile 64), 512 rows over 385 experts (tile 16) and 2,048 x 9 pairs over 385 experts (tile 64).

  • Nemotron 3.5 Lightning (TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit @ d9d758fb, the 1.0.2 release's sm121 kernel set), tensorfold run, main (78ee0f4) against this branch built the same way. Three prompts (11, 20 and 1,090 tokens; the long one's prefill takes the wide plan), greedy and sampled (temperature 0.8, top_k 20, top_p 0.95, seed 7). All six reply hashes are equal:

    prompt greedy sampled
    11 tokens 5923b40d570b both e8332a360154 both
    20 tokens c5c4b6cb25f0 both b8d9ce6085d8 both
    1,090 tokens 95bce61a71a7 both a6961a8c7589 both

    One sampled run took 60 rounds on this branch and 61 on main, with the same reply. MTP's draft length follows measured round costs, so the round count can differ between runs; the reply can't.

If you'd rather keep the plan inside the families, say so and I'll close this.

The plan that groups routed pairs by expert (experts.route on experts.cu's
plan kernels) lived inside families/nemotron. It moves to cuda/grouped.zig
(maxItems, Plan, Router.route) with the same kernels, grids and arguments;
Nemotron keeps its names as aliases and Ops.plan delegates, so no caller
changes. tf-cuda-test grouped-plan compares members, items and counts with
experts.route for one-block and wide plans at tiles 16 and 64.
@jschmied
jschmied marked this pull request as ready for review October 9, 2026 19:52
@ashhart
ashhart merged commit 4c1e4cf into ashhart:main Oct 10, 2026
2 checks passed
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. This is merged into main (4c1e4cf), with your commit as it was, and it ships in the next
release.

We checked it on a GB10. tf-cuda-test grouped-plan matched experts.route's bytes in all five cases, from the
one-block plan at 1 and 3 rows to the wide plans at 300, 512 and 2,048 rows. Nemotron didn't move: 29 of 29 served
replies equal main's and 1.0.4's, from an 18-token prompt to a 9,640-token one that takes the wide plan, greedy and
seeded sampled, alone and three conversations at once. The four release prompts give the same tokens too.

With the plan in one module, the MoE ports you listed (#481, #472, #509) can share it instead of carrying copies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants