Skip to content

hy4_flash: NVFP4 routed experts on CUDA at one rank (slice 2 of #3801) - #4934

Merged
ashhart merged 5 commits into
ashhart:mainfrom
atakann:hy4-nvfp4-s2
Nov 25, 2026
Merged

ashhart merged 5 commits into
ashhart:mainfrom
atakann:hy4-nvfp4-s2

Conversation

@atakann

@atakann atakann commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Slice 2 of #3801, on top of #4110 (merged): the build's NVFP4 routed experts run on CUDA at one rank. No serving path yet; the loader and the engine are the next slices.

  • moe_nvfp4_cuda.zig packs the ModelOpt per-expert tensors of the build (gate and up [intermediate, latent], down [latent, intermediate]) for core's grouped NVFP4 kernels (BF16 activations, W4A16) and runs them on grouped.zig's plan with Hy4's SwiGLU clamp. The router, its top-k and the weighted sum are the EXL3 path's. A tensor stored wider than the layer is refused, never sliced.
  • tf-cuda-test hy4-nvfp4-experts: 8 experts, 4 picks a row, 1 to 300 rows (the one-block and the wide plans); every pair's gate-up and fp32 down is FP64-bounded with the clamp crossed, and a wider stored gate is refused. The 300-row run goes first; the gate-up and down bytes of the 1, 5, 64, 255 and 256-row runs must equal the same rows of it exactly. Both output buffers are filled with 0xFF (NaN) before every run, so a row a run leaves unwritten fails instead of showing the last run's values. A planted control flips one bit in a 5-row copy of the gate-up and checks that the comparison reports that byte.
  • tf-cuda-test hy4-nvfp4-experts-ckpt <ckpt> <layer>: one layer's 512 experts of atakans/Hy4-flash-NVFP4 load and pack; 64 rows of 16 picks run, and the first 8 rows' 128 pairs are FP64-bounded and equal to the same rows in an 8-row run (outputs poisoned before both runs).

Other families are unchanged: the only shared lines are the runner's registrations in zig/build/cuda.zig, zig/tests/cuda/main.zig and main_usage.zig.

Checks

On one GB10 (sm_121, Zig 0.17.0, nvcc 13.3, ReleaseSafe), at 713e7d5a9:

Test Result Worst tolerance used
hy4-nvfp4-experts PASS gate-up 0.400, fp32 down 0.007
hy4-nvfp4-experts-ckpt, layer 1 PASS gate-up 0.324, down 0.001
hy4-nvfp4-experts-ckpt, layer 2 PASS gate-up 0.339, down 0.001
hy4-nvfp4-experts-ckpt, layer 40 PASS gate-up 0.335, down 0.001

On the real weights the clamp is not crossed (0 of 196,608 gate-up columns), so the synthetic test is the one that covers it.

  • zig fmt --check on the three files; tools/zig/lean_check.py against main: 165 problems, 165 on the base, 0 new.
  • atc overlap: the shared files are the runner registration lines above; the report is incomplete (pull request and time limits), and the conflicts it lists are older pull requests' with main.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @atakann. This slice merges cleanly and leaves existing serving paths untouched. The wrapper keeps the stored codes and scales and uses the existing BF16/FP32 grouped kernels without TF32.

The synthetic test checks FP64 bounds, but it never compares bytes across row counts; the shared report still says those bits are equal. Please add exact comparisons for gate-up and down across all listed widths, retaining the clamp checks, and show that the new comparison rejects a planted mismatch. The checkpoint test already has the separate 8/64-row comparisons, and your three layer receipts are useful.

  • Synthena

@atakann

atakann commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart, you're right: the report claimed equal bits it never compared. In 713e7d5a9 the synthetic test runs 300 rows first and compares the gate-up and fp32 down bytes of the 1, 5, 64, 255 and 256-row runs exactly against the same rows of that run, with the FP64 bounds and the clamp check kept. A planted control flips one bit in a 5-row copy of the gate-up and checks that the comparison reports that byte.

While doing it I found a second gap: the output buffers kept the previous run's values, so a run that left rows unwritten would still have passed. Both buffers are now filled with 0xFF (NaN) before every run, in the checkpoint test's 8 and 64-row runs too. On GB10 the synthetic test and layers 1, 2 and 40 pass again; the description has the details.

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @atakann. The synthetic test now compares both output buffers exactly across all listed row counts, retains the clamp and float64 checks, and detects the planted mismatch. Poisoning the buffers also closes the stale-output gap. Your passes at this head cover the synthetic case and all three checkpoint layers.

The runtime wrapper is unchanged, existing serving paths remain untouched, and the branch merges cleanly. This slice is ready to land through the normal final-tree checks.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I checked this slice together with the other Hy4 packing PR. On 4c79cfe346, #4895 (6bd6b9590b) and #4934 (713e7d5a9e) merge cleanly in that order.

zig build test-hy4-flash-host compile-cuda-tests -Dtarget=aarch64-linux-gnu -Dfixed-cpu -j2 --summary all

The combined tree passed all 31 Hy4 host tests on the M5 Max, and the CUDA test runner cross-compiled for ARM64 Linux in the same 18-step build. This checks build compatibility of the FP8 and NVFP4 slices. The combined device run remains unverified.

Igor Lessio - AIFLOW LABS

atakann and others added 5 commits November 25, 2026 09:10
…rt#3801)

moe_nvfp4_cuda.zig packs the build's ModelOpt per-expert tensors (gate and up [intermediate, latent], down
[latent, intermediate]) for core's grouped NVFP4 kernels (BF16 activations, W4A16) and runs them on grouped.zig's
plan with Hy4's SwiGLU clamp; the router, its top-k and the weighted sum are the EXL3 path's. A tensor stored wider
than the layer is refused, never sliced.

tf-cuda-test hy4-nvfp4-experts: 8 experts, 4 picks a row, 1 to 300 rows (the one-block and the wide plans), every
pair's gate-up and fp32 down FP64-bounded with the clamp crossed; a wider stored gate refused.
…t hy4-nvfp4-experts-ckpt)

One layer's 512 experts of atakans/Hy4-flash-NVFP4 load and pack; 64 rows of 16 picks run, the first 8 rows' 128
pairs are FP64-bounded and equal to the same rows in an 8-row run. Layer 1 passes on GB10.
…the widest run, poison the outputs before each run, and a planted flip shows the comparison finds it

The synthetic test runs 300 rows first; the gate-up and fp32 down of the 1, 5, 64, 255 and 256-row runs must equal
the same rows of that run byte for byte, with the FP64 bounds and the clamp check kept. Before every run the gate-up
and down buffers are filled with 0xFF (NaN), so a row a run leaves unwritten fails instead of showing the last run's
values; the checkpoint test's 8 and 64-row runs get the same. A planted control flips one bit in a 5-row copy of the
gate-up and checks that the comparison reports that byte. On GB10: the synthetic test and layers 1, 2 and 40 pass.
@ashhart
ashhart merged commit aa80cd2 into ashhart:main Nov 25, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @atakann. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

3 participants