Repository navigation
onnx EP: give the three host-routed projection shapes a device gate at 32 rows - #909
Conversation
…t 32 rows `gemm_q8` routes by rows (`kDeviceMinRows = 16`) since #862, so the 5-row o_proj / down_proj / gate-up cases stopped reaching the array: three of the five projection shapes docs/onnx-pack.md claims had no device gate at all, while the run still printed `PASS worst |d| = 0`. Same failure family as the "host gate dressed as a device one" this lane has recorded twice, in its quietest form. - `quark-o32`, `quark-d32`, `quark-gu32` (32 rows: 2048x1024, 3072x1024, 1024x3072), placed after the `rss` case so their arena cannot move that measurement. The 5-row cases stay: they are what asserts host routing. - The proof now asserts that a fused case at or above the threshold did not fall back, so a device that quietly declined to run is a red line in the test instead of only in a lane script. - Gate on the new cases is one LSB, not zero: the CPU EP accumulates in float32 and the fused path rounds an exact int32 sum, so a quantisation boundary can round to different neighbours. Measured 1 of 32768 on o_proj (K=2048), 0 on down_proj and gate/up; above one LSB is a defect. - docs: "16 is the first row count at which no shape was slower" was wrong -- 12 is (worst shape 0.86x of the host loop), and 16 is the first that keeps more margin than the box's run-to-run spread. Both pages corrected, and the device-gate paragraph now says which row count the claim is measured at.
…e gate measured 7236 kB) The paragraph quotes its own eight runs (6136-7004 kB) and says why the figure moves; a head re-run of the same gate on the same tree produced 7236 kB, so a reader who re-measured would have found the band too tight. Stated as a range with a wider tail rather than widened silently -- the 6.1 MB identity it rests on is unaffected.
PR Reviewer Guide 🔍(Review updated until commit 1233aa3)Here are some key observations to aid the review process:
|
Device gate: both arms passed on the arrayTwo Ticket BEFORE (
|
|
Persistent review updated to latest commit 64a4af4 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
At 64a4af460. I built the ORT target here (-DONEBIT_ORT=ON, Release, 0 warnings) and ran the proof, so the new cases are measured rather than read:
onebit-ort-qdq: case quark-o32: 1 of 32768 int8 values differ, worst |d|=1 LSB, path=fused
onebit-ort-qdq: case quark-d32: 0 of 32768 int8 values differ, worst |d|=0 LSB, path=fused
onebit-ort-qdq: case quark-gu32: 0 of 98304 int8 values differ, worst |d|=0 LSB, path=fused
onebit-ort-qdq: PASS OneBitEp fused the A8W8 QDQ group: worst |d| = 0/0/0/0 LSB …, device-width
projections (32 rows: o_proj, down_proj, gate/up) worst |d|=1, peak RSS -6692 kB
That is exactly the body's claim down to the counts — 1 of 32768 on o_proj, 0 on down_proj and gate/up — and the peak-RSS delta 6692 kB sits inside the documented band (6136-7236), so the "indicative, not a bound" wording in the last commit is honest.
The routing is right, and it cannot drift. kDeviceMinRows = 16 (onnx/ep/onebit_ep_kernel.h:51) with the new cases at m=32, so they are device width while their 5-row twins are host width. The proof #includes that header rather than restating 16 — the constant lives in one place, once.
The assertion this PR exists for is the fallback one, and it is the right shape: a case at or above the threshold that logs npu_qdq_fallback now fails instead of printing a green |d| = 0 produced by the host loop. That is the failure the docs name plainly ("a host gate dressed as a device gate … the run still printed PASS and worst |d| = 0"), and it is now checked in the test rather than in a lane script. fused_cases 10 → 13 matches the three added cases — the run passes that check too.
What I could not run: the device half. Both halves of the routing assertion live inside if (r.fused && std::getenv("ONEBIT_EP_NPU_ELFS")), so on this box (no ELFs configured) the three new cases take the fused host path and assert nothing about the array. Everything the flag does not gate I ran; the "the array ran this shape" claim remains the lane's, and it is now enforced where it will be re-checked.
One note for whoever owns this gate next: the o_proj bound has no headroom — 1 LSB passes, 2 fails, and the 1 is a property of the CPU EP's float32 accumulation order against the fused path's exact int32. If that order ever changes (a different microarchitecture's FMA/SIMD path in ORT, a new ORT build), the same arithmetic could land on 2 of 32768 and the row would go red with no defect behind it. The docs already anchor the number to a real Quark export showing the same 1-in-5120, so this is a "know what a red row means here" note, not a change request — but a column-level tolerance would be the fix if it ever fires.
The docs edits are consistent with the code: the 12-vs-16 row-count story is told once with both numbers and the reason 16 is kept (run-to-run spread 1.2-1.3x), and docs/onnx.md keeps the device leg correctness-only rather than quoting a device speedup.
|
Persistent review updated to latest commit 1233aa3 |
What this fixes
gemm_q8routes by rows since #862 (kDeviceMinRows = 16), and the proof's device cases foro_proj (5×2048×1024), down_proj (5×3072×1024) and gate_proj/up_proj (5×1024×3072) are all
5 rows. So from that merge on those three cases ran on the host loop —
npu_qdq_host_rows— and thearray never saw those shapes. Three of the five projection shapes
docs/onnx-pack.mdclaims asdevice-covered had no device gate at all, and nothing said so: the proof still printed
PASS … worst |d| = 0, because the shapes that do reach the device (q at 64 rows, k/v at 256) were stillcovered and a host-routed call is a legitimate outcome, not a failure.
That is this lane's recurring "host gate dressed as a device one" failure in its quietest form: the run looks
perfect and the trace is the only thing that disagrees.
Found on resume, not from a report: the 5-row cases were correct when they were written and #862's routing
silently changed what they prove.
The fix
quark-o32/quark-d32/quark-gu32— 32 rows at 2048×1024, 3072×1024, 1024×3072, placed after thersscasekDeviceMinRowsmust not lognpu_qdq_fallbackdocs/onnx.md,docs/onnx-pack.mdWhy the new cases are gated at one LSB
The CPU EP dequantises and then accumulates in float32; the fused path sums exact int32 and rounds once.
At a quantisation boundary the two can therefore round to different neighbours. Measured on the 32-row cases:
quark-o32(o_proj)quark-d32(down_proj)quark-gu32(gate/up)That is the same 1-in-5120 the real Quark A8W8 export showed in #695, and it is the reason the existing
quark-stresscase is already gated at ≤1. Above one LSB is a real defect — a wrong weight layout or atruncated K reads as hundreds of LSB — so the bound does not weaken the gate: it stops it asserting an
arithmetic identity the CPU EP does not provide.
Two shipped statements were wrong, both mine
45-cell sweep taken with the fixed probe has every shape faster from 12 rows (worst shape 0.86× of the
host loop at 12). 16 is the first count that keeps more margin than the box's own run-to-run spread —
1.59–1.75× at 16 against 1.16–1.32× at 12 — which is the actual reason for the constant. Corrected on both
pages, with the reason.
docs/onnx.mdsaid the device "crosses over between 8 and 16 rows"; anddocs/onnx-pack.md's five-shapedevice paragraph did not say which row count its numbers were taken at, so after onnx EP: gemm_q8 routes by rows, so a decode step stops paying for a dispatch-bound device call #862 it read as current
coverage. Both now state the row count and that the 5-row cases are decode-width and host-routed.
Gates
Host (this tree,
cmake -S onnx -B …with noCMAKE_BUILD_TYPE, i.e. the stricter unoptimized build):ctest6/6;tools/copyright.py --checkrc 0; no new files, so no new notices.The RSS figure is unchanged from the documented band (6136–7004 kB), which is the check that the new cases sit
where their comment says they do.
Device:
ONEBIT_EP_NPU=ONRelease builds of bothorigin/mainand this branch, onenpu-hold -l qdqticket running both arms — the positive (five designs, o/d/gu on the array at 32 rows, per-shape
host_rows/fallback/epilogue counts read back from the trace) and the negative arm (o_proj's designreplaced by a file the runtime refuses, so the new assertion must FAIL and name
quark-o32; a gate never seento fail is not a gate). Result in the comment below.
Not in this PR
Concat), which tracking: zero-copy on the serving paths (hybrid KV handoff, NPU activations in BOs, ONNX EP IO binding, audit) #698 hands topi-ortep/pi-qdq: it cannot be removed by an EP-side memcpy fix, because the copy is how
presentisproduced; it needs a cache written in place, i.e. an op that mutates a buffer, which ONNX's functional graphs
cannot express without new kernel work. Recorded in my state file, not attempted here.