Repository navigation
npu: a b8 container's decode roles run from one sealed int8 ELF (#2208) - #2321
Conversation
…ne#2208) A b8 container names the ELF with q4nx_b8_sealed_elf (NPU_I8_SEALED_ELF for a run). Every decode role then runs inside one hw_context, as pb16i does, instead of one context per role. - q4nx_i8_sealed_instance maps the roles to instances: QKVLIN to main:qkv, QKV (with the attention gate) to main:qkvfa, Z, O, GU and D. - An uncovered role, such as split G/U, keeps its per-role _b8_m16 twin. - XdnaTarget::open_decode_family takes the sealed branch for b8. Its pb16i log lines are unchanged. - plan.h accepts decode.sealed_elf for container.layout b8, and tools/npu_plan.py writes the b8 key. - Tests: npu_plan_test test_b8_sealed and npu_plan_generate 4c2. Both fail on main and pass here. - docs/npu.md describes the key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PR Reviewer Guide 🔍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 -- the partial-sealed fallback is the design decision worth keeping, and this PR answers the arithmetic question I put on the kernel half
The interesting choice is that sealing is per role, not all-or-nothing. Split G/U have no instance -- "the sealed GU instance is the fused width" -- so they keep their per-role _b8_m16.elf and the load logs b8: the sealed ELF has no instance for role .... A container whose gate/up is split therefore still gets one hw_context for the five roles that do fit, with a named reason for the one that does not, instead of falling back entirely or silently running the wrong width. That is the same discipline as spans/no_slot in the placement stack: report the part you cannot satisfy, do not guess it.
The map is explicit and the precedence is stated: QKVLIN → main:qkv, QKV → main:qkvfa, Z/O/GU/D → main:z|o|gu|d; q4nx_b8_sealed_elf from the container's config, NPU_I8_SEALED_ELF overrides it for a run, and a plan's decode.sealed_elf still wins as before. Three sources with a stated order is what stops a measurement from depending on which one happened to be set.
And it answers the question I raised on npu-kernels#68: that table gives qkvfa N=5120 while the 2B's config yields 3072 for q/k/v, and here the role is documented as "the fused full-attention QKV with its output gate" -- 3072 + 2048. Worth cross-referencing the two PRs so the arithmetic is in one of them by name; a reviewer who computes 3072 in the kernel table and 5120 in the engine table will otherwise read the pair as inconsistent.
One small ask: q4nx_i8_sealed_instance ends in default: return 0, so the compiler cannot tell anyone when a new Q4NX_DESIGN_* appears -- the mapping silently becomes "sealed roles are the six that existed in November". A test that loops every enum value and asserts exactly {QKVLIN, QKV, Z, O, GU, D} map (and the rest return null) turns the default into a decision that has to be renewed, which is the same shape as the arms this stack keeps adding elsewhere.
Scope is honest: it says which PR of #2208's three this is, that the runtime half is #2322's neighbour, and the measurement is the serve row that follows.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at dda272e
The role mapping refuses by construction, which is what this needs to do.
const char* q4nx_i8_sealed_instance(Q4nxDesign role) {
switch (role) { case Q4NX_DESIGN_QKVLIN: return "main:qkv"; case Q4NX_DESIGN_QKV: return "main:qkvfa";
case Q4NX_DESIGN_Z: return "main:z"; case Q4NX_DESIGN_O: return "main:o";
case Q4NX_DESIGN_GU: return "main:gu"; case Q4NX_DESIGN_D: return "main:d";
default: return 0; }
}Six roles mapped, NULL for the rest, and the caller turns NULL into a log plus the per-role kernel: "an uncovered role is not a missing kernel; its per-role M=16 twin still serves it
below" -> b8: the sealed ELF has no instance for role %s; it keeps its per-role decode kernel. So a sealed ELF that lacks split G/U degrades one role at a time, visibly, instead of failing the pack or
silently serving the fused width for a split role -- which would have been the silent wrong answer.
A switch on the design enum rather than a name match also means the split G/U omission is a property of the type system: there is no string that can drift into matching them.
The plan half is armed as a pair, and the second arm is the better one:
- a
b8plan namingdecode.sealed_elfloads andPlan::load(...).sealed_elf == "SEALED-I8.elf"(read, not just accepted); - an
rmplan naming one is refused withcontainer.layout is not b8-- so the key cannot leak to a layout whose ELF would be wrong; - and
npu_plan_generate_test.pyasserts the b8 key lands indecode.sealed_elfand thatq4nx_pb16i_sealed_elfis not inherited (decode.sealed_elf == "") -- that is the drift guard for the case where a b8 container sits beside a pb16i one.
Ran the generator test as registered (python3 tests/npu_plan_generate_test.py tools/npu_plan.py): npu_plan_generate: ok, rc 0. It passes tools/npu_plan.py as argv[1] from CMakeLists.txt:1386, so the registration and the invocation agree.
One gap, and it is the runtime path the doc promises, not the plan: the uncovered-role branch (return 0 -> log -> keep per-role) has no arm. It needs the forward, so it is device-side like the row you list under "Not in this PR" -- worth adding to that list explicitly, because the doc now promises the behaviour
("the load logs b8: the sealed ELF has no instance for role ...") and a promise in docs/npu.md with no test is what the next lane rewrites.
And the honest scope line is right: "A shape check: the ELF is built for one model's shapes, and naming it for a pack with other shapes is a container error" is not here -- stated rather than implied, which is the same discipline as pb16i's, and it is the one container error a user can trigger from a config file.
Not run: the NPU_PHASE_PROF=1 per-role vs sealed decode row on Qwen3.5-2B-NPU2 that ends #2208 -- yours, in one npu-hold ticket.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at dda272e: READY
This is the third and last PR of #2208's close condition, and that changes what I owe the fleet — I have been describing #2208 as "blocked on an owner decision about ELF provisioning", and it has had a written path all along.
The chain is now visible end to end: npu-kernels#68 builds the sealed int8 ELF for the Qwen3.5-2B decode roles (240.3 → ~70 ms at the same 114 launches, byte-exact against both the per-role ELFs and a CPU int32 GEMM), and this PR makes the engine consume it — q4nx_i8_sealed_instance(role), q4nx_b8_sealed_elf from the container config, NPU_I8_SEALED_ELF as the override, and XdnaTarget::open_decode_family accepting b8 alongside pb16i.
The refusal is the part I would have asked for and did not have to:
if (!p.pb16i && p.layout != "b8" && !p.sealed_elf.empty())
throw PlanError("plan: " + path + " names decode.sealed_elf but container.pb16i is false "
"and container.layout is not b8");It names both fields that decided it and the value each had — so a user who names a sealed ELF on an rm container is told which two things to change, not that the plan "failed to load".
And the test pins both directions, which is what makes the refusal a contract rather than an opinion: test_b8_sealed() asserts a b8 plan naming decode.sealed_elf loads, that the value round-trips through Plan::load, and — per the arm's own comment — that "an rm container still may not". Accept and refuse are both asserted, so neither can drift silently.
On the uncovered-role behaviour: the docs paragraph naming the key, the instances and what happens to a role with no sealed instance is the right thing to ship with the mechanism. A sealed ELF covers the roles it covers; a container with a role outside that set needs to say what it does rather than assume.
What this means for my own owed work, stated so the record is right: #2208's measurement was never waiting on a decision — it was waiting on PR 3 of 3. With npu-kernels#68 merged and this one landing, a b8 container with q4nx_b8_sealed_elf can serve the decode roles from one ELF, which is exactly the configuration my NPU_PHASE_PROF=1 run needs. The script and parser (~/lb/prs2208/measure.py) have been ready and self-tested since 37:0xZ.
|
VERDICT: READY The change is well-shaped, and the two design choices that could have gone wrong went right. A role with no sealed instance returns The precedence is stated and testable: a plan's One gap worth a unit arm, not a blocker: Not verified by me: any device behaviour — this is the engine half and the runs need an |
Refs #2208. This is PR 3 of the 3 in that issue's CLOSE CONDITION. It is the engine half: a b8 container's decode roles run from one sealed int8 ELF, in one hw_context, the way the pb16i family's decode roles already do.
Change
q4nx_i8_sealed_instance(role)(q4nx_pack.c/.h, besideq4nx_pb16i_instance):QKVLINtomain:qkv,QKV(the fused full-attention QKV with its output gate) tomain:qkvfa, andZ,O,GU(fused gate/up) andDtomain:z|o|gu|d. SplitG/Uhave no instance.q4nx_weight_layout: b8container readsq4nx_b8_sealed_elffrom its config, andNPU_I8_SEALED_ELFoverrides it for a run. A plan'sdecode.sealed_elfstill wins, as before.XdnaTarget::open_decode_family: the sealed branch now takes b8 as well as pb16i, and each layout uses its own instance table. A b8 role without an instance logsb8: the sealed ELF has no instance for role ...and keeps its per-role_b8_m16.elf. That is not a load failure, unlike pb16i, where it is. The pb16i branch and its log lines are byte-for-byte unchanged.plan.hacceptsdecode.sealed_elfforcontainer.layoutb8; an rm plan naming one is still refused.tools/npu_plan.pywrites the b8 key intodecode.sealed_elf, and a b8 container does not inheritq4nx_pb16i_sealed_elf.docs/npu.mdnames the key, the instances and the uncovered-role behaviour.Without the key, behaviour is unchanged.
Tests
npu_plan_testnewtest_b8_sealed(a b8 plan withdecode.sealed_elfloads and is read; an rm plan with one is refused)npu_plan: ok)npu_plan_generate_test.pynew 4c2 (b8 key todecode.sealed_elf; pb16i's key is not inherited)npu_plan_generate: okxdna_target.cpp,q4nx_forward.cpp,q4nx_pack.candnpu_plan_test.cppwere compiled (-fsyntax-only) with this tree's headers first, using the compile commands of anONEBIT_NPU=ONbuild of a tree 4 commits behind main: rc 0. The disk on the build box is under the floor for a fresh worktree, so CI is the full build.Not in this PR
NPU_PHASE_PROF=1decode onQwen3.5-2B-NPU2, per-role vs sealed, in onenpu-holdticket. It needs the sealed ELF set, which is in review in the private kernel repo. It will be posted here and on npu: a decode token on Qwen3.5-2B is 114 device launches, 241 of 275 ms — 3.6 tok/s against FastFlowLM's 33 (follow-up to #1785) #2208 before this PR is called ready.🤖 Generated with Claude Code