Skip to content

cuda experts: Inkling 2 Mini's stored NVFP4 and MXFP8 experts in core (C3, proposal) - #4365

Closed
jschmied wants to merge 2 commits into
ashhart:mainfrom
jschmied:inkling2-mini-c3
Closed

jschmied wants to merge 2 commits into
ashhart:mainfrom
jschmied:inkling2-mini-c3

Conversation

@jschmied

@jschmied jschmied commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Proposal for review, draft. Slice C3 of the Inkling 2 Mini plan (#4274), claimed in #4274 (comment) and not yet confirmed. I'm opening it as a draft so the approach can be reviewed early; it stays a draft until the claim is confirmed. If @akol1 takes C3 instead, this can serve as a reference or be closed.

What this changes

Inkling 2 Mini's routed experts as stored, on core grouped experts (src/cuda/experts.zig), not as a family kernel: NVFP4 and MXFP8 weights decoded in registers, bf16 activations, FP32 sums (decision 2 as corrected in #4274 (comment)).

Open for the maintainer

  1. F1, the NVFP4 factor: nvfp4Factor computes fp32(bf16(amax) / bf16(2688)), as Metal: experimental Inkling 2 Mini text, vision and bundled DSpark #4337 does. It is the one place to change once decision 2 settles rounding.
  2. Rounding before the activation: gate and up go into the soft-capped SwiGLU as FP32 sums, with one bf16 rounding after it (Small's tf_ink2_gateup form). Metal: experimental Inkling 2 Mini text, vision and bundled DSpark #4337 rounds gate and up to bf16 first. Which one is the contract for Mini?

Checks on this head

Head b2cea56fe6, rebased onto main 14951bc65d on the user's request (was eed574b91f on main 362107c4c9); GB10 (sm_121).

What the rebase changed. Main's #4493 (paired NVFP4 prompt experts) touched the same files:

  • nvfp4_experts.cu: prompt_tiles and prompt_body keep main's X_b, out_b, split and take this PR's limit2 after them (default 0); the pair branch's epilogues pass it too (EPI 2 and 3 ignore it). The file reached 600 lines, so the two soft-capped entries moved unchanged to nvfp4_experts_softcap.cuh, included at the end of the same unit (same fatbin, same symbols; pinned in gradient-serving.tsv).
  • cuda/experts.zig and cuda/root.zig: main's experts_prompt_layout and pair_experts imports kept beside this PR's experts_mx. Main dropped the three promptSmem asserts from the test this PR moves to experts_host_test.zig; the moved copy drops them too.
  • gradient-serving.tsv: the rows this PR touches take the rebased files' sha256, main's note plus this PR's.
  • Five two-line comments folded to one line each (tools/zig/lean_check.py's multi-line rule).

Because code under the PR moved, every device check was rerun on this head (tf-cuda-test md5 3a853326):

  • Kernel contract (stored experts): 9 kernels pass gates 1-4; 7 controls, 7 red as planted (each new kernel launched one 32-input group short); 0 limit problems. Gate 5 records for nvcc 13.0 and 13.2 (record file unchanged).
  • Original checkpoint ed40e7da, layer 0 (NVFP4) and layer 20 (MXFP8): every w13 and w2 weight of all 128 experts read back on the GPU equals the host decode; outputs at 4 tokens (decode) and 64 (prompt) within the FP32 bound, worst error over bound 0.95 (gate-up) and 0.99 (down), the same as on eed574b91f. The NVFP4 peak code × scale is 2,688 in every expert. 13 of 13 checks pass.
  • Off equal to main (against main 14951bc65d): all 475 pre-existing (unit, SM, function) triples in the 13 units that include experts.cuh, main's new paired prompt entries among them, have SASS identical to main on sm_80, 86, 89, 120 and 121; 35 new.
  • Layout tests: a code planted in stored row 1 must land in the up half (red under gate-then-up); E8M0 bytes 0 to 240 through tf_mxfp8_down_f32 match the host decode on the GPU.
  • Refusals by name, with mock-launcher tests showing 0 launches: FormatNotLoaded, EpilogueNotBuilt, OptionNotBuilt, BadSoftcap, UnexpectedShape.
  • Host, on this head: test-cuda-host and test-gradient-serving pass on the GB10. On x86: check-native-cuda-host, compile-cuda-tests, test-host, test, test-golden, test-kernel-contract, test-server-security, test-pull-security, fuzz-cortheon, check-release-paths pass, except request_admission_http_test "every way an n-choices request ends returns its places". That test fails on main 14951bc65d on the same x86 box and passed on a rerun of this head, so it is main's flaky test, not this PR. tools/pr_check.py: 0 errors, lean 165 vs 165, 0 new. zig fmt --check: clean.
  • Not applicable: seeded, resume and concurrency rows. Nothing serves Mini yet (C4, inkling2: Inkling 2 Mini served on CUDA at one rank (H2 + C4), stacked on #4364 and #4365 #4441); existing served paths are SASS-identical to main, so there is no token-changing path to compare against main.

Speed

Main has no CUDA Inkling, so these rows have no main baseline; they are absolute numbers for the new entries. What main already serves is covered by the SASS check above: all 475 pre-existing functions in the 13 units that include experts.cuh are identical to main 14951bc65d, so no existing family's expert path can be slower. The new entries' SASS on this head is also identical to eed574b91f's (sm_121, all 32 functions of nvfp4_experts and fp8_experts that head had).

One layer, gate-up plus down, real weights, median of 5 × 200, GB10 (273 GB/s), one run on this head b2cea56fe6:

Layer Tokens Experts Bytes Time GB/s Of 273
L0 NVFP4 1 8 35.9 MB 175 µs 205 75 %
L0 NVFP4 4 28 126 MB 582 µs 216 79 %
L0 NVFP4 512 128 613 MB 2.70 ms 227 83 %
L20 MXFP8 1 8 65.8 MB 309 µs 213 78 %
L20 MXFP8 4 28 230 MB 1.05 ms 219 80 %
L20 MXFP8 512 128 1.09 GB 5.14 ms 212 78 %

On eed574b91f the same rows were 170 / 575 µs, 2.69 ms, 302 µs, 1.05 ms, 5.12 ms. With identical SASS, the 1-3 % on the two small NVFP4 rows is run-to-run spread, not code.

Receipt

n/a: no served path reaches these kernels until C4.

Proposed CHANGELOG line

…SwiGLU in core

Core grouped experts gain Format.mxfp8 (e4m3 codes times one E8M0 scale per row per 32 inputs, folded
exactly into the bf16 mma operand, fp32 sums) and Layer.caps, Inkling's soft-capped SwiGLU epilogue
(experts.cuh epilogue 4) on the NVFP4 decode and prompt kernels and on the new MXFP8 ones. NVFP4's
per-expert factor is amax / denominator, each rounded to bf16 (experts_mx.nvfp4Factor, open question F1).

Evidence: stored-experts contract 9 kernels pass gates 1-4, 7 short-K controls red; checkpoint layers 0
and 20 decode bit for bit on every weight of 128 experts, outputs within the fp32 bound; SASS of all
465 pre-existing (unit, sm, function) triples equal main on sm_80/86/89/120/121.
… checked on the GPU

experts_mx.splitGateUp takes stored row 2j to gate j and 2j + 1 to up j before packGateUp (the kernels are
unchanged); a host test plants a code in stored row 1 and requires it in the up part. The checkpoint
reference reads row 2j + m. stored-experts ckpt adds E8M0 bytes 0 to 240 through tf_mxfp8_down_f32
against the host decode (byte 0 = 2^-127).
@jschmied

Copy link
Copy Markdown
Contributor Author

Closing as superseded. Mini on CUDA now goes through #4387's engine: #4640 for correctness, and #4697, #4718, #4728 and #4729 for speed. Those four take it from 5.6 to 28.2 tok/s stacked, bit-equal to #4640, and a PR sharing one forward across streams follows. This stack would be a second Mini engine beside it (see #4387, comment 7092191800). The branch stays on my fork, so it can be reopened if a piece of it is wanted. The likeliest candidate is #4365's core NVFP4/MXFP8 expert entries, if Mini or another family moves onto core experts.

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.

1 participant