Skip to content

cuda: grouped experts behind one call (experts.zig): Nemotron's 4-bit experts route through it, block-FP8 experts join - #605

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

ashhart merged 1 commit into
ashhart:mainfrom
jschmied:cuda-experts

Conversation

@jschmied

@jschmied jschmied commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

The grouped-MoE step from #548: one call for grouped experts on #558's plan, with a layer view per format and decode and prompt rows apart. Rebased on main after #602 and #591. #591's tf-cuda-test train packed experts with Nemotron's pack_experts directly; it now packs through Affine4Experts.pack, the same launch, as 9041e20 did for #602.

  • cuda/experts.zig:
    • Layer (format, up/down tables, their scales, width, dims, experts, SwiGLU limit), Epi (up with the format's activation, down to fp32 or to bf16 sums) and Rows.
    • Grouped.decode and Grouped.prompt take the plan and a bound on its items. A format that isn't loaded is refused before any launch, as is an epilogue or option its kernels weren't built with.
    • Affine4Experts holds Nemotron's experts.cu, experts_prefill.cu and experts_pack.cu launches, moved unchanged: run, runPrompt, pack, bytes.
    • Fp8Experts adds block-FP8 experts (fp8/experts.cu's device code, decode and prompt forms) with the Python packing.
  • families/nemotron/cuda_kernels.zig:
    • Kernels holds one Affine4Experts instead of five functions and the occupancy pair.
    • Ops.experts and Ops.expertsPrefill delegate, so no caller changes.
    • The loader's expert repack goes through Affine4Experts.pack.
  • tf-cuda-test fp8-experts <dir> with oracle/fp8_experts.py, through Grouped. It uses the pattern from d7469ca: a blocking stream, and outputs filled before each call.

NVFP4 experts follow as their own PR on the same Grouped (decode rows). @Bizuayeu's staged kernel then takes NVFP4's prompt rows, as agreed in #548.

Receipts on GB10 (DGX Spark, sm_121, CUDA 13.0). main (2f8284e) and this branch were each built with nvcc for sm_121:

  • zig build test passes and lean_check is clean for the touched files. zig fmt --check build.zig zig flags only files outside this PR.
  • tf-cuda-test fp8-experts against fp8/experts.py (python-0.6 lineage), 33 experts x [512, 2560], 7 slots: the packing and scales, then the plan, gate-up and down. Decode at 1 and 3 rows (7 and 14 items) and prompt at 300 rows (the wide plan, 40 items) are byte-equal. The device code is the copy whose SASS we compared with the Python build's on 10-09 (6/6 instances).
  • Nemotron 3.5 Lightning MLX-4bit @ d9d758fb, every expert packed and launched through the moved code:
    • tensorfold check-kernels: 1,008 of 1,008 projection cases and 384 of 384 forked-MoE cases (the decode experts), both builds.
    • tensorfold run: three prompts (11, 20, 1,090 tokens; the long one's prefill takes experts_prefill), greedy and sampled (0.8 / 20 / 0.95, seed 7). All six reply hashes equal main's: 5923b40d570b, d38725819372, ead827be94f5, bb8855c2f084, 068276d3ec75, a6961a8c7589.

After the rebase, on main 9041e20a and this branch: tf-cuda-test train passes (every kernel within 2.40e-6 of its f64 reference), fp8-experts is byte-equal, and check-kernels plus the six Nemotron reply hashes are equal.

… experts route through it, block-FP8 experts join
@ashhart
ashhart merged commit c93351f 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 (c93351f), your commit as it was, and it ships in 1.0.6. On a GB10 against main: tf-cuda-test train passes (the dequantization still matches MLX's in all 25,600 values), check-kernels passes 1,008 of 1,008 projection cases and 384 of 384 forked-MoE cases, 29 of 29 served replies are equal with drafted == plain and concurrent == solo 10 of 10 in each arm, and the four release prompts keep their SHAs. Decode and cold prompts are within run-to-run noise. The release fatbins gain fp8_experts.fatbin.

One commit of ours on top, 6ed796d: we are retiring the Python engine, so tooling that imports it doesn't land in the tree, and it removes oracle/fp8_experts.py. tf-cuda-test fp8-experts still reads recorded fixtures. If you'd like a follow-up, a float64 reference inside the test (as train has) would let it run with no Python at all. The same applies to the oracles in #595 and #629, which we'll land the same way.

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