Skip to content

cuda: NVFP4 prompt rows on a staged grouped kernel behind experts.Grouped - #641

Closed
Bizuayeu wants to merge 3 commits into
ashhart:mainfrom
Bizuayeu:pr3/nvfp4-experts-prompt
Closed

Bizuayeu wants to merge 3 commits into
ashhart:mainfrom
Bizuayeu:pr3/nvfp4-experts-prompt

Conversation

@Bizuayeu

Copy link
Copy Markdown
Contributor

NVFP4 prompt rows behind experts.Grouped, the entry point @jschmied left in #629 for the kernel we agreed on in #548. Stacked on #629 (and so #605); this PR's own commit is the last one.

  • zig/kernels/cuda/nvfp4_experts_prompt.cu: the device code of the BIZ 2.x engine's nvfp4/experts_prompt.cu (Bizuayeu/TensorFold release/2.8.0), the kernel GLM-5.3-Flash's NVFP4 prompt chunks run on there.
    • Items are 64 pairs × 128 columns, staged through shared memory.
    • Each weight is exact in bf16, and each 32-input block's mma sum is added in fp32, with the (expert, matrix) scale last.
    • Three instances: SwiGLU gate-up on two stages, and fp32 and bf16 down on three (34,816 and 38,400 bytes of shared memory a CTA).
    • A pair's bits depend on its row and its expert alone. They are not the decode kernel's, so prompt rows are compared with prompt rows.
  • cuda/experts.zig:
    • Nvfp4Experts loads the prompt module beside the decode one.
    • runPrompt launches a CTA per (item, four column blocks), and both forms share one argument list.
    • Grouped.prompt dispatches NVFP4 to it, so the PromptFormNotBuilt refusal and its test are gone. A host test checks the refusal when the format is not loaded and the shared-memory sizes.
  • tf-cuda-test nvfp4-experts:
    • oracle/nvfp4_experts.py adds staged rows (64, 300 and 1,000), routed in items of 64 through the BIZ 2.x engine's prompt_gate_up / prompt_down. Upstream's Python lineage has no staged kernel, so the fixtures come from that engine, whose decode kernel is the same nvfp4/experts.cu.
    • The test checks the plan, then up, then down as bf16 sums and as fp32, all through Grouped.prompt. The existing decode cases are unchanged.

Receipts on GB10 (DGX Spark, sm_121, CUDA 13.3, driver 580.173.02), this branch built with nvcc for sm_121:

  • zig build test passes.

  • zig fmt --check is clean for the touched files.

  • lean_check reports 542 problems, the same as cuda: grouped NVFP4 experts behind experts.Grouped (decode rows); prompt rows refused until a staged kernel takes them #629's head (4678ffac), so it adds zero.

  • tf-cuda-test nvfp4-experts against the BIZ 2.x engine's nvfp4/experts.py is byte-equal in every case:

    fixture experts x [NI, D], slots cases
    default 33 x [512, 2560], 7 pack; decode 1 and 3 rows; 300 rows on the decode form; staged 64, 300 and 1,000 rows (40, 65 and 142 items of 64): up, down bf16, down fp32
    GLM-like 65 x [704, 4096], 9 pack; decode 1 and 3 rows; 300 rows on the decode form; staged 64, 300 and 1,000 rows (74, 107 and 205 items): up, down bf16, down fp32
  • Speed of the same two kernels on GLM-5.3-Flash's real layer-3 experts (288 routed, swiglu_limit 10, top-8 plus the skipped shared slot, uniform random routing), CUDA events, the decode form (items of 16) against the staged kernel (items of 64), gate-up plus down:

    width rows decode form staged
    704 2,048 15.07 ms 7.69 ms 1.96x
    1024 2,048 30.18 ms 10.94 ms 2.76x
    2048 2,048 63.58 ms 19.93 ms 3.19x
    1024 512 10.72 ms 9.21 ms 1.16x
    1024 128 8.76 ms 8.82 ms 0.99x

    These were measured through the 2.x engine's Python launchers (Zig CUDA ports: shared layers below lanes.Backend, and one place to coordinate them #548, 10-10), and the Zig launch uses the same grid. The staged form also matched our golden of 200 real prompt rows byte for byte at widths 704 and 2048.

Written with Weave (My Symbiotic AI)

jschmied and others added 3 commits October 10, 2026 14:36
… experts route through it, block-FP8 experts join
…mpt rows refused until a staged kernel takes them
…uped

Grouped.prompt took NVFP4 layers only as a refusal (ashhart#629). Prompt rows now run on
nvfp4_experts_prompt.cu, the device code of the BIZ 2.x engine's nvfp4/experts_prompt.cu
(Bizuayeu/TensorFold release/2.8.0), the kernel GLM-5.3-Flash's NVFP4 prompt chunks use
there: items of 64 pairs x 128 columns staged through shared memory, each weight exact in
bf16 and each 32-input block's mma sum added in fp32, the (expert, matrix) scale last. A
pair's bits depend on its row and its expert alone; they are not the decode kernel's, so a
prompt row is compared with prompt rows only.

- experts.zig: Nvfp4Experts loads the prompt module beside the decode one (three instances:
  SwiGLU gate-up on two stages, fp32 and bf16 down on three; 34,816 and 38,400 bytes of
  shared memory a CTA) and runPrompt launches a CTA an (item, four column blocks); both
  forms share one argument list. Grouped.prompt dispatches NVFP4 to it.
- tf-cuda-test nvfp4-experts: oracle/nvfp4_experts.py adds staged rows (64, 300, 1000)
  routed in items of 64 from the BIZ 2.x engine's prompt_gate_up and prompt_down; the
  test checks the plan, up, and down as bf16 sums and as fp32 through Grouped.prompt.
@Bizuayeu

Bizuayeu commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing: main already has a staged NVFP4 prompt kernel (a6aa478), so this would be a second one. The comparison on GLM's real experts follows in #548.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants