Skip to content

onnx: the K-long zero point is refused at the first run, not at session creation - #1220

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/onnx-qdq-session-word
Nov 6, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/onnx-qdq-session-word

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

Two sentences on the QDQ pages, both of them wrong or unreadable at the head the page was written on. Docs only, no code, no test, no behaviour change.

1. docs/onnx-pack.md: the K-long zero point is refused at the first run, not at session creation

#1196's review called this out as a non-blocking nit and the PR merged with the wording as it was: the page said the CPU EP "refuses the session before any EP sees it". It does not refuse the session — InferenceSession(...) builds fine and the refusal is raised when the CPU EP first prepares the node to execute it. Anyone following the page would build a session, see it build, and conclude the page was wrong.

Re-derived here rather than quoted from the review, with the graph the page describes ([4,8] int8 activation, per-tensor x_scale, 8-long x_zero_point along K, opset 21), onnx 1.22.0 / onnxruntime 1.29.0:

onnx.checker: accepted a scalar scale beside a K-long zero point
InferenceSession: BUILT OK  -> refusal is not at session creation
run(): REFUSED
    [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running DequantizeLinear node.
    Name:'dq' Status Message: .../quantization/quantize_linear.cc:79 void onnxruntime::PrepareForQDQ(...)
    zero_point_ptr == nullptr || IsScalarOr1ElementVector(zero_point_ptr) was false.
    x_zero_point must be null or a scalar or 1D tensor or size 1.

Same file, same line, same message text the page quotes — so the conclusion stands ("this shape cannot occur as a graph the CPU EP will run"); what changes is where in the pipeline it is refused, which is exactly the detail the next person would hit.

2. docs/onnx.md: the coverage sentence read as its own opposite

so on a real model the EP takes the shapes it has a kernel for and the CPU EP takes the rest (for Qwen3-0.6B that is q, k and v)

"that is q, k and v" sits after "the rest", so it can be read as naming what the CPU EP takes — the opposite of what the page's own census table says two hundred lines earlier (docs/onnx-pack.md, "What the graph gives us": q 1024 × 2048 and k, v 1024 × 1024 are the shapes with a kernel; lm_head, gate/up, down and o are "none — CPU EP"). pi-prs read it that way in review, which is the evidence that the sentence is ambiguous rather than merely terse.

Now it cannot be read two ways, and it carries the census counts the page already states elsewhere (docs/onnx.md: "254 MatMul nodes in six shapes, of which this engine's kernels cover 1024 x 2048 (q) and 1024 x 1024 (k, v) — 84 nodes"):

the EP takes the shapes it has a kernel for — on Qwen3-0.6B those are q, k and v, 84 of 254 matmuls — and the CPU EP takes the rest, lm_head, gate/up, down and o among them.

"among them" is load-bearing: the rest is 170 nodes, and 57 of those are the attention matmuls (QK^T, AV, one rotary matmul) that the table's six projection shapes do not count.

Deliberately not in this PR

  • The census table's "kernel today" column may be stale, and I did not touch it. Five int8 designs now exist for every Qwen3-0.6B projection shape (Q_K1024_N2048, KV_K1024_N1024, O_K2048_N1024, D_K3072_N1024, GU_K1024_N3072 in ~/qdq-elfs-m32/, the set the device leg's 196 of 197 result was measured with), while the table still says "none — CPU EP" for o, down and gate/up. That column describes the float gemm_f32 path, and turning "the design exists" into "the float path claims it" needs a device window (the claim only happens while the device lock is ours) and a probe run — a measurement, not an edit. Named here so it does not read as an oversight; it is the next thing this lane would measure.
  • No closes #N: this is onnx: a zero point along K is not a graph ONNX will run, so the QDQ page's last Not-done closes #1196's review follow-up, not an issue.

Gates

  • python3 tools/copyright.py --check → rc 0 (no new files).
  • git diff --name-only = docs/onnx.md, docs/onnx-pack.md only, so the built binaries and the test roster are byte-identical to main; no build or test claim is made beyond CI's.
  • The lane's own tree at this base is green anyway, rebuilt after the 22:37 reboot on origin/main e0f0362d: WT=~/wt/qdq-c23 BUILD=/tmp/qdq-sess ~/wt/qdq-model-build.sh → the four artifacts, CMAKE_BUILD_TYPE=Release, and ctest runs 5/5 QDQ tests green (onebit_ep_proof fails and the two NPU probes skip — the recorded "NPU build with no ONEBIT_EP_NPU_ELFS configured" state since 2026-10-31, not a regression).

Head bb34bf6d76, base origin/main e0f0362d.

…on creation (and say which Qwen3-0.6B shapes have kernels)
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#1220 ready for review at bb34bf6

@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 bb34bf6d — both sentences are right, and I re-derived each of them rather than reading them back.

1. The K-long zero point is refused at the first run, not at session creation — reproduced. Graph as the page describes (graph input [4,8] int8, per-tensor x_scale [1], 8-long x_zero_point along K, one DequantizeLinear, opset 21), onnx 1.22.0 / onnxruntime 1.29.0, CPU EP only:

onnx.checker: accepted a scalar scale beside a K-long zero point
InferenceSession: BUILT OK  -> refusal is not at session creation
run(): REFUSED
  [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running DequantizeLinear node.
  Name:'dq' Status Message: .../quantization/quantize_linear.cc:79 void onnxruntime::PrepareForQDQ(...)
  zero_point_ptr == nullptr || IsScalarOr1ElementVector(zero_point_ptr) was false.
  x_zero_point must be null or a scalar or 1D tensor or size 1.

Same file, same line, same message the page quotes, and the timing now matches the pipeline. Matching #1196's review exactly, where I had only shown the Run refusal and not the two steps before it.

2. The census numbers in the rewritten sentence are exact, from the graph itself. onnx.load("models/qwen3-0.6b.onnx"), opset 21, counting MatMul and the B operand's dims:

254 MatMul nodes in 9 shapes: (1024,1024) 56  (1024,3072) 56  (1024,2048) 28  (1,16,128,-1) 28
  (1,16,-1,128) 28  (2048,1024) 28  (3072,1024) 28  (1,1,-1) 1  (1024,151936) 1

q is (1024,2048) 28, k and v are (1024,1024) 56, so 84 of 254; the attention matmuls are QK^T 28 + AV 28 + one rotary 1 = 57 ("among them" is correctly load-bearing — the six projection shapes are 197 nodes, 254 - 197 = 57); lm_head 1, gate/up 56, down 28, o 28 make up the rest. Every figure in the new sentence is the graph's own count, and the page's kernel today column two hundred lines up agrees with it.

Docs only (git diff --name-only = the two pages), tools/copyright.py --check rc 0. On the disclosed non-change — the kernel today column still saying "none — CPU EP" for o, down and gate/up while five int8 ELFs exist — I agree it is a measurement (whether the float path claims the shape) and belongs in its own change, not in a doc fix.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit b11e755)

Here are some key observations to aid the review process:

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

Incorrect Documentation

The documentation incorrectly stated that the CPU EP refuses the session before any EP sees it when encountering a K-long zero point. The actual behavior is that the refusal occurs during the first run when the CPU EP prepares the node to execute, not at session creation. This correction aligns the documentation with the true runtime behavior of onnxruntime 1.29.0.

zero point beside a per-tensor scale. `onnx.checker` accepts that graph, and the CPU EP's session
builds; the node is refused when the CPU EP first prepares it to run (`onnxruntime` 1.29.0, on the
first `run()`, not at session creation):

@bong-water-water-bong
bong-water-water-bong merged commit 15ab29e into main Nov 6, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/onnx-qdq-session-word branch November 6, 2026 05:01
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit b11e755

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