Skip to content

cuda: DeepSeek release MXFP4 expert kernels and the router's eps (#3527 4/5) - #3533

Draft
laudney wants to merge 8 commits into
ashhart:mainfrom
laudney:dsv41-rel-4-expert-kernels
Draft

laudney wants to merge 8 commits into
ashhart:mainfrom
laudney:dsv41-rel-4-expert-kernels

Conversation

@laudney

@laudney laudney commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Step 4 of #3527: the release's MXFP4 routed experts and the routing weights' reference guard.

main this PR
MXFP4 (E2M1 + UE8M0 per 32) experts none grouping by held slot, gate/up with the reference SwiGLU epilogue and v's round trip, down, rank-local combine
Routing weights s / sum (EXL3 kit) s / (sum + eps): release 1e-20, EXL3 0 (bytes unchanged)
Expert groups (EP) n/a an id -> slot table: holding fewer experts is a plan change
Decode GB/s (top-6 of 384, weights from memory) n/a gate/up 163 (1 token) to 230 (512 tokens); down 165-201

Why

Serving the checkpoint as DeepSeek released it is crucial for benchmarking and for adoption: SGLang, vLLM and TRT-LLM serve these same bytes, so comparisons are like for like with no conversion step, and users run the checkpoint they already download, with no TensorFold-specific requant (#3527).

What this changes

Adds release_experts.cu, release_moe.cuh, release_moe_tile.cuh and their launches (kernels_release_ex.zig), the router's eps argument (in the old tail padding of Args), its device check, refreshed router limit records, the expert contract files and bench.

Checks on this head

  • Head commit: 85ced53
  • Lean checker on the base and on this head: 337 and 337, 0 new.
  • Tests run: zig build test test-golden test-dsv41-cuda-host test-dsv41-forward test-dsv41-device-host test-kernel-contract compile-dsv41-cuda compile-dsv41-server on the stack head: 5296/5334 passed, 37 skipped, 1 failed (cli_config_test "serve --config: expand ...", which fails identically on main e7e2424 on the same host: inherited). zig fmt --check build.zig zig and git diff --check pass at every stack head. Each commit ran the family host suites when it was made (on main 811c384).
  • CI: pending on this head.
  • Not run: the full unfiltered zig build kernel-contract (the release filter dsv41_rel ran; see the kernel section); other SMs (the release images are sm_121a only).

Receipt

  • n/a for serving on its own (callers in step 5); kernel speed from tf-dsv41-test release-bench 10 experts in the table.
  • Environment: TensorFold main e7e2424 + this stack, Zig 0.17.0, nvcc 13.5 (V13.5.37; contract records also for 13.0), four GB10 (sm_121a), driver 580.178.04, NCCL 2.30.7; deepseek-ai/DeepSeek-V4.1-Flash-1017 @ 08c8657f02291e11b6f6b63e0e16014f8e748518
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered: tf_dsv41_rel_group, tf_dsv41_rel_gateup / _prompt / _warp, tf_dsv41_rel_down / _prompt / _warp, tf_dsv41_rel_combine, tf_dsv41_rel_swiglu_actq (new); the router keeps its kernels, with an eps argument.
  • Planted controls: poisoned outputs on every launch; a launch missing one slot must differ (red 3/3); an exact FP32-order combine with cancellation [2^24, 1, -2^24] + shared 1 must give exactly 1.
  • tf-cuda-test kernel-contract dsv41_rel (nvcc 13.5, GB10): (filtered) SUMMARY 22 kernels: 22 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems, exit 0 (PR 3's 9 + 13 here). End to end (group -> gate/up -> down -> combine, top-6/384 and top-3/128): a token equals its one-row bytes in batches of 5..2,048, at every position of 16- and 64-pair tiles, and in one-CTA and warp-form launches. tf-dsv41-test router-eps: zero sums give NaN at eps 0 and +0 at 1e-20, ordinary bytes equal, narrow and wide kernels.
  • Limits: records for nvcc 13.0 and 13.5 overrides; router records refreshed for its new argument (13.0); audits report no stale release record.
  • Chips not run: every SM but sm_121a for the expert images; the router change runs everywhere the router runs (EXL3 passes eps 0, bytes unchanged; not re-run on other SMs).

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency.

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafts and concurrency: equal, receipt above. Resume: not run, sessions are off at 4 slots.)

  • No precision traded for speed. The release arithmetic is the checkpoint's own (DeepSeek-V4.1-Flash release weights (FP8 + MXFP4) on CUDA at world 4 on four GB10s #3527); EXL3 bits are unchanged.

  • Decode and prompt processing are no slower than main at one stream and the widest admitted. (n/a for the release checkpoint: main refuses it. EXL3 paths are untouched by format gating; not re-measured, no EXL3 pack on the test machines.)

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. The MXFP4 experts have contract entries and fixed pair ordering. The changed router was covered only by router-eps, and loading its image into the contract executable does not register the operator, so we have done that part ourselves: a commit on top registers the narrow and wide router variants with the CUDA contract, at both epsilon values, with non-finite inputs, repeatability, guards and planted controls, and shortens the new inline image comment.

One thing from you: this changes EXL3's router too, so please post EXL3 before and after timings with unchanged tokens. We can repeat the kernel checks on a GB10; release serving still needs four ranks.

  • Synthena

@laudney
laudney force-pushed the dsv41-rel-4-expert-kernels branch from 85ced53 to e136fc1 Compare November 17, 2026 07:51
@laudney

laudney commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart rebased onto main 699094f705 (#3388 landed), head e136fc1429 (was 85ced537b3). No content change: git range-diff shows every commit equal. The split-rows plan commit is now dropped from the top of the stack (#3534), which takes the fix from main; checks and the 4 × GB10 receipt are in #3534.

@laudney

laudney commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart thanks for the router contract commit. EXL3 before and after, on one GB10 (sm_121a), the router kernel as main has it against this PR's, at EXL3's settings: eps 0, kit rounding, top-6 plus the shared slot, 384 experts, bf16 gate. Event timing, 100 launches each, median (p10).

Rows Kernel main #3533
1 narrow 15.6 us (15.4) 15.6 us (15.4)
5 narrow 34.0 us (33.8) 34.0 us (33.9)
16 narrow 72.9 us (72.7) 73.0 us (72.8)
64 wide 67.9 us (65.9) 67.9 us (65.8)
512 wide 323.1 us (319.8) 322.0 us (319.8)
2,048 wide 1,243-1,298 us over three runs 1,268-1,313 us over three runs

The picks and weights of all six shapes are byte-equal between the two (148,176 bytes). That follows from the change: with eps 0 the denominator is total + 0.0f, and for a sum of non-negative scores that is total exactly, so EXL3's arithmetic is the same and only one add is new.

Served EXL3 tokens I cannot add here: these four GB10 hold the release checkpoint and NVFP4, not the EXL3 one, and I would rather not download it for this. If you want the served EXL3 tokens on your GB10, the kernel result above says they cannot change; I am glad to run any other check you name.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney for the patch-identical rebase and the EXL3 router comparison. Across all six shapes the timings are effectively unchanged, and all 148,176 bytes of router picks and weights are identical.

The zero-epsilon defaults and the exact total + 0.0f identity mean downstream EXL3 inputs stay unchanged. I accept the complete kernel-output equality as resolving the token-equivalence ask; a separate served EXL3 token run is not needed. The release expert contract also covers 22 kernels, deterministic grouping and combine order.

The remaining issue is application to current main. The cumulative diff conflicts in zig/build/cuda.zig, zig/src/core/contract/registry.zig, and zig/tests/cuda/contract_family_sets.zig. Current main moved the later compiler sets to zig/src/core/contract/registry_cuda_sets.zig, so carry the nvcc-13.5 entry there. Please rebase with the lower steps, retaining current main's registrations alongside both release and release_ex; this step adds no new conflict path.

  • Synthena

@laudney
laudney force-pushed the dsv41-rel-4-expert-kernels branch from e136fc1 to 4a711de Compare November 24, 2026 17:36
@laudney

laudney commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart rebased with the lower steps onto main a0f809ea09: head 4a711de8a3 (was e136fc1429).

Item Before After
Base 699094f705 main a0f809ea09
This step's commits (router eps, router limit records, MXFP4 experts) 3 3, the same added and removed lines (git range-diff)
zig/build/cuda.zig, registry.zig, contract_family_sets.zig conflicted resolved in step 3 (#3532): the nvcc 13.5 set is in registry_cuda_sets.zig; main's idol, idol decoder, GLM MoE, muse and inkling2 registrations stay beside release and release_ex
Mergeable no yes

Checks at the stack head (541354be0b, this step unchanged under it), one GB10, sm_121a, nvcc 13.5:

Check Result
tf-cuda-test kernel-contract dsv41_rel (matches dsv41_rel and dsv41_rel_ex) (filtered) SUMMARY 22 kernels: 22 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems
kernel-contract-limits, nvcc 13.0 and 13.5 the same problem lines as main's (diff empty); the release records are current under both
Full zig build kernel-contract, stack head vs main a0f809ea09 (same GB10 model, nvcc 13.5) head SUMMARY 854 kernels: 852 pass gates 1-4, 2 fail, 12 known findings; 521 controls: 521 red as planted, 0 missed; 1039 limit problems; main SUMMARY 832 kernels: 830 pass gates 1-4, 2 fail, 12 known findings; 521 controls: 521 red as planted, 0 missed; 1039 limit problems. The 22 more kernels are the release ones; the failures and known findings are the same lines
The router's live limit lines in that run main already misses its records on 26 of the router's 40 instances (the live run compiles with nvcc 13.5 and the router has no 13.5 records); the eps argument moves 5 instances by 1-5 registers, so narrow_kernel<2,4> now matches and narrow_kernel<1,8> (99 against 101) does not: still 26. The per-compiler audits (13.0, 13.5) are line-equal to main's
Host suites test-kernel-contract 315/315, test-dsv41-cuda-host 456/456, test-dsv41-device-host 250/250, test-dsv41-forward 205/207 (2 skipped), test-dsv41-draft 185/185, test-golden, zig build test 13153/13240 (87 skipped, 0 failed)
Lean 165 problems on main, 165 on the head, 0 new

The CUDA plan typed every projection as an EXL3 group, so another
weight format would have to thread branches through every reader.
GroupPlan and ExpertsPlan now hold their stored form in a tagged union
with an EXL3 arm, readers go through it, and the expert width splits
on a per-format block (expertShare: 128 for EXL3, 64 for the release
format). EXL3 plans, emitted calls and pinned fingerprints are
unchanged; block.Options gains the checkpoint format for the release
arms to come.
The CUDA reader opens engram-l<L>-r<R>of<W>.bin, but the packer wrote
only rank 0 of 1, so a four-rank release had no tables to read from
SSD. A rank's rows are now its whole hash columns (rankRows, the
reader's headShard), the packer, verifier and manifest work on that
span with shard-relative offsets, the tool takes --rank and --world,
and checkShards validates a rank's shards against its span at boot.
DeepSeek's own checkpoint stores FP8 32x32 blocks, MXFP4 experts and
BF16 matrices that the CUDA plan could not express. The plan gains
FP8, BF16 and MXFP4 forms with the rank's rows, columns and expert
ids, cut on the mesh (release_shard over fabric/mesh), the Engram
tables are checked and left on disk, and staging uploads the stored
bytes unchanged. The real release plans at worlds 1, 2 and 4 with no
tensor left over: 72.31 GiB a rank at world 4. Serving still refuses
the format until its kernels land.
The release checkpoint's dense projections need GB10 kernels that
multiply its FP8 block-scaled and BF16 weights as stored, with prompt
and decode rows bit-equal; this adds block-scaled mxf8f6f4 and BF16
MMA tiles (decode, mid, prompt and a stage-free warp form) over one
per-element K order and a row-independent split, the FP8 activation
round trip with and without RMSNorm, the fixed split sum, a separate
sm_121a image set loaded only for release checkpoints, contract
checks (prompt equals decode, every tile position, one-CTA grids,
group views, cancellation) and records for nvcc 13.0 and 13.5.
The release contract's prompt-versus-decode, row-independence and
launch-shape checks ran FP8 only at splits 4 and 1, while the world-4
plan serves wkv and the shared w1/w3 at split 8. A wkv case (K 5120,
N 512, BF16 out) now runs every check at split 8, the case table's
comment names the splits it covers, and the tile comment no longer
quotes a bandwidth measurement.
The release reference normalizes routing weights as s / (sum + 1e-20)
so a row of zero scores stays finite; the CUDA router divided by the
sum alone. Args gains an eps in its old tail padding (size and other
offsets unchanged), the replay reads it as an optional argument, and
EXL3 keeps passing 0, which leaves its bytes unchanged because the
sum is never below +0. A device check covers zero sums (NaN at 0, +0
at 1e-20, lower ids on ties) and equal bytes for ordinary scores at
top-k 6 of 384 and 3 of 128 on the narrow and wide kernels.
Adding eps to the router's Args moved the register count of ten of
its sm_121 instances under nvcc 13.0, the compiler the base records
pin; the records now hold the measured values. Shared memory is
unchanged, and the 13.2 measurements stay as measured on 13.2.
The release checkpoint's routed experts store MXFP4 weights, so the
MoE needs GB10 kernels that multiply E2M1 codes with their UE8M0
scales against the FP8 round trip of the FFN input. This adds the
grouping of (row, k) pairs by the rank's held slots (an id -> slot
table, so expert groups need only a plan change), gate/up with the
reference SwiGLU epilogue and the round trip of v, down to bf16
partials, the rank-local combine in top-k order then the shared
partial, and the shared expert's SwiGLU round trip; each staged
kernel has a stage-free warp form with the same bytes. Contract
checks cover prompt equals decode, every tile position, one-CTA
grids, exact FP32 combine order and refusals; records for nvcc
13.0 and 13.5.
@laudney
laudney force-pushed the dsv41-rel-4-expert-kernels branch from 4a711de to 60f04eb Compare November 24, 2026 22:19
@laudney

laudney commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart rebased again with the lower steps onto main a15c7b0603: head 60f04ebdd1 (was 4a711de8a3); this step's commits have the same added and removed lines. The filtered release contract at the stack head passes all 22 kernels (gates 1-4, 0 limit problems). The earlier benchmark-clients (windows-latest) failure is a timing check in tools/tests/test_bench_prose.py, outside this stack's files.

This branch has not been deployed

No deployments
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