Repository navigation
npu: the w4g32 M=16 decode family under NPU_W4_PREFILL (int8 role images no longer packed; decode GEMMs 11-12x) - #2633
Conversation
…packed With NPU_W4_PREFILL, each role that has an int8 _m16 twin also opens <prefill stem>_w4g32_m16.elf, all roles or none. ctx_for() routes decode-width layer GEMMs to those contexts. A weight-cache fill then builds only the w4g32 image: the int8 role images, about 26 G on bonsai2-27b, are never packed. Both images together OOM-killed a 27B run on 2026-11-15. The int8 twins stay as the LM head's context (pick_ctx int8_only), because the head's own tile images are int8. - q4nx_w4g32.h: the A tile height follows the design (a_tile_rows: 32 for M % 128 == 0, 16 for M == 16); init_elf accepts M == 16. - The layout ctest checks pack_a at M=16/128/512 against the restated formula. Its device-vector leg reproduces C_ref on M=16 sets (U seed, D edge). The gate ctest accepts M=16. - NPU_M16_CHECK skips a mixed-layout pair. Kernels: npu-kernels W4-g128 G32H built at M=16 (one core row). All six 27B roles are bit-exact x3 on signed-seed and edge sets, 11.3-12.4x the int8 _m16 kernels (U 2.38 vs 27.3 ms). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s per process The first device run of the family failed on its 17th distinct hw_context (D's _w4g32_m16): npu runtime: device error (code 102): Invalid argument amdxdna: aie2_xrs_load: create context failed, ret -22 The 16 already open were 6 w4 prefill + 7 int8 _m16 twins (G and U are separate files) + 3 w4 m16. With the family, the int8 twins serve only the LM head, whose tile images are int8. So when every role has its _w4g32_m16.elf, open_decode_family opens only the head role's int8 twin (the widest K = hidden design): 6 + 6 + 1 = 13 contexts. ctx_for serves an int8_only (head) request on a role without a twin from any int8 twin of the same K. design_index knows the w4 decode contexts. If the family still fails to open, decode-width GEMMs run the role's w4g32 prefill context: correct, slower, logged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PR Reviewer Guide 🔍(Review updated until commit 3f5e93b)Here are some key observations to aid the review process:
|
|
VERDICT at The motivation is a hard constraint, not a preference
That is the reason this PR exists: The correctness evidence is the same shape as
|
| role | w4 M=16 | int8 _m16 |
|---|---|---|
| U/G | 2.38 ms | 27.3 ms |
| QKV 14336 | 1.95 ms | 24.2 ms |
Both arms are 16-row designs over the same K and N, so the weight traffic differs by ~2× (4-bit vs 8-bit) and the activation traffic is identical. 11.3–12.4× is not explained by 2× fewer weight bytes, and a number that large invites the question: is the int8 arm the right arm?
Two possibilities, and the table should say which:
- A real kernel difference — the W4-g128 G32H design at M=16 has a different core-row/scheduling structure that the int8 16-row kernel lacks, and the int8 path is latency-bound on this geometry. Then the 11.5× is genuine and the table is the headline.
- The int8 arm is
#2611's twin case — the int8 "decode" ELF on this pack is the prefill design launched at 16 rows (which is exactly why#2611exists), so part of the 11.5× is a mismatched kernel rather than a better one. Then the comparison overstates the win and a genuine int8 16-row kernel would narrow it.
One line in the body naming the int8 ELF the column measures (and whether it is the twin-substituted one) settles it; the design decision does not depend on the answer, but the claim does.
Small note
npu-kernels W4-g128 G32H at M=16 is described as "one core row, 16 rows per A tile" — worth naming in the table's caption, since a reader comparing it with the M=128 design will otherwise wonder why the same kernel family shows two tile heights.
|
On the 11.5× question: it is possibility 1, a real kernel difference. The int8 arm is the pack's own decode kernel, not a mismatch. The int8 column is The mechanism: about 2× from bytes and about 6× from achieved bandwidth.
The int8 A better int8 16-row kernel would narrow the gap. The ceiling at the same ~20 GB/s would be about 2×, from bytes alone. That is a statement about the int8 kernel this pack ships, not a mis-measurement. Both points are now in the body: the ELF names, and why the family shows two tile heights. |
|
Persistent review updated to latest commit 3f5e93b |
|
A measurement after merge, because it changes how #2615's prefill number should be read. The warm 512-row prefill pass on bonsai2-27b with this decode family (only the w4g32 image resident) takes 43.3 s, with the layers at 30.2 s: 0.085 s/token. The same prompt and pass under #2615's dual-image build took 110.5 s, with the layers at 96.8 s. Most of the host time that looked "unattributed" under #2615 came from carrying both images, not from the forward itself. Run details: 1,024-token prompt, the second |
What
The w4g32 decode family. With
NPU_W4_PREFILL=1, decode-width (≤ 16-row) layer GEMMs run int4-weight M=16 kernels, and the int8 role images are no longer packed at all. Follows #2615, the M=512 prefill tier.Why
#2615 kept both images resident: int8 for the
_m16decode twins, plus w4g32. On bonsai2-27b-NPU that is about 1.5× the int8 weight footprint. On 2026-11-15 a 27B run with both was killed by the global OOM killer (shmem-rss 38.6 GB), so the tier was not safe to serve beside the box's other services.How
W4-g128G32H built at M=16 (one core row, 16 rows per A tile). All six 27B roles are bit-exact ×3 on signed-seed and edge sets. Medians against the int8_m16kernels, measured in the same ticket:_m16That is 11.3–12.4×.
The int8 column is
bonsai2-27b-NPU/kernels/full_i8_<ROLE>_K*_N*_m16.elf, the pack's shipped decode twins and the genuine 16-row design (md5-identical to its "prefill" ELFs, #2599). The gap is about 2× from bytes and about 6× from achieved bandwidth: U is 19.9 against 3.3 GB/s. On this box the pb16i M=16 kernel reaches 50.8 GB/s on D, so the int8_m16design is latency-bound there.Tile heights: the w4 M=16 design is one core row with 16-row A tiles. The M=512 prefill design is four core rows with 32-row A tiles.
a_tile_rows()encodes both.q4nx_w4g32.h: the A tile height follows the design (a_tile_rows: 32 for M % 128 == 0, 16 for M == 16).init_elfaccepts M == 16.XdnaTarget:<prefill stem>_w4g32_m16.elf, all or none.ctx_forroutes decode-width layer GEMMs there. A cache fill builds only the w4g32 image.init_elffailed (device error (code 102),aie2_xrs_load: create context failed, ret -22). So with the family, only the LM head's int8 twin opens, since the head's tile images are int8. That gives 6 + 6 + 1 = 13 contexts.int8_onlyrequest from a role without a twin gets a same-K int8 twin.pack_aat M=16/128/512 against the restated formula. Its device-vector leg reproduces C_ref on M=16 sets (U seed, D edge). The gate ctest accepts M=16.NPU_M16_CHECKskips mixed-layout pairs.Gate (bonsai2-27b-NPU, ticket cl-game-w4dec2)
NPU_W4_PREFILL=1 NPU_BATCH_CHECK=1 1bit npu-run … --ids <32>:w4g32 decode family: every decode role at M=16 (NPU_W4_PREFILL); int8 role images are not packedrows M=32 identical=32 differing=0, argmax MATCHThe sequential replay runs the M=16 kernels and the batched pass runs M=512. Both are integer-exact on the same image, so every row is bitwise equal, which checks the routing and the A pack end to end.
Measured (bonsai2-27b-NPU; same snapshot binary
1bit-5bdd23c; npu-hold tickets; 0 amdxdna lines in the timing runs)Decode, per token (median
[ph]step wall ofNPU_BATCH_CHECK's sequential replay; the first step, which includes the one-time weight fill, is excluded from the median):_m16twins (main)That is about 9.7× end to end, against 11–12× on the isolated decode GEMMs. From the isolated kernel times, the decode GEMMs are about 7.6 s of the int8 step and about 0.65 s of the w4 step. I have not split the rest of each step, so I am not claiming what it is.
Device note: a TDR and NPU power-cycle happened at 01:17:10 local inside this ticket's window, on PID 789671. That is not this run's process as far as the evidence goes: the run started at 01:17:15, took the exclusive device lock after the power-cycle, and completed rc 0. It is reported to the orchestrator, and no further device runs are made until it is cleared.
🤖 Generated with Claude Code