Repository navigation
Description
The forward decodes every 2-D weight as a 5120-byte q4_1 tile, so a bf16 container loads garbage instead of refusing
Found while chasing #796's d3 parity gap. Measured, with one binary and one prompt, on two containers of the same
weights:
| container | engine's dequantized layers.0.linear_attn.qkv_proj.weight row 0 vs the pack's own row 0 |
mean|·| engine / pack |
|---|---|---|
d3-lite-conv (q4_1, what the format expects) |
cos +0.99663 (row 0, i.e. the right row) | 0.011284 / 0.011118 |
d3-lite-bf16 (pack --dtype bf16, #846) |
cos +0.12465 at its best row out of all 6144, median |cos| 0.021 | 0.091705 / 0.011118 (8.2×) |
And a search of the bf16 container's 1024-value row against every 2-D tensor in the pack tops out at |cos| 0.157,
i.e. it is in no tensor at all.
Why
dequant_any() (npu/forward/src/q4nx_forward.cpp:159-168) picks a decoder purely from bytes per tile:
const int cb = (int)(nbytes / n); // n = (rows/32) * (cols/256)
if (cb == Q4NX_TILE_BYTES || cb == Q4NX_CHUNK_Q4K || cb == Q4NX_CHUNK_Q8)
return q4nx_dequant_tensor_chunked(...);
return q4nx_dequant_tensor(...); // <-- also q4_1 tiles onlyand q4nx_dequant_tensor() (npu/forward/src/q4nx_dequant.c:126-152) reads 5120-byte q4_1 tiles
unconditionally — there is no bf16 branch. It only checks nbytes >= q4nx_tensor_bytes(rows, cols), so a bf16 tensor
does not fail, it is silently mis-decoded: layer 0's in_proj_qkv (6144×1024) needs 3,932,160 B as tiles and the
bf16 container holds 12,582,912 B (exactly the 3.2× that 2 B/value vs 0.625 B/value implies), so the first third of
a bf16 buffer is read as q4_1 tiles.
1-D tensors are unaffected — read_bf16() reads those directly, which is why the same run shows
layers.0.input_layernorm.weight matching the pack to the bit (cos 1.000000, rel 0.000000) and
XN == rmsnorm(X, in_norm_[0]) holding exactly, while every fine-grained weight is garbage.
Impact
- A bf16 container is not loadable by this forward, and nothing says so: it converts, it verifies 320/320 against
the source (tools/safetensors_to_q4nx.py verifycompares container-vs-source, not container-vs-engine), it loads,
it answers — with weights that are not the model's. - Every row measured on such a container is void. For npu: a real d3 pack (vllm-sr/d3-lite, 0.8B-GDN) answering through /v1/systemone — converter transforms, name map, and the 7-design ELF set #796 that includes the parity table's
engine(bf16)rows
(0.8382vs the reference) and, worse, the row that readengine(q4_1) vs engine(bf16) = 0.4959as "what
quantization costs in the engine" — that number is the mis-decode, not quantisation. The d3 hidden-vector and
per-layer rows measured today on the bf16 container are void for the same reason; the layer-0 divergence they showed
is explained by this bug and not by a GDN defect. - npu converter: --dtype bf16 writes no tiles, so the engine and a reference can be compared on the same weights (#796) #846's
--dtype bf16flag is what produced the container; its ctest only checks the written tensor set.
Fix shape
Either refuse, or teach the dequant a plain-bf16 branch — the size check is already there to be made explicit:
- in
dequant_any():if ((size_t)rows * (size_t)cols * 2 == nbytes) return q4nx_dequant_plain_bf16(data, rows, cols, out);
(a ~10-line sibling ofq4nx_dequant_plain_i8, which exists for exactly this kind of "plain, no tile header"
tensor); - and in
q4nx_dequant_tensor()bis: keep the tile path, but make the size test exact (need != nbytes→ error)
so a future container family that nobody taught the decoder cannot be read as tiles again; - a ctest row with a synthetic 64×512 bf16 tensor whose values are known, decoded through
dequant_anyand compared
exactly, plus a row asserting that a bf16-sized tensor no longer takes the tile path; tools/safetensors_to_q4nx.py pack --dtype bf16either stays and works, or refuses with a message naming this
issue.
Found by measuring wqkvlin_/xn/in_norm_[0] at the layer-0 call site on the real pack; harness in
~/lb/d3parity/ (find_w.py, norm_cmp.py, w_run.sh, w_run_q41.sh). Tickets: one per run, host-GEMM, amdxdna
errors 0.
Activity
bong-water-water-bong commentedon Nov 3, 2026
Verified at tonight's pin (
23d6972d9) — the mechanism is exactly as described, and the fix's risk is lower than the issueimplies.
bug+npuapplied.The three lines that matter, confirmed
So an oversized buffer is not refused, and there is no bf16 branch anywhere (
git grep plain_bf16 npu/→ 0). The precedentthe issue cites is real:
q4nx_dequant_plain_i8exists atnpu/forward/src/q4nx_dequant.c:163with its declaration atnpu/forward/include/q4nx_dequant.h:106, used for Gemma4's plain-int8 tables — a bf16 sibling fits that shape exactly.Two additions to the fix shape
!=breaks anycaller that passes a padded slice:
git grep 'q4nx_dequant_tensor(' npu/ tools/). Soneed != nbytes → -1is safe today and itis the part that closes the class: a container family nobody taught the decoder cannot be read as tiles again.
#846's--dtype bf16a loud failure instead of asilently wrong model, which is worth having even if the bf16 branch takes longer. If
pack --dtype bf16is meant to stay,then item 1 (the plain-bf16 branch) is the one that makes it work, and the ctest in item 3 should pin both directions —
bf16 decodes exactly and a bf16-sized tensor no longer takes the tile path.
The blast radius is bigger than #796, and it is worth writing into the issue
Every number measured through a bf16 container is void, and there are more of them than the parity table: the d3 hidden-vector
and per-layer rows measured on 11-02 are in the same category, and the layer-0 divergence they showed is now explained by
this bug, not by a GDN defect — which also means #847's mask fix and #849's pairing fix must be re-scored on a q4_1
container before anyone concludes they closed the parity gap. That ordering (refuse/bf16 decode → re-measure on q4_1 → then
judge #849/#847) is the single most valuable line in this issue.
Owner
pi-npufeat(the #796 cluster, which this voids), bucket A. Host-side only:NPU_INFER_HOST_GEMM=1, no device,no ticket — the reproducer is
tools/safetensors_to_q4nx.py pack --dtype bf16on a small tensor plus the layer-0 comparison in~/lb/d3parity/.bong-water-water-bong commentedon Nov 3, 2026
Closing note (issue keeper): closed by
#882 → 0314f19a— and the test it shipped is the one the row asked for, run here#882's title carries(closes #875); GitHub closed this at 11:29:01Z. Verified device-free at2fc5c4fd:So both halves of the acceptance are covered by an executable check: decoded exactly when the buffer is bf16-sized, refused when it is off by two bytes (the
nbytes < need→ exact-size change atq4nx_dequant.c:131), and the q4_1 tile path still decodes tiles. The 3×5 case pins the no-alignment claim.The ordering item stands and is now the live one: every measurement taken through a
pack --dtype bf16container is void, and#847's 06:35Z re-run (engine-causal vs reference-causal worst |Δp| 0.6367) is the first set of numbers measured after this fix — so #796's parity rung is now scored on numbers that are not the mis-decode, and the remaining gap is a real forward difference, not a decoder artefact.