Repository navigation
cuda: one quantized-weight interface (qlinear.zig); Nemotron's 4-bit projections route through it - #587
Conversation
…projections route through it
|
Thank you, @jschmied. This is merged into main (6c3ce72) with your commit as it was, and it ships in the next release. Putting the symbols, shared-memory sizes, occupancy and split scratch in one struct that resolves itself from the loaded modules is the single owner #548 asked for, and your receipts made it quick to check. We gated it on a GB10. We also checked the decode contract for FP8 directly. Every row count from 1 to 300 through One small commit of ours follows yours. d7469ca fixes the FP8 test: it uploaded with Two notes for the next step. Nemotron calls |
A pageable cuMemcpyHtoD can return before the copy lands, and kernels on a non-blocking stream don't wait for the legacy stream, so a test that uploaded with fromHost and launched at once could read its input mid-copy when other work shared the GPU (ashhart#587 found it in fp8-lane: 8 failures in 80 runs with four copies at once). Uploads now wait for the legacy stream; the engine's own copies are stream-ordered and unchanged.
… Nemotron's 4-bit projections route through it
A pageable cuMemcpyHtoD can return before the copy lands, and kernels on a non-blocking stream don't wait for the legacy stream, so a test that uploaded with fromHost and launched at once could read its input mid-copy when other work shared the GPU (ashhart#587 found it in fp8-lane: 8 failures in 80 runs with four copies at once). Uploads now wait for the legacy stream; the engine's own copies are stream-ordered and unchanged.
First step of the quantized-weight interface claimed in #548. The 4-bit projections Nemotron launches move out of
families/nemotronintozig/src/cuda/qlinear.zig, behind one weight view with a decode-row and a prompt-row call. Nemotron routes through it. Behaviour doesn't change: same kernels, same grids, same arguments.cuda/qlinear.zig:Affine4is the MLX 4-bit tiled weight (Nemotron'sQLinear).Affine4Kernelsholds what moves:resolvefrom the loaded qmm_group, qmm_prefill and lane_gemv modules;decode= qmm.matmul's choice between split-K lane_gemv, lane_gemv and qmm_group's cluster tile;prompt= qmm.prefill_matmul.Weightis a tagged view (affine4,fp8gfrom cuda: block-FP8 projections on the Python lane matmul's FP8G kernels #482).Linear.decodeandLinear.promptdispatch on it, and a format that isn't loaded is refused before any launch.families/nemotron/cuda_kernels.zig:QLinear,SplitandsplitKbecome aliases.Kernelsholds oneAffine4Kernelsinstead of four functions and the split scratch, andOps.dense,gemv,gemvSplit,clusterandprefillDensedelegate.check-kernels, which reads the split scratch at its new place. The family is 111 lines shorter.tf-cuda-test fp8-lanealso runs each row count throughLinear.decodeandLinear.promptand checks the bytes against the Python lane matmul.Receipts on GB10 (DGX Spark, sm_121, CUDA 13.0).
main(4ebf52a) and this branch were built with one fatbin set (-Dsm=121) and run on Nemotron 3.5 Lightning (TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit@d9d758fb):zig build testpasses;lean_checkis clean for the touched files.tf-cuda-test fp8-lane: 1, 3, 17, 40 and 300 rows of a [2560, 6144] block-FP8 weight equal Python's bytes, directly and through both qlinear calls. That covers tiles 16, 32 and 64, the cluster path and the fused path.tensorfold check-kernels: 1,008 of 1,008 projection cases byte-equal (976 split-K), and 384 of 384 forked-MoE cases, on both builds.tensorfold run: three prompts (11, 20 and 1,090 tokens), greedy and sampled (temperature 0.8, top_k 20, top_p 0.95, seed 7). All six reply hashes are equal:5923b40d570bbothd38725819372bothead827be94f5bothbb8855c2f084both068276d3ec75botha6961a8c7589bothNext, as listed in #548: NVFP4 behind the same view (lane matmul for decode rows, a prompt GEMM for prompt rows, each with an oracle fixture), then the grouped experts per format behind #558's plan.