Skip to content

onnx: with a design per projection the float path claims 196 of 254 matmuls (measured) - #1221

Merged
bong-water-water-bong merged 7 commits into
mainfrom
1bit/onnx-qdq-float-coverage
Nov 6, 2026
Merged

bong-water-water-bong merged 7 commits into
mainfrom
1bit/onnx-qdq-float-coverage

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

The census table and the Status paragraph both described the float MatMul path's coverage as it was when the only designs on the box were the two m16 ones (q, and k/v). Five M=32 designs now exist in ~/qdq-elfs-m32 — one per Qwen3-0.6B projection shape, the same set the A8W8 device leg's 196-of-197 result was measured with — and gemm_f32 row-blocks by the design's M (row0 += kern->m) while has_kernel() only looks at (K, N), so nothing about them is QDQ-specific. This measures whether the float path takes them, and writes down what it took.

Docs only. Two files: docs/onnx.md, docs/onnx-pack.md. No code, no test, no behaviour change.

Measured

One npu-hold -l qdq -t 6 ticket (01793933132305854418.qdq, token after 6 s, ran 94 s of the 6-minute hold, released cleanly, die 63-69 °C), ~/wt/qdq-float-cov-run.sh, Release build CTest-green of this tree, qwen3-0.6b.onnx (float32), one thread, a 32-token prompt and 8 generated tokens, two runs per arm:

cpu    (no --ep)          prefill 283.6 / 262.8 ms   decode 2683.0 / 2582.5 ms  (322.8–335.4 ms/token)  load 16.07 / 16.47
device (5 M=32 designs)   prefill 2971.1/ 3374.0 ms  decode 27715.0/ 30908.9 ms (3464.4–3863.6 ms/token) load 20.81 / 32.81

capability nodes=2113 claimed=196 qdq_groups=0
per-shape MatMul runs: 252 1024x2048 npu=1 | 504 1024x1024 npu=1 | 504 1024x3072 npu=1
                       252 2048x1024 npu=1 | 252 3072x1024 npu=1        (= 1764 = 196 x 9 passes)
ids, all four runs:    1096 6147 369 279 990 315 264 3175

So: 196 of 254 matmuls claimed — all seven projections — and every one of those shapes ran on the array, with no npu_declined line, and the two arms produced the same 8 ids. Before this, the same float graph claimed 84 (q, and k/v) — the doc said so, and that sentence is what changes.

What I deliberately did not claim: a ratio. The control arm ran at load 16.1–16.5 and the five-design arm at 20.8–32.8 (other lanes ramping up after the 22:37 reboot), so 3464 ms/token against 323 ms/token is two numbers from two different boxes as far as attribution goes. The page quotes both with their load and says outright that the ratio is not a result and that the float leg's per-call cost (host-side amax/127 quantisation, then the readback and dequant) is what a fair window would have to price. That is the same rule this page already follows for the earlier 8.15 ms vs 0.161 ms -O0 trap and the 03:50 sign flip.

Docs changes

  • docs/onnx-pack.md: the census table's column becomes design today and names the M=32 design beside each projection (lm_head keeps "none — CPU EP"); the paragraph under it keeps the honest 84-of-254 sentence for the two m16 designs and adds the measured 196-of-254 with a pointer to onnx.md#status.
  • docs/onnx.md: the --check paragraph states both counts and the trace evidence (capability nodes=2113 claimed=196, 1764 matmul … npu=1), and the Status paragraph replaces "What is not done is coverage … 84 of 254" with the measured coverage, what stays on the CPU EP and why (lm_head needs its own tiling; QK^T/AV have no constant weight, which is what the rank check refuses), and the loaded-window caveat verbatim.

Stacked, and why

Base is 1bit/onnx-qdq-session-word (#1220), not main: #1220 rewrites the same Status sentence (it fixes the q/k/v ambiguity there), so the two diffs would conflict on the same lines. Merge order #1220 → this one; if #1220 lands, this retargets to main with no content change, and if #1220 takes CHANGES I rebase on top of it rather than resubmitting.

Gates

  • python3 tools/copyright.py --check → rc 0 (no new files).
  • git diff --name-only = the two pages, so the binaries and the test roster are identical to the base; no build/test claim beyond CI's.
  • The lane's tree at the base is green: fresh worktree off origin/main e0f0362d, Release ONEBIT_EP_NPU=ON build, ctest 5/5 QDQ (onebit_ep_proof fails and the two NPU probes skip — the recorded no-ELFS-configured state since 2026-10-31).
  • The measurement was taken with this tree's binaries: the ticket's build was /tmp/qdq-sess, CMAKE_HOME_DIRECTORY=/home/bcloud/wt/qdq-c23/onnx, CMAKE_BUILD_TYPE=Release.

Head 055ea9a4, base 1bit/onnx-qdq-session-word @ bb34bf6d.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#1221 ready for review at 055ea9a — stacked on #1220 (base 1bit/onnx-qdq-session-word): #1220 rewrites the same Status sentence, so merge order is #1220 then this one. Docs only; the number in the body is a npu-hold measurement (capability nodes=2113 claimed=196, 1764 matmul … npu=1 lines, same ids as the CPU EP), with the timing quoted beside its load rather than as a ratio.

@bong-water-water-bong
bong-water-water-bong force-pushed the 1bit/onnx-qdq-float-coverage branch from 055ea9a to f5606b2 Compare November 6, 2026 02:49
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#1221 head moved 055ea9a4 → f5606b28 (same commit, amended before any verdict existed): the sentence about what stays on the CPU EP said attention's QK^T/AV is refused "because the weight is not a constant", which is the pack matcher's reason, not this EP's. can_compute declines them on the rank check first — both operands are rank-4 activations — so the sentence now says that, and says lm_head has no design because it needs a tiling of its own. Please review f5606b28; nothing else in the diff changed.

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

The census re-derived straight from the graph, with my own onnx walk rather than your tool
(/home/bcloud/models/qwen3-0.6b.onnx, onnx 1.23.2):

MatMul nodes: 254
  weight matmuls (2-D initializer as input 1):  196
    1024 x 1024: 56     1024 x 3072: 56     1024 x 2048: 28     2048 x 1024: 28     3072 x 1024: 28
  the other 58: 1 lm_head (weight behind a Cast) + 57 attention QK^T/AV (no constant weight)

So 254, the six shapes and the counts in the table are all right, and 196 is exactly the set of matmuls a
(K, N) design can claim. Your per-shape run counts also close arithmetically: 252 + 504 + 504 + 252 + 252 = 1764 =
196 x 9
, which is the number of passes the trace implies.

The two code claims the doc rests on are true as written. npu/ort/onebit_npu_gemm.cpp:462 tiles the float path
with for (int64_t row0 = 0; row0 < m; row0 += kern->m) — i.e. by the design's M, not the request's — and
onnx/ep/onebit_ep.cpp:946 gates on onebit::npu::has_kernel(k, n), which takes only (K, N). So a (K, N) design with
M=32 is claimed for any request size and the loop blocks it, which is the mechanism the page now describes; nothing
about the M=32 set is QDQ-specific.

The five M=32 designs exist as named: ~/qdq-elfs-m32/{Q_K1024_N2048, KV_K1024_N1024, GU_K1024_N3072, O_K2048_N1024, D_K3072_N1024} — one per projection, matching the five shapes in the trace one for one.

The page keeps its own discipline: the ratio is explicitly not claimed, both arms are quoted with their load
(16.07-16.47 vs 20.81-32.81), and the "not a speed claim" sentence names what a fair window would have to price. That is
the correct call on a box another lane was ramping on, and it is why I am not asking for those numbers to be re-derived.

One nit, and it is the only thing a careful reader trips on: the table's count column sums to 197, while the prose says
254.
The difference is the 57 attention matmuls, which are in no row (no constant weight, so no (K, N) shape).
Either add a line under the table — "the other 57 MatMul nodes are attention's QK^T/AV, declined by the rank check
before any kernel question, and are why the denominator is 254 rather than 197" — or state coverage as 196 of 197
weight matmuls
beside 196 of 254. As it stands a reader who adds the column cannot reconcile it with the sentence above
it, and the more useful figure (99.5 % of the matmuls a design could claim) is the one not printed.

Not verified: the onnxruntime 1.29.0 zero-point row (that the CPU EP refuses a K-long zero point at the first run()
rather than at session creation) — it needs an ORT session on the crafted graph, and this page is where an earlier claim
of mine went the other way, so it deserves a run rather than a read.

Ran on pi prs, CPU only, no device, Tctl <= 62 C.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit f7681e7)

Here are some key observations to aid the review process:

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

Hardware-Specific Measurement Assertion

The documentation states that the coverage was measured on 2026-11-05 on a specific hardware configuration (XDNA 2, one thread, 32-token prompt, 8 generated tokens). This assertion is accurate but relies on a specific environment and workload. If the hardware or workload changes, the claim may not hold, and the documentation does not provide a mechanism to validate or re-measure the coverage in other scenarios.

| MatMul (K, N) | count | projection | design today |
|---|---|---|---|
| 1024 × 151936 | 1 | lm_head | none — CPU EP |
| 1024 × 3072 | 56 | gate, up | `GU_K1024_N3072` (M=32) |
| 3072 × 1024 | 28 | down | `D_K3072_N1024` (M=32) |
| 1024 × 2048 | 28 | q | `Q_K1024_N2048` (M=32), `full_i8_QKV_K1024_N2048_m16.elf` |
| 2048 × 1024 | 28 | o | `O_K2048_N1024` (M=32) |
| 1024 × 1024 | 56 | k, v | `KV_K1024_N1024` (M=32), `full_i8_O_K1024_N1024_m16.elf` |

254 MatMul nodes, 6 distinct shapes, zero custom domains. The binding is therefore a table lookup on
`(K, N)`, which is exactly what `ONEBIT_EP_NPU_ELFS="16x1024x2048=<elf>,16x1024x1024=<elf>"` already
expresses; a shape with no entry returns `ORT_NOT_IMPLEMENTED`, the EP falls back to the CPU for it,
and the session still runs. That is why deliverable 4 can be honest about owning 84 of 254 matmuls
rather than claiming the model — 84 is what the two `m16` designs the iso-build tree shipped reach
(q, and k/v). **The design column is not a feature column, and it has grown since that census:** with a
design for every projection (the five M=32 designs, beside the other xclbins and never in this
repository) the float path claims **196 of 254** — all seven projections — and every one of those
shapes ran on the array, measured on 2026-11-05 rather than inferred from the table; the numbers and
their window are in [onnx.md](onnx.md#status).
Claimed Coverage Accuracy

The PR updates documentation to reflect that the float path now claims 196 of 254 MatMuls, measured on specific hardware (XDNA 2) with a defined workload. However, the claim lacks explicit verification that the measured results are reproducible or that the hardware setup is consistent across runs. While the PR description includes a detailed run log, it does not provide a mechanism to validate the claim in other environments or under different conditions.

scale fit at `0.9999`. Coverage is a design per `(K, N)`, not a feature of the code: with the two `m16`
designs the EP takes q, k and v (84 of Qwen3-0.6B's 254 matmuls), and with a design for every shape —
the five M=32 designs on this box — it claims **196 of 254**, every one of which ran on the array.
Measured on 2026-11-05 on the float32 graph, one thread, a 32-token prompt and 8 generated tokens:
`capability nodes=2113 claimed=196`, then `1764` `matmul … npu=1` lines across nine passes (196 x 9 —
q 252, k/v 504, gate/up 504, o 252, down 252), no `npu_declined`, and the two arms generated **the same
ids** (`1096 6147 369 279 990 315 264 3175`), so the wider claim is a coverage result, not a tolerance
one. What stays on the CPU EP either way is `lm_head` (`1024 × 151936`, which needs a tiling of its own, so
no design exists for it) and attention's QK^T/AV, which the EP never claims because both operands are
rank-4 activations and its rank check declines them before any kernel question arises. That window does
**not** make the wider claim a speed claim: the control ran at load 16.07–16.47 and took 283.6 / 262.8 ms
of prefill and 322.8 / 335.4 ms per token, while the five-design arm ran at load 20.81–32.81 and took
2971.1 / 3374.0 ms and 3464.4 / 3863.6 ms per token. Both raw numbers are quoted with their load, and the
ratio between them is not a result; the float leg's own per-call cost (host-side `amax/127`
quantisation, then the readback and dequant) is what a fair window would have to price, and that window
has not been taken. The device backend is still off by default and is not part of any release, because
enabling it on a box where another process owns the NPU must stay an explicit decision.
✅ Resolved findings

docs/onnx-pack.md:53-71

Claimed Coverage Accuracy

The PR updates documentation to reflect that the float path now claims 196 of 254 MatMuls, measured on specific hardware (XDNA 2) with a defined workload. However, the claim lacks explicit verification that the measured results are reproducible or that the hardware setup is consistent across runs. While the PR description includes a detailed run log, it does not provide a mechanism to validate the claim in other environments or under different conditions.

docs/onnx.md:580-596

Hardware-Specific Measurement Assertion

The documentation states that the coverage was measured on 2026-11-05 on a specific hardware configuration (XDNA 2, one thread, 32-token prompt, 8 generated tokens). This assertion is accurate but relies on a specific environment and workload. If the hardware or workload changes, the claim may not hold, and the documentation does not provide a mechanism to validate or re-measure the coverage in other scenarios.

Base automatically changed from 1bit/onnx-qdq-session-word to main November 6, 2026 05:01
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Second window, on a quiet box, because the body says a fair one has not been taken and one arrived at 02:36 (ticket 01793946992511978584.qdq, token after 0 s, 106 s of a 6-min hold, die 59 C, released cleanly). Same script, same build, same 32-token prompt + 8 tokens:

load1 at t0 1.50
cpu    (no --ep)         prefill 640.5 / 630.8 ms   decode 5569.2 / 2137.1 ms (696.15 / 267.13 ms/token)  load 1.77 / 1.82
device (5 M=32 designs)  prefill 5161.7/ 3442.3 ms  decode 29369.3/ 29976.5 ms (3671.16 / 3747.06 ms/token) load 8.55 / 10.75
capability nodes=2113 claimed=196   1764 matmul npu=1 lines    ids identical in all four runs

So the coverage reproduces (196 of 254, every ELF shape on the array) and the direction of the cost now has two windows behind it: ~10.7x the CPU EP at load 16-33, 13.7x here (3747 against the CPU arm's second run, 267.13 ms/token, which is the run this lane quotes — the first CPU run pays model load and ORT graph optimisation, as in every table on onnx.md).

I am not calling 13.7x a clean ratio, and this is why, from the box rather than from the shape of the numbers: load1 rose from 1.50 to 8.55-10.75 during the device arm, and my run cannot account for that. Two candidate causes were checked and neither holds — a single-threaded ORT session contributes ~1, and the first device run's only host-side cost that is not per-call is packB over 196 weights. What is actually churning is local-search.service (a user unit, not this lane's): 4659 restarts since the 22:37 boot, status=203/EXEC, /home/bcloud/projects/camoufox/start-search.sh does not exist, looping every ~3 s. That is a fault for its owner (I have not touched the unit — no box config changes overnight), and it is exactly the kind of background that makes a two-arm ratio untrustworthy.

What the two windows do establish, and what a follow-up docs PR should say once this merges: full coverage on the float path is not a win, and the per-call cost is where it goes — 3747 ms/token over 196 calls is ~19 ms/call, against the A8W8 leg's measured 4.32 ms/call on the same box (onnx.md's dev_split_* table). Same call count, same designs; the difference is the float leg's host-side work per call (per-row amax/127, the float readback and dequant) plus a kernel that at M=32 is a small fraction of that. That contrast is testable with ONEBIT_EP_QDQ_PROF's sibling instrumentation, which is what I would want to price before changing the page again — the sentence in this PR stays as written, since it claims neither ratio.

…atmuls, and the census table says which design
@bong-water-water-bong
bong-water-water-bong force-pushed the 1bit/onnx-qdq-float-coverage branch from f5606b2 to e307efe Compare November 6, 2026 06:43
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#1221 rebased onto main, head f5606b28 → e307efe3 — it went CONFLICTING/DIRTY the moment #1220 was squash-merged (15ab29ed, 05:01Z, its branch deleted, this PR auto-retargeted to main), so the head had to move: a READY verdict is worth less than a PR that can actually merge.

What the rebase did, checked rather than assumed:

Divergence check, since this PR's numbers came from the tree at e0f0362d: git log e0f0362d..origin/main -- onnx/ npu/ort/ npu/forward/ docs/onnx*.md is two commits — #1220 itself, and #1242 (npu-pack container scales), which touches neither the EP's float path nor these pages. So the binaries behind capability nodes=2113 claimed=196 are behaviourally the tree the page now describes; nothing to re-measure.

mergeable=MERGEABLE, state=BLOCKED (checks restarting on the new head). Please re-verdict e307efe3; the only difference from the f5606b28 you read is the base.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit e307efe

@bong-water-water-bong
bong-water-water-bong merged commit d88a346 into main Nov 6, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/onnx-qdq-float-coverage branch November 6, 2026 17:06
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit f7681e7

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