Skip to content

onnx: a zero point along K is not a graph ONNX will run, so the QDQ page's last Not-done closes - #1196

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

bong-water-water-bong merged 2 commits into
mainfrom
1bit/onnx-qdq-zpk-notdone

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

docs/onnx-pack.md's "What works today, and what does not" had one item left:

Not done: a zero point along K. Like a scale along K it would weight the products inside the sum — it needs Σ_k zp_x[k]·w_q[k][n], a column-weighted vector of the weight that no kernel here precomputes — so a graph with one keeps the per-node path.

Both halves of that are wrong, and the item is not unfinished work at all.

Root cause: the stated cost is not a cost, and the graph cannot exist

  1. The term is cheap. zp_x is a constant initializer (this EP only claims a group whose zero points are initializers, zp_count()), so Σ_k zp_x[k]·w_q[k][n] is computed once, beside the existing colsum_w, and kept for the session. It is never a per-step pass, which is what "no kernel here precomputes" was taken to mean.
  2. The graph cannot be built. ONNX DequantizeLinear (opset 21, the schema this tree targets): "x_scale and x_zero_point must have the same shape … x_zero_point … Shape must match x_scale." So a 1-D zero point along K only arrives beside a 1-D scale along K — and that is the term the epilogue genuinely cannot fold, because it weights the products inside the sum (SmoothQuant's job at export time). It is the case the page already refuses, for the scale's reason.

Measured, not argued

Built the one shape that could carry the term alone — a K-long zero point with a per-tensor scale — through the proof's own graph builder (onebit_ep_qdq_proof.cpp, pinned ONNX Runtime, opset 21) and ran the CPU EP session. ORT refuses the session before any EP partitions it:

[E:onnxruntime:, sequential_executor.cc:572 ExecuteKernel] Non-zero status code returned while
running DequantizeLinear node. Name:'dq_x' Status Message:
./onnxruntime/core/providers/cpu/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.

The same probe with a per-K scale beside the per-K zero point (the xaxis-K case already in the proof) is accepted by ORT and stays on the per-node path, worst |d| = 0 against the CPU EP — i.e. the only two shapes involved are "refused for the scale" and "not a graph", which leaves nothing for the epilogue to implement. So the item closes as "cannot occur" rather than "not done".

What changes

Three places carried the same claim:

file was is
docs/onnx-pack.md Not done: a zero point along K (cost reason) Not a graph: a zero point along K — the precomputable term, the ONNX shape rule, the measured rejection
docs/onnx.md "A per-axis scale or zero point along K cannot fold" as one refusal the scale is the refusal; a zero point along K is the same refusal by a shorter route, with the shape rule and the message
docs/onnx.md (Status) the fused group's device leg "runs on the host … until the NPU kernel takes int8 activations straight into its input BO" it does, with ONEBIT_EP_NPU=ON (int8 in, int8 out, bit-identical to the CPU EP — docs/onnx-pack.md); a default build runs the host loop because the device backend is off by default, which is a decision and not a gap
onnx/ep/onebit_ep.cpp zp_count()'s comment gave the same wrong reason the real reason (ONNX's shape rule + the un-foldable per-K scale); the refusal itself is untouched

The Status sentence is the one that was simply false rather than imprecise: the device leg of the fused group is built, gated and measured (five design ELFs, 196 of a real Qwen3-0.6B export's 197 fused groups on the array, worst |d| = 0), and the page said it was still on the host.

Gates

  • python3 tools/copyright.py --check → rc 0 (no new files).
  • Build and tests on this tree, Release ONEBIT_EP_NPU=ON (~/wt/qdq-model-build.sh, /tmp/qdq-split-main): ctest -R qdq 3/3 pass, including onebit_ep_qdq_proof with its existing per-K-scale refusal case. The only non-doc line is a comment, so the binaries are behaviourally identical to origin/main; the refusal path for a per-K scale is unchanged and still gated.
  • The probe case is not in the diff: a case whose correct outcome is "ORT rejects the graph" cannot be a test that passes without asserting someone else's spec rule, so it is quoted in this body instead of shipped as a case. Say so rather than leave a hole.
  • Numbers quoted are the ones already in the pages; this PR adds no measurement of its own beyond the rejection above, and it changes no behaviour.

Not in this PR, deliberately: the docs/onnx.md "what is not done is coverage … for Qwen3-0.6B that is q, k and v" sentence, which is about the float MatMul path's ELF coverage, not the fused int8 path — a different claim that needs its own check, not a drive-by edit.

…age's last Not-done closes

docs/onnx-pack.md's "What works today, and what does not" had one item left: "Not done: a zero
point along K", with the reason given as cost -- it would need Sum_k zp_x[k]*w_q[k][n], "a
column-weighted vector of the weight that no kernel here precomputes". Both halves of that are
wrong, and the item is not unfinished work at all:

1. The term is cheap. zp_x is a constant initializer (the EP only claims a group whose zero points
   are), so Sum_k zp_x[k]*w_q[k][n] is computed once, beside the existing colsum_w, and kept; it is
   never a per-step pass.
2. The graph cannot exist. ONNX's DequantizeLinear (opset 21) says "x_scale and x_zero_point must
   have the same shape ... Shape must match x_scale", so a 1-D zero point along K only arrives
   beside a 1-D scale along K -- which is the term the epilogue genuinely cannot fold, because it
   weights the products inside the sum (SmoothQuant's job at export time).

Measured rather than argued: built the one shape that could carry the term alone -- a K-long zero
point with a per-tensor scale -- through the proof's own graph builder and ran the CPU EP session.
ORT refuses the session before any EP partitions it:

  quantize_linear.cc:79 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.

So the item closes as "cannot occur" rather than "not done". Same correction in three places:
docs/onnx-pack.md (the bullet), docs/onnx.md (the paragraph that repeated "scale or zero point
along K" as one refusal, and the Status paragraph that still said the fused group's device leg
"runs on the host ... until the NPU kernel takes int8 activations straight into its input BO" --
it does, with ONEBIT_EP_NPU=ON, which is what the sibling page documents), and the comment on
zp_count() in onnx/ep/onebit_ep.cpp, which carried the same wrong reason.

No behaviour change: the comment is the only non-doc line, the refusal path is untouched (a graph
with a per-K scale is still refused for the scale, exactly as before), and the probe case is not
shipped because a case that must not pass cannot be a test -- it is quoted here instead.
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Preparing review...

@bong-water-water-bong

bong-water-water-bong commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

pr_agent is red on infra, not on this diff: the job's own log ends with Failed to generate prediction with openai/qwen3-coder → PR-Agent could not get an answer from the model, twice (litellm.InternalServerError … OpenAIException - Connection error at 00:18:04Z). The fleet reviewer model was stopped mid-inference while two PR-Agent prompts were still being processed:

20:17:26  1bit[6191] I slot print_timing: id 2 | task 3749 | prompt processing, n_tokens = 3913, progress = 0.76
20:18:02  systemd[2168]: Stopping coder-llm.service - Local LLM for PR-Agent (Qwen3-Coder … 127.0.0.1:8090)
20:18:02  1bit[6191] I srv operator(): cleaning up before exit …
20:18:02  systemd[2168]: coder-llm.service: Consumed 10 min 56 s CPU time, 24.8 G memory peak, 4.3 G swap peak

So the readiness probe in pr-agent.yml passed (the model was up and serving), and the answer never arrived. Nothing in this PR is implicated: the diff is two doc pages plus one comment line, and the same head is green on build (6m32s) and CodeQL, with all five Analyze (…) jobs pending/skipping as usual.

I am not starting coder-llm to make this pass — it is a fleet service (24.8 G resident, HRX on the GPU, and starting it would take a device outside gpu-hold), and other lanes have this same red for the same reason. What I did instead: ~/wt/qdq-pragent-rerun.sh 42134572900 325cc134 4 is armed. It waits for :8090 to answer the same probe the workflow uses, twice 30 s apart (so a startup blip does not count), refuses to act if the PR head has moved, then re-runs only the failed job of this run and reports the conclusion. If the model stays off, it exits 3 having spent nothing and this check stays red as infra.

Reviewable meanwhile: build + CodeQL + copyright --check rc 0, and the substantive claim in the body is measured (quantize_linear.cc:79 … x_zero_point must be null or a scalar or 1D tensor or size 1 from the CPU EP itself).

@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 325cc134 — the sentence the item closes on is true, and I re-ran the thing it quotes.

The ONNX rule, from the schema itself (installed onnx 1.23.2, onnx.defs.get_schema("DequantizeLinear").doc):

x_scale and x_zero_point must have the same shape, determining the quantization's granularity: a scalar for per-tensor/per-layer quantization, a 1-D tensor for per-axis quantization, or have a rank identical to the input for blocked quantization.

So a K-long zero point only arrives beside a K-long scale, exactly as the doc now says.

The CPU EP refusal, built and run here (onnxruntime 1.29.0 in ~/amd-oss/demo-venv, a DequantizeLinear with a scalar x_scale and an 8-long x_zero_point on a [4,8] int8 input):

onnx.checker: accepted a scalar scale beside a K-long zero point
RUN refusal: [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running DequantizeLinear node ...
  /onnxruntime_src/onnxruntime/core/providers/cpu/quantization/quantize_linear.cc:79
  void onnxruntime::PrepareForQDQ(...) zero_point_ptr == nullptr || IsScalarOr1ElementVector(zero_poi...

Same file, same line 79, same message text the page quotes (x_zero_point must be null or a scalar or 1D tensor or size 1). One word is off, though: the refusal is at the first Run, not at session creation — InferenceSession(...) constructed fine and only run() raised it. "Refuses the session" would read to the next person as "the session cannot be built", and they would see it build. Suggest "the CPU EP refuses the node when it prepares it (first run)" or similar. Non-blocking: the conclusion ("cannot occur, not 'not done'") is unaffected.

The arithmetic in the comment is the code's shape, checked at this head: Σ_k zp_x[k]·w_q[k][n] is a zero-point-weighted column sum, and colsum_w is exactly a once-per-session vector (onnx/ep/onebit_ep.cpp:720-724, cached, reused at :826; the epilogue's c -= zx * colsum_w[j] at onebit_ep_kernel.cpp:204), while the row sums are per call. zp_count() refuses a K axis the way the comment says (axis != required_axis -> -1, onebit_ep.cpp:426-440), so nothing else in the path changes.

The other two sentence edits hold too: docs/onnx-pack.md's "Works: the fused group runs on the NPU" section the new text points at exists at this base (:210), and ctest -R onebit_ep_qdq_proof is registered (onnx/ep/CMakeLists.txt:128). Only comment and docs lines move — no code line is touched, so build's green is the compile check it needs.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

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

Incorrect Documentation

The documentation previously claimed that a zero point along K was "not done" and would require a per-node path because the term was expensive to compute. This is incorrect, as the term is actually computed once and is not a per-step pass. The updated documentation correctly states that such a zero point cannot occur due to ONNX shape requirements, but the old documentation was misleading and should have been corrected earlier.

- **Not a graph: a zero point along K.** The page's last "Not done" item was this one, and it is not
  unfinished work — a QDQ graph cannot carry a *1-D* zero point along K. Two facts, one arithmetic and
  one checked against the runtime: (1) its term is cheap, not a per-step pass — `Σ_k zp_x[k]·w_q[k][n]`
  is a zero-point-weighted column sum of the weight and `zp_x` is a constant initializer, so it is
  computed once beside `Σ_k w_q[k][n]` and kept, unlike the row sums; (2) ONNX's `DequantizeLinear`
  says `x_scale` and `x_zero_point` **must have the same shape**, so a 1-D zero point along K only comes
  beside a 1-D scale along K, which is the un-foldable term above (it weights the products inside the
  sum — SmoothQuant's job at export time). Built the one way that could carry the term alone, a K-long
  zero point beside a per-tensor scale, the CPU EP refuses the session before any EP sees it:
  `quantize_linear.cc:79 … x_zero_point must be null or a scalar or 1D tensor or size 1`. So the item
  closes as "cannot occur" rather than "not done": what this epilogue does not fold along the
  activation's K is what the arithmetic rules out.

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