Repository navigation
npu plan P1: plan.json + tools/npu_plan.py + loader; the forward derives its designs from the plan (#800) - #807
Conversation
…ward derives its designs from the plan (engine #800) The forward decided three things by looking at which files were in --kernels: whether gate/up is fused (the fused GU kernel won, and with no split kernel on disk the split layout was assumed), which artifact family to run (""/_b8/_pb16i, i.e. whichever container layout the config named), and where the M=16 decode twins live (<model>/kernels-m16, <kernels>/m16, then <kernels>). Serving the same model against a different kernel directory therefore changed path silently -- the trap the serve switch hit. This adds the plan those decisions belong in, and it is additive: a model directory WITHOUT a plan.json keeps the probes exactly as they were, byte for byte. - npu/plan/plan.h: schema v1 ("1bit-npu-plan/1") and a loader that refuses by name -- a format it does not read, a layer role it does not know, a kernels.tag that disagrees with the container, a sealed ELF named outside the pb16i family, a decode dir that is absolute or contains "..", a layer count that disagrees with layers[], an enabled batched-expert kernel with no geometry, half a projection. A default here would be a different model, which is the failure mode the plan exists to remove. - tools/npu_plan.py: generates it from config.json plus the kernel directory (roles from layer_types, projection shapes from the model's own dimensions, the same derivation the forward uses), with --print and --check (re-generate and diff, rc 1 on any difference, so a stale plan is a gate failure). - q4nx_forward: reads the plan for fused gate/up, the kernel tag (asserted against the container's layout), the decode dirs, the sealed ELF and the batched-expert kernel; a missing kernel now says which plan asked for it ("plan <path>: this model's plan needs the QKV kernel "..." in <dir> (missing)"). - docs/npu.md: what the plan decides, and what a model without one keeps. - configs/plans/: the four plans for the model directories on the build box. Gate (engine #800): window11 3/3 identical + prof table unchanged on bonsai2-27b-pb16i, same binary, run once with the plan and once with it renamed aside (legacy probes), each under an npu-hold ticket on the sealed family only: texts: 3/3 identical prof rows: 17 identical (phase, role, M); worst row +4.6% (dec D 1.254 -> 1.253, pre D 2.571 -> 2.689), all inside the 10% tolerance A took the plan path ([plan] line present, 2 decode dirs), B took the probe path (no [plan] line); both loaded "8 role(s) at M=16, 1 on M=128" ctest npu_plan (18 assertions) and npu_plan_generate pass; copyright rc 0.
PR Reviewer Guide 🔍(Review updated until commit 13f73d6)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 window11 row the gate asks for is in the body (texts: 3/3 identical, window11: PASS, 17 prof rows) and the plan
machinery does what it claims — I checked it against the four real model dirs rather than the synthetic one.
Ran at b5d23507:
$ for m in Qwen3-0.6B bonsai2-27b-NPU bonsai2-27b-NPU-b8 bonsai2-27b-pb16i; do npu_plan.py <dir> --check; done
Qwen3-0.6B rc 0 "matches the model dir"
bonsai2-27b-NPU rc 0 "matches the model dir"
bonsai2-27b-NPU-b8 rc 0 "matches the model dir"
bonsai2-27b-pb16i rc 0 "matches the model dir"
# the silent decision this PR exists to remove, flipped by hand in a copy of the plan:
- "gate_up": "split" (on disk)
+ "gate_up": "fused" (generated)
$ npu_plan.py ~/models/npu/Qwen3-0.6B --check rc 1, "differs from what the model dir generates -- regenerate it"
$ … format changed to "1bit-npu-plan/2" rc 1, diff on the format line
$ cmake -DONEBIT_NPU=ON -DONEBIT_NPU_RT_DIR=<private runtime> … && ninja npu_plan_test onebit_npu_forward
rc 0 — and this matters because **CI does not compile the NPU lane**, so `q4nx_forward.cpp`'s +74/−15 is only compiled here.
$ ./npu_plan_test "npu_plan: ok"
$ python3 tests/npu_plan_generate_test.py tools/npu_plan.py "npu_plan_generate: ok"
So the fused/split decision, the artifact family and the decode dirs now come from a checked-in file, a disagreement is a
named refusal, and --check catches a plan that has drifted from its model dir. The additive migration (no plan.json →
the old probes) is the right way to land this: nothing changes for a model dir without a plan, and the four dirs on this box
have one.
Two notes, neither blocking:
- "prof table unchanged" is measured as "inside the 10 % tolerance". #800's gate says unchanged; the body shows deltas
of +0.1 % … +4.6 % (worstpre D, same binary, two runs) and calls the criterion a 10 % tolerance. Those are different
claims, and the honest one is the one the harness enforces — worth one line in the body stating the tolerance as the
criterion, plus (cheaply) a second A/B pair to show the run-to-run spread, since 4.6 % on a single pair is indistinguishable
from harness noise without it. - nothing in CI re-checks the four committed
configs/plans/*.plan.json.npu_plan_generatetests--checkagainst a
synthetic dir (good), but the committed plans are only verified when someone runs--checkby hand — I did, all four pass
today. That is a structural gap (CI has no model dirs), not a defect; a sentence indocs/npu.mdnaming the command and
where it runs would close it honestly.
tprs-ready applied.
|
Persistent review updated to latest commit 13f73d6 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
At 13f73d6a (the night waiter's rebase): own paths byte-identical to the head I verdicted
(git diff --stat b5d23507 <head> -- npu/plan/plan.h npu/forward/ tools/npu_plan.py tests/npu_plan_test.cpp tests/npu_plan_generate_test.py configs/plans/ scripts/npu-window11.sh docs/npu.md CMakeLists.txt → empty), and green on
both checks (build: success, CodeQL: success).
Evidence stands: the body carries the gate row (texts: 3/3 identical, window11: PASS, 17 prof rows), npu_plan.py --check
returns rc 0 against all four committed plans and rc 1 when I flipped fusion.gate_up fused→split or the format
string, npu_plan_test → npu_plan: ok, npu_plan_generate_test → npu_plan_generate: ok, and the NPU lane compiles
(ninja onebit_npu_forward, rc 0 — CI does not build it).
Two notes carried, neither blocking: #800's word "unchanged" vs the PR's measured "+0.1 % … +4.6 %, inside a 10 % tolerance"
(the tolerance should be the stated criterion, with a second A/B pair for the spread), and no CI gate re-checks the four
committed configs/plans/*.plan.json because CI has no model dirs — a manual --check worth naming in docs/npu.md.
tprs-ready stays. This is the head to merge on.
…cating the derivation Rebased onto 11c760b (#807) and wired the plan through the seam: XdnaTarget::open(plan, kernels_dir) now takes onebit::npu::plan::Plan (P1's namespace, not the local forward-declaration I had), keeps it, and refuses by name when the geometry it was handed disagrees with the plan - layer count, prefill M, decode M (and decode.enabled with no twin), the kernels.tag family, and no-device/no-design. The forward calls it once the geometry is final, at the end of init_impl, and skips it in host-GEMM mode because that path is the model's own fallback and has no target. That is the overlap the orchestrator asked for, and only that: A1 still does not derive the design table from the plan (A2 does), so the filename probes the forward keeps for a directory without a plan.json stay exactly as P1 left them. A target that ignored the plan would be the probe trap with extra steps. npu/forward/src/q4nx_forward.cpp: rebased over P1's plan block (the plan overrides the container's sealed ELF name, so the local the target receives is plan-derived); CMakeLists keeps P1's PUBLIC nlohmann_json dependency alongside the repo-root include path the target needs.
…cating the derivation Rebased onto 11c760b (#807) and wired the plan through the seam: XdnaTarget::open(plan, kernels_dir) now takes onebit::npu::plan::Plan (P1's namespace, not the local forward-declaration I had), keeps it, and refuses by name when the geometry it was handed disagrees with the plan - layer count, prefill M, decode M (and decode.enabled with no twin), the kernels.tag family, and no-device/no-design. The forward calls it once the geometry is final, at the end of init_impl, and skips it in host-GEMM mode because that path is the model's own fallback and has no target. That is the overlap the orchestrator asked for, and only that: A1 still does not derive the design table from the plan (A2 does), so the filename probes the forward keeps for a directory without a plan.json stay exactly as P1 left them. A target that ignored the plan would be the probe trap with extra steps. npu/forward/src/q4nx_forward.cpp: rebased over P1's plan block (the plan overrides the container's sealed ELF name, so the local the target receives is plan-derived); CMakeLists keeps P1's PUBLIC nlohmann_json dependency alongside the repo-root include path the target needs.
…cating the derivation Rebased onto 11c760b (#807) and wired the plan through the seam: XdnaTarget::open(plan, kernels_dir) now takes onebit::npu::plan::Plan (P1's namespace, not the local forward-declaration I had), keeps it, and refuses by name when the geometry it was handed disagrees with the plan - layer count, prefill M, decode M (and decode.enabled with no twin), the kernels.tag family, and no-device/no-design. The forward calls it once the geometry is final, at the end of init_impl, and skips it in host-GEMM mode because that path is the model's own fallback and has no target. That is the overlap the orchestrator asked for, and only that: A1 still does not derive the design table from the plan (A2 does), so the filename probes the forward keeps for a directory without a plan.json stay exactly as P1 left them. A target that ignored the plan would be the probe trap with extra steps. npu/forward/src/q4nx_forward.cpp: rebased over P1's plan block (the plan overrides the container's sealed ELF name, so the local the target receives is plan-derived); CMakeLists keeps P1's PUBLIC nlohmann_json dependency alongside the repo-root include path the target needs.
…cating the derivation Rebased onto 11c760b (#807) and wired the plan through the seam: XdnaTarget::open(plan, kernels_dir) now takes onebit::npu::plan::Plan (P1's namespace, not the local forward-declaration I had), keeps it, and refuses by name when the geometry it was handed disagrees with the plan - layer count, prefill M, decode M (and decode.enabled with no twin), the kernels.tag family, and no-device/no-design. The forward calls it once the geometry is final, at the end of init_impl, and skips it in host-GEMM mode because that path is the model's own fallback and has no target. That is the overlap the orchestrator asked for, and only that: A1 still does not derive the design table from the plan (A2 does), so the filename probes the forward keeps for a directory without a plan.json stay exactly as P1 left them. A target that ignored the plan would be the probe trap with extra steps. npu/forward/src/q4nx_forward.cpp: rebased over P1's plan block (the plan overrides the container's sealed ELF name, so the local the target receives is plan-derived); CMakeLists keeps P1's PUBLIC nlohmann_json dependency alongside the repo-root include path the target needs.
…cating the derivation Rebased onto 11c760b (#807) and wired the plan through the seam: XdnaTarget::open(plan, kernels_dir) now takes onebit::npu::plan::Plan (P1's namespace, not the local forward-declaration I had), keeps it, and refuses by name when the geometry it was handed disagrees with the plan - layer count, prefill M, decode M (and decode.enabled with no twin), the kernels.tag family, and no-device/no-design. The forward calls it once the geometry is final, at the end of init_impl, and skips it in host-GEMM mode because that path is the model's own fallback and has no target. That is the overlap the orchestrator asked for, and only that: A1 still does not derive the design table from the plan (A2 does), so the filename probes the forward keeps for a directory without a plan.json stay exactly as P1 left them. A target that ignored the plan would be the probe trap with extra steps. npu/forward/src/q4nx_forward.cpp: rebased over P1's plan block (the plan overrides the container's sealed ELF name, so the local the target receives is plan-derived); CMakeLists keeps P1's PUBLIC nlohmann_json dependency alongside the repo-root include path the target needs.
…cating the derivation Rebased onto 11c760b (#807) and wired the plan through the seam: XdnaTarget::open(plan, kernels_dir) now takes onebit::npu::plan::Plan (P1's namespace, not the local forward-declaration I had), keeps it, and refuses by name when the geometry it was handed disagrees with the plan - layer count, prefill M, decode M (and decode.enabled with no twin), the kernels.tag family, and no-device/no-design. The forward calls it once the geometry is final, at the end of init_impl, and skips it in host-GEMM mode because that path is the model's own fallback and has no target. That is the overlap the orchestrator asked for, and only that: A1 still does not derive the design table from the plan (A2 does), so the filename probes the forward keeps for a directory without a plan.json stay exactly as P1 left them. A target that ignored the plan would be the probe trap with extra steps. npu/forward/src/q4nx_forward.cpp: rebased over P1's plan block (the plan overrides the container's sealed ELF name, so the local the target receives is plan-derived); CMakeLists keeps P1's PUBLIC nlohmann_json dependency alongside the repo-root include path the target needs.
…cating the derivation Rebased onto 11c760b (#807) and wired the plan through the seam: XdnaTarget::open(plan, kernels_dir) now takes onebit::npu::plan::Plan (P1's namespace, not the local forward-declaration I had), keeps it, and refuses by name when the geometry it was handed disagrees with the plan - layer count, prefill M, decode M (and decode.enabled with no twin), the kernels.tag family, and no-device/no-design. The forward calls it once the geometry is final, at the end of init_impl, and skips it in host-GEMM mode because that path is the model's own fallback and has no target. That is the overlap the orchestrator asked for, and only that: A1 still does not derive the design table from the plan (A2 does), so the filename probes the forward keeps for a directory without a plan.json stay exactly as P1 left them. A target that ignored the plan would be the probe trap with extra steps. npu/forward/src/q4nx_forward.cpp: rebased over P1's plan block (the plan overrides the container's sealed ELF name, so the local the target receives is plan-derived); CMakeLists keeps P1's PUBLIC nlohmann_json dependency alongside the repo-root include path the target needs.
…cating the derivation Rebased onto 11c760b (#807) and wired the plan through the seam: XdnaTarget::open(plan, kernels_dir) now takes onebit::npu::plan::Plan (P1's namespace, not the local forward-declaration I had), keeps it, and refuses by name when the geometry it was handed disagrees with the plan - layer count, prefill M, decode M (and decode.enabled with no twin), the kernels.tag family, and no-device/no-design. The forward calls it once the geometry is final, at the end of init_impl, and skips it in host-GEMM mode because that path is the model's own fallback and has no target. That is the overlap the orchestrator asked for, and only that: A1 still does not derive the design table from the plan (A2 does), so the filename probes the forward keeps for a directory without a plan.json stay exactly as P1 left them. A target that ignored the plan would be the probe trap with extra steps. npu/forward/src/q4nx_forward.cpp: rebased over P1's plan block (the plan overrides the container's sealed ELF name, so the local the target receives is plan-derived); CMakeLists keeps P1's PUBLIC nlohmann_json dependency alongside the repo-root include path the target needs.
What
Part of #799 (the NPU plan layer), P1 = #800. The forward decided three things by looking at which files were in
--kernels:full_i8_GU_*kernel won; with no split kernel on disk the split layout was assumed""/_b8/_pb16icame from the container'sq4nx_weight_layout, so a kernel dir of the other family changed which kernels ran<model>/kernels-m16, then<kernels>/m16, then<kernels>Serving the same model against a different kernel directory therefore changed path silently — the trap the serve
switch hit. This puts those decisions in a generated, checked-in
plan.jsonand makes a disagreement a named refusal.Additive and behaviour-preserving by construction: a model directory without a
plan.jsonkeeps the probesexactly as they were; the new code path only runs when a plan is present.
Files
npu/plan/plan.h— schema v1 ("1bit-npu-plan/1") + loader. Every refusal names the field: a format it does notread, an unknown layer role, a
kernels.tagthat disagrees with the container, a sealed ELF named outside the pb16ifamily, a decode dir that is absolute or contains
..(a plan file must not be able to point the loader at adirectory the command line never named), a layer count that disagrees with
layers[], an enabled batched-expertkernel with no geometry, half a projection. A default here would be a different model.
tools/npu_plan.py— generates the plan fromconfig.json+ the kernel directory: roles fromlayer_types,projection shapes from the model's own dimensions (the same derivation the forward does — verified: Qwen3-0.6B comes
out
QKV 1024×4096,GU 1024×6144,D 3072×1024, which are exactly its kernel names).--print, and--checkwhich re-generates and diffs,
rc 1on any difference, so a stale plan fails a gate instead of producing a number.q4nx_forward— reads the plan for fused gate/up, the tag (asserted against the container layout), the decodedirs, the sealed ELF and the batched-expert kernel. A missing kernel now says who asked for it:
plan <path>: this model's plan needs the QKV kernel "full_i8_QKV_K1024_N4096.elf" in <dir> (missing).docs/npu.md— what the plan decides, what a model without one keeps.configs/plans/— the four plans for the model directories on the build box.scripts/npu-window11.sh— the gate harness (there was none in the tree): three fixed greedy prompts + the proftable,
--compare A B.Gate (engine #800): window11 3/3 identical + prof table unchanged on
bonsai2-27b-pb16iSame binary, run twice under
npu-holdtickets on the sealed family only, memory-capped(
systemd-run -p MemoryMax=32G, 14 GB of sidecar weights): A withplan.jsonpresent, B with it renamed asideso the legacy probes decide. Which path each took is visible in the serve log — A printed the
[plan]line with 2decode dirs, B printed none.
Both runs loaded
8 role(s) at M=16, 1 on M=128, and both transcripts are the full assistant message(
content+reasoning_content+finish_reason) — a short greedy reply on this model is allreasoning_content,and comparing two empty
contentstrings would have "passed" without testing anything (it did, in my first draft).Tests
ctest npu_plan(18 assertions: valid plans, and 14 named refusals)ctest npu_plan_generate(synthetic model dir: fused/split both ways, no-kernel fallback, pb16i tag + sealed ELF,--checkcatching a changed kernel set)ctest npu_sampling / systemone_contract / systemone_route / decision_headtools/copyright.py --checkTwo bugs my own tests caught before the device saw them: the loader rejected the valid
pb16ilayout (it accepted onlyrm/b8), and the plan-load sat before the layout block so every pb16i model refused withkernels.tag "_pb16i" but the container is "rm"— the refusal was right, its input was not.Not in this PR
NpuTarget/NpuModelextraction and the t2 chunk kind (P2/P4 in #799's table). The plan'slayers[]block isdescriptive today: P4 consumes it.
scripts/npu-window11.shis committed because the gate names it and nothing in thetree implemented it; if another lane already has one privately, this one should be replaced by that.