Repository navigation
Flash Next CUDA: routed NVFP4 experts in the checkpoint's own math (FP4 x FP4), prompts −9…−10 % - #211
Flash Next CUDA: routed NVFP4 experts in the checkpoint's own math (FP4 x FP4), prompts −9…−10 %#211jschmied wants to merge 2 commits into
Conversation
…ath (FP4 x FP4) under --precision checkpoint Rows enter gate|up once a layer in NVFP4 under the experts' static input scale (the largest of a layer's, which the checkpoints we know store once for every expert), on the block-scaled FP4 mma against the lane matmul's words and block scales; SiLU(gate) * up leaves for down as NVFP4 rows under each expert's own down input scale. One K chain a pair, so drafted == serial and resumed == fresh hold. One rank on SM 12.x; --precision full, two ranks and other GPUs keep the W4A16 kernel. The MTP layer's draft-only experts keep theirs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011SuBgdp87NbfLbiigmzn1z
|
Tested 99ccde3 on one DGX Spark (GB10, NGC It refuses this checkpoint at startup: In this export the MTP layer's experts are per-expert NVFP4 ( - if nvfp4_moe.own_math(world): # rows in NVFP4 under the checkpoint's static input scales
+ if nvfp4_moe.own_math(world) and not name.startswith("mtp."): # MTP draft-only experts keep nvfp4_expert_kernelThe branch merges cleanly onto v0.6.2, and the merged code reaches the same check ( With that one line, the startup line reports "routed NVFP4 experts in the checkpoint's math (FP4 x FP4 under its static input scales)", and against v0.6.1,
The prefill gain (+8 to +12 %) was consistent across both runs at each length on this checkpoint. The decode differences are uncertain: two runs each, and one-stream runs spread by about ±2.5 tok/s. Greedy replies differ from v0.6.1 on 6 of 6 fixed prompts, as expected for a change in arithmetic; a small known-answer set (10 questions: arithmetic, counting, facts) scored 10/10 on both. |
…input scales keep nvfp4_expert_kernel under --precision checkpoint
|
@SvangenStudios thanks for testing this and finding the bug. Your diagnosis was right, and the fix is your line: 5ad55f9. Our checkpoint stores the MTP layer's experts with input scales, so it never reached that check. The commit also adds a test: the tiny checkpoint writer can now store MTP experts as per-expert NVFP4 without input scales, like your export. On that checkpoint, under |
|
Thank you, @jschmied. Running Flash Next's routed experts in the checkpoint's own FP4 x FP4 math, with one fp32 chain over K for each pair, keeps a pair's bits independent of the others, and the KL, top-1 and perplexity table is the documentation that mode needs. The Python engine is frozen (#286), so this won't merge. Zig CUDA runs only Nemotron's MLX 4-bit weights so far, on a copy of the same expert plan your kernel uses, and it has no NVFP4 kernels yet. When Flash Next's NVFP4 checkpoints serve on Zig CUDA, the block-scaled FP4 expert kernel and its SiLU-to-NVFP4 epilogue come across under |
Follow-up to #173. In 0.6.1
--precision checkpointreaches the 27B only:precision.mode()andcuda/nvfp4/checkpoint.pyare used byfamilies/qwen3_5, and Flash Next's routed experts still runnvfp4_expert_kernelon bf16 rows whatever the flag. This puts them under the same contract.quant4) under the experts' static input scale. The checkpoint storesone per expert; ours holds a single value for all 512 in every layer but layer 0 (two values), so the layer takes the
largest, as FlashInfer's CUTLASS MoE does.
cuda/nvfp4/experts_ck.cu: a warp per (plan item, 32 columns) on the block-scaled FP4 mma (mma4.cuh), againstthe lane matmul's words and block scales (
pack4) stacked per projection and re-laid lane-major, four K steps inflight. gate|up's epilogue is SiLU(gate) * up in fp32, quantized to down's NVFP4 input under each expert's own down
input scale (
nvfp4q.cuh, asgemm_gu_ckdoes); down writes each pair's row in fp32 or bf16.hold. Same weight bytes as the W4A16 blocks.
--precision full, two ranks and other GPUs keepnvfp4_expert_kernel; so do the MTPlayer's draft-only experts. The startup line names the experts' math. A checkpoint without the experts' input scales
is refused under
checkpoint(as the 27B's loader does).Measured
One DGX Spark (GB10), our ModelOpt export (NVFP4 routed experts, block-FP8 dense layers),
--precision fullvscheckpointon this branch, one process an arm(data):
The first 16 tokens after both prompts are the same in both modes. Decode rounds are 3 % faster (54.6 vs 56.3 ms) and
carry 3.8 % fewer tokens: the replies differ, and so do their drafts.
Quality, teacher-forced, 8 sequences of 4,096 positions (wikitext-2 test x 4, CPython source x 4), the decode path,
against
--precision full(Flash Next has no fp32 forward):KL takes the reference's top 32 tokens and the rest as one bucket.
Tests
tests/cuda/test_nvfp4_experts_ck.py: gate|up's NVFP4 bytes against a torch quantizer of the fp64 SwiGLU (fewerthan 1 % of bytes differ, where an fp32 sum sits on an e2m1 edge); down equals the fp64 product of its NVFP4 rows to
1e-5, bf16 = fp32 rounded; a pair's bits alone and in decode or prompt plans (16- and 64-pair items); the scales
make_cktakes.tests/cuda/test_flashnext_nvfp4_loader.py: the W4A16 face tests pin--precision full; a new one loads the tinycheckpoint under
checkpoint.tests/cuda1,208 passed, 98 skipped. Drafted == serial on the real checkpoint undercheckpoint: 4 of4 prompts, 160 tokens each.
Not run: two ranks, other SM 12.x cards, RadixArk's and local-inference-lab's exports (both store per-expert input
scales; I haven't checked whether gate/up's are uniform there).
Written with AI assistance (Claude Code); the author reviewed every change.