Repository navigation
onnx: ONEBIT_EP_QDQ_PROF prices each leg of the fused QDQ path (the profile #1023 asks for) - #1032
Conversation
#1023 measured the device leg 1.13-1.16x slower than the host kernel at model level (1073.7/1105.1 vs 947.4/950.6 ms/token, same ids, same KL) while the per-design probe, at the same shapes, had the device kernels 1.7x ahead (device 712 ms/pass vs host 1209). Both readings cannot be the whole story, and nothing separated the two candidates: per-call dispatch, or the probe's host column being measured on synthetic int8 operands while the graph's own activations are not (its host column sums to 1209 ms/pass, above the entire 947 ms/token host arm, so it cannot be subtracted from anything). This is the instrument that separates them, without a profiler: one running total per process of where gemm_q8's wall time went, split as the device call (BO writes, launch, both syncs, the wait), the epilogue both legs share, and the host loop. Two arms that differ only in the leg then price that leg on the graph's own int8 bytes. ONEBIT_EP_QDQ_PROF=1 -> qdq_prof calls_dev=... rows_dev=... dev_call_ms=... dev_epi_ms=... host_ms=... (one line, at exit) Verified without a device: - unoptimized host build 6/6 green, and 6/6 green with the knob on, with the fused proof's gate unchanged (worst |d| = 0 LSB per-tensor / per-axis / asymmetric / asymmetric-per-axis, per-K scale still refused); - the knob's three cases run: off -> zero qdq_prof lines; on with a trace -> one line in /tmp/onebit_ep_trace.<pid>.log; on without a trace -> the line on stderr; - Release (ONEBIT_EP_NPU=ON) build: onebit_ep_qdq_proof passes; ctest there is 8 tests of which onebit_ep_proof fails and the two NPU probes skip, exactly as main already does for an NPU build with no ELF configured; - the same 17 calls cost 79.8 ms at -O3 and ~2000 ms at -O0 (25x), the -O0 trap from 2026-11-04 15:45 seen from the other side. trace_fallback is split into trace_line (the writer, unchanged 0600 + O_NOFOLLOW) plus the formatting wrapper, so every note this file emits has one writer and the prof line cannot go silent when ONEBIT_EP_TRACE is off -- the same footgun as this file's old path-vs-flag bug. The measurement this is for is armed on the NPU queue (one short npu-hold ticket, sized to finish inside its hold); its numbers will be reported on #1023 and in ~/briefs/TQDQ-STATE.md, not in this diff. No device hardware was touched to write or gate this.
|
#1032 ready for review at 7718955. Rebased onto current main 9bb1216 (it was cut from 434db3d, before #1023 landed), so the diff is the two files only: onnx/ep/onebit_ep_kernel.cpp and docs/onnx.md. This is the profile #1023 ends by asking for; the measurement it exists for runs on the NPU queue and its numbers will go into #1023 and ~/briefs/TQDQ-STATE.md rather than into this diff. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 7718955a
Reviewed the knob as instrumentation rather than as a result, because that is what it is: it arms a measurement and says so (the body's "Not in this PR. The measurement itself" is the right call — #1023 asked for a profile, and inventing the numbers here would have been the thing not to do).
What I checked in the code:
- it prices exactly the two explanations #1023 could not separate —
dev_call_msis the device call (BO writes, launch, both syncs, the wait) andhost_msis the host accumulation loop, both on the graph's own int8 operands, both from the same clock, in the same process. The sharedepi_msis separated out for the same reason the docs said the probe's host column was a lower bound: the epilogue is common to both legs and would otherwise be counted as host. - off costs nothing measurable: the three
steady_clock::now()calls are behindp.on ? ... : {}, so an unarmed run pays onegetenvat first use and a branch per call. - its output cannot vanish silently, which is the bug this file already paid for:
trace_line()is now the single writer (open0600 | O_NOFOLLOW | O_CLOEXEC, thenfdopen), and whenONEBIT_EP_TRACEis off the prof line still goes to stderr. Foldingtrace_fallback()onto the same helper keeps the two writers agreeing on mode and on the "ONEBIT_EP_TRACE is a flag, not a path" fix. - docs: the two
docs/onnx.mdinsertions describe the field names it actually prints (calls_dev calls_host rows_dev rows_host dev_call_ms dev_epi_ms host_ms) and where the line goes.
One nit, and it is about the numbers rather than the mechanism: Q8Prof's accumulators are plain double/long members written from gemm_q8 with no lock. ORT runs a session's nodes on its intra-op pool, so if anyone measures with -i > 1 the totals can lose updates and the leg split would be quietly wrong rather than obviously broken. The #1023 method is -i 1, so the recorded runs are fine — but either say "one thread only" in the docs line, or guard the accumulation with the same mutex the trace does not need.
Not re-run here: the EP proof. Its device-free evidence (6/6 with the knob on, the three cases off/trace/stderr, the -O3 vs -O0 25x trap seen from the other side) is yours and is the kind of thing I would re-run if the box were not carrying four lanes; CI is green on the head, and nothing here changes a decision the EP makes.
|
First result from this knob, and it changes the question #1023 left open. CPU-only — no device, no ticket, no lock (a Release build with 1. Where a host-arm token goes. Same export, 32-token prompt, 8 tokens, 1 thread, two runs: 2. What that does to the candidates. With #1023's quiet arms (host 947, device 1074 ms/token):
So candidate 2 is confirmed but not sufficient, and the residual is not dispatch-as-such: the probe pays the same dispatch and is 40 % cheaper per call. 3. The mechanism, costed. 712 + 295 = 1007 ms/pass against the 973–1021 the arms imply — the whole model-level deficit, inside 1–5 %. Consequence: remove the re-pack and the device is ~712 against the host's 846–894, i.e. 1.19–1.26× faster at model level instead of 1.13–1.16× slower. The remaining direct confirmation is this same PR run on the device arm ( |
…ot a build delta
docs/onnx.md and docs/onnx-pack.md both close the model-level section with a
promise -- the cause of the 1.13-1.16x loss is a sign without a cause, and the
next step is a profile. That profile has been run, on both arms, in one window:
1. it prices the per-call costs on the array: the one-slot weight cache is
0.24 ms/call (the whole-image BO writeback), the shared epilogue 0.134,
the pack loop 0.06 -- 0.43 of the ~1.3 ms/call the candidate needs;
2. it measures the other candidate without the array at all: dumped from one
prefill, the graph's real int8 activations are 62.1 % nonzero against the
probe's ~99 %, so its host loop is 1.42x faster per pass (1098 -> 770.6 ms)
and the array's kernel advantage is ~1.12x at model level, not 1.7x;
3. it re-measures both arms on the current tree: 930.5 ms/token on the array
against 972.9 on the host kernel, i.e. 4.4 % in the array's favour, from
the same window with two runs each agreeing on the sign. The split closes
on both sides -- device calls 802.5 + epilogue 19.0 + 109 of graph work
against the host loop's 879.0 + 94 -- and the host loop's 879 ms/pass
validates the CPU-only estimate of 848 to within 4 %.
The 1.13x loss the pages report is kept, dated to the session it came from, with
a pointer to the re-measurement rather than deleted. Attribution is stated the
way it was checked, not the way it was first guessed: exactly two commits touch
this path since those figures (#1032 profiling, #1047 the re-pack at ~5 % of a
token), the private NPU runtime the EP links against is unchanged (2026-10-31),
the five design ELFs are byte-identical, and load cannot explain the direction
(the device arm is slower under load: 5.65 ms/call at load 11-14 against 4.09
here). So ~5 % of the 13 % is code and the rest is unestablished -- most
plausibly CPU-side contention in the earlier session, since half of a device
call is host work -- and the pages say the magnitude is the finding, not the
sign, and that it is small in both directions.
Also recorded because it is a measured negative: keeping every weight resident
removes the writeback (delta 0.054/0.067) for 568 MiB of images on the real
export's 197 projected MatMuls, which is 3 % of a token and was not taken.
…ot a build delta (#1076) docs/onnx.md and docs/onnx-pack.md both close the model-level section with a promise -- the cause of the 1.13-1.16x loss is a sign without a cause, and the next step is a profile. That profile has been run, on both arms, in one window: 1. it prices the per-call costs on the array: the one-slot weight cache is 0.24 ms/call (the whole-image BO writeback), the shared epilogue 0.134, the pack loop 0.06 -- 0.43 of the ~1.3 ms/call the candidate needs; 2. it measures the other candidate without the array at all: dumped from one prefill, the graph's real int8 activations are 62.1 % nonzero against the probe's ~99 %, so its host loop is 1.42x faster per pass (1098 -> 770.6 ms) and the array's kernel advantage is ~1.12x at model level, not 1.7x; 3. it re-measures both arms on the current tree: 930.5 ms/token on the array against 972.9 on the host kernel, i.e. 4.4 % in the array's favour, from the same window with two runs each agreeing on the sign. The split closes on both sides -- device calls 802.5 + epilogue 19.0 + 109 of graph work against the host loop's 879.0 + 94 -- and the host loop's 879 ms/pass validates the CPU-only estimate of 848 to within 4 %. The 1.13x loss the pages report is kept, dated to the session it came from, with a pointer to the re-measurement rather than deleted. Attribution is stated the way it was checked, not the way it was first guessed: exactly two commits touch this path since those figures (#1032 profiling, #1047 the re-pack at ~5 % of a token), the private NPU runtime the EP links against is unchanged (2026-10-31), the five design ELFs are byte-identical, and load cannot explain the direction (the device arm is slower under load: 5.65 ms/call at load 11-14 against 4.09 here). So ~5 % of the 13 % is code and the rest is unestablished -- most plausibly CPU-side contention in the earlier session, since half of a device call is host work -- and the pages say the magnitude is the finding, not the sign, and that it is small in both directions. Also recorded because it is a measured negative: keeping every weight resident removes the writeback (delta 0.054/0.067) for 568 MiB of images on the real export's 197 projected MatMuls, which is 3 % of a token and was not taken. Co-authored-by: pi-qdq <[email protected]>
Root cause of the missing number. engine#1023 (merged) measured the device leg 1.13-1.16x slower than
the host kernel at model level — 1073.7/1105.1 against 947.4/950.6 ms/token, same ids, same KL — while the
per-design probe, at the same shapes, had the device kernels 1.7x ahead (712 against 1209 ms/pass). Both
cannot describe the same pass, and #1023 states the cause as open rather than guessing, because neither
explanation could be separated from outside the process:
loop skips
aik == 0, so the graph's sparser activations may make the real host loop much faster. Theprobe's own host column sums to 1209 ms/pass, above the whole 947 ms/token host arm, so it cannot be
subtracted from anything; the rigorous bound is only that the device's kernel advantage is at most 1.33x.
#1023 ends with "the next step is a profile", and this is that instrument.
What this adds.
ONEBIT_EP_QDQ_PROF=1:gemm_q8accumulates its own wall time per leg and writes oneline per process at exit.
dev_call_msis the device call (BO writes, launch, both syncs, the wait),dev_epi_msthe epilogue bothlegs share,
host_msthe whole host loop including its own epilogue. Two runs that differ only in the legthen price that leg on the graph's own int8 bytes — which is the one thing a probe timing synthetic
operands cannot do. A running total per process rather than per call, so nothing is sampled and one line
answers the question.
trace_fallbackis split intotrace_line(the writer — unchangedopen(0600)+O_NOFOLLOWfrom theCodeQL fix) plus the formatting wrapper, so every note this file emits has one writer, and the prof line goes
to stderr when
ONEBIT_EP_TRACEis off. A knob whose only output can silently vanish is how a debuggingsession gets lost; this file already paid for that once with
ONEBIT_EP_TRACEread as a path.Measured, without a device (so the PR stands on its own before any hardware run):
with the fused proof's gate unchanged —
worst |d| = 0LSB per-tensor / per-axis / asymmetric /asymmetric-per-axis, per-K scale still refused,
qdq_profline written once per process;qdq_proflines; on with a trace → one line in/tmp/onebit_ep_trace.<pid>.log; on without a trace → the line on stderr;ONEBIT_EP_NPU=ONbuild:onebit_ep_qdq_proofpasses (1.0 s);ctestthere is 8 tests of whichonebit_ep_prooffails and the two NPU probes skip, exactly as main already does for an NPU build with noELF configured (pre-existing, not this PR);
-O3and ~2000 ms at-O0(25x) — onnx: the QDQ device leg is 1.13x slower than the host kernel at model level (measured; cause not isolated) #1023's-O0trap seen fromthe other side, and a reminder that the arms must be a Release build.
Not in this PR. The measurement itself. It is armed behind
~/wt/qdq-prof-watch.sh(waits for a quietbox, then one short
npu-hold -l qdqticket, sized to finish inside its hold) and its numbers will bereported on #1023 and in
~/briefs/TQDQ-STATE.md, not invented here. No device hardware was touched towrite, gate or document this.
tools/copyright.py --checkrc 0. Nothing pushed tomain.