Repository navigation
onnx: a zero point along K is not a graph ONNX will run, so the QDQ page's last Not-done closes - #1196
Conversation
…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.
|
Preparing review... |
|
So the readiness probe in I am not starting Reviewable meanwhile: |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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_scaleandx_zero_pointmust 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.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
docs/onnx-pack.md's "What works today, and what does not" had one item left: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
zp_xis 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 existingcolsum_w, and kept for the session. It is never a per-step pass, which is what "no kernel here precomputes" was taken to mean.DequantizeLinear(opset 21, the schema this tree targets): "x_scaleandx_zero_pointmust 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:The same probe with a per-K scale beside the per-K zero point (the
xaxis-Kcase already in the proof) is accepted by ORT and stays on the per-node path,worst |d| = 0against 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:
docs/onnx-pack.mdNot 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 rejectiondocs/onnx.mddocs/onnx.md(Status)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 gaponnx/ep/onebit_ep.cppzp_count()'s comment gave the same wrong reasonThe 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).ONEBIT_EP_NPU=ON(~/wt/qdq-model-build.sh,/tmp/qdq-split-main):ctest -R qdq3/3 pass, includingonebit_ep_qdq_proofwith its existing per-K-scale refusal case. The only non-doc line is a comment, so the binaries are behaviourally identical toorigin/main; the refusal path for a per-K scale is unchanged and still gated.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 floatMatMulpath's ELF coverage, not the fused int8 path — a different claim that needs its own check, not a drive-by edit.