Repository navigation
cuda: NVFP4 projections behind qlinear: the lane matmul for decode rows, the prompt GEMM for prompt rows - #595
Conversation
|
@jschmied I reran this branch at 64ef98d on a GB10 with GLM-5.3-Flash's real NVFP4 tensors, as promised in #548. It was built in our tf-dev (nvcc 13.3, sm_121). The Python bytes come from our fork's tree (release/2.8.0 lineage), and your oracle ran unmodified for the synthetic cases.
Each GLM fixture checks the repack, then lane and prompt rows at 1, 7, 16, 17, 40, 256, 300 and 1,000, both direct and through |
…ws, the prompt GEMM for prompt rows
64ef98d to
44cb4bb
Compare
|
Thank you, @jschmied. This is merged into main (8f757e5) with both your commits as they were, and it ships in 1.0.6. On a GB10 against main, with the full kernel set rebuilt ( One commit of ours on top, bcc1e43: like NVFP4 is now a priority for us: next we serve NVIDIA's NVFP4 Nemotron checkpoint end to end on these pieces, then Flash Next and the 27B. |
…s on the lane matmul, prompt rows on the prompt GEMM) Thanks @jschmied. # Conflicts: # zig/tests/cuda/main.zig
Second step of the quantized-weight interface (#548, after #587): NVFP4 projections behind
qlinear.The Python lane matmul (
nvfp4/qmmf.cu) reads FP8G and FP4 from one kernel template, so the Zig side now does too. FP4 decode rows run on it. FP4 prompt rows run onnvfp4/prompt.cu's GEMM, asFp4Linear.prefilldoes.zig/kernels/cuda/fp8_lane.cubecomesqmmf.cuwith the FP4 instances added beside the FP8G ones;prompt16.cuisprompt.cu's FP4 tile 4 (PROMPT_TILE).cuda/qmmf.zig:Lanetakes over fromfp8.Lane. OneWeightcarries its mode (FP4 or FP8G) and its tensor scale; plan, tiles, slices and cluster choice are unchanged.cuda/nvfp4.zig:packWordsandpackScales(qmm.pack's layout, ModelOpt tensors as stored: uint8 [N, K/2], e4m3 [N, K/16], the global scale),weight, andPrompt.cuda/fp8.zigkeeps the block-FP8 packing;fp8.weightreturns the lane's view.cuda/qlinear.zig:Weightgainsnvfp4.Linearholdslane(fp8g rows of both kinds and nvfp4 decode rows) andnvfp4_prompt. A weight whose stored mode doesn't match its tag is refused before any launch, as is a format that isn't loaded.tf-cuda-test nvfp4 <dir>withoracle/nvfp4.py. It uses cuda: one quantized-weight interface (qlinear.zig); Nemotron's 4-bit projections route through it #587's test pattern from d7469ca: a blocking stream, and the output filled before every call, both directly and viaLinear. Here a prompt path that wrote nothing would otherwise pass on the decode call's bytes.fixture.zigreads arrays up to 16 GiB: 288 experts' packed tables passed 2 GiB in @Bizuayeu's GLM run (Zig CUDA ports: shared layers belowlanes.Backend, and one place to coordinate them #548).Receipts on GB10 (DGX Spark, sm_121, CUDA 13.0).
main(c37d0a4) and this branch were each built with nvcc forsm_121:zig build testandzig fmt --checkpass;lean_checkis clean for the touched files.tf-cuda-test nvfp4againstFp4Linear(python-0.6 lineage): the repack, then the lane matmul at 1, 3, 17, 40 and 300 rows (tiles 16/32/64, cluster and fused paths) and the prompt GEMM at 17, 300 and 1,000 rows. Every case is byte-equal, directly and throughLinear.decode/Linear.prompt, at [5120, 6144] and at [704, 2048] (rows not a multiple of 128, as GLM's TP=3 experts).tf-cuda-test fp8-lanethrough the merged lane: 1 to 300 rows byte-equal, directly and viaLinear.d9d758fb.tensorfold check-kernelspasses 1,008 of 1,008 projection cases and 384 of 384 forked-MoE cases on both builds.tensorfold runon three prompts (11, 20, 1,090 tokens), greedy and sampled (0.8 / 20 / 0.95, seed 7): all six reply hashes equal main's.@Bizuayeu ran this NVFP4 code on GLM-5.3-Flash's real tensors before the rebase (#548: dense lane and prompt rows 13/13 per tensor), and plans to rerun on this branch.
Next in #548's order: grouped NVFP4 / FP8 experts on #558's plan for decode rows, with @Bizuayeu's staged prompt-row kernel to follow.