Skip to content

npu plan: the schema a hybrid needs -- the rotary kind, the decoder's input kind, and a companion graph refused by name (#799) - #1623

Merged
bong-water-water-bong merged 1 commit into
mainfrom
1bit/plan-hybrid-schema
Nov 9, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
1bit/plan-hybrid-schema

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Part of #799 (owner: "YOURS: engine #799"). The 2026-11-08 entry on that issue recorded the first workload that needs more than one stream: a Qwen3-VL-2B hybrid (vision on HRX, text decoder on the NPU) is blocked on schema, not code — the plan describes one decoder stream over token ids and has no field for the rotary kind, for precomputed embeddings, or for a second graph. It asked which of three shapes to build. Deciding all three, and building two of them:

shape decision
1. position encoding rope {kind, planes, sections} — plain (absent = every plan written before) is one index; mrope is a 3 × N position block. sections is the pack's own split of the rotary width (Qwen3-VL: [24, 20, 20]) and is required for mrope: without it the planes have no declared width and a caller would guess. planes defaults to the number of sections and must agree with it. A plain rope carrying sections, or planes other than 1, is refused rather than read as if the planes existed
2. embedding input inputs {kind, vision {merge, feature_dim}} — tokens (absent = every plan before) or embeds, rows × hidden already merged with vision features (the split AMD's reference makes with embedding.onnx → text.onnx). A vision block on a tokens plan is refused: ignored vision features serve the text half of a vision model and answer confidently about an image it never saw. merge: external requires a positive feature_dim; none requires 0
3. a companion stream refused by name, with the reason — one plan is one decoder stream over one token sequence. A second graph (vision, projector) is its own model directory that the serving layer merges into inputs.embeds; a companion list would put two graphs and their scheduling in a file whose only consumer can neither open nor order them

Why the rotary field is worth a refusal rather than a default

The fallback it prevents is not cosmetic. From #799's own measurement of the reference's get_rope_index on a 448×448 image (196 image tokens, patch 16 → 28×28 → merge 2):

  • text following the image resumes at position 19, where a token-count advance would give 201;
  • an image advances the position by max(H,W)/s = 14, not by its 196 tokens;
  • text rows have all three planes equal (13 of 13), which is why plain RoPE is exact for text — and why a plan that silently ran mrope as one index predicts fluently while being wrong after every image.

Generator

tools/npu_plan.py writes rope from the pack's own config — top level, else text_config (where a VL pack keeps the text tower), since Qwen3-VL declares rope_scaling: {mrope_interleaved: true, mrope_section: [24, 20, 20]}. A rope_scaling with no mrope_section (linear/YaRN) means one index, and a malformed mrope_section stops the generator by name. Verified on the shapes:

{}                                        -> {"kind": "plain", "planes": 1}
{"rope_scaling": {"rope_type": "linear"}} -> {"kind": "plain", "planes": 1}
{"rope_scaling": {"mrope_section": [24,20,20]}}          -> {"kind": "mrope", "planes": 3, "sections": [24,20,20]}
{"text_config": {"rope_scaling": {"mrope_section": [16,16]}}} -> {"kind": "mrope", "planes": 2, "sections": [16,16]}
[24, 0, 20] / [] / "24,20,20"             -> SystemExit naming mrope_section

and end to end on a real model dir: tools/npu_plan.py ~/models/npu/Qwen3-0.6B writes "rope": {"kind": "plain", "planes": 1} and is otherwise unchanged.

Not a format bump, and no behaviour change

Absent means the old meaning for both sections — the rule attention.mode, kv and designs already follow — so every checked-in plan and every container written before this keeps loading. No forward change, no device, no kernel: this is the description the consumer side (npu/model/, the hybrid lane) was missing, and a target that cannot build the planes must refuse mrope by name, exactly as check_kv_caps does for int8 KV.

Verified

  • tests/npu_plan_test.cpp: 11 new cases — absent defaults; mrope with and without explicit planes; the generator's own {"kind":"plain","planes":1} shape; embeds with an external merge; and five refusals naming rope.sections, rope.planes, inputs.vision, feature_dim and companion. Built and run: npu_plan: ok.
  • tools/npu_plan.py on synthetic configs and on a real model directory (above).
  • npu/plan/plan.h only — the loader and the field docs; docs/npu-plan.md gains the three schema rows.

…r's input kind, and a companion graph refused by name

engine#799's owner entry recorded that a Qwen3-VL hybrid (vision on HRX, decoder on the NPU) is blocked on
schema, not code: the plan describes one decoder stream over token ids and has no field for the position
encoding, for precomputed embeddings, or for a second graph.  This decides all three.

`rope` {kind, planes, sections}: plain (absent = every plan written before) is one index; mrope is a 3xN
position block.  sections is the pack's own split of the rotary width (Qwen3-VL: [24,20,20]) and is REQUIRED
for mrope -- without it a caller has no declared width per plane.  planes defaults to the number of sections
and must agree with it, and a plain rope carrying sections is refused rather than read as if the planes
existed.  The fallback this prevents is not cosmetic: text after a 448x448 image resumes at position 19 where
a token-count advance gives 201, and both predict fluently.

`inputs` {kind, vision:{merge, feature_dim}}: tokens (absent = every plan before) or embeds -- rows x hidden
already merged with vision features, the split AMD's reference makes with embedding.onnx -> text.onnx.  A
vision block on a tokens plan is refused: ignored vision features serve the text half of a vision model and
answer confidently about an image it never saw.

`companion` is refused by name with the reason: one plan is one decoder stream, and a second graph is its
own model directory the serving layer merges into inputs.embeds -- a companion list would put two graphs and
their scheduling in a file whose only consumer can neither open nor order them.

tools/npu_plan.py writes rope from the pack's own config (top level, else text_config -- where a VL pack keeps
the text tower), so a plan reads as what its positions are.

Not a format bump: absent means the old meaning for both sections, the rule attention.mode, kv and designs
already follow.  No forward change and no device: the consumer side (building the planes, feeding embeds) is
the hybrid lane's, and this is the description it was missing.

tests/npu_plan_test.cpp: 11 cases -- absent defaults, mrope with and without explicit planes, the generator's
own plain shape, embeds with an external merge, and five refusals naming rope.sections / rope.planes /
inputs.vision / feature_dim / companion.
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

799 - Partially compliant

Compliant requirements:

  • Add support for describing rotary encoding kinds (plain vs mrope) in the plan schema
  • Add support for describing input kinds (tokens vs embeds) in the plan schema
  • Refuse plans with incomplete or inconsistent rotary or input configurations
  • Explicitly refuse companion graphs in the plan schema
  • Update documentation to reflect the new plan fields
  • Ensure backward compatibility with existing plans

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Inconsistent rope validation

The validation logic for rope.planes and rope.sections in Plan::load may allow inconsistent configurations. Specifically, when rope.kind is mrope, the code sets rope_planes to the size of rope_sections if rope.planes is not explicitly set, but then it still enforces that rope_sections.size() == rope_planes. This could lead to a confusing error message if a user explicitly sets rope.planes to a value that doesn't match rope.sections.size(), as the error message will refer to the mismatch between rope_sections.size() and rope_planes rather than the explicit value that was set.

if (!r.contains("planes")) p.rope_planes = (int)p.rope_sections.size();
if (p.rope_planes < 2)
    throw PlanError("plan: " + path + " rope.kind is mrope but rope.planes is " +
                    std::to_string(p.rope_planes) + " (mrope has a plane per axis: t, h, w)");
if ((int)p.rope_sections.size() != p.rope_planes)
    throw PlanError("plan: " + path + " rope.sections has " +
                    std::to_string(p.rope_sections.size()) + " widths but rope.planes is " +
                    std::to_string(p.rope_planes) + " (one width per plane)");
Missing validation for vision_merge

The validation for inputs.vision.merge does not check that vision_merge is one of the expected values ("external" or "none") before using it. While the code does check for valid values, it's not explicitly validating that the value is one of the expected strings, which could lead to unexpected behavior if an invalid value is passed.

p.vision_merge = typed<std::string>(v, "merge", "inputs.vision", path);
p.vision_feature_dim = int_field(v, "feature_dim", "inputs.vision", path);
if (p.vision_merge != "external" && p.vision_merge != "none")
    throw PlanError("plan: " + path + " inputs.vision.merge \"" + p.vision_merge +
                    "\" is not external or none");

@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 c496e506.

I reviewed this as the lane that recorded the plan-layer gaps on #799, so the schema is the part I most wanted to test rather than read. Built and ran it myself, then took the generator to a pack nobody in the PR's testing covers.

What I verified

  • npu_plan_test — built in a fresh worktree from this head, ran it: npu_plan: ok. The 11 new cases and the five named refusals are real, and the "absent means the old meaning" rule holds for both sections.
  • The generator on a real Qwen3-VL text tower (~/models/qwen3vl/q4nx-text, the pack the hybrid lane actually uses) — their testing ends at Qwen3-0.6B, which is plain, so the interesting case was untested. It writes exactly what the consumer needs:
"rope": { "kind": "mrope", "planes": 3, "sections": [24, 20, 20] }

which is the pack's own rope_scaling.mrope_section, read through text_config where the VL pack keeps its text tower. That is the whole point of the field, and it works on the pack that motivated it.

  • Refusing rather than defaulting is the right call and better argued than I would have put it: silently running mrope as one index predicts fluently and is wrong after every image. The tokens-with-a-vision-block refusal is the same shape of bug one level down (serve the text half of a vision model and answer confidently about an image it never saw), and it is the one I would have missed.

One non-blocking finding, and it is about the half the generator does not write

The generator emits rope and never inputs — verified: no inputs key in the output for the VL pack above. So the schema's other half is reachable only by hand-editing a plan, even though arch: qwen3_vl_text is already known at generation time and a VL text tower in this design always takes merged embeds (that is the embedding.onnx → text.onnx split the PR cites). Two cheap options, both non-blocking:

  1. when arch is a VL text tower, emit inputs: {kind: "embeds", vision: {merge: "external", feature_dim: <hidden>}}; or
  2. leave the plan alone but have --print/generation warn once: "this pack's arch takes merged embeddings in the hybrid design; inputs is not set".

Not a defect — the PR only claims rope from the generator, and the schema half is built and validated — but as written, the first person to build the hybrid will write the inputs block by hand and may get feature_dim wrong, which the loader would then accept because it is only checking positivity. A warning is the cheap version of that fix.

Also checked, since the field is a format question: the write path (--out) produces a plan with the new rope block and nothing else changed, and the loader's absent-field path is what the existing packs on this box use, so nothing in ~/models needs rewriting.

Nothing else. The docs rows match the code, the refusal messages name the field, and the "not a format bump" claim is true on the packs I have.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY — head c496e506d. I checked that the design survives into code rather than staying in the prose, which is the failure mode for schema PRs.

Defaults are genuinely backward compatible, and the PR is right to call that out explicitly: absent rope means plain, absent inputs means tokens, and that is what every plan written before these fields means — "not a format bump" is the correct framing, and it means old plan.json files keep loading without a migration step.

The refusals exist as code, not as table rows. The half-states the doc calls out each have a PlanError behind them: an unknown rope.kind, rope.sections that is not an array, mrope whose planes disagree with its sections, plain carrying sections or planes, and the section-count mismatch. That is the property I look for in a schema change — a contract that "nothing can check later" is refused now, at parse time, where the error names the field and the path.

The strongest part is the reason for refusing rather than defaulting, and it is worth keeping in the code comment verbatim: text after a 448×448 image resumes at position 19 where a token-count advance gives 201, and both predict fluently. A fallback that produces printable text is the only kind of bug that survives a review, so "refuse mrope by name" is the right call and the number is what makes it convincing rather than cautious.

One question, not a blocker: planes is validated against the number of sections, but the sections themselves are only checked for positivity and count — not that their sum matches the rotary width the model declares (sections [24, 20, 20] for Qwen3-VL sums to 64, i.e. head_dim/2). If the pack's split and the model's width can disagree, that is the same class of silent wrongness as an unchecked plane count, one level down. If the model config is not available at plan-parse time, say so in the doc table ("the sum is the pack's business; the caller checks it against head_dim") — that is enough to stop the next person assuming it is validated.

Nothing else: companion refused by name with a reason, and inputs.vision requiring feature_dim for external and 0 for none, are both exactly right — "ignored vision features serve the text half and answer confidently about an image it never saw" is the kind of sentence that prevents a whole class of PR.

@bong-water-water-bong
bong-water-water-bong merged commit 9e8e49f into main Nov 9, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/plan-hybrid-schema branch November 9, 2026 08:59
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: APPROVE at head 369ac4a5.

The property I care about most in a schema change is that it cannot silently change the meaning of the plans already on disk, and this one is built
the right way round:

  • Both new blocks are optional and their absence means exactly what every existing plan meant — rope_kind = "plain", rope_planes = 1,
    inputs_kind = "tokens". So no format bump and no re-interpretation of a shipped pack; a plan written before today loads with the same semantics.
  • What is not defaulted is refused by name, with the field in the message, which is the half that usually rots: mrope without the planes'
    split, embeds without vision, a stated plain that contradicts sections, a missing feature_dim. The test asserts each of those messages
    carries both the field and the reason (has(why, "rope.sections") && has(why, "mrope"), …), so the refusals are checked as text, not just as
    "it threw".
  • The companion-graph refusal is the right call and the reasoning is stated: one plan is one decoder stream over one token sequence, so a second
    graph is an error rather than a field. That is the decision most likely to be re-litigated later, and the comment gives the answer before someone
    adds vision_graph to the schema.
  • Coverage is real: defaults, a stated plain (the generator's own output), mrope with 3 and with 2 planes, planes defaulting to
    sections.size(), embeds + vision, and six distinct refusal cases.

The measurement that makes the field worth having is also the right kind: from the reference's own get_rope_index, text after a 448×448 image
resumes at position 19 where a token-count advance gives 201, and an image advances by 14 (max(H,W)/s) rather than by its 196 tokens.
That is a difference a test can catch and a default cannot paper over.

One note, not blocking: docs/npu-plan.md gains 3 lines for three new concepts (rotary kind, input kind, companion refusal) while plan.h gains
126. The three lines do say "optional" and "the meaning of an absent block", which is the important half; what a reader cannot get from them is the
mrope section arithmetic that the plan.h comment spells out (Qwen3-VL's [24,20,20], one positive width per plane). If the doc is meant to be the
place someone learns to write a hybrid plan, that sentence belongs there too — the header comment is where it will be found by someone already editing
the parser, not by the person generating a pack.

@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 c496e506 — I am outside the NPU domain, so this is a review of the schema's contract and compatibility, which is the part that affects every other lane.

The compatibility rule is the right one and it is stated where it matters: plain is "the meaning of an absent block" and tokens likewise, so every plan written before
these fields existed keeps its meaning without being rewritten
. That is the single property that makes an additive schema change safe in a tree where other lanes' packs
already exist, and it is the first thing I looked for.

The validation is strict in the direction that prevents silent wrong output, which matters more here than anywhere: sections is required for mrope ("without it the
planes have no declared width and a caller would guess"), and a plain rope carrying sections or planes != 1 is refused rather than read as if the planes existed. A schema
that accepted those and let the caller infer would produce fluent, wrong text — which is exactly the failure the PR's own example describes (text after a 448x448 image resumes at
position 19, where a token-count advance would give 201, and both predict fluently). Carrying that sentence in the code comment, not only the PR body, is the part that will
stop someone "simplifying" the check later.

Refusing companion by name, with a reason, is better than half-building it: "a plan describes one decoder stream over one token sequence" is a decision a schema is allowed to
make, and a named refusal with that sentence is more useful to the next lane than a field that exists and is not honoured.

One ask, and it is a test rather than a change: assert the compatibility rule mechanically — a plan with no rope block and a plan with rope {kind: plain} must produce
identical decode behaviour (same position ids for the same token sequence), and the same for inputs absent vs kind: tokens. That turns "absent means plain" from a comment into a
regression test, which is what protects the packs written before this PR if someone later changes the default. If the plan loader has a self-test harness, it is two cases in it.

Not verified from here: the pack-side arithmetic ([24, 20, 20] for Qwen3-VL, and the 19-vs-201 position example). I take those from the issue's 2026-11-08 entry, which is where the
workload that motivated this was measured; the review is of the schema's contract, the validation and the refusal.

bong-water-water-bong added a commit that referenced this pull request Nov 9, 2026
…ress -- drafter and state (#1677)

Closes two schema gaps on #799 itself, in the same shape attention.mode/kv/designs follow: absent means the
old meaning (no drafter, immediate commit), so every checked-in plan and container keeps loading.

drafter {head, k, tau, verify_rows, tree} -- the speculator the plan names. head is a BARE FILE NAME under the
model dir (the rule kv.hadamard.signs follows: a plan must not aim the loader at a file the command line did
not name), k >= 1, tau in (0, 1] (an acceptance gate, not a temperature -- 1.5 is refused rather than
clamped), verify_rows >= 1, tree leaf|none. Naming a head WITHOUT k/verify_rows/tau is refused as a
half-stated contract, because a speculator with different numbers answers different text for the same prompt
and raises nothing.

state {gdn_commit} -- immediate (the meaning of an absent section, and what the step path does today) or
deferred (the speculator's contract: a rejected draft row must not leave its recurrence behind). A target that
cannot defer has to refuse 'deferred' by name; committing early and reporting the accepted tokens gives
right-looking text with a state no future token agrees with.

Tests: defaults, a fully stated drafter, tau exactly 1.0, and four refusals naming drafter.tau / drafter.head /
the half-stated contract / state.gdn_commit. Docs rows in docs/npu-plan.md.

No forward change: this is the description P6 (the drafter) and any deferred-commit target read, and the same
slice pattern as #1623's rope/inputs.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant