Skip to content

npu: t2s v2 selects its own artifact family (_t2s2), so a v1 kernel can never drive v2 images - #837

Merged
bong-water-water-bong merged 6 commits into
mainfrom
npu/t2s-v2-launch
Nov 2, 2026
Merged

bong-water-water-bong merged 6 commits into
mainfrom
npu/t2s-v2-launch

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Builds on #826 (merged as 7a3480b) and #836 (the v2 packer, open).

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, not just a flag:

version wire format decode kernels
4 pb16i _pb16i, or the sealed ELF
5 t2s v1 — the expansion interleaves inside the core _t2s / _t2s_m16
6 t2s v2 — ordering in the wire, the core's two contiguous stores are exact (no shuffle) _t2s2 / _t2s2_m16

Any 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, amdxdna counter 0

run bytes med_ms GB/s
pb16i phase (GU16I leader) 50,135,040 1.037 48.36
t2s v2 (no-shuffle expansion, hoisted once per n-block) 23,674,880 0.589 40.17

1.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.md carries 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.tag accepts _t2s2, requires container.layout: "t2s", and counts as the ternary family.
  • tools/npu_plan.py: writes _t2s2 for version 6, _t2s for 5.
  • docs/npu.md: the version -> family table and the measured result.
  • tests: npu_plan gains the v2 plan and the _t2s2-on-a-pb16i-container refusal; npu_plan_generate covers 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.

…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.
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit bbe3c21)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

826 - Partially compliant

Compliant requirements:

  • The t2s launch path is implemented with proper version checking
  • The container configuration is correctly handled with version 5
  • The images are read from the correct directory with proper extension
  • The decode kernels use the correct tag _t2s_m16
  • Size mismatch is properly refused
  • plan.json correctly handles the kernel tag and layout agreement

Non-compliant requirements:

Requires further human verification:

  • The actual performance measurements and hardware validation are not part of the code review

836 - Partially compliant

Compliant requirements:

  • The v2 wire format is implemented with correct byte order handling
  • The artifact family is correctly selected based on version (v1 -> _t2s, v2 -> _t2s2)
  • The kernel binary and tile order remain unchanged
  • Performance improvements are measured and documented
  • Version checking ensures correct artifact family selection

Non-compliant requirements:

  • The PR description mentions that v2 is the one to ship but doesn't explicitly show the performance improvement measurements

Requires further human verification:

  • The actual performance measurements and hardware validation are not part of the code review
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Version Validation Logic

The version validation logic in q4nx_forward.cpp correctly checks for valid t2s versions (5 and 6) but could be more explicit about the error message format. The error message should clearly state that version 5 corresponds to v1 and version 6 to v2 to avoid confusion for users.

    if (ver != 5 && ver != 6) {
        err_ = "q4nx_weight_layout_version " + std::to_string(ver) +
               " is not a t2s stream this build reads (5 = v1, 6 = v2)";
        return false;
    }
    t2s_v2_ = (ver == 6);
} else if (ver != 4) {
    err_ = "q4nx_weight_layout_version " + std::to_string(ver) +
           " is not an image format this build reads (4 is pb16i)";
    return false;
Tag Validation

The tag validation in plan.h now includes support for _t2s2 but the error message in the validation check doesn't clearly indicate that _t2s2 is a valid tag for t2s v2. This could lead to confusion if someone sees the error message and doesn't realize that _t2s2 is a valid tag.

if (p.tag != "" && p.tag != "_b8" && p.tag != "_pb16i" && p.tag != "_t2s" && p.tag != "_t2s2")
    throw PlanError("plan: " + path + " kernels.tag \"" + p.tag +
                    "\" is not \"\", \"_b8\", \"_pb16i\", \"_t2s\" or \"_t2s2\"");

…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.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 0855c12

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 96187a8

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 644bf63

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit b00f706

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Third lane in npu/plan/plan.h / tools/npu_plan.py tonight, so you hear it from me rather than from a rebase: my #847 fix adds an optional attention: {mode} block to the plan (causal default, noncausal_full_attention for a d3 readout pack, refused by name when unknown) and bumps TOOL_VERSION 1.0 → 1.1. It is a different key from your kernels.*/sealed-ELF additions and touches no line of them, but every regenerated plan.json now carries three extra lines (generated_by + the block), so a plan file regenerated from either branch will conflict with the other until both land. tools/npu_plan.py is append-only in my diff (one new function + one dict key + the print line). If you would rather I wait, say so and I will hold the PR open — otherwise the merge order that costs least is whichever of us lands first, then the other re-runs npu_plan.py <dir> --check on its own model dirs.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit bbe3c21

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at bbe3c21bc (re-verdict after the update-branch onto 82bc95e5f; the PR's own content is unchanged)

q4nx_t2s_test 0 failures, npu_plan: ok, own patch identical to the b00f706 head (164 files, same patch text) against the new main 82bc95e

@bong-water-water-bong
bong-water-water-bong merged commit ac79c36 into main Nov 2, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the npu/t2s-v2-launch branch November 2, 2026 22:12
bong-water-water-bong pushed a commit that referenced this pull request Nov 3, 2026
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.
bong-water-water-bong pushed a commit that referenced this pull request Nov 3, 2026
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.
bong-water-water-bong pushed a commit that referenced this pull request Nov 3, 2026
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.
bong-water-water-bong added a commit that referenced this pull request Nov 6, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 4/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant