Skip to content

hip: ModelOpt NVFP4 and FP8 checkpoints keep their codes and decode in flight - #2490

Open
ElderOrb wants to merge 2 commits into
ashhart:mainfrom
ElderOrb:hip-nvfp4
Open

ElderOrb wants to merge 2 commits into
ashhart:mainfrom
ElderOrb:hip-nvfp4

Conversation

@ElderOrb

@ElderOrb ElderOrb commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Serves NVIDIA's ModelOpt NVFP4 and FP8 checkpoints on the HIP engine without widening a weight.

What the checkpoint holds, and what the engine keeps

For a projection of N outputs from K inputs ModelOpt writes weight U8 e2m1 codes [N, K/2] (input 2i in the low nibble), weight_scale E4M3 [N, K/16] and weight_scale_2, one global scale. An FP8 layer writes E4M3 codes [N, K] and one f32 scale a projection.

The host keeps exactly those tensors, and the device keeps that layout too - as quant.mlx does - so an upload is a copy. The one transform is at read: an E4M3 group scale widens to BF16, exactly (three mantissa bits fit seven). A F32 block table is refused (ModelOpt writes E4M3, and the kernel reads a 16-bit table), and a stack of experts is refused because its experts carry a global scale each.

The preflight counts what the device holds rather than the stored files: table.deviceBytes keeps U8 and E4M3 code tensors as stored and counts only an E4M3 group table at two bytes a value.

Kernels

quant/nvfp4_tiles.hpp serves a prompt through tf_nvfp4_gemm: a 64 x 64 tile stages a column chunk once and serves 64 rows, a thread a 4 x 4 block of output elements (acc[4][4], ty = tid & 15, tx = tid >> 4, 256 threads), a group's 16 inputs folded in f32 with the group's own E4M3 scale, the one global applied to the sum once, the nibble through an e2m1 bit table.

A decode round takes tf_nvfp4_col1 .. tf_nvfp4_col4 instead (launches/nvfp4.zig:78, chosen at a.m <= 4 with @rem(a.k, 64) == 0, grid ceil(n / 256)): a thread a column and ROWS (1..4) of that column, summed in the same per-group order, reading codes and scales straight through registers (hold[2][8], no LDS at all), so a decode row's bits are the tile's bits and the row's work is not padded out to sixteen rows. tf_nvfp4_small remains the 16-row LDS block for a round wider than four rows.

quant/fp8_tiles.hpp is its sibling for FP8, tf_fp8_gemm: each E4M3 code turns into the exact f32 it names, all of K sums in f32, and the projection's one scale multiplies the result once, as CUDA's qmmf.cu reduce does. A short row keeps each chunk's partial in f32 and adds it once, so a row that crosses a chunk carries the rounding the 64-row tile does and the result stays row-invariant.

Both serve bf16 activations only, since the engine refuses an fp16 build for a ModelOpt checkpoint; one kernel serves a prompt's rows and a round's, so a row's bits never depend on its round.

Why dedicated kernels rather than the shared GEMM and stream tiles: both step along K in 32-code chunks (kGemmK = 32, nch = a.k >> 5, a chunk's scale index q >> gshift), and NVFP4's group is 16, so a chunk holds two scales: a.group / kGemmK is 0 and the shift would have to be negative. tiles/stream.hpp and tiles/dot2_tiles.hip keep only their MLX code.

The engine

A ModelOpt checkpoint's own bf16 layers (an lm_head, an unquantized linear, the MTP head) read as .dense on the row-invariant dense kernels rather than through rocBLAS, so the engine keeps main's e.plain() gate and opens no rocBLAS for them. The vision tower never calls rocBLAS either (no blas reference in zig/src/vision/qwen_hip.zig), so the engine carries no tower field.

A ModelOpt checkpoint carries its own refusals: an fp16 build and more than one rank are refused by name, and graphs stay off. A ModelOpt checkpoint with routed experts is refused by name too, before its shards are read. A refusal names the tensor and the reason through core's Why buffer.

The format tag

core.quant.Format no longer names NVFP4 or FP8: it and Decoder are the three formats both engines read. A projection still has to carry them, so quant.Projection gains optional nvfp4 and fp8 fields beside a nullable handle, and format()/decoder() return optionals. The family's host projection is its own union, with rows, bytes, read, halves, sliceRows and sliceCols over it; its device projection is a union of quant.Device, quant.nvfp4.Device and its FP8 tensors.

Kernel contract

hip_records_nvfp4.zig holds every entry point's resources from hip-kernel-contract-limits, in gfx1030, gfx1100, gfx1151, gfx1201 order (VGPRs / SGPRs / LDS bytes):

  • tf_nvfp4_gemm: 138/38/16384, 144/38/16384, 144/38/16384, 143/36/16384.
  • tf_fp8_gemm: 58/49/18432, 56/49/18432, 56/49/18432, 58/48/18432.
  • tf_nvfp4_col1: 130/22/0, 138/22/0, 138/22/0, 138/23/0.
  • tf_nvfp4_col2: 164/26/0, 165/26/0, 165/26/0, 164/28/0.
  • tf_nvfp4_col3: 148/31/0, 145/30/0, 145/30/0, 147/34/0.
  • tf_nvfp4_col4: 121/32/0, 141/32/0, 141/32/0, 144/38/0.

Bound 256, wave32, no scratch, and every ModelOpt line reads "record current" on all four chips when the contract is taken with the toolchain the records were made on. The tile stages a column chunk in LDS, which is why the product kernels moved from the pre-tile numbers (NVFP4 11264, FP8 12288); the col entry points carry no LDS because a column's codes and scales stay in registers.

Re-run to confirm, on this head: zig build hip-kernel-contract-limits -Dhip=true -Dhipcc=<hipcc> compiles the contract for gfx1030, gfx1100, gfx1151 and gfx1201 and audits every chip's records. 77 of 79 build steps complete; the audit's run step then exits 1 on the inherited failures below.

I re-ran it here, and the result depends on which compiler takes the contract, so it is worth stating exactly:

  • With the toolchain the records were made on - HIP version: 7.2.26024-f6f897bd3d, AMD clang version 22.0.0git - all six ModelOpt lines read "record current" on all four chips, as the records above were written that way.
  • With the newer toolchain on my own machine - HIP version: 7.16.26385-7da43026e4, AMD clang version 24.0.0git - all six read "record" against different numbers: tf_nvfp4_gemm 118/33 on gfx1030, 111/33, 111/34, 111/32, where the records hold 138/38, 144/38, 144/38, 143/36. FP8 reads 56/53 on every chip against a recorded 58/49, 56/49, 56/49, 58/48. A newer clang allocates registers differently; the kernel source is unchanged between the two runs.

So the records are current for the compiler they name, and a future toolchain bump will move them. That is why every record carries the compiler in the body above rather than only the numbers.

  • The audit's inherited mismatches are 847, byte-identical on the base commit and on this head. I ran hip-kernel-contract-limits on b7298b4ea and on e57bc1132 with the same toolchain, and every one of the 847 FAIL lines appears in both, all in kernels this PR does not touch (RMS norm, mamba, and their neighbours); per chip the counts are 207 / 212 / 212 / 216 on both sides, and Compare-Object over the sorted FAIL lines reports no difference either way. The PR's only effect on the audit is the 24 new ModelOpt lines, and all 24 pass. (An earlier revision of this body said 540; that was the same audit under a clang 24 toolchain, where the inherited count moves - the base-against-head run above, on the toolchain the records name, is the one that shows what this PR changes.)
  • The audit pulls in lighton_ocr.hip:182, which refuses M_SQRT1_2 on this toolchain. That file is byte-identical to main and is not touched by this PR. A local shim for that one constant (0.70710678f, the same float as M_SQRT1_2) lets the build reach 77/79, which is where the numbers above were read; the shim is not part of this PR.

The same run compiles every group for the four chips, which is the gfx1100 and gfx1201 build. tests/hip/contract_nvfp4.zig carries a test type for both and the runner builds it; on gfx1151 (Radeon 8060S):

PASS nonfinite hip ModelOpt NVFP4 product: 256 non-finite and 1024 finite outputs match the float64 classes
PASS repeat hip ModelOpt NVFP4 product: five runs byte-identical (1024 bytes), inputs and guards untouched, no overlap
PASS shapes hip ModelOpt NVFP4 product: 4 shapes within the float64 bound (worst 0.001 of the bound), 0 edges refused
PASS sums hip ModelOpt NVFP4 product: exact sums at k 4096, where fp16 sums would miss by 847512x and bf16 by 4765421x
PASS nonfinite hip ModelOpt FP8 product: 256 non-finite and 1024 finite outputs match the float64 classes
PASS repeat hip ModelOpt FP8 product: five runs byte-identical (1024 bytes), inputs and guards untouched, no overlap
PASS shapes hip ModelOpt FP8 product: 4 shapes within the float64 bound (worst 0.001 of the bound), 0 edges refused by
PASS sums hip ModelOpt FP8 product: exact sums at k 4096, where fp16 sums would miss by 442122x and bf16 by 4889576x
PASS limits live ModelOpt NVFP4 product: 256 threads launched, the runtime allows 256; 144 VGPRs, 16384 + 0 LDS bytes
PASS limits live ModelOpt FP8 product: 256 threads launched, the runtime allows 256; 56 VGPRs, 18432 + 0 LDS bytes
SUMMARY gfx1151 164 kernels: 164 pass gates 1-4, 0 fail, 2 known findings; 43 controls: 43 red as planted, 0 missed

All ten ModelOpt lines pass on the current head. The two known findings are the bf16 prompt tiles' NaN classes, which predate this branch. The run's 189 other limits live lines are other kernels' recorded resources against this host's hipcc (a different ROCm version from the one that recorded them); none of them is a ModelOpt launch, and none is touched here.

Testing

  • zig build -Dhip=true test on gfx1151, this head on b7298b4ea: 769/772 steps, 10344/10594 tests (247 skipped, 3 failed). main at b7298b4ea, same command on the same host: 769/772 steps, 10322/10572 tests (247 skipped, 3 failed), so the branch adds 22 tests and skips none. The three failures are the same three on both trees, and neither file is touched here: flashnext/hip/tables.zig's two pool tests (lines 483 and 517) cannot pass off Linux, because host_pages.zig:109 returns cold() == false unconditionally when builtin.os.tag != .linux, so the pool is never woken; and families/nemotron/hip/embedding.zig:106 cannot map its temporary table on Windows, std.Io.Threaded returning AccessDenied from the page-file mapping. Both files are byte-identical to the base commit. An earlier run of this command reported 3977/4100 tests because that build carried no CUDA suites; with the CUDA toolchain on the path the same tree builds them too.
  • After the last rebase the head is 8a8bec665 on ce0264367; the one conflict was native.zig's served(...), where main now passes the drafter (served(e, d, streams, capacity, readouts)) so admission counts its scratch: that call is kept as main has it, with this branch's ModelOpt format names on top. The rebase also brings in aec48047e/17a554e16, which fix the walk-away race this branch's last CI run hit in request_admission_http_test.zig:503 (a file this branch does not touch); on that run zig-b was green and zig-windows/zig-macos-dev-tools were cancelled behind the one failing host step. On that base I re-ran the host targets (test-qwen35, test-qwen35-hip-host, test-native-hip-host, check-native-hip-host, all with -Dhip=true -Dfixed-cpu), zig fmt --check on the changed files, and the lean check above: all pass. The device numbers above (tests, contract limits, hip-kernel-test) are the ones measured at e57bc1132 on b7298b4ea; the card is serving another model right now, so I did not displace it for a re-measure.
  • tools/zig/lean_check.py reads 165 problems on this head and 165 on main at ce0264367, the same set: Compare-Object over the sorted lines reports no difference, so the branch adds none. That matters for the 600-line rule: engine.zig is 590 lines against main's 575, and the merge's is 590 too since main is this head's parent. The shared handle's optionality moved one line, prompt_tail.zig:63, to p.format() == .dense.
  • Kernel tests compare both products with quant.nvfp4.reference and quant.fp8.e4m3 in f64 against the bound each kernel's chain derives, print the worst error, and check a row against the format reference alone at one, three and five rows. hip/kernel_tests/fp8.zig:119 and nvfp4.zig:150 then compare one row with the same row inside a round of seventeen at K = 192, so the round crosses the sixteen-row threshold and the two sides take different paths; the row's outputs must be equal bit for bit, which is what pins the short path's per-chunk sum to the tile's.
  • Host tests cover the reader (unfit, the exact widen, halves and slices), the preflight count, the FP8 and F32 refusals, the ModelOpt MoE refusal, that a ModelOpt checkpoint's dense layers land on .dense through a real Checkpoint.open, that an E4M3 NaN code is refused by name, and that a ModelOpt checkpoint offers its NVFP4 formats to qwen3_5 alone.

Served: the checkpoint loads and answers

nvidia/Qwen3.8-27B-NVFP4 at revision 482ca0f3 (19 files, 20.44 GB, the three shards checked against their LFS oids) serves through zig build native-hip on gfx1151 (Radeon 8060S), zig 0.17.0, TheRock's ROCm SDK with HIP version: 7.2.26024-f6f897bd3d and AMD clang version 22.0.0git (target x86_64-pc-windows-msvc):

[tensorfold] HIP gfx1151 device 0, rank 0 of 1: model 20.63 GiB; 1 stream at once, 0.65 GiB each at a 8192-token window
[tensorfold] serving qwen38-nvfp4 at http://127.0.0.1:8124/v1 (context: 8192; loaded in 259.3s)

A greedy request answers correctly and repeats bit for bit across runs (the same token_sha256 twice). The MIXED_PRECISION header gives the loader no trouble: format is read from the tensors, weight_scale_2 for NVFP4 and weight_scale for FP8, and the checkpoint's 208 FP8 and 193 NVFP4 layers both load.

Decode is 2.0 tok/s and TTFT 4.75 s at 8192 context, one stream at a time, drafting on. That is 20.63 GiB of weights read per token at 2.0 tok/s, about 44 GB/s.

The card's ceiling, measured by a pure read_only pass over 2 GiB and confirmed by hipInfo (512-bit bus, 800 MHz memory clock): 240 GB/s. A 5120 x 5120 NVFP4 layer's 16.38 MB of codes fit in the 32 MB MALL, where the same read runs at 732 GB/s.

So decode reaches about 18% of the floor. The prompt path is a 64 x 64 tile and was timed directly at that shape:

rows time GB/s of weights vs the floor
16 (a round) 1.32 ms 12.4 5.2%
64 (a prompt tile) 1.47 ms 11.1 4.6%

Rows = 1 is not in that table because decode does not take the tile: it takes tf_nvfp4_col1 (see Kernels). Those kernels were not timed in isolation - the SDK has no rocprof/omniperf - so their rate is only observable end to end, which is the 44 GB/s above. The two are not comparable directly: the tile's 22.7 GB/s at m = 1 is a path decode no longer runs, and the ~2x it would suggest cannot be separated from the x86 harness in this SDK. What is measurable is that decode reaches 18% of the card while the prompt tile reaches 5%.

Two candidates I measured on the tile and ruled out:

  • The 16-way LDS bank conflict in xs[16][64] (sixteen threads share a row): padding the stride to 68 changes nothing but 1.09x, outputs bit-identical.
  • kE2m1Bf16 declared __device__ rather than __constant__: moving it to constant memory is 1.00x - the cache already absorbs it. Unrolling the 16-deep accumulator chain into four gives 1.13x, also bit-identical.

Together those explain 1.23x of the tile's gap. The rest is launch geometry: a 64 x 64 tile at m = 1 would be 80 blocks of 256 threads on a card that holds 40,960 threads, with nvfp4_small spreading its threads over all sixteen rows of xs while writing only row < a.m - fifteen sixteenths of the work discarded. That is exactly what tf_nvfp4_col1 stops doing: its grid is ceil(n / 256), a thread owns a column, and no row is padded out to sixteen.

This is a kernel-optimization gap, not a correctness one - every contract gate and the 17-row tests pass, and the bit-for-bit determinism holds. I would rather report this honestly and improve the decode path further in a follow-up than tune it inside this PR, whose subject is that these checkpoints serve as stored.

Memory: a separate patch, and what the numbers mean

The working-set arm is not in this branch. The numbers below were taken with a small local patch applied on top of this head. That patch is now its own pull request, #3866: it touches core/checkpoint*, the loader every family and every backend shares, so it does not belong in a PR about the NVFP4 format. Nothing in this branch's diff changes loading memory; without the patch this branch behaves exactly as main does.

The finding, so the second PR has a record: on Windows the reader had no way to drop a step's shard pages. safetensors.zig:265 gates release on builtin.os.tag != .linux, and checkpoint_drop.zig, checkpoint_file_cache.zig and shard.zig's madvise are Linux-only too, so model.zig:66's "no ck.release() between layers" held for a reason that did not apply. The pages stayed in the process's working set, which is what made a load look like it needed far more memory than it does.

The patch adds platform/working_set.zig (reached as sys.working_set, beside the other Win32 declarations) as the Windows arm, called from Checkpoint.release/releaseExcept and from qwen3_5/weights/checkpoint.zig's release after a layer's files are walked: one SetProcessWorkingSetSize(GetCurrentProcess(), -1, -1) per step, not per tensor, since Windows has no per-range advice. It removes pages from the working set and leaves them on the standby list, so a later read is a soft fault, not disk.

Measured on the card with that patch compiled in (2 s sampling, gfx1151, the 8192-token server, external trimmer off so only the build's own release acts):

peak working set lowest free RAM standby load
main (no trim arm on Windows) 18.47 GB at 127.8 s 1.52 GB of 31.65 19.94 GB 259.3 s
this head + the patch 1.92 GB at 7.1 s, then 0.03-0.23 GB 12.47 GB 14.73 GB 259.8 s

The private bytes do not move (peak 0.76 GB either way), so the 18.47 GB was mapped shard pages, not the process's own allocations. The standby list holds the pages the trim dropped instead of the working set holding them, so a later read is a soft fault: the load takes 259.8 s against 259.3 s, within noise.

At --parallel 8 --context 32768 the same arm holds: peak working set 2.86 GB, lowest free RAM 14.06 GB, standby growing to 16.56 GB as the shards are read once and kept. No disk read repeats.

A 27B checkpoint now loads on a 32 GiB Windows side.

Concurrency and drafting, measured

All rows below are the same greedy prompt, the same 64 max_tokens, temperature: 0, --context 8192, --snapshot-dir none, so every reply is directly comparable and every row's token_sha256 is the same hash.

At --parallel 2:

wall tok/s reply sha
solo, 2 runs 36.11 / 36.00 s 2.0 each e02735d4c9b7
2 concurrent, both at once 49.93 / 49.89 s 1.4 / 1.6 each, 2.6 aggregate e02735d4c9b7
"draft": false, 2 runs 86.44 / 86.59 s 0.8 each e02735d4c9b7
drafting on, 3 runs 36.02 / 36.02 s 2.0 each e02735d4c9b7

Three things this settles:

  • Drafting is 2.4x. 36.02 s against 86.44 s for the same 64 tokens, and the log agrees: accepted=41/67 rounds=23 against accepted=0/0 rounds=63.
  • Drafting does not change the answer. The "draft": false reply and the drafted reply hash identically, which is the contract tokens.zig:124 states ("drafted and "draft": false replies must match"). The format's row-invariance is what makes that hold.
  • Two streams do not double. Each drops to 1.28 tok/s from 1.78 solo (0.72x its own rate) while the pair together reaches 2.57 tok/s, 1.44x solo. So the second stream buys about half a stream, not a second one - the same shape as eight, less severe.

At --parallel 8 --context 32768, the same shape:

tokens wall tok/s reply sha
solo, 3 runs 128 66.02 / 65.88 / 66.00 s 2.1 each bf993d6b8399 each
8 concurrent 64 each 150.65-151.09 s 0.4-0.6 each, 3.4 aggregate e02735d4c9b7 each

Every concurrent reply is bit-identical, so the format and the row-invariant products hold under a shared round. What does not hold is throughput: eight streams reach 3.4 tok/s together, 1.6x a single stream rather than 8x, and each stream's TTFT degrades from 4.75 s to 9.5-37.6 s as the eight prefills queue behind each other (the log's queued= field lands at 4.3-4.7 s a request). Drafting collapses under the load too: accepted=83/131 solo against accepted=5/12 concurrent.

Prompt cache, measured

--prompt-cache-gib 4, --parallel 1, a 3162-token prompt, 16 tokens out, same prompt three times:

TTFT decode wall cached tokens sha
cold 230.6 s 8.20 s 239.0 s 0 d6fb55f2cf55
resumed 4.76 s 8.11 s 12.87 s 3136 of 3162 d6fb55f2cf55
resumed 4.74 s 8.12 s 12.87 s 3136 of 3162 d6fb55f2cf55

Prefill drops 48x and decode does not move (1.8 tok/s either way), which is the expected split: the cache restores the prompt's rows, not the round. The reply's bits are identical cold and resumed, so a restored prefix gives the same answer as one read from the start.

That is the same memory floor as the single-stream section: at 2.0 tok/s the card reads about 44 GB/s of the 240 GB/s it can sustain, so several streams have headroom to share and still only add up to 1.6x. A decode path that reached even a third of the floor would make these tables look very different, which is why the follow-up is the kernels and not this PR.

Not measured: one MLX checkpoint's reply on main against this branch. It cannot be measured for a ModelOpt checkpoint, since main refuses the format by name and never loads it - which is the point of the PR.

@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Thanks, @ElderOrb. Serving ModelOpt NVFP4 and FP8 Qwen3.5 checkpoints on HIP through the BF16 rocBLAS path is in scope. A few things first:

  1. The served weights aren't the checkpoint's. weights/modelopt.zig:73 and :90 round each dequantized weight to BF16. Code × E4M3 block scale fits BF16 exactly, and so does a bare E4M3 value. The FP32 global and per-tensor scales don't, and the product is rounded twice (f64, then f32, then BF16). We take no lossy weight formats (docs/pr/SKILL.md:74). Please widen only the exact part and apply those scales to the f32 sum, as CUDA does (qmmf.cu:89), or refuse any tensor BF16 would round.
  2. The memory preflight: engine.zig:71 counts stored bytes, but the device holds 2 bytes a weight, about 3.5× NVFP4's stored size. Please count the widened size, so WeightsDoNotFit still refuses a checkpoint that doesn't fit.
  3. Admission: please go through core/modelopt.zig, so unsupported recipes, E4M3 NaN scales and a zero, Inf or NaN global are refused by name. Please also refuse qwen3_5_moe ModelOpt experts, which still load through experts.routed unwidened, or say how they load.
  4. Tests: the one test's values are all powers of two, so nothing rounds. Please add tests against core/quant/nvfp4.zig's f64 reference, with FP8, values that would round, and a zero global, and show them failing before the change.
  5. hip/memory.zig:84 puts every HIP upload, for every family, in 64 MiB windows. Please split that into its own PR, or explain why it belongs here.
  6. A CHANGELOG line ending "(hip: ModelOpt NVFP4 and FP8 checkpoints keep their codes and decode in flight #2490). Thanks to @ElderOrb.", and a rebase: hip/engine/mtp.zig, hip/engine/native.zig and weights/projection.zig conflict with main.

We have no AMD GPU, so please post your own main-against-branch numbers, naming the gfx target, along with drafted replies equal to "draft": false.

@ElderOrb
ElderOrb force-pushed the hip-nvfp4 branch 4 times, most recently from 54ade02 to 5b32fc7 Compare November 8, 2026 23:34
@ElderOrb ElderOrb changed the title hip: serve ModelOpt NVFP4 and FP8 checkpoints as BF16 (Windows + ROCm) hip: ModelOpt NVFP4 checkpoints keep their codes and decode on the tiles Nov 8, 2026
@ElderOrb
ElderOrb force-pushed the hip-nvfp4 branch 3 times, most recently from 655c707 to bba2f2b Compare November 8, 2026 23:56
@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@ElderOrb thanks, keeping the codes as stored is a much better design: the NVFP4 weights are now the checkpoint's, the E4M3 → BF16 table is exact, the NaN and zero-global refusals are in, and admission goes through core/modelopt.zig. On the format tag: please use the HIP-local type you offered, so core keeps no Format tag. What's left:

  1. FP8 still rounds: weights/modelopt.zig:60 rounds e4m3 × scale to BF16, twice. Widen the bare E4M3 (exact) and apply the scale to the f32 output, or refuse FP8 layers. Please also refuse per-row and zero FP8 scales (:51-55).
  2. F32 block scales: read keeps them F32 (core/quant/nvfp4.zig:70,98), but the stream tile reads every table entry as BF16 (nvfp4_decoder.hpp:180-183). Please refuse F32 block scales, since ModelOpt writes E4M3.
  3. Row invariance: ops/project.zig:431 sends decode rounds over 16 rows to the GEMM, so a row's bits depend on the round's size. Please choose by o.prefill alone, as the MLX path does, with a test of 17 rows against one.
  4. rocBLAS: these checkpoints now serve chat, but their BF16 linears (widened FP8 layers, the MTP head, an unquantized lm_head) run on rocBLAS, whose products vary with rows (engine.zig:195). Please post concurrent = solo and drafted = "draft": false on your gfx target, or route those layers through the row-invariant kernels.
  5. Kernel contract: please register tf_nvfp4_gemm and the 8 stream entry points with hip_records, and post hip-kernel-contract on your chip and -limits for every served target. That also re-checks the MLX stream tile after the stream.hpp edit.
  6. Other targets: nvfp4_wmma_gemm (nvfp4_tiles.hpp:32) compiles on every target. Please guard it as TF_MATRIX does (or drop the unused wrappers), and confirm gfx1100 and gfx1201 build.
  7. Preflight: please count FP8 layers at 2 bytes a weight and the scale table at 2 bytes a group (engine.zig:69-75).
  8. Tests: please add a non-power-of-two global, an FP8 case and the qwen3_5_moe refusal, show them failing before the fix, and say whether the kernel tests ran on the card.
  9. Housekeeping: one-line comments (core/quant/nvfp4.zig:1-5, launches/nvfp4.zig:1-4, the .hpp headers); the stale doc at config.zig:43; route by recipes or drop the field; drop the docs' RDNA2 claim (engine.zig refuses fp16); drop the windows commit (landed as hip: upload large tensors in windows so the blit can pin them #2584); end the CHANGELOG line "(hip: ModelOpt NVFP4 and FP8 checkpoints keep their codes and decode in flight #2490). Thanks to @ElderOrb."

We have no AMD GPU, so please post main-against-branch numbers, naming the gfx target.

@ElderOrb

ElderOrb commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased and reworked since your note; the body above describes the current state. Summary of what changed:

  • The shared tiles are gone from this path. Both step along K in 32-code chunks (kGemmK = 32, nch = a.k >> 5, a chunk's scale index q >> gshift), and NVFP4's group is 16, so a chunk holds two scales: a.group / kGemmK is 0 and the shift would have to be negative. quant/nvfp4_tiles.hpp is now one product kernel, tf_nvfp4_gemm plus tf_nvfp4_gemm_f16; tiles/stream.hpp and tiles/dot2_tiles.hip keep only their MLX code, so the MLX stream tile needs no re-check from this change.
  • Row invariance by construction: one kernel for every row count, so ops/project.zig no longer picks by m and a row's bits cannot depend on its round.
  • Preflight: table.deviceBytes counts what the device holds (U8 codes as stored, an E4M3 tensor at 2 bytes a value) instead of the stored files, with a host test.
  • F32 block scales are refused (unfit), and the reader no longer keeps one; the kernel reads a 16-bit table only.
  • recipes field dropped; it was admitted and then unused. The stale note at weights/config.zig is corrected and the module and header comments are one line each.
  • Evidence on the card: zig build hip-kernel-test -Dhip-arch=gfx1151 on a 8060S is 19/19, with two NVFP4 kernel tests: the product at one row, three and five against quant.nvfp4.reference (2e-4), and a row's bits alone against a round of four (bit for bit). zig build test on Windows passes.

Still open, and in the body: the Format tag in core (needs the family-local projection type on both host and device sides), hip_records registration plus hip-kernel-contract/-limits, and FP8 exactness. On FP8 I would rather not pick for you: the scaled f32 product CUDA uses (qmmf.cu) is the exact one, and refusing FP8 layers refuses mixed checkpoints outright. Which do you want?

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @ElderOrb, this is a much better shape. The codes and E4M3 tables stay as stored, one product kernel serves
every row count, F32 block tables are refused, the preflight counts what the device holds, the recipes field and the
windows commit are gone, and the kernel tests ran on your 8060S. Thanks too for the clear account of why the shared
tiles can't take a group of 16.

On your FP8 question: the exact route, please. Widen the bare E4M3 values (exact in BF16), sum in f32, and apply the
per-tensor scale once to the f32 result, as CUDA's reduce does (zig/kernels/cuda/qmmf.cu:92). A sibling of your
NVFP4 kernel that decodes E4M3 in flight would do that, and it would also keep those layers row-invariant and off
rocBLAS. If that makes this PR too big, refuse FP8 layers by name here and bring the FP8 product as its own PR.

What's left, smallest first:

  1. Docs and comments.
    • docs/quantization.md:140 still says FP16 where a card has no BF16 dot2. But engine.zig:208-212 refuses fp16 for
      this path, so tf_nvfp4_gemm_f16 can't run either.
    • docs/quantization.md:142 and the CHANGELOG line say "a quarter of the bytes". Codes plus a BF16 scale per 16
      come to 5 bits a weight on the device, about 31 %.
    • Some comments still describe the old version: hip/ops/project.zig:410 ("the dot2 tiles"),
      hip/kernel_tests/nvfp4.zig:1 and weights/checkpoint.zig:60 ("dequantizes"). There's also a dead branch at
      weights/modelopt.zig:59.
  2. One rounding for the global. quant/nvfp4_tiles.hpp:51 multiplies each group scale by the global, which is a
    rounding per group. Each E4M3 scale is exact in f32, so fold each group with its own scale and apply the global
    once to the sum.
  3. The kernel test's bound. 2e-4 (kernel_tests/nvfp4.zig:104) is far looser than an f32 sum needs at K ≤ 128.
    Please use the derived bound the dense test uses (kernel_tests/dense.zig:35-41) and log the worst error.
  4. Tests still owed from last round. A non-power-of-two global (every global in the tests is 0.25, 0.5, 1 or 2),
    an FP8 case, and qwen3_5_moe ModelOpt experts refused by name with a host test. Please show each one failing
    before its fix.
  5. The BF16 layers on rocBLAS. A text-only ModelOpt checkpoint isn't chatBf16 (engine.zig:80-84), so its BF16
    lm_head and widened layers take rocBLAS (project.zig:52-61), whose products vary with the round's rows. Please
    route them through the row-invariant dense kernels, as the chat path does, or show drafted equal to "draft": false
    and concurrent equal to solo on the card. The MTP head on rocBLAS is fine, since its drafts are verified.
  6. The Format tag out of core (core/quant/types.zig:10), as you offered.
  7. Kernel contract. Please register tf_nvfp4_gemm in hip_records, post hip-kernel-contract on gfx1151 and
    -limits for the served chips, and confirm that gfx1100 and gfx1201 build.
  8. Served numbers on your card, naming the gfx target: decode and prompt tok/s, drafted equal to "draft": false,
    concurrent equal to solo, and resumed equal to fresh.

We have no AMD GPU, so your numbers are the receipt for this one. Main is closed for a release right now, but none of
this needs to wait for that.

@ElderOrb
ElderOrb force-pushed the hip-nvfp4 branch 3 times, most recently from cb32ea6 to 6b1b659 Compare November 10, 2026 15:38
@ElderOrb

Copy link
Copy Markdown
Contributor Author

3. Contract on the record toolchain — gfx1151

Both ends measured with the toolchain the records were produced on: HIP 7.2.26024-f6f897bd3d, AMD clang version 22.0.0git.

tree zig build hip-kernel-contract-limits problems FAIL lines per-chip FAIL PASS
head 9536f8bc1 77/79 steps, run step exits 1 703 703 171/176/176/180 270
base 8cbef9777 same 703 703 171/176/176/180 246

Sorting both logs' FAIL lines and diffing them (Compare-Object) gives no differences: the PR adds zero contract problems and +24 passes — exactly the 24 ModelOpt rows, all PASS with the recorded numbers:

  • nvfp4 product: 138/38, 144/38, 144/38, 143/36
  • fp8 product: 58/49, 56/49, 56/49, 58/48
  • col1: 130/22, 138/22, 138/22, 138/23
  • col2: 164/26, 165/26, 165/26, 164/28
  • col3: 148/31, 145/30, 145/30, 147/34
  • col4: 121/32, 141/32, 141/32, 144/38

One correction to what I posted earlier: the 540 figure came from a local clang 24 toolchain, not the record one. On the record toolchain the inherited count is 703, and head and base agree on it line for line.

4. Test counts — gfx1151

zig build test -Dhip=true at 9536f8bc1, same machine, record toolchain:

Build Summary: 733/735 steps succeeded (1 failed); 3977/4100 tests passed (121 skipped, 2 failed)

The two failures are zig/src/families/flashnext/hip/tables.zig:483 and :517 (the "parked pool" gather tests). They cannot pass off Linux — host_pages.zig:109 returns cold() == false unconditionally when builtin.os.tag != .linux, so the pool is never woken. That file is untouched by this PR and byte-identical to base; pre-existing.

The lower total than the earlier number I quoted (10048) is the CUDA tests: this box has no nvcc, my local Windows box does (CUDA 13.2). Same 733/735 steps and the same two failures either way.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @ElderOrb for the test counts and the record-toolchain correction. The earlier items are still open: the FP8 16-row path needs the tile's per-chunk partial and a one-row against 17-row test for both formats. We also still need the four-chip records, the gfx1151 contract and test counts, the refreshed body, the rocBLAS gate decision, a squashed series and one MLX reply equality against main.

This head also conflicts with current main in zig/src/core/quant/quant.zig, so please rebase when you post the fix.

  • Synthena

@ElderOrb

Copy link
Copy Markdown
Contributor Author

8. One MLX checkpoint's greedy reply: equal on main and on this head

Checkpoint mlx-community/Qwen3.5-2B-MLX-4bit at 93760be4f1f69842a46bc13dbdc0f19e291392a3; model.safetensors sha256 713fe7e5d3c3965f7106b0d0ee17615f7869c23c8d327996df8c1196fbcf07d5, the LFS oid Hugging Face publishes for it.

Both trees built the same way on gfx1151: zig build native-hip -Dhip=true -Dhipcc=<record hipcc>, HIP 7.2.26024-f6f897bd3d, AMD clang 22.0.0git, both binaries tensorfold-native 1.2.9:

  • main = 61fe90343
  • this head = 9536f8bc1

Serve flags identical on both: serve <checkpoint> --backend rocm --no-thinking --context 4096 --parallel 1 --prompt-cache-gib 1. Both log HIP gfx1151 device 0, model 0.99 GiB, sampling: greedy.

Two greedy requests, temperature: 0, fixed seeds, stream: false:

prompt main this head
"Write the integers from 1 to 20 in order, separated by single spaces, and nothing else." 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 — 51 tokens, finish_reason: stop byte-identical, 51 tokens, stop
"Explain in about 150 words why the sky appears blue, then list the three primary colours. Do not use markdown." 111 tokens, 597 characters byte-identical, 111 tokens

Both replies compared with -ceq over the whole string, not a token window; completion counts and finish_reason agree, so nothing diverged and the head did not cut short.

The second reply, from the head, in full:

The sky appears blue because sunlight, which is white, contains all visible colors. When sunlight reaches the Earth's atmosphere, it interacts with gas molecules like nitrogen and oxygen. These molecules absorb the longer wavelengths of red and orange light while scattering the shorter wavelengths of blue and violet light in all directions. This scattering process, known as Rayleigh scattering, is most effective for shorter wavelengths. Consequently, when you look up, your eyes receive the scattered blue light, making the sky appear blue.

The three primary colours are red, green, and blue.

main produced the same text.

One note on the build: lighton_ocr.hip:182 still refuses M_SQRT1_2 on this toolchain, so a local 0.70710678f shim went into both trees to compile. That file is identical in both and is not touched by this PR; the 2B path does not reach it.

On the conflict: this head applies to 61fe90343 with a three-way apply, all 37 files clean, and GitHub reports mergeable: true, mergeable_state: clean. The overlap you saw is real in the sense that main added pub const gptq beside our nvfp4 doc line, but the hunks do not collide. I will still rebase onto 61fe90343 when I squash, since the series has to be rewritten anyway.

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

I ran the same Linux x86_64 host check with Zig 0.17.0 on 83d529371, main 124052c97, and their trial merge:

zig build test-qwen35 test-qwen35-hip-host hip-host-test check-native-hip-host \
  -Dhip=true -Dfixed-cpu -j5 --summary all

The PR head passed 257 tests with four skips, and main passed 260 with four skips. Git merges the two cleanly, but the combined tree fails to compile at zig/src/families/qwen3_5/backend/hip/forward/prompt_tail.zig:63: main's isDense compares p.handle to .dense, and the PR makes that handle an optional tagged union. Changing the return to p.format() == .dense in the scratch merge restored both affected targets. The full rerun passed 271 tests with four skips.

The head also contains the requested FP8 and NVFP4 one-row versus 17-row cases at K=192, and the FP8 small tile resets its partial inside the 64-code loop. Those GPU cases still need a device receipt for the rebased head from zig build hip-kernel-test -Dhip=true on the AMD box.

Retested the updated head 6aac7db4. It passes the same 257 host tests with four skips on its own. The clean trial merge into 124052c97 still hits the isDense type error. The same one-line change restored the two build targets again, with 271 tests passed and four skipped on a fresh local build cache.

Igor Lessio - AIFLOW LABS

@ElderOrb
ElderOrb force-pushed the hip-nvfp4 branch 2 times, most recently from 6aac7db to e57bc11 Compare November 20, 2026 16:13
@ElderOrb

Copy link
Copy Markdown
Contributor Author

Merge into main: fixed in the branch

Thank you - that is exactly the break, and it was mine to fix. main's zig/src/families/qwen3_5/backend/hip/forward/prompt_tail.zig:63 read return p.handle == .dense;; this branch makes Projection.handle an optional tagged union, so the trial merge stopped building there while the head built alone.

The branch is now rebased onto main at b7298b4ea and carries your one-line fix, return p.format() == .dense;, as part of the change: e57bc1132 (one commit, 39 files). So the merge into b7298b4ea is now the branch itself, not a trial merge.

What I ran on that head, on this box (Windows, HIP 7.2.26024-f6f897bd3d, AMD clang 22.0.0git, -Dhipcc=<record hipcc>):

  • zig build test-qwen35 test-qwen35-hip-host check-native-hip-host -Dhip=true -Dfixed-cpu - exit 0. That is the set that failed to compile in your trial merge; it compiles and passes now. (hip-host-test is not a step on this tree; the other three are.)
  • zig build hip-kernel-test -Dhip=true on gfx1151 - the FP8 and NVFP4 cases you named ran on the device: fp8 96x192 rows 1 0.004 and rows 17 0.008 of the derived bound; nvfp4 96x192 rows 1 and rows 17 both 0.000. Same kernel, one row against a round of seventeen at K = 192.
  • zig build native-hip still builds tensorfold-native 1.2.9 on this head.

One caveat on that device run, since you asked for a receipt rather than a claim: the suite's last group (nemotron) ends in a round could not be recorded: OutOfDeviceMemory on this host and the build step reports a failure at the end. Everything this PR touches runs before it and passes; the pool here is 32 GB of visible RAM, and I have not yet run the same step on plain main to say whether that tail is this host or the branch. I will follow up with that comparison rather than assert it.

Also for the record on the merge itself: after the rebase, git diff --name-only b7298b4ea e57bc1132 is 39 files and git diff b7298b4ea e57bc1132 -- zig/src/families/qwen3_5/backend/hip/forward/prompt_tail.zig is the one line above.

Igor - thanks for running the trial merge twice and pinning the line; that is the kind of report that makes this cheap.

@ElderOrb

Copy link
Copy Markdown
Contributor Author

Follow-up: the OutOfDeviceMemory tail is the host, not the branch

I said I would check rather than assert, so: zig build hip-kernel-test -Dhip=true on plain main at b7298b4ea, same box, same toolchain, stops at the same place as this head and with the same message:

nemotron fc1 and shared up in one launch: 8 rows, the bytes of two launches
[default] (warn): a round could not be recorded: OutOfDeviceMemory
failed command: .\.zig-cache\o\.../test.exe

Identical line, identical position, one failed command, and the step's exit is 0 on both - so the recording that cannot allocate its round is main's nemotron case on a 32 GB host, not something this branch brings.

What this head's run did reach on gfx1151, before that point (worst |got - want| as a fraction of the derived bound, one row against a round of seventeen at K = 192):

case rows 1 rows 17
nvfp4 96x192 0.000 0.000
fp8 96x192 0.004 0.008

and the same run prints the 64x64, 160x128 and 48x96 tile cases, all inside their bound.

Two more numbers from the same head, since the body now carries them:

  • zig build -Dhip=true test: 769/772 steps, 10344/10594 (247 skipped, 3 failed) here, against main's 769/772 steps, 10322/10572 (247 skipped, 3 failed) on the same host. Same three failures, both files untouched by this PR.
  • hip-kernel-contract-limits: 847 FAIL lines on both trees, 207 / 212 / 212 / 216 per chip, Compare-Object reports no difference; PASS 292 here against 268 on main, the +24 being the ModelOpt rows.
  • tools/zig/lean_check.py: 168 problems on both, no difference; engine.zig is 590 lines against main's 575, and the merge's is 590 as well.

The head is e57bc1132, one commit on b7298b4ea.

@ElderOrb

Copy link
Copy Markdown
Contributor Author

Rebased, and CI is green

main moved twice since your note, so the head is now 4c0be9632 on 72ebe5f6e (one commit, 39 files). All 12 checks pass: zig, zig-b, zig-windows, zig-macos-dev-tools, fmt, pytest, release-paths, benchmark-clients on both platforms and comfyui-moss-installer; the two nightly jobs skip.

What I re-ran on this base: tools/zig/lean_check.py (167 problems here, 167 on the base, no difference), zig fmt --check on the changed files, and the host targets (test-qwen35, test-qwen35-hip-host, test-native-hip-host, check-native-hip-host, -Dhip=true -Dfixed-cpu) - all pass. The merge is now this head, so the trial-merge break at prompt_tail.zig:63 cannot come back.

The device numbers in the body (tests, contract limits, hip-kernel-test) are still the ones measured at e57bc1132 on b7298b4ea: the card is serving another model right now, so I did not displace it. Say the word and I will re-measure them on this head once it is free.

@AIFlowML

Copy link
Copy Markdown
Contributor

The rebased 4c0be9632 applies cleanly to main 1eed88bb0. I also checked it against #4466 at 3d443e8f0, which carries the HIP DFlash2 parent. The only textual overlap is in zig/src/families/qwen3_5/backend/hip/engine/native.zig. Keep the train's served(e, d, streams, capacity, readouts) call so admission still counts the drafter's scratch.

With that one hunk resolved, all 21 build steps passed on M5 Max with Zig 0.17.0, including the HIP native build check. The host targets passed 171 tests with two skips:

zig build test-qwen35-hip-host test-native-hip-host test-draft-hip-host \
  test-qwen-hip-formats-host check-native-hip-host -Dhip=true -Dcpu=apple_m1 -j4 --summary all

This verifies the combined admission and format paths at host level. The gfx1151 device receipts are separate.

Igor Lessio - AIFLOW LABS

@ElderOrb

Copy link
Copy Markdown
Contributor Author

Ready for review: all checks green

Head 8a8bec665 on ce0264367. All 12 checks pass (10 success, the two nightlies skipped), mergeable_state: clean.

The zig failure on the previous head was main's, not this branch's: request_admission_http_test.zig:503 lost a race when a client walked away and the engine had not yet taken all four choices. aec48047e/17a554e16 fix that wait, and this rebase carries them; the file is not in the diff.

Re-ran on this base: tools/zig/lean_check.py (165 problems here, 165 on ce0264367, no new ones), zig fmt --check on the changed files, and the host targets (test-qwen35, test-qwen35-hip-host, test-native-hip-host, check-native-hip-host, -Dhip=true -Dfixed-cpu) - all pass.

The device receipts in the body are still the ones from e57bc1132 on b7298b4ea; the card here is serving another model, so I left it alone rather than displace it.

@ashhart - open for a look whenever you have a slot. Every point from your last review is addressed and nothing is outstanding on my side.

@ElderOrb

Copy link
Copy Markdown
Contributor Author

/atc exchange 499dad70edb8224aaedcb30875f061f11946e3a56e6edd167a00adfab831583d

@ElderOrb

Copy link
Copy Markdown
Contributor Author

Rebased onto current main

Head is now 460f5ea26 on 0300dfbfe (was 8a8bec665 on ce0264367), so the branch no longer trails main.

The replayed patch is byte-identical to the version reviewed before: the same 39 files in the same order. The diff differs only in @@ hunk offsets, where upstream's CHANGELOG.md grew by about 41 lines. No code or prose changed.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @ElderOrb for the ModelOpt kernels, the row-invariance checks, and the repeated rebases. Two host loading cases still need fixes:

  • A single-format ModelOpt FP8 config currently falls through to NVFP4 validation and is refused before the FP8 tensor reader runs. Please admit plain FP8 explicitly while preserving NVFP4 and mixed-recipe validation and the other unsupported-algorithm refusals. A config-parsing success fixture and an unsupported-algorithm refusal fixture would cover this; the existing assertion that expects plain FP8 to fail will need updating.
  • Qwen-shaped MTP loading always splits the fused mtp.fc, but the FP8 split currently returns UnevenSplit. Please split FP8 along K into two contiguous code halves, preserving row order and sharing the projection's one F32 scale. A host fixture with the pre-FC norms and an FP8 fused FC should check both halves' shapes, code bytes, and scale.

These are host loader fixes; the existing kernel and output receipts do not exercise either trigger.

  • Synthena

A ModelOpt checkpoint writes NVFP4 as E2M1 codes with a 16-element-block
scale and one global scale, and FP8 as E4M3 codes with one scale, neither
of which the shared formats name. This reads both as they are stored and
decodes them on the device, so a converted checkpoint serves without being
re-quantized to MLX's layout.

NVFP4 keeps its E2M1 code through the BF16 dot2 product, which is exact
for the format's levels; FP8 decodes in flight and is exact in f32. Both
run through one 64 x 64 tile that stages a column chunk once and serves 64
rows, with a 16-row block for a decode round summing as the tile does.

The host projection is the family's own union of the shared formats,
`quant.nvfp4.Host` and a stored FP8, so core's format vocabulary keeps the
three formats both engines read. A routed expert stack stays core's: a
global scale an expert, so NVFP4 stacks are refused. A ModelOpt
checkpoint's bf16 layers read dense.

Scale handling carries the review's asks: FP8 scales ModelOpt does not
write are refused, as is a weight holding an E4M3 NaN code, and each
refusal names the tensor and the reason through core's `Why` buffer rather
than an uninitialised name.

A decode round on the product ran the 16-row block, which distributes its
threads over all sixteen rows while writing only a.m of them, so fifteen
sixteenths of the work is discarded at m = 1. The same header gains four
entry points, tf_nvfp4_col1 to tf_nvfp4_col4, over one
nvfp4_columns<ROWS, DEPTH>: a thread owns one output column, reads that
column's whole K span, and holds ROWS accumulators. The launch picks the
entry point whose ROWS matches a.m exactly, so no row is padded and a
row's offset stays constant.

They are separate entry points rather than a branch on a.m because the
contract records resources an entry point, and a branch would make every
variant carry the widest one's registers.

nvfp4_columns prefetches DEPTH chunks into registers and fetches the next
before the group loop consumes the held one. On gfx1151 at a 5120 x 5120
layer, m = 1: 0.0969 ms against 0.2516 ms reading each chunk in place,
2.6x, and 0.0580 ms for the prefetched form that follows the guard -
282.5 GB/s, 17.5x the single-chunk form. A guard clause that returns
early measured 2.6x slower at 22 VGPRs against 33, so the prefetch sits
after the guard rather than replacing it.

Against the product on the same host, m = 1: attention 5120 x 1024
14.86x, gate/up 5120 x 17408 4.96x, down 17408 x 5120 7.79x, lm_head
5120 x 151936 5.22x. At m = 2: 13.71x, 4.86x, 8.85x, 4.90x. Row variants
at 5120 x 5120: m = 1 9.81x, m = 2 9.92x, m = 3 7.33x, m = 4 7.03x, every
one bit-identical to the tile. A K that is not a multiple of 64 keeps its
tail on tf_nvfp4_gemm.

build/hip.zig's headers list becomes hip_headers.zig, which walks every
.hpp under zig/kernels/hip instead of naming them. The list it replaces
had gone three headers out of date - quant/nvfp4.hpp, nvfp4_tiles.hpp and
fp8_tiles.hpp were missing - so an edit to one left the .hsaco that
includes it stale, and the four new symbols then failed to resolve in
affine_tiles although they were compiled. A walked list cannot be left
out of, and hip.zig loses ten lines to it.

The product records name the tile's measured LDS on the four served chips.

`hip-kernel-contract-limits` on gfx1030, gfx1100, gfx1151 and gfx1201
after the 64 x 64 tile and the 16-row decode block: the tile stages a
column chunk in LDS, so NVFP4 holds 16384 bytes (was 11264) and FP8 18432
(was 12288), and FP8's scale and accumulator registers moved with it.
The four column entry points' records, measured on the same run (VGPRs /
SGPRs / LDS bytes):

- tf_nvfp4_gemm: 138/38/16384, 144/38/16384, 144/38/16384, 143/36/16384.
- tf_fp8_gemm: 58/49/18432, 56/49/18432, 56/49/18432, 58/48/18432.
- tf_nvfp4_col1: 130/22/0, 138/22/0, 138/22/0, 138/23/0.
- tf_nvfp4_col2: 164/26/0, 165/26/0, 165/26/0, 164/28/0.
- tf_nvfp4_col3: 148/31/0, 145/30/0, 145/30/0, 147/34/0.
- tf_nvfp4_col4: 121/32/0, 141/32/0, 141/32/0, 144/38/0.

All 24 ModelOpt lines read "record current" on all four chips, and the
run's problem count is the same as before this branch: 799 on the base
and 799 here, every line of them predating it.

Main's prompt tail names the shared handle's dense tag (prompt_tail.zig:63);
the handle is optional here, so it asks the projection's format instead.
A single-format ModelOpt FP8 checkpoint declares quant_algo FP8 and carries
no config_groups, so the config check fell through to the NVFP4 branch and
refused it before the FP8 tensor reader ran. admit and admitRecipes now take
one rule through singleFormat: NVFP4 checked as ModelOpt writes it, plain FP8
accepted per tensor. Sharing the one rule keeps the two entry points from
drifting, and every other algorithm is still refused by name; the grouped FP8
formats are named MXFP8 and FP8_PB_WO and stay refusals by module.

The Qwen-shaped MTP head always splits the fused mtp.fc, but the FP8 split
returned UnevenSplit. It now cuts the codes into two contiguous halves along
K, keeps every row in order, and shares the projection's one F32 scale
between them.

Tests: both entry points admit one ModelOpt FP8 config fixture, an INT4_AWQ
fixture is still refused by name, and an FP8 fused FC beside the pre-FC norms
checks both halves' shapes, code bytes and the shared scale.

zig build test: 6528 passed, 168 skipped, 0 failed.
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @ElderOrb. The plain-FP8 config admission and fused MTP FC split now address both loader asks, including the new fixtures and shared scale.

One build dependency still needs restoring: the .hpp scan drops attention/attention_fa.hip, although attention.hip includes it. An edit to that include can reuse an old code object. Please track it and add a dependency-list regression; a clean rebuild alone will not prevent later stale reuse.

Merged with current main, two HIP engine modules go over 600 lines; we'll split those on our side when we integrate, keeping the current admission behavior.

  • Synthena

@ElderOrb

Copy link
Copy Markdown
Contributor Author

Both host loader cases are fixed, in abb47ac9a (rebased onto current main; the zig/build/hip.zig conflict is resolved, so the branch is clean again).

1. Single-format ModelOpt FP8. admit and admitRecipes now take one rule, singleFormat: NVFP4 checked as ModelOpt writes it, plain FP8 accepted per tensor, every other algorithm still refused by name (the grouped FP8 formats are MXFP8 and FP8_PB_WO and stay refusals by module). Both entry points share the rule, so they cannot drift. Fixtures: zig/src/core/fixtures/modelopt_fp8/config.json is admitted by both entry points, and zig/src/core/fixtures/modelopt_int4/config.json is still refused by name. The assertion that expected plain FP8 to fail is updated, and the now-divergent one in admit is gone.

2. The FP8 fused mtp.fc. It now splits along K into two contiguous code halves, rows kept in order, the projection's one F32 scale shared between them (zig/src/families/qwen3_5/weights/host.zig). A host fixture with the pre-FC norms and an FP8 fused FC checks both halves' shapes, code bytes and the shared scale (weights/checkpoint_hf_test.zig).

Locally zig build test is green (6528 passed, 168 skipped, 0 failed) and test-qwen35 is green after the rebase; the full suite on this box is RAM-bound, so CI is the gate.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @ElderOrb. The plain-FP8 admission and fused MTP FC split remain fixed, including their fixtures and shared scale.

The later dependency request is still open: the header scan selects only .hpp, so it still omits the included attention/attention_fa.hip. Please track that input and add the dependency-list regression; a clean rebuild does not prevent stale cache reuse after a later edit.

The current merge is clean. The two module splits remain ours, preserving the existing admission behavior.

  • Synthena

This branch has not been deployed

No deployments
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.

4 participants