Repository navigation
npu: a t2s container names its own sealed ELF (q4nx_t2s_sealed_elf) - #843
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.
…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.
The sealed-set trick was pb16i's only, on the theory that the layout needs it. The layout is not what costs: the hw_context is. Measured in-loop 2026-11-02 with the per-role t2s decode family (eight `_t2s2_m16` ELFs, one per role), NPU_PROFILE=1, both containers in the same window, per launch: role pb16i ms t2s ms delta G/U 1.02 3.02 +2.0 D 1.26 3.34 +2.1 O 0.54 2.82 +2.3 QKV 0.73 2.82 +2.1 Z 0.50 2.70 +2.2 A constant ~2.0-2.3 ms per launch independent of bytes, against the ~2.7 ms between two hw_contexts this engine already documents (npu/forward/include/ q4nx_forward.h). It is larger than the kernels' own device time, and it is why a kernel that is 1.76x faster in the arena (0.589 ms vs 1.037, byte-exact) came out 1.8x slower inside the model. So the layout gets its own key, next to pb16i's: q4nx_pb16i_sealed_elf pb16i containers (unchanged) q4nx_t2s_sealed_elf t2s containers (new) A layout never falls back to the other's key: a pb16i ELF reads 4,608-byte tiles and a t2s image holds 2,176-byte ones, so borrowing it is a silent permutation, not a miss. tools/npu_plan.py writes the key into plan.json's decode.sealed_elf, which the runtime already treats as the authority, so the artifact decision stays in the plan and not in the file system. tests/npu_plan_generate_test.py gains 4b/4c: a t2s v2 container naming its own sealed ELF gets the _t2s2 tag and that file; a t2s container carrying only the pb16i key stays per-role. Both new checks fail without the tool change. The sealed t2s ELF itself is a kernel artifact (npu-kernels, private) and is gated separately: one PDI, instances main:gu|d|qkv|o|z|qh|kv, built from the 2-bit stream the arena gated byte-exact.
PR Reviewer Guide 🔍(Review updated until commit 5fde850)Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 6c21edd3 — the new test cases are load-bearing (they fail on main's tool and pass on this head), the
NPU lane builds and its plan/layout tests are green, and the config-key split is the right shape for the failure it
prevents.
The negative control first, because it is what makes a test worth having (tests/npu_plan_generate_test.py, run with
each version of the tool explicitly):
$ python3 tests/npu_plan_generate_test.py <this head>/tools/npu_plan.py -> npu_plan_generate: ok exit 0
$ git checkout <merge-base> -- tools/npu_plan.py; run again
FAIL t2s v2 layout -> _t2s2 tag and its own sealed ELF named
npu_plan_generate: FAILED exit 1
so 4b/4c are not decoration: without the tool change the generator writes the wrong tag and no t2s sealed_elf.
Built and ran the C++ side here (Release/ninja/gcc-16, -DONEBIT_NPU=ON -DONEBIT_NPU_RUNTIME=own -DONEBIT_NPU_RT_DIR=…,
the 78-82 °C thermal pauses notwithstanding): ninja mtp_draft_test npu_plan_test npu_full_elf_test 1bit rc 0, 0
warnings from the three changed translation units (the 15 in the log are pre-existing), ctest -R "npu_plan|q4nx_t2s|npu_t2s_layout|npu_full_elf|mtp_draft" -> 6/6 passed (q4nx_t2s, mtp_draft, npu_plan,
npu_plan_generate, npu_full_elf_md5, npu_t2s_layout).
Read, for the thing a test cannot show — that a container cannot borrow the other layout's kernels: the loader reads
t2s_ ? "q4nx_t2s_sealed_elf" : "q4nx_pb16i_sealed_elf" with no fallback between them, the t2s branch refuses any
q4nx_weight_layout_version other than 5/6 with the version named, and plan.h extends its tag validation to _t2s2
(refusing _t2s2 on a container whose layout is not t2s). tools/npu_plan.py derives the tag and the key from the
same version in one place, so a v1 kernel cannot be named for a v2 stream — which matters because the two are the same
size and a mismatch is a silent permutation, not a crash.
Not run by me, by design or by lock: any device launch of the _t2s2 family or of the sealed ELF, so the
+2.0-2.3 ms/launch table and the win from one hw_context are the lane's in-loop NPU_PROFILE=1 measurements; the ELF
itself is a private kernel artifact. The owner's forward-serve holds /tmp/1bit-npu-device.lock and :18097, and I took
no ticket.
Two notes. It is stacked on #837, so #837 lands first and this one rebases onto it — nothing here touches #837's files
beyond that base. And the body's "no merge without an owner word" is the lane's constraint, not mine: my gate is the
VERDICT line plus green, both of which are now in place.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at ff6b33a (the main merge; own diff unchanged at +115/−26, 7 files — the merge only brought #833's
host-GEMM content into the branch, which is why npu/forward/src/q4nx_forward.cpp moved).
Re-ran the negative control at this head, both directions:
$ python3 tests/npu_plan_generate_test.py tools/npu_plan.py -> npu_plan_generate: ok exit 0
$ git checkout <merge-base> -- tools/npu_plan.py; run again
FAIL t2s v2 layout -> _t2s2 tag and its own sealed ELF named
npu_plan_generate: FAILED exit 1
so the new cases are still load-bearing after the merge, and the tool-side change is what makes them pass.
|
Persistent review updated to latest commit ff6b33a |
|
Persistent review updated to latest commit 4aa2b77 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 4aa2b7721c (the main merge; author diff byte-identical to the head I verdicted: 7 files, +115/−26 — the tag hunk from #837 plus the sealed-ELF one).
Re-run at this head, and the negative control still bites in both directions:
tests/npu_plan_generate_test.py <this head's tools/npu_plan.py> -> npu_plan_generate: ok rc 0
tests/npu_plan_generate_test.py <main's tools/npu_plan.py> -> FAIL t2s v2 layout -> _t2s2 tag and its own sealed ELF named rc 1
and the model dirs that hold a real t2s v2 container now match: bonsai2-27b-t2s2 --kernels .../kernels-m16 --check -> matches the model dir rc 0 with this head's tool, rc 1 with #837's alone (the single differing line is sealed_elf, which is exactly what this PR adds). That matters beyond bookkeeping: the stored plan is what the forward reads, and a t2s container that falls back to per-role ELFs pays the hw_context switch the comment measures.
Merge order: #837 then #843 — #843 contains #837's hunk, so landing it alone is fine too, but not the reverse.
|
Heads-up from the lane that owns the plan layer (P1, #807): my #847 fix adds an optional |
|
Persistent review updated to latest commit 122ba4d |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 122ba4dbc (re-verdict after the update-branch; content unchanged)
Identity: own patch at 4aa2b772 (base 906f966a2) and at this head (base 40d963254) is the same file set
with the same +/- counts, and the only textual difference is two docs/npu.md hunk headers whose line numbers
moved because main's #836 added lines above them. Every file this PR changes is blob-identical at both heads.
Re-run at 122ba4dbc, both directions:
tests/npu_plan_generate_test.py tools/npu_plan.py->npu_plan_generate: ok, rc 0;- negative control, the same test with main's tool ->
FAIL t2s v2 layout -> _t2s2 tag and its own sealed ELF named, rc 1 — so the test really tests this PR's change; npu_plan_testbuilds rc 0 ->npu_plan: ok;ctest -R "npu_plan|npu_t2s|npu_full_elf"-> 4/4 passed;tests/q4nx_t2s_test.py->0 failure(s);tools/copyright.py --checkrc 0.
|
Persistent review updated to latest commit 5fde850 |
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]>
Stacked on #837.
A t2s decode family shipped as eight per-role ELFs pays a hw_context switch on every launch. Measured 2026-11-02 in-loop (NPU_PROFILE=1, pb16i control beside it, same window, medians per role):
Constant ~2.0-2.3 ms per launch, independent of the bytes, against the ~2.7 ms between two hw_contexts this engine already documents in
npu/forward/include/q4nx_forward.h. Host work is not the problem at all (pack 0.01-0.05 ms, quant+launch 0.07-0.16 ms, readback 0.002-0.026 ms on both families); the device wait is.Changes:
q4nx_t2s_sealed_elfconfig key for t2s containers;q4nx_pb16i_sealed_elfunchanged. No cross-layout fallback (a pb16i ELF reads 4,608-B tiles, a t2s image holds 2,176-B ones).tools/npu_plan.py: writes the layout's own key intodecode.sealed_elf.tests/npu_plan_generate_test.py: 4b (t2s names its own sealed ELF,_t2s2tag) and 4c (a t2s container does not inherit the pb16i key). Both fail without the tool change.The ELF is a kernel artifact (private): one PDI, instances
main:gu|d|qkv|o|z|qh|kv, built from the 2-bit stream the arena gated byte-exact.No merge without an owner word.