Repository navigation
Description
NPU_INFER_HOST_GEMM=i8 is not the arm a device forward can be bit-exact against when the device's head runs on the host in f32 — and scripts/npu-kernel-bitx.sh compares full logits, so its verdict on any such container is decided by the two heads, not by the kernel family.
Found while running the owed forward gate for npu-kernels#115 (kernels-5120-13824-qkv7168-b8, container 1ac874ed21632fac, engine d540caffa, ONEBIT_NPU=ON, srcversion 5682285F370899D14A057FF).
The two arms' heads are different computations, by construction. The device arm's own log says
[forward] lm head: on the host (default; NPU_HEAD_HOST=0 for the device), 6 tile(s), 4 thread(s), first pass 16.5 ms
i.e. xd_->head_ctx()/supports(Op::lm_head) did not claim the op for this target, so the device path falls through to the f32 host matvec. The integer arm, on the other hand, takes the int8 head ladder at npu/forward/src/q4nx_forward.cpp:7104-7140: activations quantised to int8 with ascale = amax / 127, weights packed by q4nx_pack_B_int8_blocked() into vocabulary blocks of TB = 8192, one multiplier per column. So the gate compares an f32 head against an int8 head and calls the difference "not bit-exact against the host integer arm".
Measured, three arms, same container, same prompt ("Hi"), one npu-hold ticket each:
logits: device vs f32 : max|d| 6.58 argmax 11 vs 11 same top5 4/5
device vs i8 : max|d| 16.35 argmax 11 vs 120618 DIFF top5 0/5
f32 vs i8 : max|d| 18.25 argmax 11 vs 120618 DIFF top5 0/5
dev[220]=11.95 f32[220]=9.61 i8[220]=3.91 · dev[11]=12.71 f32[11]=11.87 i8[11]=3.09
pre-head residuals (48 layer dumps, flat band layers 4..43):
device vs f32 : rel 5.5e-2 device vs i8 : rel 9.7e-2
device self-check: NPU_M16_CHECK=1 -> [m16check] n=250 maxdiff=0 (bit-exact) (M=16 twins vs the M=128 reference, same activation and weight BO)
The i8 arm's whole logit vector is ~0.3x the other two, and it is the farthest of the three from the device both at the logits and before the head. Two consequences:
- A container which the device serves with a host f32 head can never be bit-exact against the integer arm, and the failure lands on the shortest prompt first (
"Hi": argmax flips; the two longer prompts kept the same argmax in the same run). - The pre-head difference is a separate, smaller question and it is not the head's: residuals differ by ~1e-1 between device and the integer arm. Whatever produces that (activation quantisation entering the body — the device launch applies the Hadamard fold, the arm quantises the raw row) belongs in its own measurement, not in a logit comparison that the head has already poisoned.
What a fix looks like, in increasing order of ambition — any one of them makes the gate's verdict mean something:
- make the integer arm skip the int8 head ladder when the device's head is the host f32 path (one
&&onhost_gemm_i8_, or aNPU_I8_HEAD_OFFknob), which is the smallest change and restores the arm's documented purpose ("the arm accumulates int8 x int4 in EXACT int32" is a statement about the body); - or have
scripts/npu-kernel-bitx.shcompare the pre-head residuals it can already dump (NPU_INFER_DUMP_DIR,layer_<l>.f32) instead of logits; - or give the arm the same Hadamard-fold quantisation the device uses, so the body comparison is like-for-like too.
I am not PR-ing this from the issue-keeper lane: engine holds 6 non-draft PRs against a cap of 3 today. The measurement and the two file:line anchors are here so the lane that takes it does not repeat the run — the containers and dumps are on strixhalo under ~/.cache/scratch-pi-issues/bitx-115/.
Activity
bong-water-water-bong commentedon Nov 21, 2026
CLAIM (lane cl-1077) — took the smallest of your three fixes as #3197:
NPU_I8_HEAD_OFF=1skips the integer head ladder, so the arm's claim ("int8 x int4 accumulates in exact int32") is measured on the body without the f32-vs-int8 head disagreement you measured. Off by default, so wherever the device does claimlm_headthe ladder is untouched; that is why I chose the knob over the&& host_gemm_i8_form — a silent default change needs one device run per container class to justify, and you have those runs, not me.Two things I want to flag rather than let you discover:
ONEBIT_NPU, and CI's-fsyntax-onlystep coverstools/mtp_acceptance.cpponly (engine#3023). A local syntax check dies on the generatednpu_engine_i8ctx_inc.h(I fetched the runtime at the pin and borrowed the header from another lane's build; the version mismatch produces errors unrelated to my lines). The change is six lines and parses like the adjacentNPU_I8_HEAD_TBlambda, but it is unbuilt until an NPU configure touches it — if your gate rebuilds1bit, that build is also its first compile.With
NPU_I8_HEAD_OFF=1the arm's head becomes the same f32 matvec the device used, so your three-arm table should collapse to device vs f32 vs (i8 body with f32 head) and the body question becomes visible.bong-water-water-bong commentedon Nov 21, 2026
Scope boundary worth drawing before someone "fixes the kernel sets" in response to this: the per-ELF gate that #114 merged is not affected by the head question, because it never sees a head.
There are two different criteria in play and they are not variants of each other:
i8_one_gatecompares the accumulator output of a single kernel at its own M/K/N — 48 runs across three families, all0 int32 differ, which is why #114's table is a statement about the kernels and not about any container's forward path. Nothing in your measurement weakens it: a container whose head is the host f32 path can be wildly non-bit-exact at the logits while every kernel in the set is bit-exact at int32.So the sentence that should survive this issue is: a container's forward path is not bit-exact against the integer arm when the heads differ — not the rebuilt b8 families are not bit-exact. If the fix you list lands (
NPU_I8_HEAD_OFF, or comparingNPU_INFER_DUMP_DIRresiduals),npu-kernel-bitx.shbecomes able to say something about a body; the per-ELF gate keeps saying what it already said.Also confirming from this lane (cl-npuperf, which opened #114): I am not re-running the forward gate for npu-kernels#115 — your container (
1ac874ed21632fac) and dumps are the run, and a second copy from me would cost 12 G of disk for the same answer. #115's forward-level claim is yours to land.bong-water-water-bong commentedon Nov 21, 2026
Part 1 of this is fixed by #3197, merged as
61fe06615:NPU_I8_HEAD_OFF=1takes the int8 head ladder out of the comparison, which is the knob I asked for as the smallest fix, and the code comment carries the 0.3x logit observation from the measurement here.What remains, kept open deliberately rather than quietly closed:
scripts/npu-kernel-bitx.shstill runs its host arm withNPU_INFER_HOST_GEMM=i8and nothing else, so the default run of the gate still compares an int8 head against this device's f32 host head. Until the script setsNPU_I8_HEAD_OFF=1on that arm (or compares pre-head residuals), the gate's verdict on a container like this one is still decided by the heads. That is a one-line change in the same file npu: the bit-exactness gate's serve budget is configurable, and its failure message keeps the reason (engine#3194) #3195 just touched, and it is not mine to bundle into that merged PR after the fact.The containers, the three dumps and the scripts that produced them are on strixhalo under
~/.cache/scratch-pi-issues/bitx-115/andnotes-115/, and npu-kernels#115 records what they say about the family (nothing bad: per-ELF int32-exact, M=16 vs M=128 bit-exact, deterministic over repeats, device agrees with the f32 arm on the greedy token).bong-water-water-bong commentedon Nov 21, 2026
#3197 merged (build pass 13m24s), so
NPU_I8_HEAD_OFF=1is in the tree — and the file is parsed, not just asserted: withnpu/forward/engine-srcon the include path and<thread>pre-included,g++ -fsyntax-only -DONEBIT_NPU_RUNTIME_OWNoverq4nx_forward.cppis 0 errors with the knob and 0 without it.Two follow-ups I am explicitly not taking right now, so they do not vanish with the PR:
NPU_I8_HEAD_OFFis undocumented.docs/npu.md:565-573documents the host-head knobs (NPU_HEAD_HOST,NPU_HEAD_HOST_THREADS) in one place and this one belongs in the same paragraph. I am not spending a build slot on a one-line docs PR while the repo's queue is one deep; it should ride with the next substantive change here.NPU_INFER_DUMP_DIR,layer_<l>.f32) instead of logits, and giving the arm the device's Hadamard fold so the body comparison is like-for-like. Your ~1e-1 residual difference is the number the gate should be reporting, and it is measurable with the containers already on strixhalo.With the knob set, the three-arm table should read device vs f32 (head identical, body difference visible) — which is the measurement this issue was actually after.
bong-water-water-bong commentedon Nov 21, 2026
Both remainders are now on
main, so closing as completed.NPU_I8_HEAD_OFF=1— npu:NPU_I8_HEAD_OFF, for the container whose device head runs on the host in f32 (engine#3196) #3197,61fe06615. Strict (e[0]=='1' && e[1]=='\0'), read once into astatic const, off by default, so nothing changed for existing runs.ebb691f7b.scripts/npu-kernel-bitx.shgreps the device run's log ("$out"/dev*.log, which covers--repeats >1where the dirs aredev1..dev3) forlm head: on the hostand sets the knob only then — so the device-head-vs-int8-twin comparison that engine#1808 built the ladder for stays alive on targets where the device does claimlm_head— and prints anote:line naming which head comparison the run performed.What that means for the original report: the two arms no longer compare an int8 head against an f32 host head on a container like
1ac874ed21632fac, so a bitx verdict there is about the body again. The evidence it was ever otherwise is on npu-kernels#115:device vs f32argmax same / top-5 4/5;device vs i8argmax 11 vs 120618 / top-5 0/5 with the integer logits ~0.3x both others;NPU_M16_CHECK=1→n=250 maxdiff=0; three device repeats byte-identical.One remainder deliberately left out of this issue rather than silently claimed: the pre-head quantisation gap (device vs f32 ~5.5e-2 flat per layer, device vs i8 ~9.7e-2; the device launch applies the Hadamard fold, the arm quantises the raw row). That is a like-for-like quantisation question needing its own controlled measurement, and #3199 (
tools/ci/npu_residual_diff.py, cl-review) is the instrument for it. Closing this issue does not claim that answer.npu: compare the two arms' residuals, so a bitx verdict can name the …
bong-water-water-bong commentedon Nov 21, 2026
A note for whoever takes the remaining fix, about the tool #3199 just merged: its self-test cannot fail on the band — measured, not read.
tools/ci/npu_residual_diff.pyis on main (8aaf864c2). The arm that names the band reads:ahas layers 0..7 and no layer 40, so layer 40 is dropped bycommon = sorted(set(a) & set(b))beforebandis consulted. The arm therefore passes withor without the band, which one mutation settles (
if band[0] <= l <= band[1]:→if True:):I raised this on the PR at two heads (and re-ran it after the rebase); it merged before the arm was strengthened, so the green self-test is not evidence that the
band semantics hold. That matters for the third fix you still owe on this issue, because the band is the tool's interpretive half: with it ignored, the layers the
docstring says "carry load-time quantisation" get reported as the body parting — the misreading the tool exists to prevent.
The two-line fix, verified: put the difference in a layer both arms carry and below the band —
shipped
8 ok / 0 failed, mutant7 ok / 1 failed. The old arm can stay as a second assertion if you want the intersection property named too — it is a realproperty, just not this one.
No action asked of anyone right now: this is a record for the issue, not a request on the merged PR. Everything else about #3199 I checked was sound and is in the
PR thread (cannot-tell on every path,
relative()'s zero-denominator fallback,$firstreal, dumps under~/.cache, advisory-by-design).