Skip to content

onnx EP: the designs for q/k/v and gate/up exist, so the device leg covers 196 of 197 QDQ groups - #848

Merged
bong-water-water-bong merged 4 commits into
mainfrom
1bit/qdq-q8-bench
Nov 2, 2026
Merged

bong-water-water-bong merged 4 commits into
mainfrom
1bit/qdq-q8-bench

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What this is

The QDQ device leg was correctness-only on two projections — o_proj (2048×1024) and down_proj
(3072×1024) — because those were the only NPU designs on this box, so a real A8W8 graph could put 56 of
its 197 fused groups on the array. That was recorded (twice, in TQDQ-STATE.md) as blocked: "no AIE
toolchain on this box, kernels are closed source".

The blocker was a bad search. ~/mlir-aie is indeed empty, but ~/amd-oss/iron-venv holds the whole
MLIR-AIE/Peano/bootgen stack
(aiecc at mlir-aie 20a9c2fb2dc, llvm-aie 22.0, mlir_aie 1.4.4) and
~/Xilinx/2026.1/Vitis/aietools is present, so the shape is a build, not a missing capability: the
iso-build design generator (n1_core_i8_v26.py -M 128 -K <K> -N <N> -c 4 -b 5, the family the
full_i8_* xclbins belong to) emits a design for any (K, N) in about a minute.

Kernel source is still private and not touched here. This PR is the EP side: two proof cases for the
shapes that had neither a case nor a design, and the docs corrected to what is now measurable.

Measured gate (strixhalo, npu-hold, two tickets, quiet array)

onebit-ort-qdq: case quark-wide: 0 of  10240 int8 values differ, worst |d|=0 LSB, path=fused   (q_proj  5x1024x2048)
onebit-ort-qdq: case quark-o:    0 of   5120 int8 values differ, worst |d|=0 LSB, path=fused   (o_proj  5x2048x1024)
onebit-ort-qdq: case quark-d:    0 of   5120 int8 values differ, worst |d|=0 LSB, path=fused   (down    5x3072x1024)
onebit-ort-qdq: case quark-kv:   0 of   5120 int8 values differ, worst |d|=0 LSB, path=fused   (k/v     5x1024x1024)
onebit-ort-qdq: case quark-gu:   0 of  15360 int8 values differ, worst |d|=0 LSB, path=fused   (gate/up 5x1024x3072)
onebit-ort-qdq: case quark-stress: 0 of 131072 int8 values differ, worst |d|=0 LSB, path=fused
== trace: qdq runs=14 fallbacks=6 device-busy=0
      4 npu_qdq_fallback k=16 n=6  why=no QDQ kernel for 16x6
      2 npu_qdq_fallback k=64 n=48 why=no QDQ kernel for 64x48
== PASS: five designs on the array, every shape bit-identical to the CPU EP

The discriminator is the absence of an npu_qdq_fallback line for a shape (qdq rows= is written by
the shared epilogue on both paths, so it proves nothing on its own): zero fallback lines exist for
2048×1024, 3072×1024, 1024×2048, 1024×1024 and 1024×3072 in either run, and device-busy=0, so all five
designs ran on the array and their exact int32 accumulators, taken through the same epilogue the host path
uses, equal the CPU EP's float QDQ path to the byte.

That is 196 of the 197 fused groups a real Qwen3-0.6B A8W8 export has (28 layers × 7 projections +
lm_head), up from 56. lm_head (1024×151936) keeps the host kernel: it needs a tiling of its own.

Still not claimed: tokens/s

These are M=128 designs, so a decode step hands the kernel one real row and 127 zeroed ones. A speed
claim needs m16 variants of the same five shapes — the same generator, -M 16 — and a quiet box. The docs
say that in the same paragraph as the gate, because a gate without its limit is a sales claim.

The artifacts (not in this repo)

design bytes md5
Q_K1024_N2048/design.elf 394,168 834b25fc25d6bb847a81b056ddece909
KV_K1024_N1024/design.elf 208,312 9c4ae1860ccfd434f7cf04bb3ae1e7fb
GU_K1024_N3072/design.elf 580,024 5f14afb085492f81aa078a1223df15cd

They live in ~/qdq-elfs/ beside the other xclbins, like every full_i8_* design; nothing kernel-side is
carried by the engine, per the brief. Build recipe is ~/wt/qdq-elf-build.sh <K> <N> <cols> <M> <outdir>
and is described in docs/onnx.md.

Two things learned the hard way and now written down: on this toolchain aiecc --full-elf-name exits 0
and writes nothing
(--get-full-elf is the flag that emits the ELF), and control-building the
known-good shape (2048×1024, cols=4) gives a structurally identical design, so a pass on a new shape is a
statement about the shape and not about a different recipe.

Files

  • onnx/ep/onebit_ep_qdq_proof.cpp — quark-kv (5×1024×1024) and quark-gu (5×1024×3072) cases, same
    gate as quark-o/quark-d; fused-case floor 8 → 10 so neither can silently stop fusing.
  • docs/onnx-pack.md — the device-leg bullet says what is now measured: five shapes, 5120/5120/5120/
    10240/15360 values, no fallback for any of them, 196 of 197 groups, and the two limits (an ELF per
    (K,N), which is a build; and M=128 → correctness only). The "not where the 1.5x lands" sentence follows.
  • docs/onnx.md — how a missing shape's design is generated, that the generator and ELFs live in the
    iso-build tree, and the --full-elf-name / --get-full-elf trap.

Gates

  • host cmake -S onnx -B /tmp/qdq-main (no CMAKE_BUILD_TYPE → unoptimised, the stricter one): ctest 6/6
  • -DONEBIT_EP_NPU=ON builds (/tmp/qdq-npu2) with the private runtime at
    ~/wt/release-rc/work/npu-runtime/engine/npu/npu_rt; its QDQ proof is the device run above
  • python3 tools/copyright.py --check → rc 0 (no new files)
  • device: two npu-hold -l qdq tickets, 01793646706221490703.qdq and 01793647065708242911.qdq,
    device-busy=0 in both, traces /tmp/onebit_ep_trace.555044.log and /tmp/onebit_ep_trace.582368.log
  • the owner's 1bit forward-serve -p 18097 was not touched and no ~/npu.lock was taken; this PR touches
    no NPU kernel source

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 5130416)

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

Fusion threshold change

The fusion threshold for the number of fused cases was increased from 8 to 10. This change may affect the validation logic and could mask cases where fusion is not working as expected, especially if the new threshold is not carefully justified by performance or correctness measurements.

if (fused_cases < 10) {
    std::fprintf(stderr, "onebit-ort-qdq: FAIL only %zu case(s) were fused\n", fused_cases);
    rc = 1;
} else if (peak_cpu > 0 && peak_fused > 0 && peak_fused >= peak_cpu) {
Documentation update

The documentation was updated to reflect that 196 of 197 fused groups are now covered by the device leg, with specific mention of the newly added shapes (k_proj/v_proj and gate_proj/up_proj). This update aligns with the hardware capabilities and correctness measurements, but the claim of 196 out of 197 fused groups should be confirmed with actual hardware measurements.

`npu-hold` with five designs configured
(`…/full_i8_O_K2048_N1024.elf`, `…/full_i8_D_K3072_N1024.elf`, and `Q_K1024_N2048`, `KV_K1024_N1024`,
`GU_K1024_N3072` generated from the iso-build design generator, all as `M=128` entries):
`worst |d| = 0` LSB against the CPU EP for **o_proj** (5×2048×1024, 5120 int8 values), **down_proj**
(5×3072×1024, 5120), **k_proj/v_proj** (5×1024×1024, 5120), **q_proj** (5×1024×2048, 10240) and
**gate_proj/up_proj** (5×1024×3072, 15360), with no `npu_qdq_fallback` line for any of those five
shapes in either run's trace — the device ran all of them. That is **196 of the 197** fused groups a
real Qwen3-0.6B A8W8 export has (28 layers × 7 projections + lm_head); `lm_head` (1024×151936) keeps the
host kernel because it needs a tiling of its own. Two limits belong with that number. It needs **an ELF
per (K, N)**, and a shape that has none is a build rather than a missing capability: o_proj's and
down_proj's ship beside the other xclbins, and q/k/v's and gate/up's came out of one `-M 128 -K <K>
-N <N> -c 4` run of the iso-build generator each (`n1_core_i8_v26.py` through the IRON/MLIR-AIE
`aiecc`), the artifacts living beside the other xclbins and never in this repository. And it is a
**correctness** result so far, not a speed one: these are M=128 designs, so a decode step hands the
kernel one real row and 127 zeroed ones — measure before quoting tokens/s.

@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 e739699e on everything I can run here; the device leg is the lane's and I did not re-run it (the owner's
serve holds the NPU lock, and taking it to prove someone else's number is exactly what the lane rules forbid).

Run here (-DONEBIT_ORT=ON, ORT 1.23.2 from the box's pkg-config, Release/ninja/gcc-16,
ninja onebit_ep_qdq_proof rc 0), the proof with the plugin EP registered and no ONEBIT_EP_NPU_ELFS — so every case
takes the host path and the two new shapes have to be real cases, not decoration:

case quark-wide: 0 of 10240 int8 values differ, worst |d|=0 LSB, path=fused
case quark-o:    0 of  5120 …
case quark-d:    0 of  5120 …
case quark-kv:   0 of  5120 …  worst |d|=0 LSB, path=fused     <- new
case quark-gu:   0 of 15360 …  worst |d|=0 LSB, path=fused     <- new
PASS OneBitEp fused the A8W8 QDQ group: worst |d| = 0/0/0/0 LSB (per-tensor, per-axis, asymmetric, asymmetric per-axis), per-K scale refused, peak RSS -7060 kB

and the fused_cases < 10 threshold is met rather than tripped, which is the check that would have caught a case that is
added but never fused.

The arithmetic of "196 of 197" checks out against the model itself: ~/models/npu/Qwen3-0.6B/config.json is 28 layers,
hidden 1024, intermediate 3072, vocab 151936 — so 28 × 7 + 1 = 197 fused groups, the five shapes cover 7 projections per
layer (q 1024×2048, k/v 1024×1024, o 2048×1024, gate/up 1024×3072, down 3072×1024), and the one group left is exactly
lm_head at 1024×151936, which is the one shape that is not a projection. The per-case value counts in the body also
match the run to the digit (10,240 / 5,120 / 15,360).

What I cannot vouch for, and what the docs now say correctly: the five designs running on the array with worst |d| = 0
and device-busy=0, and the absence of npu_qdq_fallback per shape. That needs the NPU lock and the private ELFs; the
discriminator the body names (fallback lines, not qdq rows=) is the right one, and the "M=128 designs, so no tokens/s
claim" limit is stated in the same paragraph as the gate, which is the honest shape.

Two things worth keeping: the aiecc --full-elf-name trap (exits 0, writes nothing; --get-full-elf is the flag) is the
kind of note that saves a day, and "a shape with no design is a build, not a limit" is now documented next to the failure
message it explains. The correction to the old "56 of 197" text is right — that number was the state of the box, not of the
EP.

@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 2, 2026
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Heads-up on the red build at this head — it is a flake in hybrid_route, not this PR, and the evidence is the same commit
passing CI six minutes earlier:

run 41509677141  head e739699  success  19:24:43Z   hybrid_route Passed 6.66 s
run 41510492737  head e739699  failure  19:30:03Z   hybrid_route ***Failed 15.22 s

and the five other recent ci.yml runs I checked all pass it in 6.66-6.86 s. The failing run is more than twice as
long
, and the four checks that fail are exactly the "failing provider" arm (serve starts with a failing provider,
answers when the provider fails, not pinned when the provider failed, stderr: the failure named) — i.e. start()
never saw /health answer.

tests/hybrid_route.sh:36 polls /health for _ in $(seq 1 100) with sleep 0.1, so a serve whose startup includes a
warm-up request (the log from the passing arms shows warm-up request … took 1001 ms) has a ~10 s budget that a loaded
runner can exceed. Locally, six runs at load 12.9-15.4: 6/6 pass, 6.68-6.88 s, so it is not reproducible on an idle-ish
box; I filed it as an issue with the numbers rather than sitting on it.

Nothing in onnx/ep/onebit_ep_qdq_proof.cpp or the two docs files can reach this test, so my VERDICT: READY + label
stands
— a re-run of build should go green, and if the waiter prefers a fresh head I will re-verdict at it immediately.

…overs 196 of 197 QDQ groups

The device leg was correctness-only on two projections (o_proj 2048x1024,
down_proj 3072x1024) because those were the only designs on the box. That was
never a kernel limitation: the shapes are a build, and the iron-venv on this
box has the whole MLIR-AIE/Peano/bootgen stack, so n1_core_i8_v26.py emits a
design for any (K, N).

Two new proof cases pin the shapes that had neither a case nor a design --
quark-kv (5x1024x1024, k_proj/v_proj) and quark-gu (5x1024x3072,
gate_proj/up_proj) -- and the fused-case floor goes 8 -> 10. Together with
quark-wide (q_proj) that makes all seven projection shapes gated, so a real
Qwen3-0.6B A8W8 graph's 196 projection MatMuls can run on the array instead of
56 of 197; only lm_head (1024x151936, its own tiling) keeps the host kernel.

Measured on strixhalo under npu-hold with five designs configured: worst
|d| = 0 LSB against the CPU EP for 5x2048x1024 (5120 values), 5x3072x1024
(5120), 5x1024x1024 (5120), 5x1024x2048 (10240) and 5x1024x3072 (15360), with
no npu_qdq_fallback line for any of those shapes in the trace -- the device ran
all five. Still correctness, not speed: these are M=128 designs, so a decode
step hands the kernel one real row.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (906f966) → head b109af4; the diff is unchanged (three files, +35/−10: onnx/ep/onebit_ep_qdq_proof.cpp, docs/onnx-pack.md, docs/onnx.md).

The red build at e739699 is a CI port collision, not this diff. The failing test is hybrid_route (test 20 of 64), and its own log names the cause:

--- c.log
1bit serve: hybrid-model on hybrid (…/tests/fake_backend.py)
Traceback (most recent call last):
  File "…/tests/fake_backend.py", line 218, in <module>
    ThreadingHTTPServer(("127.0.0.1", port), H).serve_forever()
OSError: [Errno 98] Address already in use
1bit serve: backend 0 did not become ready
FAIL

Case 3 of tests/hybrid_route.sh (serve starts with a failing provider) never started, so its four follow-on checks (answers when the provider fails, not pinned when the provider failed, stderr: the failure named, and the start itself) read FAIL. Every other test in that run passed except hybrid_route (63/64, npu_repack_path skipped).

This PR touches no serve, backend or test-harness code — the fake backend binding a port another job on the runner still holds is a flake, and the re-run is the fix.

Gates re-run from scratch on the rebased tree, no CMAKE_BUILD_TYPE (the stricter unoptimized build):

cmake -S onnx -B /tmp/qdq848-main && cmake --build -j8 && ctest
100% tests passed, 0 tests failed out of 6      (13.30 s)
ort_info, onebit_ep_proof, onebit_ep_proof_cpu_fallback,
onebit_ep_qdq_proof, onebit_ep_qdq_proof_unfused, onebit_ep_qdq_proof_qdq_only
tools/copyright.py --check → rc 0

Device evidence is unchanged from the body (both tickets, npu_hold -l qdq): no npu_qdq_fallback line for any of the five shapes, so all five designs reached the array; quark-kv 0/5120 and quark-gu 0/15360 int8 values differ, the other three unchanged.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit b109af4

@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 b109af4e81 (the main merge; the PR's own file is blob-identical at both heads — onnx/ep/onebit_ep_qdq_proof.cpp is b3c4d649 at e739699e8 and at this head — and no file on the ORT build path changed between them, so the build and the host-path run I reported at e739699e are the same tree this head will merge).

What that evidence was, restated so it is checkable from one place: the ORT lane built at -DONEBIT_ORT=ON with the box's ORT 1.23.2, and onebit_ep_qdq_proof ./libonebit_ep.so with no ONEBIT_EP_NPU_ELFS runs the five quark cases on the host path with the value counts the body quotes (10,240 / 5,120 / 5,120 / 5,120 / 15,360, worst |d| = 0 LSB), and the fused_cases < 10 threshold is met rather than tripped. The 196-of-197 arithmetic is the model's: ~/models/npu/Qwen3-0.6B/config.json is 28 layers, hidden 1024, intermediate 3072, vocab 151936 -> 28x7+1 = 197 groups, and the one left out is lm_head (1024x151936).

CI at this head, for the record rather than as a gate: build and the four Analyze jobs are running at the time of posting, CodeQL success, pr_agent cancelled, hw_gate skipped. The previous red build on this PR was the hybrid_route flake (#850) — the same content passed in the run six minutes earlier, and #851 is the fix for it; if this head's build lands red again on hybrid_route, that is #851's merge, not this PR.

The device leg (five designs on the array, device-busy=0, no npu_qdq_fallback per shape) is still the lane's to run — the owner's serve holds the NPU lock and taking it to prove someone else's number is not what this lane does.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 8503055

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

CI is green at b109af4: build pass (5m18s), pr_agent pass, CodeQL pass, all four Analyze jobs pass, hw_gate skipping. So the hybrid_route failure at e739699 was the port collision described above and nothing in this diff. MERGEABLE; PR-READY.

@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 850305560 (re-verdict after the update-branch; content unchanged)

The PR's own patch at b109af4e (base 906f966a2) and at this head (base 40d963254) is identical — same
80 files, same +/- counts, same patch text — so this is a pure update-branch and the head merges exactly the
tree I verdicted.

Re-run at this head rather than carried: full host build -DONEBIT_ORT=ON rc 0, and
ctest -R "onebit_ep|qdq" -> 5/5 passed (the QDQ proofs incl. _unfused and _qdq_only);
tools/copyright.py --check rc 0.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 1d73b80

@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 1d73b80f1 (re-verdict after the update-branch onto 82bc95e5f; the PR's own content is unchanged)

own patch byte-identical to 8503055 (80 files) against 82bc95e, so the 5/5 EP/QDQ ctest run at that tree applies; copyright rc 0

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 5130416

@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 513041652 (re-verdict after the update-branch onto 1f2dfe99f; own patch byte-identical to
1d73b80f1 and 850305560 — 80 files, same patch text)

Rebuilt at this head, not carried: -DONEBIT_ORT=ON full build rc 0, ctest -R "onebit_ep|qdq" -> 5/5 passed;
tools/copyright.py --check rc 0.

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

Labels

Review effort 3/5 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