Skip to content

npu: a decode role with no fitting ternary tile says so, instead of silently staying on M=128 - #1397

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/npu-decline-log
Nov 8, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/npu-decline-log

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

The M=16 twin pass sets designs16_[i].M = 0 when the container's geometry cannot be held by the ternary tile (pb16i: N % (COLS*ROWS*NW), t2s: N % NW), and the role then quietly keeps its M=128 kernel. That is correct — not a missing artifact, not an error — but the only symptom is a decode step that costs what a prefill step costs, with nothing in the log to say why.

Now it says so, once per affected role, at load:

[forward] dec QKV: no pb16i twin (K=1024 N=1536 does not fit the tile), staying on M=128

Why this is worth a PR of its own

It is the same "nothing logs the decline yet" gap the HRX prefill N % 16 note names for a different dispatcher (~/amd-oss/hrx-study/FACTS-prefill-n16.md, and the owner asked this lane to check whether that finding touches it): a matcher declining a tile is a decision, and a decision that leaves no trace is one nobody can audit later. The audit I posted found this lane has three independent geometry guards (split designs, the twin pass, and init_elf inside the runtime) — so no wrong output, but the twin pass was the one that declined silently.

Reachable, measured with the guards themselves

K, N pb16i fits t2s fits
1024, 1536 false true
1024, 9728 false true
1024, 2048 / 1024, 1024 / 3072, 1024 true true
4864, 1024 true true

So a Qwen3-class container (all its N on the 1024 grid) never prints the line, and a padded-N model — the hidden-896 shapes engine#845 exists for derive (1024,1536) and (1024,9728) — prints it for the roles that really do fall back.

Rows

row verdict
ctest -j1, whole tree built 123/124, the single failure pm_route (engine#1070's port-timing flake, which fails on the base at the same rate)
onebit build clean, Release / ONEBIT_NPU=ON / ONEBIT_JINJA=ON under thermal-run.sh
tools/copyright.py --check rc 0
no behaviour change the line is inside the branch that already set M = 0; the launch path and the twin selection are untouched

Refs #803 (the A2 audit's one actionable gap). Part of #799.

…ilently staying on M=128

The M=16 twin pass sets designs16_[i].M = 0 when the container's geometry cannot be held by the
ternary tile (pb16i: N % (COLS*ROWS*NW); t2s: N % NW), and the role then quietly keeps its M=128
kernel. That is correct -- not a missing artifact, not an error -- but the only symptom is a decode
step that costs what a prefill step costs, with nothing in the log to say why.

Reachable in exactly the interesting geometry: measured with the guards themselves, fits(K,N) is
false for pb16i at (1024,1536) and (1024,9728) -- the padded-N shapes a hidden-896 model derives
(engine#845) -- and true at (1024,2048), (1024,1024), (3072,1024), so a Qwen3-class container never
prints the line and a Qwen2.5-0.5B-class one does.

This is the same 'nothing logs the decline' gap the HRX prefill N%16 note names for a different
dispatcher (amd-oss/hrx-study/FACTS-prefill-n16.md): a matcher declining a tile is a decision, and a
decision that leaves no trace is one nobody can audit later. One line per affected role, once at
load, only when a geometry actually refused.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#1397 ready for review at 7877e266 — small, and it exists because of an audit rather than a symptom.

The ternary twin pass declines a role by setting designs16_[i].M = 0 (right thing: the geometry cannot be held, so it keeps M=128 and stays correct) — but it declined silently, so the only symptom of a padded-N model falling back is a decode step that costs what a prefill step costs, with nothing in the log.

That is the same "nothing logs the decline yet" gap the HRX prefill N % 16 note names for a different dispatcher, which the owner asked this lane to check against itself. The check found three geometry guards here (split designs, the twin pass, init_elf inside the runtime) and no wrong-output path — this PR closes the one that was mute.

Reachability is measured with the guards themselves rather than argued: fits is false for pb16i at (1024,1536) and (1024,9728) — the padded-N shapes a hidden-896 model derives — and true at (1024,2048), (1024,1024), (3072,1024). So Qwen3-class containers never print the line and Qwen2.5-0.5B-class ones do, for exactly the roles that fall back.

ctest 123/124 (pm_route, engine#1070), build clean, no launch-path change.

@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 7877e266b96cc724a79ae618764102bc535d2edf

A log line inside the branch that already set designs16_[i].M = 0. The launch path and twin selection are untouched, so this changes nothing about what runs.

  • The guard only fires on a real geometry decline. M > 0 && !geo_ok excludes the roles the earlier continues handle (the two split roles, and a wide QKV covered by the splits).
  • It prints once per role, at load, using the same role_tag() the other [forward] lines use.

Your fits table, checked against the guards:

  • q4nx_pb16i::fits is K % 256 == 0 && N % (8·4·32 = 1024) == 0, and q4nx_t2s::fits is K % 256 == 0 && N % 32 == 0.
  • That gives (1024, 1536) and (1024, 9728) false for pb16i and true for t2s, and (4864, 1024) true for both (4864 = 19 × 256). All as stated.

Following the "audit every matcher" lesson: one more decline only shows up as a count. The int8 twin derivation (q4nx_derive_decode_designs, q4nx_pack.c:223) drops a role when K % 64 != 0 || N % Q4NX_N_GRID (512) != 0. The twin loop then just does skipped++ (q4nx_forward.cpp:1261), so it appears in the aggregate "made … skipped … stay on M=128" line with no role and no reason. That's the same audit gap, for the non-ternary family. It isn't a defect and doesn't block this PR, but a per-role line there would make the "decline is a decision" rule complete for both families.

What I ran at this head:

  • cmake --build --target onebit_npu_forward (thermal-run.sh): clean, with no new warning on the added lines.
  • tools/copyright.py --check: rc 0.
  • I didn't rerun your full ctest (123/124; pm_route is the known #1070 flake). No device run: the line prints only at load on a padded-N pack, and a log line can't change a value.

@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 83589256bf8cdb996a7cf95a0c122559859747cf

Main merge only over the head that was verdicted (7877e266b9): the PR's own added lines hash to 2d00cd0f31c2 at both heads, and the change is the same 12 lines in npu/forward/src/q4nx_forward.cpp — a decode role with no fitting ternary tile now says so instead of standing in silently.

@bong-water-water-bong
bong-water-water-bong merged commit 4426893 into main Nov 8, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/npu-decline-log branch November 8, 2026 03:51
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

803 - Partially compliant

Compliant requirements:

  • Extracted NpuTarget + NpuModel interfaces
  • NpuModel owns the math and calls the target
  • XDNA target wraps I8Ctx/npu_rt_api path with no new kernels
  • Default flag --npu-target xdna

Non-compliant requirements:

  • Gate: identical outputs (window11 + logits KLD 0 on 8 prompts), prof table within 2 %, ctest green

Requires further human verification:

  • Verification of identical outputs and prof table within 2%
  • Confirmation that ctest passes

799 - Partially compliant

Compliant requirements:

  • One model description (plan.json)
  • T2 ternary chunks
  • NpuTarget per NPU (XDNA, Hexagon)
  • NpuModel owns the math and calls an NpuTarget for tensor ops
  • Host fallbacks for every optional op
  • XDNA target wraps today's I8Ctx/npu_rt_api path with no new kernels

Non-compliant requirements:

Requires further human verification:

  • Verification of gate and lane per the plan table
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Logging of geometry decline

The change adds logging when a decode role cannot fit the ternary tile geometry, which improves auditability. However, the logging is done to stderr and may not be captured in all logging setups, potentially missing audit trails in production environments.

if (designs16_[i].M > 0 && !geo_ok)
    fprintf(stderr,
            "  [forward] dec %-3s: no %s twin (K=%d N=%d does not fit the tile), "
            "staying on M=128\n",
            role_tag(designs16_[i].role), t2s_ ? "t2s" : "pb16i",
            designs16_[i].K, designs16_[i].N);

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