Skip to content

onnx: exercise down_proj's device design in the QDQ proof (and the docs on the device leg match main) - #731

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/onnx-qdq-down-proj-case
Nov 1, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/onnx-qdq-down-proj-case

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Two things #702 left behind. Both came out of pi-ortep's question about which designs the |d| = 0 gate actually covered — the answer was "one", because the down_proj ELF was configured and never exercised.

The proof now exercises full_i8_D_K3072_N1024.elf

ONEBIT_EP_NPU_ELFS has named that ELF since the first device run, and no case used its shape, so a defect in that design could only have appeared on a real model run. New case quark-d, 5×3072×1024 — down_proj's own shape — beside the o_proj case:

host:    case quark-d: 0 of 5120 int8 values differ, worst |d|=0 LSB, path=fused
device:  case quark-d: 0 of 5120 int8 values differ, worst |d|=0 LSB, path=fused

The device run is ONEBIT_EP_NPU_ELFS=128x2048x1024=…/full_i8_O_K2048_N1024.elf,128x3072x1024=…/full_i8_D_K3072_N1024.elf under npu-hold, and the trace contains no npu_qdq_fallback k=3072 n=1024 — that absence, not the PASS, is what makes it a device result (qdq rows= is written by the shared epilogue on both paths).

The fused-case floor goes 7 → 8, so the new case cannot silently stop fusing.

docs/onnx-pack.md: the device leg is not "not done" any more

The bullet still read "Not done: the device leg of the fused path. The fused node's int8 GEMM runs on the host today." — false since #702 merged. It is now a Works bullet carrying its measured gate (0 LSB on both shapes, no fallback line) and, because a gate without its limits is a sales claim, its two limits:

  • an ELF is needed per (K, N), and on this box only those two Qwen3-0.6B projections have one (q_proj's 1024×2048 and k/v's 1024×1024 do not) → the device share of a real graph is 56 of 197 MatMuls;
  • it is a correctness result, not a speed one: the designs are M=128, so a decode step hands the kernel one real row and 127 zeroed ones. No tokens/s number is claimed here.

The two downstream sentences that leaned on the old bullet ("the device leg is where the 1.5x argument lands", "leaves the one documented gap above") are corrected the same way.

docs/onnx.md: the paragraph the QDQ device path was missing

Beside the float gemm_f32 description: gemm_q8, ONEBIT_EP_NPU_ELFS, no packB/amax/127 (the int8 bytes already carry the graph's scales), the shared epilogue, and the discriminator above.

Gates

ctest on the host build 6/6; ONEBIT_EP_NPU=ON build compiles; tools/copyright.py --check rc 0; the device run above was taken through npu-hold on a quiet array, with the trace read back. Diff is three files (onnx/ep/onebit_ep_qdq_proof.cpp, docs/onnx-pack.md, docs/onnx.md).

…e docs say the device leg is done

Two things #702 left behind, found while answering pi-ortep's question about which designs our
|d| = 0 gate actually covers.

The proof configured `full_i8_D_K3072_N1024.elf` in every device gate and no case ever used it, so a
defect in that design could only have surfaced on a real model run. New case `quark-d`, 5x3072x1024 --
down_proj's own shape, next to the o_proj one that has had a case since the device leg landed:

  host:    case quark-d: 0 of 5120 int8 values differ, worst |d|=0 LSB, path=fused
  device:  case quark-d: 0 of 5120 int8 values differ, worst |d|=0 LSB, path=fused
           (ONEBIT_EP_NPU_ELFS=128x2048x1024=…O_K2048_N1024.elf,128x3072x1024=…D_K3072_N1024.elf,
            no `npu_qdq_fallback k=3072 n=1024` in the trace, so the array ran it)

The fused-case floor goes 7 -> 8 so the new case cannot silently stop fusing.

docs/onnx-pack.md said "Not done: the device leg of the fused path ... runs on the host today", which
stopped being true when #702 merged. It is now a "Works" bullet with its measured gate (0 LSB on both
shapes, no fallback line) and its two limits: an ELF is needed per (K, N) and only two Qwen3-0.6B
projections have one (56 of 197 MatMuls on a real graph run on the array), and it is a correctness
result, not a speed one -- the designs are M=128, so a decode step hands the kernel one real row. The
two sentences downstream that leaned on the old bullet are corrected the same way.

docs/onnx.md gains the paragraph the QDQ device path was missing: `gemm_q8` beside `gemm_f32`,
`ONEBIT_EP_NPU_ELFS`, no `packB`/`amax/127`, the shared epilogue, and the fact that `qdq rows=` is
written by both paths so the absence of a fallback line is what makes a run a device run.
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 5fb00d1)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

702 - Fully compliant

Compliant requirements:

  • Add fused A8W8 QDQ path on NPU device (TQDQ device leg)
  • Implement gemm_q8_raw in npu/ort for int8 activations and weights
  • Modify onnx/ep/onebit_ep_kernel.cpp to try device path and fall back to host
  • Share epilogue function between device and host paths
  • Proof with quark-o case at o_proj's real shape (5×2048×1024)
  • Fix ONEBIT_EP_TRACE flag handling bug
  • Fix ELF initialization failure causing repeated rebuilds
  • Add quark-d case for down_proj shape (5×3072×1024) to exercise second device design
  • Update documentation to reflect device leg now works
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Error Handling

The new quark-d test case is added to the test suite, but there's no explicit error handling or validation that the device kernel actually runs for this case. The test relies on the absence of a fallback line in the trace, but this could be missed if the trace file is not properly checked or if there are issues with the trace logging mechanism itself.

{"quark-d", 5, 3072, 1024, kPerTensor, kPerAxisCols, kZpZero, kZpZero, 0, true, false, 1},
Documentation Clarity

The documentation states that the device leg runs the same epilogue as the host path, but it doesn't clearly explain how the device and host paths are synchronized to ensure bit-identical results. This could be important for users to understand the correctness guarantees.

- **Works: the fused group runs on the NPU, and its int8 output is bit-identical there too.** With
  `-DONEBIT_EP_NPU=ON` and `ONEBIT_EP_NPU_ELFS` naming the designs, `gemm_q8` writes the graph's int8
  activations and int8 weights straight into the kernel's BOs (no `packB`, no `amax/127` — those bytes
  already carry the graph's scales) and reads the int32 accumulators back into the **same epilogue** the
  host path runs, so the two can only differ if the accumulator does. Measured on `strixhalo` under
  `npu-hold` with `ONEBIT_EP_NPU_ELFS=128x2048x1024=…/full_i8_O_K2048_N1024.elf,128x3072x1024=…/full_i8_D_K3072_N1024.elf`:
  `worst |d| = 0` LSB against the CPU EP over 5120 int8 values for **o_proj** (5×2048×1024) and
  **down_proj** (5×3072×1024), with no `npu_qdq_fallback` line for either shape in the trace — the device
  ran both. Two limits belong with that number. It needs **an ELF per (K, N)**, and on this box only those
  two Qwen3-0.6B projections have one (q_proj's 1024×2048 and k/v's 1024×1024 do not), so the device share
  of a real graph is 56 of 197 MatMuls and everything else keeps the host kernel. And it is a
  **correctness** result so far, not a speed one: the ELFs 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 9f7ef749 (docs/onnx-pack.md +40 −10, 3 files). A docs update replacing "Not done: the device leg" with a measured result, and it is written with the limits attached, which is the part I care about most.

Everything it cites exists on main, so the text is describing real machinery rather than intent:

  • gemm_q8(a, w, y, rows, k, n, epilogue) — onnx/ep/onebit_ep_kernel.cpp:119, called from onebit_ep.cpp:828;
  • the device path onebit::npu::gemm_q8_raw(...) at onebit_ep_kernel.cpp:167 and, one line later, the trace_fallback("npu_qdq_fallback k=%lld n=%lld why=%s") that the new text says is absent for the two shapes — i.e. the claim "the device ran both" is stated in terms of a log line that really is the right discriminator;
  • the ELF naming convention the doc quotes (full_i8_O_K2048_N1024.elf) matches npu/forward/include/q4qx_pack.h's full_i8_<ROLE>_K<K>_N<N>[_m16].elf, and onebit_ep_qdq_proof.cpp:732 already refers to that same artifact.

The limits are stated as limits, which is why I am comfortable with the numbers being the author's: "an ELF per (K, N)" and only two of Qwen3-0.6B's projections have one, so "the device share of a real graph is 56 of 197 MatMuls and everything else keeps the host kernel"; and "it is a correctness result so far, not a speed one: the ELFs are M=128 designs, so a decode step hands the kernel one real row and 127 zeroed ones — measure before quoting tokens/s". That last sentence is exactly the caveat that stops this paragraph being quoted as a throughput claim, and the same restraint is applied to the 1.46x/0.67x host numbers below it.

Not verified: worst |d| = 0 LSB over 5120 int8 values for o_proj (5×2048×1024) and down_proj (5×3072×1024) with ONEBIT_EP_NPU_ELFS set under npu-hold. That needs the array, the two ELFs and a window, and the NPU belongs to the owner's serve; it stays the author's measurement, stated with its conditions (both shapes, no fallback line in the trace).

tprs-ready applied.

@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
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 5fb00d1

@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 5fb00d1, rebased after the merges ahead of it. The author patch is byte-identical to the head I reviewed (9f7ef749) — patch-id from the merge base is the same before and after — so my review stands without re-reading: only main arrived in the rebase.

Nothing new to verify. Everything in my earlier verdict on this PR applies at this head unchanged, including what I noted as not-verified-by-me there.

@bong-water-water-bong
bong-water-water-bong merged commit 850529e into main Nov 1, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/onnx-qdq-down-proj-case branch November 1, 2026 04:23
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