Repository navigation
npu: t2s v2 selects its own artifact family (_t2s2), so a v1 kernel can never drive v2 images - #837
Conversation
…an never drive v2 images `q4nx_weight_layout_version` 5 and 6 are the same weights at the same size in different byte orders; reading one with the other's kernel is a silent permutation of the weight matrix, not a crash. So the version picks the *artifact family*: 5 -> `_t2s_m16` (the interleaving kernel), 6 -> `_t2s2_m16` (the no-shuffle kernel v2 was designed for), and a container may only name the one its images were packed for -- any other version is refused by name at init. - npu/forward: `t2s_v2_` from the version, `family_tag()` returns `_t2s`/`_t2s2`, and the layout banner says which wire order is running. - npu/plan: `kernels.tag` accepts `_t2s2`, requires `container.layout: "t2s"` for it, and treats it as the ternary family like `_t2s`/`_pb16i`. - tools/npu_plan.py writes `_t2s2` for version 6 (and `_t2s` for 5). - docs/npu.md: the version -> family mapping and the measured v2 result (0.589 ms vs the pb16i phase's 1.037 ms in the same window, 40.2 GB/s, seeds 1/2/3 byte-exact, counter 0). - tests: npu_plan_test gains the v2 plan and the `_t2s2`-on-a-pb16i-container refusal; npu_plan_generate covers both versions' tags. Green locally: npu_plan, npu_plan_generate, npu_t2s_layout, q4nx_t2s.
PR Reviewer Guide 🔍(Review updated until commit bbe3c21)Here are some key observations to aid the review process:
|
…de suffix Found wiring up a real t2s container: the fusion probe looked for `full_i8_GU_K5120_N34816_t2s2.elf` / `full_i8_G_K5120_N17408_t2s2.elf`, and a t2s container has neither -- its decode kernels carry `_t2s2_m16` while its M=128 prefill is the plain int8 family. So the probe found no artifact, took its "fused" fallback, and the forward then refused by name for a `full_i8_GU_K5120_N34816.elf` that the box's own pb16i container does not use either (its plan says split). The gate/up probe is about the *prefill* family, which is not the stream's suffix: b8 blocks the tap at every M so it is `_b8`; a pb16i or t2s container's M=128 prefill stays the plain int8 family and only its decode kernels carry the stream tag. With that, a t2s v2 container's plan now says `split`, matching the live pb16i container on this box (checked field by field), and `npu_plan_generate` still passes.
|
Persistent review updated to latest commit 0855c12 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 0855c12f8 — the version now picks the artifact family on every path I can exercise, and the generator
change is checked against the box's own containers.
Built and ran the lane at this head (Release, -G Ninja, gcc-16, -DONEBIT_NPU=ON -DONEBIT_NPU_RUNTIME=own -DONEBIT_NPU_RT_DIR=<private rt>):
ctest -R "npu_plan|q4nx_t2s|npu_t2s_layout|mtp_draft" → 5/5 passed, including the new npu_plan cases (_t2s2 is
read as the ternary family with its own tag; a _t2s2 tag on a container.layout: pb16i is refused by name).
The version→family logic, read and checked: family_tag() is the single place the suffix is decided
(t2s_v2_ ? "_t2s2" : "_t2s"), init_impl refuses anything but 5 or 6 for a t2s container with the exact message the
body quotes (… is not a t2s stream this build reads (5 = v1, 6 = v2)) and still refuses ≠4 for pb16i, and every probe
and ELF name downstream goes through family_tag(), so a v1 kernel cannot be handed v2 images — which is the failure this
PR is shaped to prevent, since the two are the same size and a mismatch is a silent permutation rather than a crash.
The generator change does not invalidate anything on disk, which was my main worry (the probe now uses the prefill
family's names rather than the decode suffix):
python3 tools/npu_plan.py ~/models/npu/{bonsai2-27b-NPU,-NPU-b8,-pb16i,Qwen3-0.6B} --check
-> "matches the model dir" rc 0 (all four)
and the two Bonsai containers on this box really are fusion.gate_up = split with a full_i8_G_… artifact present, which
is what the corrected probe now reads instead of guessing "fused" from a missing decode-tagged name. That bug report in the
comment (2026-11-02) is the right kind of thing to write down next to the fix.
Not run: any device launch of the _t2s2 family. The measured 0.589 ms / 40.17 GB/s and the 1.76–1.96x are the lane's
arena numbers, and #836's v2 stream bytes I did verify independently against run-t2s/v2_s1.B — the rate is the arena's
to publish.
CI at this head: build pass 5m49s, CodeQL pass, pr_agent pass. tprs-ready applied. It builds on #836, which I
verdicted READY ten minutes ago at 1395afe60, so the two can go in that order.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 96187a8 (the main merge; own diff unchanged at +67/−20, 6 files).
Re-derived at this head: tools/npu_plan.py <model dir> --check -> "matches the model dir" for all four containers on the
box (bonsai2-27b-NPU, -NPU-b8, -pb16i, Qwen3-0.6B), so the corrected gate/up probe and the _t2s2 family logic
still agree with every plan.json on disk after the merge.
The npu_plan/q4nx_t2s/mtp_draft ctests I ran at the reviewed head still stand as evidence for the C++ side (they are
that head's binaries); this head's own diff is unchanged, and #843's lane build covers the merged tree.
|
Persistent review updated to latest commit 96187a8 |
|
Persistent review updated to latest commit 644bf63 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 644bf63d70 (the main merge; author diff byte-identical to the head I verdicted: 6 files, +67/−20).
The hunk this PR exists for is a real wrong answer, and I checked it against the artifacts on this box rather than against the comment. For a pb16i or t2s container the prefill (M=128) gate/up kernels are the plain int8 family, only the decode kernels carry the stream suffix:
~/models/npu/bonsai2-t2s-v2/kernels-m16/ full_i8_G_K5120_N17408.elf present full_i8_GU_K5120_N34816.elf absent
~/models/npu/bonsai2-27b-pb16i/kernels/ full_i8_G_K5120_N17408.elf present any full_i8_GU_*.elf absent
so probing with the decode tag (_pb16i, _t2s, _t2s2) finds neither artifact and the old rule (fused_gu = artifact(gu) or not artifact(g)) writes fused — the wrong answer for a container whose real shape is split. With prefill_tag the probe finds the split kernel and writes split.
Re-run at this head, tools/npu_plan.py <dir> --kernels <each dir's own kernel dir> --check:
bonsai2-27b-pb16i rc 0 matches the model dir
bonsai2-27b-NPU rc 0 matches the model dir (--kernels .../kernels; its kernels-m16 holds only the _m16 twin)
d3-lite-conv rc 0 matches the model dir
bonsai2-27b-t2s2 rc 1 one diff line: sealed_elf "SEALED-T2S.elf" -> "" <- that is #843's hunk, not this PR's
and with #843's tool (which carries this hunk plus the sealed-ELF one) bonsai2-27b-t2s2 is rc 0, i.e. the two PRs are consistent and #837 comes first.
One correction about my own earlier passes, since it explains a discrepancy anyone re-running this will hit: I ran --check without --kernels, and the default (<model dir>/kernels) does not exist for the pb16i and t2s staging dirs (they carry kernels-m16), so the probe saw no artifacts at all and reported fused even here. That was my invocation, not the tool — with the kernel directory supplied, every generated plan on the box agrees with the tool.
|
Persistent review updated to latest commit b00f706 |
|
Third lane in |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at b00f7063b (re-verdict after the update-branch; content unchanged)
Identity: the PR's own patch at the old head 644bf63d (base 906f966a2) and at this head (base 40d963254)
is the same 164-file set with the same +/- counts and patch text, except the docs/npu.md hunk header, whose
line numbers moved because main's #836 inserted 25 lines above it. The files this PR actually changes are
blob-identical at both heads (npu/forward/src/q4nx_forward.cpp, npu/forward/include/q4nx_forward.h,
npu/plan/plan.h, tools/npu_plan.py, tests/npu_plan_test.cpp).
Re-run at b00f7063b, not carried over: npu_plan_test builds rc 0 -> npu_plan: ok; tests/q4nx_t2s_test.py
-> 0 failure(s); tools/copyright.py --check rc 0; bash -n on the changed scripts, none.
One thing a re-runner will trip on: tools/npu_plan.py <dir> --check against the four model dirs on this box now
reports a difference, because those plans were regenerated by the merged 1.1 tool (generated_by, plus the
attention.causal row). That is main having moved, not this PR: with each dir's own --kernels the
artifact-probe decisions this PR changes are the ones in its own test.
|
Persistent review updated to latest commit bbe3c21 |
Main's #837/#843 made the artifact family t2s-aware ("_t2s" / "_t2s2"), and XdnaTarget::open() was recomputing it locally from pb16i_/weight_layout_b8_. That copy could not see t2s at all, and because a t2s container also sets pb16i_ (its weights are the integer-exact ternary family), it refused every _t2s/_t2s2 plan as "this target runs family _pb16i" -- a false refusal in the same shape as the decode-twin one the #808 gate found on 2026-11-02. open() now takes `family` and the forward passes family_tag(), so there is one copy of that rule and it is the one the kernel names are built from. Found by reading the rebase against main, not by running: no t2s container of this model size is on the box, so the defect is shown from the code and the rm path is unaffected.
Main's #837/#843 made the artifact family t2s-aware ("_t2s" / "_t2s2"), and XdnaTarget::open() was recomputing it locally from pb16i_/weight_layout_b8_. That copy could not see t2s at all, and because a t2s container also sets pb16i_ (its weights are the integer-exact ternary family), it refused every _t2s/_t2s2 plan as "this target runs family _pb16i" -- a false refusal in the same shape as the decode-twin one the #808 gate found on 2026-11-02. open() now takes `family` and the forward passes family_tag(), so there is one copy of that rule and it is the one the kernel names are built from. Found by reading the rebase against main, not by running: no t2s container of this model size is on the box, so the defect is shown from the code and the rm path is unaffected.
Main's #837/#843 made the artifact family t2s-aware ("_t2s" / "_t2s2"), and XdnaTarget::open() was recomputing it locally from pb16i_/weight_layout_b8_. That copy could not see t2s at all, and because a t2s container also sets pb16i_ (its weights are the integer-exact ternary family), it refused every _t2s/_t2s2 plan as "this target runs family _pb16i" -- a false refusal in the same shape as the decode-twin one the #808 gate found on 2026-11-02. open() now takes `family` and the forward passes family_tag(), so there is one copy of that rule and it is the one the kernel names are built from. Found by reading the rebase against main, not by running: no t2s container of this model size is on the box, so the defect is shown from the code and the rm path is unaffected.
…pb16i's 410 (#1276) P3 (#802) landed as code (#826/#830/#837/#843) and is the container serving on this box, but its own gate was never recorded at the model level: the docs carry the phase win (0.589 vs 1.037 ms, 1.76x) and the leaderboard had no t2s row at all, so the claim 'halve the wire, speed up decode' was proven per kernel only. Adds the measured pair as leaderboard records - the t2s2 arm and the pb16i control it is read against, because a ratio is only a ratio if both arms are recorded - and regenerates docs/npu-leaderboard.md from them, plus a subsection in the t2s chunk of docs/npu.md that states what the stream is worth at the model level: pb16i (control) 410 ms/token (409-412), device wait 296, 12.93 GB/token t2s2 sealed 313 ms/token (311-317), device wait 209, 6.11 GB/token 1.31x per token, 1.42x on the device wait, on 2.12x fewer bytes (431 images, 14.44 -> 6.82 GB, checked on disk). The model keeps 1.31x of the kernel's 1.76x because the host half (66 ms) and the lm head (13.5 ms) do not shrink with the wire. Measured 2026-11-02 in three adjacent npu-hold tickets on :18099, amdxdna counter 0 in each, 7 steady-state tokens per arm from the serve's own [ph] tok line - not request walls, which pay the per-serve image fill once (614/651 for a 32-token request). Acceptance is byte-exactness: every decode role matched the pb16i path byte for byte at layer 0 (6/6) and layer 3 (8/8) on three seeds, and greedy text agrees on the shared prompt. Co-authored-by: bong-water-water-bong <[email protected]>
Builds on #826 (merged as
7a3480b) and #836 (the v2 packer, open).q4nx_weight_layout_version5 and 6 are the same weights at the same size in different byte orders — reading one with the other's kernel is a silent permutation of the weight matrix, not a crash. So the version picks the artifact family, not just a flag:_pb16i, or the sealed ELF_t2s/_t2s_m16_t2s2/_t2s2_m16Any other version is refused by name at init:
q4nx_weight_layout_version 7 is not a t2s stream this build reads (5 = v1, 6 = v2).Why v2 is the one to ship — measured on the array, same window, seeds 1/2/3 byte-exact,
amdxdnacounter 01.76x on a quiet box, 1.96x on a loaded one (where the leader itself falls to 30.85 GB/s) — every ratio in
~/wt/npu-arena/LEADERBOARD.mdcarries its window. 40.2 GB/s on 47 % of the bytes is 83 % of the leader's per-byte rate. The stream cost drops 12.93 -> 6.11 GB/token for a 27B decode.Contents
npu/forward:t2s_v2_from the container's version;family_tag()->_t2s/_t2s2; the layout banner names the wire order; the version check is per-layout (t2s accepts 5 or 6, pb16i only 4).npu/plan:kernels.tagaccepts_t2s2, requirescontainer.layout: "t2s", and counts as the ternary family.tools/npu_plan.py: writes_t2s2for version 6,_t2sfor 5.docs/npu.md: the version -> family table and the measured result.npu_plangains the v2 plan and the_t2s2-on-a-pb16i-container refusal;npu_plan_generatecovers both tags. Green locally (npu_plan,npu_plan_generate,npu_t2s_layout,q4nx_t2s).Not in this PR
A v2 sidecar set installed in a real container end to end — that needs the images packed for all 27B tensors (~6.8 GB) and an in-loop decode run on a quiet box. Next item; the arena numbers above are the per-phase proof it rests on.