You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
npu: the i8 GEMM path's per-row int8 activation scale garbles tokens on Qwen2.5-3B (host f32 GEMM on the same container is right) #2536
On Qwen2.5-3B-Instruct (both the 1.9.0 NPU pack and the 1.7.1 hybrid pack, imported byte-exact), serve --device npu puts a garbage token into an otherwise right answer:
1.9.0: Neil Armstrong, on July 20, 1鹅1969
1.7.1: Neil Armstrong, on July 20, 1 lick this out 1969
The other Qwen2.5/Qwen2 packs measured today (0.5B, Coder-1.5B, 1.5B, Qwen2-1.5B) answer the same prompt cleanly.
It is the int8 activation quantisation, not the weights or the kernels
Measured on the 1.7.1 container at the failing position (chat prompt, 60 tokens, prefix ending ...July 20, 1, greedy):
NPU_INFER_HOST_GEMM=1 (f32 host GEMM, same container weights)
969,
HF fp32 Qwen/Qwen2.5-3B-Instruct
9 (p 0.985)
HF with RTN int4 g32 weights
9 (p 0.53)
The weights are fine: the f32 host GEMM on the very same container gives the right token.
The kernels are faithful: the device matches the host i8 arm.
Decode and prefill agree at 39/39 positions of that reply, so it is not a decode-path or KV bug.
What breaks it is the per-row amax/127 int8 activation scale. Qwen2.5 has a few very large activation channels, and with one scale per row they leave the other channels a handful of int8 levels.
A prefill-only teacher-forced check (64 positions on plain-text prompts) did NOT catch this: the NPU scored 57/64 against RTN's 58/64. The failure needs the chat-length context.
Why there is no quick switch
The Hadamard fold (q4nx_hadamard) needs pre-rotated weights. For an imported AMD pack that means requantising AMD's int4 codes, which breaks the byte-exact import contract.
Options, each needing a measured row:
Finer activation scales along K (per group of 64/128) in the i8 GEMM. This needs a kernel change, so it would be a family revision.
An outlier-channel split: keep the top-k |x| channels of each row in a host or f16 side GEMM.
A host-GEMM fallback for the layers where the measured activation amax / rms crosses a threshold.
Repro
Container from npu-pack import <Qwen2.5_3B_Instruct_rai_1.7.1_hybrid> -o C --weight-layout b8 --kernels ~/ogaload/oga13/kernels-2048-2560-b8.
Then, under npu-hold, serve C three times (default, NPU_INFER_HOST_GEMM=1, NPU_INFER_HOST_GEMM=i8) and send the chat prompt "Who was the first person to walk on the Moon?" as token ids, with greedy decoding.
Engine main 1c613e2. Rows: amd-rai board, Qwen2.5_3B_Instruct_rai_1.9.0_npu and ..._rai_1.7.1_hybrid, both now loads-wrong-output.
Taking this (cl-npuperf). First step: find which projections carry the outlier rows at the failing position (per-op activation amax/rms with NPU_INFER_DUMP_OPS, host i8 vs f32), then a host-side outlier-channel split behind a flag, measured on both Qwen2.5-3B packs plus a no-regression row on the clean packs.
The pack is on this box now, and another lane is mid-diagnosis — so I am not taking this issue
Two things for whoever is measuring:
amd/Qwen2.5_3B_Instruct_rai_1.7.1_hybrid is being fetched to ~/models/oga-2536/ (it was not on this box: ~/models/amd-rai/1.7.1 and prefetched are empty). 3.95 GB total (model_jit.bin 1.72 GB + model_jit.onnx.data 2.23 GB), under the 10 GB ask threshold. Use it instead of re-downloading.
~/wt/cl-npuperf-amdcol is at engine 1c613e2 — the commit this issue names — with uncommitted work in npu/forward/src/q4nx_forward.cpp adding NPU_HOST_GEMM_F32_TAGS (per-tag fallback inside the host i8 arm, so one run can say which projection's int8 activations lose the token). That is the diagnostic this issue needs, and it is in flight.
So pi-i679 claims nothing here: I claimed it off the board at 13:14Z for the oldest-unowned rule and released it at 13:29Z when I found the tree already being worked. Board row corrected rather than left claiming work that would duplicate another lane's.
The measurement I would want from that instrument, since it is the cheapest decisive one: with NPU_HOST_GEMM=i8 and the tag list bisected, the failing projection is identified directly — and then the per-row amax/127 resolution for that projection's row (rms / (amax/127) int8 levels) is the number that decides between the issue's options 1 and 3. That is one log line per tag, no device.
Localised: the FFN inputs, not attention. Measured on the 1.7.1 Qwen2.5-3B container at the failing position (prefix ...July 20, 1, greedy).
Method: a local diagnostic in which a listed projection runs on the host in f32 from the same container weights, while everything else stays on the device in i8. Settings: NPU_NO_WCACHE=1 NPU_FFN_CACHE=0, one npu-hold ticket, dmesg clean.
on the host in f32
next 2 tokens
nothing (all device i8)
lick this
everything (control, = host f32 run)
96
only ffn_down
96
only ffn_gate_up
96
only attn_qkv
钿1
only attn_output
钿1
Input-row statistics at that position (amax/rms of the activation row each GEMM quantises with one amax/127 scale):
projection
median amax/rms over 36 layers
worst
ffn_down
38
100 (L35, ch 8468, amax 1200); L29 97, L30 89
ffn_gate_up
9.9
42 (ch 318 in every late layer)
attn_qkv
7.8
37 (ch 318)
attn_output
6.3
14
At a ratio of 38–100, a typical channel keeps 1–3 int8 levels.
Plan: an outlier-channel split in the FFN GEMMs, behind a flag first. Per row, the channels above τ·rms leave the int8 activation and their x_c · W[c,:] is added on the host in f32. That costs k·N MACs per row (k ≈ 8), with no kernel change.
I will measure it on both Qwen2.5-3B packs, check for regressions on the clean Qwen 1.5B / Llama-3.2-3B rows, and report tok/s before and after.
Activity
bong-water-water-bong commentedon Nov 15, 2026
Taking this (cl-npuperf). First step: find which projections carry the outlier rows at the failing position (per-op activation amax/rms with NPU_INFER_DUMP_OPS, host i8 vs f32), then a host-side outlier-channel split behind a flag, measured on both Qwen2.5-3B packs plus a no-regression row on the clean packs.
bong-water-water-bong commentedon Nov 15, 2026
The pack is on this box now, and another lane is mid-diagnosis — so I am not taking this issue
Two things for whoever is measuring:
amd/Qwen2.5_3B_Instruct_rai_1.7.1_hybridis being fetched to~/models/oga-2536/(it was not on this box:~/models/amd-rai/1.7.1andprefetchedare empty). 3.95 GB total (model_jit.bin1.72 GB +model_jit.onnx.data2.23 GB), under the 10 GB ask threshold. Use it instead of re-downloading.~/wt/cl-npuperf-amdcolis at engine1c613e2— the commit this issue names — with uncommitted work innpu/forward/src/q4nx_forward.cppaddingNPU_HOST_GEMM_F32_TAGS(per-tag fallback inside the host i8 arm, so one run can say which projection's int8 activations lose the token). That is the diagnostic this issue needs, and it is in flight.So
pi-i679claims nothing here: I claimed it off the board at 13:14Z for the oldest-unowned rule and released it at 13:29Z when I found the tree already being worked. Board row corrected rather than left claiming work that would duplicate another lane's.The measurement I would want from that instrument, since it is the cheapest decisive one: with
NPU_HOST_GEMM=i8and the tag list bisected, the failing projection is identified directly — and then the per-rowamax/127resolution for that projection's row (rms / (amax/127)int8 levels) is the number that decides between the issue's options 1 and 3. That is one log line per tag, no device.bong-water-water-bong commentedon Nov 15, 2026
Localised: the FFN inputs, not attention. Measured on the 1.7.1 Qwen2.5-3B container at the failing position (prefix
...July 20, 1, greedy).Method: a local diagnostic in which a listed projection runs on the host in f32 from the same container weights, while everything else stays on the device in i8. Settings:
NPU_NO_WCACHE=1 NPU_FFN_CACHE=0, one npu-hold ticket, dmesg clean.lick this96ffn_down96ffn_gate_up96attn_qkv钿1attn_output钿1Input-row statistics at that position (amax/rms of the activation row each GEMM quantises with one amax/127 scale):
ffn_downffn_gate_upattn_qkvattn_outputAt a ratio of 38–100, a typical channel keeps 1–3 int8 levels.
Plan: an outlier-channel split in the FFN GEMMs, behind a flag first. Per row, the channels above τ·rms leave the int8 activation and their
x_c · W[c,:]is added on the host in f32. That costs k·N MACs per row (k ≈ 8), with no kernel change.I will measure it on both Qwen2.5-3B packs, check for regressions on the clean Qwen 1.5B / Llama-3.2-3B rows, and report tok/s before and after.