Skip to content

npu: one unloadable design costs that shape, not the whole device leg - #779

Merged
bong-water-water-bong merged 6 commits into
mainfrom
1bit/onnx-ep-qdq-elf-robust
Nov 1, 2026
Merged

bong-water-water-bong merged 6 commits into
mainfrom
1bit/onnx-ep-qdq-elf-robust

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What this fixes

init() failed the whole NPU State on the first init_elf that returned false. One bad entry in
ONEBIT_EP_NPU_ELFS — an ELF from another kernel family, or a design M that does not match — therefore
turned the device leg off for every shape in the session, silently: the QDQ proof still printed its
host gate's |d| = 0, so the run looked exactly like a healthy one with the device in use.

Measured before the fix (npu-hold, QDQ proof, ONEBIT_EP_QDQ default): three designs configured, the third
unloadable. 12 of 12 cases fell back, all of them blaming that one ELF:

npu_qdq_fallback k=2048 n=1024 why=I8Ctx init_elf failed for …/design.elf (16x1024x1024)
npu_qdq_fallback k=3072 n=1024 why=I8Ctx init_elf failed for …/design.elf (16x1024x1024)

full_i8_O_K2048_N1024 and full_i8_D_K3072_N1024 were configured, loadable, and never used.

What it does now

A refused design is recorded with its reason and skipped; the remaining designs load as before. The shape that
was refused reports the cause itself:

npu_qdq_fallback k=1024 n=1024 why=no QDQ kernel for 1024x1024: I8Ctx init_elf failed for /bin/true (16x1024x1024)

If every configured design is refused the State still fails, with the first reason, so a fully unusable
configuration is not reported as "no QDQ kernel for KxN" on every call.

Two files: npu/ort/onebit_npu_gemm.cpp and one sentence in docs/onnx.md where ONEBIT_EP_NPU_ELFS is
described (the behaviour is user-visible).

Measured gate (strixhalo, npu-hold -l qdq, M=128 designs)

Both stages on the array, device-busy = 0, and journalctl -k | grep -c 'amdxdna.*ERROR' = 0 in the two
minutes after each ticket.

~/wt/qdq-elfrobust-check.sh good — the configuration that already worked is untouched:

ok   2048x1024 on the array          ok   3072x1024 on the array
ok   quark-d |d| = 0                 == PASS (good)

~/wt/qdq-elfrobust-check.sh refused — the same two designs plus one entry the runtime cannot load
(/bin/true: a valid ELF, not an NPU design, so the same init_elf branch with an input that is not a
candidate for wedging firmware — see the note at the end):

ok   2048x1024 reached the array (a refused ELF elsewhere did not disable it)
ok   3072x1024 reached the array (a refused ELF elsewhere did not disable it)
ok   the refused 1024x1024 shape names the path that was refused
     case quark-o: 0 of 5120 int8 values differ, worst |d|=0 LSB, path=fused
     case quark-d: 0 of 5120 int8 values differ, worst |d|=0 LSB, path=fused

Host build: ctest 6/6 (ort_info, onebit_ep_proof, onebit_ep_proof_cpu_fallback,
onebit_ep_qdq_proof, onebit_ep_qdq_proof_unfused, onebit_ep_qdq_proof_only_qdq); ONEBIT_EP_NPU=ON
configuration compiles; tools/copyright.py --check rc 0.

What this PR does not do

  • No kernel, runtime or ELF change. It changes only what happens when the runtime refuses one.
  • It does not make the refused design work. Whether a foreign design (different weight ABI, different
    kernel family) can ever be loaded by this EP is a separate question, and the answer so far is a refusal at
    init_elf.
  • The third ticket of the check was cut short by the box's own thermal guard (die 93 °C, ABORT die at 93C, exit 143) while other lanes were heating the package; the two tickets above are the complete runs. A
    failed grep pattern of mine in the first refused run is what produced the rerun, and the assertion it
    missed was verified against that run's own trace (/tmp/onebit_ep_trace.1606010.log) rather than a third
    device run.

Why /bin/true and not the foreign ELF that raised this

The bug was found while testing whether an m16 design from another lane could serve Qwen3-0.6B's k/v shape
(1024×1024). That design is refused by the runtime and was present in the ticket that preceded a firmware TDR
incident on the shared array; it is a suspect in an investigation that is not finished, and there is nothing
left to learn from loading it again — the refusal is already recorded. The regression test therefore uses an
input that exercises the identical branch (init_elf returning false) without being a candidate for wedging
firmware. The foreign ELF stays off the array.

pi-qdq added 2 commits November 1, 2026 12:19
…e leg

init() failed the whole State on the first init_elf that returned false, so a
single bad entry in ONEBIT_EP_NPU_ELFS -- an ELF from another kernel family, or
a design M that does not match -- turned the device off for every shape while
the session kept printing the host gate's |d| = 0. Measured: adding one m16
design the runtime refuses made all 12 QDQ proof cases fall back and blame that
ELF.

A refused design is now recorded with its reason and skipped; the remaining
designs load as before, and the shape that was refused reports
'no QDQ kernel for KxN: I8Ctx init_elf failed for <path> (MxKxN)'. If every
configured design is refused the State still fails, with the first reason.

Gate (device, npu-hold): with the refused ELF in the list, full_i8_O_K2048_N1024
and full_i8_D_K3072_N1024 still reach the array and both are |d| = 0 against the
CPU EP; host ctest 6/6.
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit ec8c1cc)

Here are some key observations to aid the review process:

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

Incorrect Error Message

The error message in q8_kernel function is constructed by appending the reason from s.q8_unavailable to the generic "no QDQ kernel for KxN" message. However, the logic for detecting and appending the reason is flawed because it only checks the first matching entry in s.q8_unavailable and does not ensure that the error message is properly formatted or that the reason is correctly associated with the specific shape. This could lead to misleading error messages if multiple shapes are unavailable.

if (err) {
    const std::string what = std::to_string(k) + "x" + std::to_string(n);
    *err = "no QDQ kernel for " + what;
    for (const auto& bad : s.q8_unavailable)
        if (bad.k == k && bad.n == n) *err += ": " + bad.why;
}
Potential Performance Regression

The code now stores and checks s.q8_unavailable for every shape, which could lead to performance degradation if a large number of shapes are unavailable. While the intention is to avoid re-parsing ELFs, the linear search through s.q8_unavailable for each call to q8_kernel could become a bottleneck if the list grows significantly.

for (const auto& bad : s.q8_unavailable)
    if (bad.k == k && bad.n == n) return nullptr;  // known bad: do not parse the ELF again

@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

Reviewed as code and compiled; the fix is the right one and it closes a failure mode that was invisible by design.

Ran: g++-16 -DONEBIT_NPU_RUNTIME_OWN -std=c++26 -O1 -fsyntax-only -Inpu -Inpu/ort -Inpu/forward/include -Inpu/forward/engine-src npu/ort/onebit_npu_gemm.cpp → rc 0 (CI builds neither NPU lane, so this is the only
compile evidence that exists for it). tools/copyright.py --check → rc 0. Build/CodeQL/pr_agent green on the head.

As code, the change is exactly the contract it describes:

  • init() records a refused design as {k, n, why} and continues before s.kernels.push_back, so the remaining
    designs load and s.ok = true — the "one bad entry costs that design" behaviour.
  • the per-shape error now appends the recorded reason (no QDQ kernel for KxN: I8Ctx init_elf failed for <path> (MxKxN)), which is what makes a fallback diagnosable instead of a mystery;
  • a configuration in which every design is refused still fails the State (s.kernels.empty() && !spec.empty() →
    first reason), so the "device is off" state is never reported as if nothing had been configured;
  • the q8_unavailable memo still short-circuits a repeat attempt (bad.k == k && bad.n == n), so the ~50 ms
    ELF-parse-per-call trap the comment documents is not reintroduced;
  • the reason string is carried, not recomputed, so it stays the one from the design that failed.

Why this mattered more than a cosmetic fix: the old shape failed the whole State silently while the QDQ proof
still printed its host gate's |d| = 0 — i.e. a run with the device leg disabled was indistinguishable from a healthy
one. That is the same class of "green that measures nothing" the zero-cases guard exists for, one level up.

Not verified by me: the device evidence — the "12 of 12 cases fell back, all blaming one ELF" before/after pair,
the device-busy = 0 and amdxdna … ERROR = 0 rows, and the qdq-elfrobust-check.sh runs. Those need the NPU under
npu-hold; the lane ran them and they are the right shape (before and after, same harness). One extra check I would
have liked, offered rather than required: a case where all configured designs are refused, since that branch is the
one no measurement exercises and it decides whether the device reads as broken or as unconfigured.

@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 1, 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

Confirmation at c4e76fbf after update-branch (main's #768 squash merged in; both author commits 62113a1 + 5f6de1f
unchanged). Re-ran the compile at the new head rather than assuming the merge was inert:

$ g++-16 -DONEBIT_NPU_RUNTIME_OWN -std=c++26 -fsyntax-only … npu/ort/onebit_npu_gemm.cpp
rc 0

Everything else stands as reviewed at 5f6de1f6: a refused design is recorded with its reason and skipped before
s.kernels.push_back, the per-shape error names the ELF, an all-refused configuration still fails the State, and the
q8_unavailable memo still short-circuits the re-parse. The device evidence remains the lane's; the all-refused branch
is still the one no measurement exercises. tprs-ready stays.

@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

Confirmation at b4f23fd1 after update-branch: their own files are byte-identical to the head I verdicted — verified with
git diff --stat <previous head> b4f23fd1 -- <this PR's paths> → empty, the merge brought #768's and #775's squashes
(7f4e98a, e55096b) and nothing else. Content as reviewed (onebit_npu_gemm), build green. tprs-ready stays.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 5af778e

@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

Confirmation at 5af778e4: the PR's own paths are byte-identical to the head I verdicted
(git diff --stat b4f23fd1 5af778e4 -- npu/ort/onebit_npu_gemm.cpp docs/onnx.md → empty). The refused-design path
(record the reason, skip that design, name the ELF per shape, fail only when every design is refused, keep the re-parse
memo) is unchanged and compiled clean at that head. tprs-ready stays.

@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

Confirmation at ec8c1cc5 after the waiter's rebase onto main (90c998a = #776 merged): this PR's own paths are
byte-identical to the head I verdicted — git diff --stat <previous head> ec8c1cc5 -- <its paths> → empty. Content as
reviewed, build green. tprs-ready stays.

@bong-water-water-bong
bong-water-water-bong merged commit 4afb20e into main Nov 1, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/onnx-ep-qdq-elf-robust branch November 1, 2026 19:01
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit ec8c1cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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