Repository navigation
nemotron metal: a new build keeps the chip's last window-cost table while a probe holds - #936
Conversation
…hile a probe holds A new build looked up its window costs by its own executable's bytes, so its first start timed the whole table again. It now reads the last table any build measured on this chip and model shape and times windows of 1, 8, 16 and 33 rows and the head step as cost_rule.measure does (the head sampled after each window, a drifted reading timed a second time). When every probed entry is within cost_rule.drift the table stands and is kept under the build's key; otherwise the full pass runs as before and becomes the last table. Costs steer windows, never bits.
cwschroeder
left a comment
There was a problem hiding this comment.
CPU review of f3889be6 on main 46a08c18. Please include the full 32-row cooperative tile before accepting a prior-build table. The current selection omits that path. I also reproduced acceptance of positive-infinite window and head references.
An applicable patch and CPU reproduction adds the existing 20-row entry, two finite-reference guards and three regressions. All three fail against the original logic and pass with the fix. Valid positive controls remain accepted. Astra reviewed the patch without a new material source blocker.
Local Zig 0.17.0 checks at 889b2e04: 18 core tests and the direct Nemotron helper regression pass in Debug and Fast; the complete No-GPU workflow commands, whole-tree formatting and lean (zero new findings) pass. The family helper was tested through a filtered temporary root, separately from CI. The reviewed PR's four GitHub checks are green; the offered patch has local validation only.
These are scripted CPU timers. No real 30% regression, hardware-cache corruption, startup-time gain or device result is claimed. The broader build-key policy and shared-round coverage remain separate decisions.
| } | ||
|
|
||
| /// Window entries a probe times: 1, 8 and 16 rows (the windows) and 33 (the widest tree). | ||
| const probed = [_]usize{ 0, 7, backend.max_window - 1, backend.max_window + wide.len - 1 }; |
There was a problem hiding this comment.
[P2] Probe the full 32-row cooperative tile before reusing the table
On the coop path, 1/8/16 rows select coop_*_1_0; 33 selects coop_*_2_1. The timed entries at 20/24/28/31 rows use coop_*_2_0 (and _2_0_sk when split-K is enabled), but none is probed. A build changing that kernel alone can therefore retain its old costs despite drift beyond the intended bound.
A CPU test of the actual private holds keeps every reference at 10 and returns 13 only for the 20-through-31-row range. This code returns true; adding index backend.max_window (20 rows) returns false. An unchanged-table control remains true. Please add a representative full-tile width. The fixture does not measure a GPU slowdown.
| pub fn probeHolds(windows: anytype, heads: anytype, at: []const usize, reference: []const f64, head: ?f64) !bool { | ||
| var best = std.math.inf(f64); | ||
| for (at) |i| { | ||
| if (i >= reference.len or !(reference[i] > 0)) return false; |
There was a problem hiding this comment.
[P3] Reject non-finite window and head references
Positive infinity passes reference[i] > 0, while changed(10, +Inf) evaluates Inf > Inf and returns false. Thus the new probe accepts that invalid reference. The head check at line 54 has the same issue. Direct CPU cases reproduce both, with valid finite controls still passing.
Please require std.math.isFinite as well as positivity for probed window references and the optional head. This is a defensive cache-validation case; I have not observed regular device measurements producing infinity.
The family's test block imports timing.zig, so the probe's table test runs in zig build test; without it no root reached that file's tests.
|
Thank you, @cwschroeder, for the close review, and for a patch that came with tests that fail on the code they fix.
The branch now carries 86711fa, your commit unchanged and under your name, and 08905cf, one line of mine: One note on scope: on M1-M4, Verified outcome
Receipt
|
There was a problem hiding this comment.
Both requested fixes are addressed at 08905cf3. I verified that 86711fa3 has the same tree as the offered 889b2e04 patch; the subsequent change adds timing.zig to the family test block.
The test import closes the standard-suite coverage gap. My earlier receipt used a separate filtered root for that helper test. The integrated head now passes the complete local No-GPU workflow commands, whole-tree formatting, whitespace and lean (517 on base and head, zero new). zig build test reports 204/204 steps, 3,000 passing tests and 10 skips on this Mac. All four current-head GitHub checks also pass.
The platform clarification is useful: rowCall handles these projections before the cooperative tile selection on M1–M4. The additional 20-row sample covers the full tile on the M5 tensor-unit path, which still needs its own device receipt. The standard macOS suite also executes Metal unit tests when a GPU is available. The M4 launch measurements remain your hardware receipt; I have not independently qualified the M5 startup probe. The build-key policy and shared-round probe coverage remain Ash's decisions.
|
Correction to my follow-up review: the local standard suite was not CPU-only. On macOS, |
|
Thank you, @cwschroeder, for checking that 86711fa matches your patch's tree, for running the full suite on the |
|
Thank you, @jishnuvenugopal, for the retained timing-table probes and boundary regressions. We merged your work for 1.1.0 in acc63c2. Our integration probes retained shared-round entries as well as lone-window and head entries. Invalid counts, widths, costs or drift trigger the full timing pass, and failed cache construction releases earlier caches. The existing 15% policy stays in place; the tables steer scheduling rather than token arithmetic. Apple M3 Ultra retained/shared-table probes passed and planted drift triggered remeasurement; this is scheduling validation. Posted by Ash's AI Assistant Synthena |
…ble while probes of each kernel path stay within drift
Thank you, Ash, for the timing rule in 420e5a7: fastest of 7 after an untimed run, dips timed again, and each table
checked against a build-independent reference with a 15% drift bound. This change leans on exactly that rule. Thank
you as well for landing #866, #875 and #881-#883 in 1.0.12. Credit to @pmeenan, who noted in #428 that the cost pass
"can be cached"; this takes that one step further. It changes what triggers a full timing pass, which you chose on purpose
(the key is the executable's bytes), so the open questions are at the end and the call is yours.
What this changes
nemotron.timing.measure(families/nemotron/timing.zig) looked up the kept table by the executable's bytes(
cost_cache.key), so the first start of every new build ran the full pass. It now first reads the last table anybuild measured on this chip and model shape (a
referenceKeywith a"costs"part) and times windows of 1, 8, 16, 20and 33 rows (the 16-row, full 32-row and edge 32-row tiles) and the head step the way
cost_rule.measuredoes:fastest of 7, the head sampled after each window, a reading past drift timed a second time (new
cost_rule.probeHolds, which refuses a kept value that is not a finite positive number). If every probed entry iswithin
cost_rule.drift, slower or faster, the table stands and is saved under the build's key; otherwise the full pass runsas before and becomes the last table. The drift reference, its second pass, and every other family's tables are
unchanged. Costs steer windows, never bits. The 20-row entry, the finite-value guards and their tests are
@cwschroeder's (86711fa, from his review);
nemotron.zig's test block now importstiming.zigso CI runs thatfile's tests.
Verified outcome
~17 s, and the extra ~25 s re-times a table that full passes on this chip reproduce within 5-11% at the probed
widths (18 of 19 tables).
today when it does not.
table run the same plan at the same speed; a table made 30% slower than the GPU is refused and re-timed.
Receipt
Environment: TensorFold 46a08c1 (1.0.12) plus this commit,
zig build native -Dcpu=apple_m1(Zig 0.17.0, Xcode27.0); Apple M4, 32 GB, macOS 27.0.1 (26A434); TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit @ d9d758fb;
serve --parallel 4 --context 8192. Each launch had its own empty cost-cache directory; a "new build" launch removedonly the build's own table, so the probe or the full pass is the only difference. The device runs used a build of
this tree from before two doc comments were shortened; the code is identical.
Exactness: in every launch, stock and this change, the drafted reply equals the
"draft": falsereply (greedy), andbench_openai.py's token hashes are identical across all launches (fib c91869ce1808, chat 5ef050084ac3).On a kept table (head f3889be, loaded in 11.0 s),
tools/bench_concurrent.py --alone --serial --levels 1,2,4 --temperatures 0,1.0, code and chat: concurrent equals alone 84/84, alone equals"draft": false30/30.Decode before and after (
tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, medians, tok/s), with loadtime, head 08905cf:
The five kept launches ran the plan of the launch that timed the table (73 rounds fib) and its speed; the fib gap to
stock is that table's draw, not the change, as the fresh-table spread below shows. With the first four probe
widths (f3889be), new builds started in 17.0-17.2 s (5/5 kept); the 20-row entry adds about 1.3 s. An earlier
version of the probe on c7137bb kept 7/8 at 17.2-20.5 s; its one refusal took 46.1 s, about 4 s more than a stock
start, because the probe runs before the full pass. That is the worst case seen.
Table spread: of 19 distinct full tables timed on this M4 (several builds, c7137bb and 1.0.12), 18 agree within
6.4%, 5.1%, 7.0% and 11.1% at 1, 8, 16 and 33 rows and 1.7% on the head step. The 19th, timed by a full pass right
after that refusal, read 13-15% slow at 1-8 rows, so a full pass can land an outlier too. On c7137bb, fresh tables
gave fib decode of 46.5-54.2 tok/s while launches on one table repeated within 0.6%.
Prompt speed: n/a. The table steers decode windows only (the backend's lane facts and
gpu_round); prompt chunksnever read it.
Tests, head 08905cf, uncached:
zig build test test-golden -Dcpu=apple_m1208/208 steps, 3,005/3,015 passed, 10skipped, 0 failed (1.0.12 alone: 2,989/2,999, 10 skipped; the 16 more are the five new cost_rule tests, which run in
three test binaries, and the table test in timing.zig, which runs in the family's);
zig build test-kernel-contract,zig build fuzz-cortheon,zig fmt --check build.zig zigandgit diff --check origin/mainpass; lean 517 on thebase and the head, 0 new. Each new test fails on the logic it guards: the second timing, the head sample after each
window, the finite-value guards, and the 20-row entry.
Not run: CUDA (Nemotron CUDA's
cuda_costs.zigis unchanged); M1-M3 and M5 (one M4 here); qwen27 and GLM on Metal,which keep their per-build keys.
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.(Drafted equals
"draft": falsein all 10 launches; bench_concurrent on a kept table 84/84 and 30/30. Resumedversus fresh not re-run: the table never reaches the prompt cache.)
(
zig build test-kernel-contractpasses).For you to decide
table, and the shared-round costs and the widths between the probed ones are not re-timed on a kept table.
probe, or a full pass in the background once the server is ready, would keep that guarantee.