Skip to content

nemotron metal: a new build keeps the chip's last window-cost table while a probe holds - #936

Merged
ashhart merged 3 commits into
ashhart:mainfrom
jishnuvenugopal:perf/nemotron-window-costs-last-table
Oct 18, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
jishnuvenugopal:perf/nemotron-window-costs-last-table

Conversation

@jishnuvenugopal

@jishnuvenugopal jishnuvenugopal commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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 any
build measured on this chip and model shape (a referenceKey with a "costs" part) and times windows of 1, 8, 16, 20
and 33 rows (the 16-row, full 32-row and edge 32-row tiles) and the head step the way cost_rule.measure does:
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 is
within cost_rule.drift, slower or faster, the table stands and is saved under the build's key; otherwise the full pass runs
as 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 imports timing.zig so CI runs that
file's tests.

Verified outcome

  • Why: on an M4 the first start of each new build (every release, every rebuild) takes ~42 s to ready instead of
    ~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).
  • What was done: a new build keeps the chip's last table when a short probe confirms it, and times the whole table as
    today when it does not.
  • Result: a new build's first start goes from 40.7-41.0 s to 18.3-18.5 s with the same tokens; launches on a kept
    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, Xcode
    27.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 removed
    only 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": false reply (greedy), and
    bench_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": false 30/30.

  • Decode before and after (tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, medians, tok/s), with load
    time, head 08905cf:

    launch n loaded in table fib chat
    1.0.12, new build 3 40.7-41.0 s timed 47.9-48.3 47.9
    this change, empty cache 1 41.5 s timed 54.2 48.3
    this change, new build 5 18.3-18.5 s kept 5/5 54.3 48.4
    this change, kept table x1.3 1 41.0 s refused, timed 48.3 47.9

    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 chunks
    never read it.

  • Tests, head 08905cf, uncached: zig build test test-golden -Dcpu=apple_m1 208/208 steps, 3,005/3,015 passed, 10
    skipped, 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 zig and git diff --check origin/main pass; lean 517 on the
    base 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.zig is unchanged); M1-M3 and M5 (one M4 here); qwen27 and GLM on Metal,
    which keep their per-build keys.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
    (Drafted equals "draft": false in all 10 launches; bench_concurrent on a kept table 84/84 and 30/30. Resumed
    versus fresh not re-run: the table never reaches the prompt cache.)
  • No precision traded for speed. Bits unchanged: costs steer windows only.
  • A new or changed GPU kernel is registered with the kernel contract: n/a, no kernel changes
    (zig build test-kernel-contract passes).
  • Prompt processing is no slower than the last release: n/a, prompt chunks do not read the table.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not: M4 only.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency (host tests, no GPU).
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

For you to decide

  • What it gives up: a build whose kernels are faster or slower by less than 15% at the probed widths keeps the older
    table, and the shared-round costs and the widths between the probed ones are not re-timed on a kept table.
  1. Is the executable key meant to catch kernel changes the drift bound would miss? If so, a tighter bound for the
    probe, or a full pass in the background once the server is ready, would keep that guarantee.
  2. Are 1, 8, 16, 20 and 33 rows and the head the right paths to probe? Shared rounds stay unprobed.
  3. Nemotron on Metal only for now, or also qwen27 and GLM on Metal?

…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 cwschroeder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread zig/src/families/nemotron/timing.zig Outdated
}

/// 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 };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread zig/src/core/lanes/cost_rule.zig Outdated
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

cwschroeder and others added 2 commits October 16, 2026 21:46
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.
@jishnuvenugopal

Copy link
Copy Markdown
Contributor Author

Thank you, @cwschroeder, for the close review, and for a patch that came with tests that fail on the code they fix.
Both points hold, and I have taken your commit as you wrote it.

  • The full 32-row tile: Forward.coop picks the tile from the row count padded to 16 (forward.zig:85-94): 1-16 rows
    use coop_*_1_0, 17-32 the full coop_*_2_0, and 33 the edge coop_*_2_1, so 1, 8, 16 and 33 never reach the
    full tile. Your table test fails with those four widths and passes with the 20-row entry.
  • Infinite references: !(x > 0) lets +inf through, and changed(ms, inf) compares inf with inf, so a kept table
    holding +inf was accepted. Your two tests fail on f3889be and pass with the guards. NaN, zero and negative values
    were already refused; your controls cover them.

The branch now carries 86711fa, your commit unchanged and under your name, and 08905cf, one line of mine:
nemotron.zig's test block imports timing.zig. No test root reached that file before, so your table test would not
have run in CI. I checked with a test in timing.zig that always fails: zig build test test-golden stayed green
without the import and failed on exactly that test with it.

One note on scope: on M1-M4, coop hands each projection to the row kernels first (rowCall), and those use one
pipeline for every row count (row_projection.zig:108-112). So the 20-row entry adds coverage on M5's tensor units, and
on this M4 it adds about 1.3 s to a new build's first start (18.3-18.5 s here, 17.0-17.2 s with four widths).

Verified outcome

  • Why: the probe could accept a kept table whose full 32-row tile had drifted, or one holding an infinite cost.
  • What was done: your patch, plus the import that makes CI run its table test.
  • Result: both cases are now refused; a new build's first start is 18.3-18.5 s against 40.7-41.0 s for 1.0.12, and the
    tokens are unchanged.

Receipt

  • Environment: as in the description (Apple M4, macOS 27.0.1, 1.0.12 + this branch, Nemotron-3.5 @ d9d758fb,
    --parallel 4 --context 8192, a separate cost cache per launch).

  • Device, head 08905cf:

    launch (head 08905cf) n loaded in table tokens
    1.0.12, new build 3 40.7-41.0 s timed equal
    this branch, empty cache 1 41.5 s timed equal
    this branch, new build 5 18.3-18.5 s kept 5/5 equal
    this branch, kept table x1.3 1 41.0 s refused, timed equal

    "Equal": each launch's drafted reply equals its "draft": false reply, and the bench's token hashes match across
    all ten launches. The five kept launches ran the plan of the launch that timed the table (73 rounds on fib).

  • Tests, uncached: zig build test test-golden -Dcpu=apple_m1 208/208 steps, 3,005/3,015 passed, 10 skipped, 0 failed
    (7 more than f3889be: your two cost_rule tests in three test binaries, and the table test in the family's);
    zig build test-kernel-contract, zig build fuzz-cortheon, zig fmt --check build.zig zig and
    git diff --check origin/main pass; lean 517 on the base and the head, 0 new.

  • Not run: M5 (the tile path this adds is M5-only; I have only an M4), CUDA.

@cwschroeder cwschroeder left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cwschroeder

Copy link
Copy Markdown
Contributor

Correction to my follow-up review: the local standard suite was not CPU-only. On macOS, zig build test also executes Metal unit tests when a GPU is available, including GLM MLA/KDA checks. I have corrected the review's scope. Those unit checks do not independently reproduce your M4 startup measurements or qualify the M5 full-tile startup probe.

@jishnuvenugopal

Copy link
Copy Markdown
Contributor Author

Thank you, @cwschroeder, for checking that 86711fa matches your patch's tree, for running the full suite on the
integrated head, and for correcting the scope of that run. Agreed on M5: the 20-row sample covers the full tile on the
tensor-unit path, and its startup still needs an M5 receipt, which I cannot produce here. Anyone with an M5 could give
one: start a new build twice, once with an empty window-cost cache and once with only that build's own table removed,
and compare the load times and the replies' token hashes. The build-key policy and shared-round coverage stay with
Ash, as you say.

@ashhart ashhart mentioned this pull request Oct 17, 2026
@ashhart
ashhart merged commit acc63c2 into ashhart:main Oct 18, 2026
4 checks passed
@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

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

@jishnuvenugopal
jishnuvenugopal deleted the perf/nemotron-window-costs-last-table branch October 19, 2026 05:40
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…ble while probes of each kernel path stay within drift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants