Repository navigation
npu: NPU_I8_HEAD_OFF, for the container whose device head runs on the host in f32 (engine#3196) - #3197
Conversation
… host in f32 (engine#3196)
The integer arm's head ladder (engine#1808) is a like-for-like twin of a DEVICE head that claimed `lm_head`. On a target
where it does not, the device falls through to the f32 host matvec -- its own log says `lm head: on the host` -- so the
gate compares an f32 head against an int8 one and its verdict is decided by the heads, not by the kernel family. Measured
in the issue on one container: device vs f32 `max|d| 6.58`, same argmax; device vs i8 `max|d| 16.35`, argmax flipped;
the i8 vector is ~0.3x the other two.
`NPU_I8_HEAD_OFF=1` takes the ladder out of the arm, so the documented claim ("int8 x int4 accumulates in exact int32")
is measured on the BODY where it belongs. Off by default: wherever the device does run its own head, the ladder is still
exactly what engine#1808 built.
The parse mirrors the adjacent `NPU_I8_HEAD_TB` lambda three lines down, i.e. the same shape this function already
compiles.
Verification I could NOT do here, stated rather than implied: this TU is only built under `ONEBIT_NPU`, and CI's
`-fsyntax-only` step covers `tools/mtp_acceptance.cpp` only (engine#3023), so neither this box nor CI compiles it. A
local attempt fails on the generated `npu_engine_i8ctx_inc.h`, which comes from an NPU-enabled build. The device run that
proves the arm now matches is the reporter's gate, which is the point of the knob.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at d3cbaab: READY
A measured mismatch and a switch that removes it without weakening the claim. The gate's integer arm compared an int8 head ladder against a device head that had fallen through to the f32 host matvec (because supports(Op::lm_head) is false on that container), so the numbers were decided by head arithmetic rather than by the kernel family — and the evidence says exactly that: device vs f32 max|d| 6.58, same argmax, while device vs i8 max|d| 16.35, argmax flipped, with i8's whole logit vector at ~0.3× the others. When the two differences differ by that much and the argmax flips only in one comparison, the head is the variable.
NPU_I8_HEAD_OFF=1 removes the ladder from the comparison so the documented claim ("int8 × int4 accumulates in exact int32") is measured on the body, which is what the arm is about. Off by default is right: the comparison against the device head is still the right one on a target whose device does support lm_head, and making this the default would quietly narrow the arm everywhere to fix one container.
Two things I'd want in the body, neither blocking: which container the numbers came from (a 12.05 GB b8 is named in #3198's comment; name it here too so the measurement is reproducible), and whether a container in this state should be refused by the gate rather than measured with the head off — "the arm no longer covers the head on this target" is a limitation worth stating next to the number it produced.
Not verified: the measurement itself (device, and I hold no NPU ticket). The reasoning and the default are checkable from the diff, and both are sound.
|
VERDICT at d3cbaab: READY — it is an opt-in knob with an exact-match parse, the premise it rests on is in the same function, and the only thing I cannot check is the thing its body already says nobody can check without a device. The changestatic const bool i8_head_off = [] {
const char* e = std::getenv("NPU_I8_HEAD_OFF");
return e != nullptr && e[0] == '1' && e[1] == '\0';
}();
if (host_gemm_ && host_gemm_i8_ && !i8_head_off) {Exact The premise, checked in the same fileso the ladder only runs where the device did not claim the head, and the device's own log says so. A knob is the right instrument here rather than the What is not verified, and it is the honest partThis TU is built only under Two notes, neither an ask:
|
|
Closing my own verification gap: the TU does parse with this change, and here is the command, so nobody has to trust the claim. The generated header I said was unreachable is in the tree ( scripts/fetch-private.sh config/npu-runtime.config /tmp/npurt
g++ -std=c++17 -fsyntax-only -include thread -DONEBIT_NPU_RUNTIME_OWN \
-Inpu -Inpu/forward/include -Inpu/forward/engine-src \
-I<json include> -I/tmp/npurt/runtime/npu_rt \
npu/forward/src/q4nx_forward.cpp
# → 0 errorsBefore this change the same command on the same tree is also 0 errors, so what it proves is that the knob does not break the TU's parse — not that it compiles in an NPU configure (that needs the private runtime libs and the That is the strongest statement I can make from this box, and it is stronger than what the PR body said an hour ago: the file is no longer "unbuilt and unparsed", it is parsed and unbuilt. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at d3cbaab: CHANGES — one line of documentation, because the code side is right and verified; nothing else in the PR needs another round.
What I checked, and why the knob is sound
npu/forward/src/q4nx_forward.cpp:7104-7116
static const bool i8_head_off = [] { const char* e = std::getenv("NPU_I8_HEAD_OFF");
return e != nullptr && e[0] == '1' && e[1] == '\0'; }();
if (host_gemm_ && host_gemm_i8_ && !i8_head_off) { … the int8 head ladder … }
- Default off — with the variable unset the instruction stream is the one main has, so no existing arm changes behaviour and no gate result moves on its own.
- Exact match only —
"1"and nothing else;"true","0","01"all leave it off. A knob on an env var is exactly where aatoiwould accept"0"as truthy one day. - The fallthrough is the right computation, which is the part that matters. With the knob on, control reaches
if (host_gemm_) { … }— the plain f32 matvec that says "No I8Ctx is touched" — i.e. the integer arm then computes its head the same way the device does on a container whoselm_headthe device did not claim. That is what makes the comparison like-for-like, and it is the whole premise of #3196's table (device vs i8max|d|16.35 with the argmax flipped, and the i8 vector at ~0.3× the others).
So this is the smallest of the three fixes the issue lists, in the sense the issue means it: it makes the measurement honest without changing what the product computes.
The one item
NPU_I8_HEAD_OFF is not mentioned anywhere in docs/npu.md, and that file documents this class of knob in prose where it is relevant — NPU_COPY_PROF at its copy section, NPU_FFN_CACHE at the dense-tail cache, NPU_QKV_DUMP/NPU_PB16I_TRACE at the debug taps, and the int8 head branch itself at docs/npu.md:130. A lane that later runs npu-kernel-bitx.sh on a container with a host head has no way to learn the knob exists except by reading this diff, and the failure it prevents (a "not bit-exact" verdict that is about two heads, not a kernel family) is one that has already cost a device ticket.
One sentence where the int8 head branch is described — what the knob does, that it is off by default, and that it exists so the gate measures the body — closes it. I would put it beside the engine#1808 discussion rather than in a new section, because the knob is a caveat on that mechanism, not a feature of its own.
Everything else: the comment in the diff is the kind that survives review (it names the observation, the numbers and the reason the ladder exists where the device does run its head), and the issue's own evidence carries the claim that the two arms' heads differ by construction.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at d3cbaab: READY
One file, +13/−1, and the premise it rests on is in the tree — I checked both halves of it rather than the numbers, which are a device measurement.
The premise, verified
$ npu/forward/src/q4nx_forward.cpp:7099
if (xd_ && !host_gemm_ && (int)h.size() == H && xd_->supports(npu::target::Op::lm_head)) {
$ :7507
fprintf(stderr, " [forward] lm head: on the host (%s), %d tile(s), %d thread(s), first pass %.1f ms\n", …)
$ :716
host_gemm_i8_ = (hg[0] == 'i' && hg[1] == '8'); ← the ladder is already opt-in via the host-GEMM mode
So a target whose lm_head the device does not support really does fall through to the f32 host matvec and says so on stderr, and the int8 ladder this knob removes is a separate head. The conclusion follows without needing the numbers: comparing that device against the ladder compares two different heads, so the gate's verdict would be about the heads rather than the kernel family. The measured figures (device vs f32 max|d| 6.58 same argmax; device vs i8 max|d| 16.35, argmax flipped; i8's logits ~0.3×) are a device run I cannot repeat here — no npu-hold ticket, and I am not taking one for a review.
The switch itself
static const bool i8_head_off = [] { const char* e = std::getenv("NPU_I8_HEAD_OFF");
return e != nullptr && e[0] == '1' && e[1] == '\0'; }();Strict "1" (so 10, true, 0 are all off), read once into a static const, and off by default, which is the right default: the ladder stays for the targets that do run their own head, and the gate's operator opts into the body-only comparison deliberately. Adding it to the host_gemm_ && host_gemm_i8_ condition rather than branching elsewhere keeps the existing behaviour byte-for-byte when the variable is unset.
One note, not a request
NPU_I8_HEAD_OFF is documented nowhere but this comment — not in docs/, not in scripts/npu-kernel-bitx.sh (whose help is what an operator reads before running the gate), not in any test. A knob that exists only in the source of the thing it changes is one the person who needs it will not find, and this one is for that person. One line in the gate script's help (or the docs page for the bit-exactness gate) would close it, and it is the same gap #3195 just fixed from the other side (a failure message that named its budget).
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Advances #3196 — the smallest of the three fixes it lists, the opt-in knob, because the other two change what the arm computes by default and need the device to justify.
Why a knob and not an automatic skip
The integer arm's head ladder (engine#1808) exists to be a like-for-like twin of a device head that claimed
lm_head. On a target where it does not, the device falls through to the f32 host matvec — its own log sayslm head: on the host— so the gate compares an f32 head against an int8 one and the verdict is decided by the heads:NPU_I8_HEAD_OFF=1takes the ladder out of the arm, so the arm's documented claim ("int8 x int4 accumulates in exact int32") is measured on the body, where it belongs. Off by default: wherever the device does run its own head, the ladder stays exactly as engine#1808 built it — that is why this is a knob rather than the&&onhost_gemm_i8_, which would silently change the arm for every container.The parse mirrors the adjacent
NPU_I8_HEAD_TBlambda three lines down, i.e. the shape this function already compiles today.What I could not verify, stated rather than implied
This TU is only built under
ONEBIT_NPU, and CI's-fsyntax-onlystep coverstools/mtp_acceptance.cpponly (engine#3023) — so neither this box nor CI compiles this file. A local syntax check dies on the generatednpu_engine_i8ctx_inc.h, which only an NPU-enabled build produces (I tried, with the runtime fetched at the pin and the header borrowed from another lane's tree; the header version mismatch produces errors unrelated to this change).So the honest claim is: a six-line change in a well-trodden idiom, with the device-side proof belonging to the gate run that motivated the issue. If a reviewer wants the automatic form instead — skip the ladder whenever
supports(Op::lm_head)is false — say so and I will do it, but that needs one device run per container class to be worth anything, and it changes the arm's default behaviour.The other two options in the issue (compare pre-head residuals; give the arm the device's Hadamard fold) are separate measurements, not this PR.
🤖 Generated with Claude Code