Repository navigation
gpu: the fused NVFP4 gate and up writes its SwiGLU in native FP4, and qwen38 counts a folder's NVFP4 rows in that form - #1040
Conversation
…the down's input holds no Q8 planes On a native FP4 build a Qwen3.8 load whose card gate, up and down are all NVFP4 runs the gate, the up and the SwiGLU as one launch, gate_up_nvfp4_mma. It stored the SwiGLU's 32-value Q8 planes, and a second launch, quantize_nvfp4_32 over the route, packed the down's native FP4 from them: 800 B of Q8 a column that only that launch read, and one launch a layer. gate_up_nvfp4_mma now packs the FP4 itself. Each block keeps its tile's Q8 codes and block scales in shared memory and packs its own 64-value step: every 16-value sub-block takes the scale amax / 6 rounded to three mantissa bits and each code the nearest E2M1 level of code times d / s. A column's scale is a power of two, so a step packs alone; its scale bytes go out in the step's own frame (its largest exponent at UE4M3 field 14), and the tile's last block to arrive (one arrival word a tile, back to 0 after it) writes the column scale 2^(top - 7) and moves each step's bytes into the column's frame. The FP4 is the transcription of the split pair's Q8 codes (gemm32::gate_up_fp4) and differs from quantize_nvfp4_32's, whose column scale is the largest block scale times 127/6. GemmAct32::new_gate_up_output makes that scratch: the native FP4 form alone, with a frame a step and an arrival word a column, 408 B a column at K = 640 where the routed scratch held 1,164 B. enqueue_gate_up_sel32 takes the fused launch only into such a scratch and no longer quantizes after it; quantize_nvfp4_32 loses its route parameters. CardRoute38 makes the scratch when every card gate and down is NVFP4, and the plan's native run token drops from 115,732 B to 108,172 B (127,361,024 B fewer than the rows form at a run of 2,048 tokens). gate_gemm's nvfp4_gate_up case holds each card slot's FP4 to the host transcription bit for bit (levels, scale bytes, column scale) and the down over it to the host product within 2^-16 of its magnitude.
…e native form PlanInputs::route_form gave the native form only where every routed stack of the file's layers is GGUF's NVFP4. A Qwen3.8 NVFP4 checkpoint folder now declares its routed stacks as NVFP4 rows, which the card holds as NVFP4's planes and runs through the same fused native launch, so the load held its card route in the native form while the plan counted the rows form: 62,188 B a run token held back that no buffer took (254,722,048 B at U = 4,096 on a GB10). route_form now reads the card format of each routed stack (card_routed): native where the card reads every one in NVFP4's planes, a GGUF's NVFP4 or a folder's NVFP4 rows.
There was a problem hiding this comment.
Verdict: CLEAN: No reachable behavior defect or proven quality defect remains.
Non-blocking
⚠ Complete the launch-fold evidence: crates/gpu/src/gemm/nvfp4mma.rs:1999.
At 640 gate/up rows, the fused epilogue adds 10 GPU-scope atomic arrivals per route tile per layer [derived: 640/64]. The “fold a launch into a neighbour” class requires an owning gate and timed A/B.
The PR supplies gate output and A/B summaries, but its timing reproduction only starts and stops the server. Add the tested head hash and the timed request commands with their output so the prefill result can be reproduced.
Checked
Duplicates: 22 new items and the moved nearest checked; no duplicate owner found. dryer reported 0 pairs. Manual searches covered the GPU and gate code.
Complexity: nvfp4_gate_up_case 72→103 adds fixture, oracle and edge-check branches; CardRoute38::new 28→32 adds load-time format selection; gate_up_nvfp4_mma 16→30 adds packing and publication branches. The kernel is exempt from splitting.
Silent failure: 3 default/fallback sites followed; the fixed-size maximum and absent optional scratch/forms have defined meanings. Non-finite SwiGLU raises QuantColumn and propagates a NaN column scale to the down projection and the host fault reader.
Tests: restoring the old predicate at crates/model/src/arch/qwen35moe/place.rs:559 fails the NVFP4_ROWS assertion. Removing the overflow-safe branch at crates/gpu/src/gemm/nvfp4mma.rs:209 fails Edge (fp4_off=16 in the supplied mutation log). Removing the Q8-scratch refusal makes the native-plane test's expect_err fail by inspection. Restoring the old scratch byte bound fails the updated planning assertions.
Gates: the changed numeric comparison, retired routed-quantizer case and unsafe ratchet have dated PIN reasons. No unpinned relaxation found.
Adversarial: checked refused/all-host routes, partial tiles, NaN and extreme finite columns, and stale frames on replay. Route guards, complete active-step writes and acquire/release arrivals block those failure paths. Frame rescaling also matched direct column framing in an independent arithmetic check.
Escape catalog: C1–C4 did not match.
Notes
Static review only; hardware gates were not rerun. dryer excluded crates/gpu and crates/gpu-gates.
The supplied card runs omit the tested head hash, so gpu.json records evidence: false.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/gemm32.rs, crates/gpu/src/arch/qwen3moe/wide38.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8 NVFP4 routed MoE에서 fused gate와 up이 SwiGLU 결과를 FP4로 바로 써서 Q8 plane과 quantize launch를 없애고, 카드 메모리와 prefill 시간을 줄입니다.
What and why
In the Qwen3.8 NVFP4 routed MoE, the fused
gate_up_nvfp4_mmawrites its SwiGLU result as Q8 planes, and a separatequantize_nvfp4_32launch per layer turns them into the FP4 input of the down projection. The Q8 planes are 800 bytes per run-token column of scratch on the card.This PR has two code changes:
gate_up_nvfp4_mmawrites the SwiGLU result straight into the native FP4 form the down projection reads. The block that arrives last at a route tile settles the column scale and each step's scale byte, so the Q8 planes and thequantize_nvfp4_32launch are gone. The plan's per-run-token bound for the native route drops from 115,732 to 108,172 bytes.PlanInputs::route_formnow reads each routed stack's card format. A checkpoint folder declares its NVFP4 routed stacks asNVFP4_ROWS, which the card reads as NVFP4 planes, but the plan counted that route in the rows form (170,360 bytes per run-token), more than the route uses. The plan now counts it in the native form.The
gpurow oftools/unsafe-ratchet.txtand itsPINlines are recounted for the new blocks.The FP4 bits differ from the previous path, so a greedy continuation can differ from main's. The
gate_qwen4exp_nvfp4oracle argmax and band checks pass on the NVFP4 folder (below).Release notes: Changed: the fused NVFP4 gate and up writes its SwiGLU in native FP4, so FP4-Local prefill of a 4096-token prompt is 1.2% faster, the card holds 30,965,760 bytes less, and the plan of an NVFP4 checkpoint folder counts 254,722,048 bytes less.
Code shape
The review reads these first. A box left unticked needs one line of why.
fp4_sub,scale_byte,column_scale) and one host transcription (gate_up_fp4) that the gate compares bit for bit.GemmAct32::new_gate_up_outputadds only the frames tonew_native_input, and the route form has one owner,route_form.CardRoute38::newpicks the fused output scratch when every card gate and down is NVFP4. The common owners gained no per-model branch, flag or trait method.quantize_nvfp4_32and the routedquantizepart ofhw_native_activation_planesare removed.tools/check-comments.shis ok.PIN(2026-10-31)lines with their reason.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": the duplicate scan lists one candidate, different.crates/gpu/src/gemm/nvfp4mma.rs:304andcrates/gpu/src/gemm/nvfp4mma.rs:338areload_gpu, one relaxed GPU-scope load, andarrive, one acq_rel GPU-scope atomic add. Each wraps its own single PTX instruction and they share only the generic-to-global address conversion.What I ran
Card conditions of every card run below, from
nvidia-smi:Speed
One DGX Spark, the default
sm_121abuild,bloomery-servewith the draft off. Each request is a 4096-token prompt with 128 greedy tokens. Three rounds per side in alternating order after a warm-up, medians below.FP4-Local (
nvidia/Qwen3.8-Flash-Next-FP4-Local), base is upstream main at904266cfc:Prefill and TTFT improve with separate ranges and decode ranges overlap, so I claim a gain only for prefill and TTFT.
NVFP4 (
nvidia/Qwen3.8-Flash-Next-NVFP4), same base and conditions:The NVFP4 prefill and TTFT differences are smaller than the spread of the same build against itself, so I claim no NVFP4 speed gain.
Card bytes from the server log of the same runs.
need bytesis the plan's card bound andresident_bytesis what the load holds. The NVFP4 folder row is from a second A/B with the route-form commit, base6a9680ae:resident_bytesneed bytesresident_bytesneed bytesBoth differences match the derived values: 4096 run-tokens times 7,560 bytes (10 columns times the 756 bytes the scratch loses per column) is 30,965,760, and 4096 times (170,360 minus 108,172) is 254,722,048.
Reproduce one round, with
baseon upstream main andheadon this branch:Checks
Host tests of the plan, including the new NVFP4_ROWS case of
a_card_route_is_counted_in_its_files_form:With
route_formback ont.ty == GgmlType::NVFP4, that test fails:The fused gate and up gate on the card. Every slot's FP4 is compared bit for bit with the host transcription, and the down output with the host down over that FP4.
SpreadandTinycross the edges of the FP4 range, andEdgecarries a column whose SwiGLU isf32::MAX:With the kernel's sub-block scale back on the old f32 formula, the same gate fails on
Edge:The PTX spill ratchet:
The NVFP4 checkpoint folder against the oracle, with the plan split between the card and the host (the route form commit):
The A/B above ran the real
bloomery-serveof this change on the card.Hardware (if the change is for a machine)
DGX Spark (GB10), driver 595.84, CUDA 13.3, build
sm_121a. The change is thesm_121akernelgate_up_nvfp4_mma.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.