Repository navigation
cuda experts: an mxfp4 format, stored E2M1 codes and E8M0 scales decoded to bf16 in registers on the bf16 experts' chain - #5042
Conversation
227aa21 to
c287b90
Compare
c287b90 to
3ed5149
Compare
|
Thank you, @Bizuayeu. The admitted code/scale range widens exactly to BF16, and the row loop retains the existing BF16 experts' sum and epilogue order. The new format remains separate from serving, and the head merges cleanly. Ready for the focused GB10 operator comparison. Please retain the full four-kernel/two-control summary and launch-limit results with the tested image identity; the supplied extract stops before that evidence. The existing byte comparisons remain credited.
|
Added to the description, with the head unchanged:
|
|
Thank you, @Bizuayeu. The source review remains clean: the BF16 decode and accumulation order, unserved scope, and unchanged existing formats all check out. The retained evidence is still absent from the supplied description. Its Checks text ends mid-command, and although the follow-up says the identities, both CHANGES REQUESTED for the retained evidence only; no new source defect found.
|
That command held a placeholder in angle brackets after
|
|
Thank you for retaining the runner and both fatbin identities, both complete contract summaries with exit statuses, and the launch-limit result. That closes the previous evidence request. The stated tested-tree differences are text-only and do not affect the reviewed kernel comparison. The stored E2M1/E8M0 decode, BF16 accumulation order and unserved scope remain confirmed, and the branch merges cleanly on current main. Two added or changed comments still exceed 120 columns:
|
3ed5149 to
99cfc92
Compare
Done in |
99cfc92 to
1b37b76
Compare
|
Rebased onto main |
|
Thank you, @Bizuayeu. Both requested comment fixes are confirmed. The new layout and scale notes are short and clear, and the two serving pins match the exact files on this head. The retained CUDA evidence still covers the unchanged arithmetic: the MXFP4 decode is exact, the existing BF16 accumulation order is preserved, and all focused kernels passed with their planted controls red. No serving checkpoint selects this new format, so existing defaults keep their output bytes. This head also merges cleanly with current main. SAFE TO LAND. No additional device run is needed.
|
1b37b76 to
0d488e8
Compare
|
Main moved after your review: |
0d488e8 to
83e0c29
Compare
|
Main moved again: #5051 added the |
83e0c29 to
31f5917
Compare
…ded to bf16 in registers on the bf16 experts' chain The two downs (fp32 and bf16 sums) in the decode and prompt forms read a checkpoint's MXFP4 experts as stored, [E][N][K/2] codes low nibble first and [E][N][K/32] scales, decode each weight to bf16 exactly and run experts_bf16's mma chain, so they give the bf16 experts' bytes on the host-decoded weights. Up is refused; checkScales takes E8M0 codes 2 to 252, where every E2M1 multiple is a finite, normal bf16. Registered with the kernel contract against float64 (two controls), with nvcc 13.0's launch records; no served checkpoint selects it.
31f5917 to
5e19194
Compare
|
Thank you @Bizuayeu. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
What this changes
Core's grouped experts on CUDA get an
mxfp4format: E2M1 codes (two a byte, low nibble first) and one E8M0 scale per 32 inputs, read from device memory as a checkpoint stores them ([E][N][K/2]and[E][N][K/32], no repack). Each weight is decoded to bf16 in registers,code × 2^(scale − 127), exactly, and then runs the bf16 experts' own chain (experts_bf16.cu: two m16n8k16 mma steps a 32-input group, in input order, one fp32 accumulator a column), so on the same inputs the output equals the bf16 experts' on the host-decoded weights byte for byte, in the decode and the prompt forms. This adds no rounding point: the decode is exact, and the sums and epilogues are the bf16 experts'.Only the two downs are built:
down_f32anddown_bf16, each in the decode and prompt forms.Epi.upis refused withEpilogueNotBuilt, because core's up epilogues (relu², SwiGLU) are not what the first user needs: ERNIE 5.5's routed experts use SiTU, which comes in its own pull request.Mxfp4Experts.checkScalestakes E8M0 codes 2 to 252 only, the range where every E2M1 multiple is a finite, normal bf16 (255 is E8M0's NaN; 253 and 254 overflow at 6×; 0 and 1 give subnormals). A loader calls it on a checkpoint's scales. ERNIE 5.5's release, sampled, holds codes 113 to 122.No served checkpoint selects the format yet, as with the bf16 format in cuda experts: a bf16 format for a checkpoint's own bf16 experts #1630. Every other format is unchanged; the files
test-gradient-servingpins (experts.zig,kernels.zig) are re-pinned with the reason.Issue: Refs ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926. This is the first pull request of the split agreed at ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926 (comment) ("First:
mxfp4in core's grouped experts, as you propose."), on the format set out at ERNIE-5.5-Flash-Preview on two DGX Sparks: a native CUDA family #4926 (comment) ("anmxfp4format in core's grouped experts (zig/src/cuda/experts.zig): stored codes and scales decoded in registers, bf16 activations and FP32 sums, as settled in Inkling 2 Small on four DGX Sparks: a native CUDA family #3476"). Related: cuda: DeepSeek release MXFP4 expert kernels and the router's eps (#3527 4/5) #3533 adds DeepSeek-V4.1's release MXFP4 experts insidedeepseek_v41with the checkpoint's own W4A8 arithmetic (an FP8 round trip of the activations and the block-scaled MMA); this format keeps bf16 activations and touches none of those files, but both add to the same contract registries.Stacked on: main (
67ae36c4dc); head31f591798a, two commits:00e867c0a5, this pull request's commit on that main, and31f591798a, the maintainer's, which adapts its registrations and pins to main and takes theCHANGELOG.mdline out. Their tree is83e0c292f6's, the third rebase below, without that line: 17 files, 739 insertions, 6 deletions. Rebased on 2026-11-26 froma3c3e5cef3, three times. Twice it was for one line ofzig/tests/fixtures/gradient-serving.tsvthat main had also changed:f0aa8088d1(hy4_flash: fused iHC and HC CUDA kernels, contracts, controls, and 5-SM limits #5100) re-pinnedkernels.zig, thencddc70cc57re-pinnedexperts.zigafterda9cc61676. The third was for core: exact row top-k, sparse index scores and block summaries for sparse indexers #5051:4fac3ce6a6re-pinnedkernels.zigwith thetopk_rowsandsparse_indeximages, anda2a965d387added those two images to the image list inzig/tests/cuda/contract_limits.zig, on the line where this pull request addsexperts_mxfp4; the line now has both. Each pin now hashes the merged file, and its note keeps main's words before this pull request's. The first rebase also re-pinnedexperts.zig, which99cfc922dahad left at its hash from before that commit's comment change. Main's commits sincea3c3e5cef3change none ofexperts_bf16.cu,experts_mxfp4.cu, the headers they include or this pull request's test files; inzig/src/cuda/experts*.zigthey change only howNvfp4ExpertsreadsTF_NVFP4_DECODE_WARPS(da9cc61676, the settings registry, the same accepted values).atc overlap --json: atc 0.9.4 withATC_READ_ONLY=1, run in this tree on 2026-11-25 at 12:46 UTC with main at9961ca4920, head227aa21762(3ed51490cbbut for this pull request's number inCHANGELOG.mdand in two notes ofgradient-serving.tsv, and the usage line):complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 44 pull requests sharing a file with this commit, most of themzig/src/core/contract/registry_joins.zig(25),zig/tests/fixtures/gradient-serving.tsv(23) ordocs/kernel-contract.md(13), and nonezig/src/cuda/experts.zig, its host test or a new file: 7conflicts(MiMo-V2.6-Flash on CUDA (2x GB10) with DFlash as the drafter #728, idol: BiRefNet background removal and preprocessing on Metal, so tf-idol-generate takes a raw photo (stacked on #1780) #1787, Implement GLP control vectors with a fused Metal kernel for Qwen3.8-27B #1835, app: control vector picker and strength in Engine advanced #1951, ricursive: load Ripple's EXL3 packs through main's shared EXL3 code #2514, qwen27 Metal: DSpine drafter for Qwen3.8-27B, opt-in #2634, test(cuda): opt-in --jobs and --shard for kernel-contract #3093), 2cleanand 35unknown. For each of the 44, and the 11 other open pull requests that changezig/tests/cuda/main_usage.zig(55 in all),git merge-tree --write-treeof the pull request's head (checked against itsheadRefOid) witha3c3e5cef3and with this head gives the same conflicting files and the same number of conflict hunks (52 conflict witha3c3e5cef3already, 3 merge cleanly with both), so this commit adds no conflict. Taken again on 2026-11-26 for0d488e8ac3against84d9b6ba13, for the same 55 (atc not run again): 54 conflict with84d9b6ba13already, 1 merges cleanly with both, and none gains a conflict. And for83e0c292f6against67ae36c4dc: atc, run again, named 33 pull requests sharing a file, all among the 55, and for the 55 none gains a conflict.Checks on this head
cbc88516d05a379ee5e434f05f35ef6aa887f75ad0c0c3e6b23200d79d61bf05, 519,275,064 bytes. It embedsexperts_mxfp4.fatbin, sha256b3409ffd5b25577351c884c44194ba5bd897a06ea52c5798961b2724d370289d, andexperts_bf16.fatbin, sha2565078708d611a06b3fc123cb4c562d5d650247652120c804785eb83e79251336f(maina3c3e5cef3's bytes): each file inzig-out/fatbin, which the limits read, is found byte for byte once inside the runner.tf-cuda-test mxfp4-experts contract, exit 0:SUMMARY mxfp4 experts: 4 kernels, 4 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missedtf-cuda-test bf16-experts contract, exit 0:SUMMARY bf16 experts: 6 kernels, 6 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missedtf-cuda-test kernel-contract-limits zig-out/fatbin: the four new kernels' 20 records (sm_80, 86, 89, 120 and 121) are current; exit 1 with154 problems, the same 154 as on main, none of them this pull request's.SUMMARYlines count.31f591798a, whose tree is83e0c292f6's but for theCHANGELOG.mdline, so the checks on83e0c292f6stand for it.83e0c292f6, on main67ae36c4dc, is99cfc922da(ona3c3e5cef3) rebased three times, the same diff but for the pins and the image-list line above. On83e0c292f6itself: in WSL 2,git diff --checkclean,zig fmt --checkandzig ast-checkclean on the 14 changed Zig files,zig build -Dfixed-cpu test-gradient-serving1 of 1 test andcompile-cuda-tests12 of 12 steps;tools/pr_check.py --base origin/main --pr 5042, 0 errors. The runs below are on the old base.99cfc922dadiffers from3ed51490cb, the head the runs below were taken for, only in two comments, each now on a line of its own (thedownfield's layout note and a test's scale range); no code changed, so the runs were not taken again. The GPU runs and the GB10's host runs below are on a tree that differs from3ed51490cbonly in text: it has noCHANGELOG.mdline, its twogradient-serving.tsvnotes read#TBDwhere this head names this pull request, andzig/tests/cuda/main_usage.zighas no line formxfp4-experts. The runs in WSL 2 are onc287b90d1b,3ed51490cbbut for that usage line, which only the runner's help text prints.python3 tools/zig/lean_check.py, on the base and on this head: 152 problems on main67ae36c4dcand 152 on this head, 0 new (164 and 164 ona3c3e5cef3before the rebases) (tools/zig/lean_new.py). The 152 are inherited from main.experts.ziggrows from 591 to 595 lines; the new files have 20 to 300.tf-cuda-test mxfp4-experts: 37 token rows of 3 picks over 6 experts (111 pairs), 256 outputs from 96 inputs, random codes over all 16 nibbles and scales 2^-9 to 2^-3: both downs give the bf16 experts' bytes on the host-decoded weights (tf_bf16_experts_pack, then the bf16 entries), in the decode form (items of 16) and the prompt form (items of 64); the fp32 down is within 9.4e-8 of float64 relative to its terms' magnitude; the prompt form's bytes equal the decode form's, and rows 0, 17 and 36 alone give the bytes they gave beside the others.a3c3e5cef3, each built from an empty global cache withzig build compile-cuda-tests fatbins kernel-contract-fatbins -Dnvcc="$NVCC" -Dsm=80,86,89,120,121($NVCCis nvcc 13.0.88): exit 0 both; the GPU runs and the limits use these builds. On the same host, that tree:zig build -Dfixed-cpu test-cuda-host --summary all: 503 of 503 steps succeeded, 9,521 of 9,565 tests passed, 44 skipped (the new host test refusesup, unaligned shapes and missing scales, and checkscheckScalesat 0, 1, 2, 113, 122, 252, 253, 254 and 255);test-kernel-contract: 43 of 43 steps, 323 of 323 tests passed;test-gradient-serving: 4 of 4 steps, 1 of 1 test passed. In WSL 2 (x86-64 Ubuntu 24.04),c287b90d1b:zig build -Dfixed-cpu test-gradient-serving --summary all: 4 of 4 steps, 1 of 1 test passed;python3 -m unittest discover -s tools/zig -p host_tests_test.py: 13 tests OK;python -m pytest -q -rs -p no:cacheproviderfrom the root, with pytest 9.2.0 and PyYAML 6.0.4 (what CI's job installs) and aclang++onPATH: 820 passed, 106 skipped, 826 subtests passed, the same counts and skip reasons as maina3c3e5cef3.31f591798a, with the same jobs and pytest counts as below. On0d488e8ac3, the head before the third rebase, it was green:fmt,zig,zig-b,zig-windows,zig-macos-dev-tools,pytest(854 passed, 115 skipped, 827 subtests passed),release-paths (ubuntu-24.04),comfyui-moss-installerand bothbenchmark-clientsjobs passed;host-nightly-linuxandhost-nightly-macoswere skipped; the annotations are GitHub's Node.js 20 deprecation warnings and a macOS runner queue notice.1b37b76e8a, the head before the second rebase, had the same jobs green and the same pytest counts. On3ed51490cbit was green as well:fmt,zig,zig-b,zig-windows,zig-macos-dev-tools,pytest(822 passed, 105 skipped, 826 subtests passed; the run in WSL 2 above has 820 and 106, and the CI log does not print skip reasons),release-paths (ubuntu-24.04),comfyui-moss-installerand bothbenchmark-clientsjobs passed;host-nightly-linuxandhost-nightly-macoswere skipped. The annotations are GitHub's Node.js 20 deprecation warnings and a macOS runner queue notice.Receipt
n/a for serving: no checkpoint selects
mxfp4yet, so no served model's tokens or speed change. The receipt is the bit equality above and the contract below.a3c3e5cef3and the tree named under "Checks on this head" (this diff on that base, before the rebase), Zig 0.17.0, nvcc 13.0.88, one GB10 (sm_121).Grouped.decodeandGrouped.promptfor.mxfp4; I ran sm_121 only.Kernel contract, only when a GPU kernel is new or changed
tf_mxfp4_experts_down_f32,tf_mxfp4_experts_down_bf16,tf_mxfp4_experts_prompt_down_f32andtf_mxfp4_experts_prompt_down_bf16(zig/tests/cuda/contract_experts_mxfp4.zig), new, against float64 on ERNIE 5.5's routed down (2,048 to 2,048, ten pairs a token row, decode windows of 1 and 32 rows, prompt rows of 40 and 72). Rounding points and sum order: the weights' decode to bf16 is exact; each column's sum is one fp32 chain of m16n8k16 mma steps over the inputs in order, the bf16 experts' chain; the bf16 down rounds that sum once. FP64 bound: gate 3'sgamma(k/16 + 36)of the terms' magnitude, as the bf16 experts' downs.SUMMARYline and exit status, and the limits: under "Checks on this head", first, with the images tested (both contracts exit 0; the limits exit 1 with the same 154 stale records of other images as maina3c3e5cef3; the 10REDlines are the limits tool's own planted controls, the same on main).The GB10 run's lines
From the runs and the images named under "Checks on this head". The run kept these lines; the
FAILlines are the planted controls' own.tf-cuda-test mxfp4-experts, exit 0:tf-cuda-test mxfp4-experts contract, exit 0:tf-cuda-test bf16-experts contract, exit 0:tf-cuda-test kernel-contract-limits zig-out/fatbin, the four new kernels' 20 lines (exit 1 with154 problems, as on main):Checklist