Skip to content

inkling2 on AMD: batched NVFP4 projections on pretiled WMMA (decode / verify rows 4-16) - #412

Merged
AzeezIsh merged 1 commit into
mainfrom
perf/inkling2-hip-batched-nvfp4
Nov 25, 2026
Merged

AzeezIsh merged 1 commit into
mainfrom
perf/inkling2-hip-batched-nvfp4

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

inkling2 on AMD: batched NVFP4 projections on pretiled WMMA (decode / verify rows 4-16)

On strix-hip the rows 2..16 Linear::Nvfp4 projections ran w4a16_gemv_batch8/16,
issue-bound at ~15-20% of the C8 step and ~21% of the DSpark verify step. This
routes rows 4..16 (N >= 1024) to a new pretiled split-K WMMA kernel derived
from Ciru AI's hip_moe_decode.hip source-NVFP4 decode GEMM (Apache-2.0,
attribution in the file header):

  • weights.rs: at load (AMD only) each Nvfp4 projection's packed E2M1 + E4M3
    scales are repacked by w4a16_wmma_pretile into the WMMA tile replay
    ([N/128][K/64][128][32] packed, [..][128][4] scale words) as extra device
    buffers beside the original q, so the rows=1 w4a16_gemv_sw path is
    untouched and bit-identical. ~560 MB extra device memory (same bytes,
    permuted).
  • w4a16_wmma: one block per 128 outputs x K slice, 8 warps, K64 software-
    pipelined bf16 WMMA, register-side NVFP4 unpack with the same E2M1 decode
    and scale math as the GEMV path, zero smem for B, next-tile prefetch.
    gridDim.y splits K (host picks 1-8 slices by shape) into f32 partials;
    w4a16_wmma_reduce sums them to BF16 (order-exact adds, deterministic).
  • Routing is measured: rows 2-3 and the N=384 rel-bias projection stay on
    w4a16_gemv_batch8/16 where WMMA's fixed per-launch cost does not pay off;
    the remaining shapes gain ~1.75x at M=8.

Microbench (us/call, M=8, cold weights): 3072x2304 batch8 57.4 -> 32.9
(121 GB/s); 1024x2304 batch8 19.5 -> 12.5 (106 GB/s); 2304x3072 batch8
51.6 -> 32.5 (122 GB/s); relbias 384 stays on batch8. M is flat on the
WMMA side; batch8 still wins at M <= 3.

Gate vs main 7a717b6 (bin 2a4d92163021), start-script serve (prefix
cache, batch 8): greedy C1 spark+strict IDENTICAL (mean|dlp| 0.00000);
decode_h2h C2 51.5=51.5, C4 69.4->70.7, C8 89.6->93.6; task_probe
30/30+10/10 all arms; pd_check 6x96/96 aligned within f373 noise; NLL
unchanged; 0 ERROR/panic/illegal on every arm; C8 rocprofv3 shows
w4a16_wmma 22.1 us/call at 6.4% of GPU (was batch8 47 us, 15.5%).

First of a linear stack of AMD Inkling 2 Mini perf PRs (PR-2: flash prefill attention, based on this branch). AMD-only (cfg!(atlas_scale) + a strix-hip-only kernel file); gb10 untouched. DevLab strix-hip build 45338457830: success.

Generated with Devin

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Queued in train #421 (integ/train-inkling-20261125), merged --no-ff in stack order. GB10 gate is running on sparky (job 187); results will be posted on #421.

🤖 Generated with Claude Code

… verify rows 4-16)

On strix-hip the rows 2..16 Linear::Nvfp4 projections ran w4a16_gemv_batch8/16,
issue-bound at ~15-20% of the C8 step and ~21% of the DSpark verify step. This
routes rows 4..16 (N >= 1024) to a new pretiled split-K WMMA kernel derived
from Ciru AI's hip_moe_decode.hip source-NVFP4 decode GEMM (Apache-2.0,
attribution in the file header):

- weights.rs: at load (AMD only) each Nvfp4 projection's packed E2M1 + E4M3
  scales are repacked by w4a16_wmma_pretile into the WMMA tile replay
  ([N/128][K/64][128][32] packed, [..][128][4] scale words) as extra device
  buffers beside the original q, so the rows=1 w4a16_gemv_sw path is
  untouched and bit-identical. ~560 MB extra device memory (same bytes,
  permuted).
- w4a16_wmma: one block per 128 outputs x K slice, 8 warps, K64 software-
  pipelined bf16 WMMA, register-side NVFP4 unpack with the same E2M1 decode
  and scale math as the GEMV path, zero smem for B, next-tile prefetch.
  gridDim.y splits K (host picks 1-8 slices by shape) into f32 partials;
  w4a16_wmma_reduce sums them to BF16 (order-exact adds, deterministic).
- Routing is measured: rows 2-3 and the N=384 rel-bias projection stay on
  w4a16_gemv_batch8/16 where WMMA's fixed per-launch cost does not pay off;
  the remaining shapes gain ~1.75x at M=8.

Microbench (us/call, M=8, cold weights): 3072x2304 batch8 57.4 -> 32.9
(121 GB/s); 1024x2304 batch8 19.5 -> 12.5 (106 GB/s); 2304x3072 batch8
51.6 -> 32.5 (122 GB/s); relbias 384 stays on batch8. M is flat on the
WMMA side; batch8 still wins at M <= 3.

Gate vs main 7a717b6 (bin 2a4d92163021), start-script serve (prefix
cache, batch 8): greedy C1 spark+strict IDENTICAL (mean|dlp| 0.00000);
decode_h2h C2 51.5=51.5, C4 69.4->70.7, C8 89.6->93.6; task_probe
30/30+10/10 all arms; pd_check 6x96/96 aligned within f373 noise; NLL
unchanged; 0 ERROR/panic/illegal on every arm; C8 rocprofv3 shows
w4a16_wmma 22.1 us/call at 6.4% of GPU (was batch8 47 us, 15.5%).
@AzeezIsh
AzeezIsh force-pushed the perf/inkling2-hip-batched-nvfp4 branch from 258d9a5 to fbb7f4f Compare November 25, 2026 10:56
AzeezIsh added a commit that referenced this pull request Nov 25, 2026
…logue bound

#412 and #413 were re-pushed with one change: w4a16_wmma's prologue loads
a K group's first weight tile only when the slice has one (a short last
slice read one tile past the pretiled buffer; HSA memory fault on a 16-row
Spark prefill chunk, DevLab 45568957561 / 45587106711). The earlier heads
are already merged above; this brings in the fixed ones.

# Conflicts:
#	kernels/strix-hip/inkling-2-mini/nvfp4/inkling2_w4a16_wmma.cu
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

The re-pushed head (with the guarded w4a16_wmma prologue) is in train #421 at 26c2a7ac7. DevLab Strix serves Spark again: C1 42.7 tok/s, C8 84.3. The old head faulted on the first 16-token Spark prefill chunk (bisect on #421).

🤖 Generated with Claude Code

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Runner + framework verification at fbb7f4fe6 (tree == 258d9a502, the gated head)

  • The squash initially dropped the split-K prologue bound (kgrp < ktiles). The k/v projections (N=1024, K=2304, 8 splits) read one tile past the buffer. That collapsed ST-995 to 11.06 at the old head, with a hipErrorIllegalAddress in w4a16_wmma. The bound is restored here, and the tree is diff-identical to the head these legs ran on.

  • ST-995 Spark (runner, run 45567019538): 79.10 / 79.63, 0 faults. Identical to main's 79.10 / 79.63.

  • agentic-webserver ×10 Spark (runner, run 45575386118): 10/10, 7.45 s/turn, 0 faults.

  • Framework, fresh build:

    • Greedy C1 is identical to main in both modes, since the rows = 1 path is untouched.
    • task_probe 30/30 + 10/10.
    • pd/NLL unchanged.
    • A replay of 150 bfcl requests (MAX_BATCH 4, prefix cache on) ran clean, with 0 hipError.
  • Speed vs main 7a717b6, aggregate tok/s:

    C1 C2 C4 C8
    framework, main 42.3 51.5 69.4 89.6
    framework, this PR 42.4 51.5 70.7 93.6
    runner, main — — 63.2 80.4
    runner, this stack — — 66.2 85.3
  • CI: the workspace jobs pass. Env budget (1139 = main), the PR benchmark gate and cargo deny fail on main too.

@AzeezIsh
AzeezIsh merged commit 73dcd4c into main Nov 25, 2026
24 of 27 checks passed
AzeezIsh added a commit that referenced this pull request Nov 25, 2026
…ute.rs, code moves only)

#408, #412 and #414 each grew glue.rs; merged it is 505 lines and the
file-size-cap job fails. The router top-k and the KV page write move as is
to a second impl block in glue/route.rs (446 + 74 lines).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AzeezIsh added a commit that referenced this pull request Nov 25, 2026
Prefill: 1,362 -> 1,525 tok/s @7.7K and 1,109 -> 1,383 @31k on framework
(hipcc 7.13); runner (hipcc 7.16) 1,192/954 -> 1,327/1,174 (+11%/+23%)
after staging V as fp16 in LDS, which drops 7.16 VGPR spill slots
128 -> 16 (fused softmax row staging; no tm/pv temporaries).

pd_check 96/96 aligned x6 prompts, mean|dlp| 0.0046-0.0188 (f373 noise);
NLL code 0.63684 (-0.00005), text 0.89670 (+0.00052, accepted:
flash accumulation order + fp16 P on AMD; pd within noise).
task_probe math 30/30 + tools 10/10 spark and strict; agentic 10/10.
gb10 inkling-2-mini PTX byte-identical to main.

ST-995 (bfcl-subset n=995): 77.99/78.19 vs main's 79.10/79.63.
Per-sample rescore vs #412-only responses: 57 verdict flips,
34 lost / 23 gained (-1.11 net); two-sided sign test p ~= 0.19,
indistinguishable from accumulation-order noise at temp 0.
Deterministic across reruns (bit-identical rerun).
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.

1 participant