Skip to content

Nemotron on Metal without tensor units skips the lane tiles no kernel reads: about 1 GiB less - #3375

Merged
ashhart merged 4 commits into
ashhart:mainfrom
jschmied:nemotron-metal-rows
Nov 16, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
jschmied:nemotron-metal-rows

Conversation

@jschmied

@jschmied jschmied commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Branch nemotron-metal-rows @ ff5bf5a (b3b1dd6 + the slide-commit fix and the tensor-unit fix below), on main d6c4cce. Don't land yet: the M5 sampled four-stream cell needs a re-run at ff5bf5a. Family-only.

Problem, measured

weights.Builder.linear and picked built lane tiles for every 4/64 dense projection on every Mac: new buffers
plus CPU tile jobs (weights.zig:175, :225). On a Mac without tensor units, every linear also gets the row
layout (Builder.rows = !tensorUnits), and every kernel that reads tiles first tries the row kernels
(forward.zig:89 coop, layers.zig:411 upRelu2), which always succeed there. So the tiles were never read,
with one exception: the MTP head's eh, which mtp.zig:91 coopParts reads directly.

The audit (#488) estimated "up to 3x". Measurement corrected that, and this PR is sized by the measurement. The
routed experts (15.39 GiB) and the embed/head (0.37 GiB) are read in place. The dense 4/64 matrices are 0.80 GiB,
so the waste was about 1 GiB, not a multiple of the model.

Change

  • Linear.lane: a 4/64 projection the lane kernels can take. Every decision that keyed on tiles != null now
    keys on lane: model.zig:125 (simd_bits pipelines), prefill.zig:152-153 (MLX qmm on raw rows for chunks
    over 128 rows), and prefill_mixers.zig:116-118. So each prompt and decode path picks exactly the kernel it did
    before. splitsAt still checks the tiles, since coopParts reads them.
  • Builder.tiled(): lane tiles and their tile jobs only with tensor units, or for the pinned MTP eh.
  • Tensor-unit Macs are unchanged: tiles are still built and used.
  • Host test (fake checkpoint, no device): without tensor units the 4/64 matrices keep lane but have no tiles,
    queue no tile job and make no buffer, and the row kernels read the checkpoint's own rows.

Evidence (M3 Pro 36 GB; against main: base = main d6c4cce built here)

TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit (17.3 GiB of weights):

base this
load line, 32K window, 1 stream 18.8 GiB kept wired 17.8 GiB
peak footprint GPU (whole GB), 4K window 19 GB 16-18 GB

Replies equal base (token_sha256):

  • greedy and seeded at 7,805 and 26,636 prompt tokens;
  • a second turn resumed from the prompt cache equals a fresh server's;
  • 4 concurrent streams equal 1 at a time;
  • one hash per prompt length across all A-B-B-A runs.

Speed, A-B-B-A, 2 rounds, a fresh server per run, 128 greedy tokens:

base this change
TTFT 7.8K 14.37/14.37/14.39/14.38 s 14.37/14.36/14.37/14.38 -0.06 %
decode 7.8K 61.49/56.13/60.10/60.77 tok/s 61.29/61.49/61.56/61.34 +3.0 % (one slow base run)
TTFT 26.6K 55.35/55.49/55.39/55.38 s 55.52/55.38/55.42/55.41 +0.06 %
decode 26.6K 58.96/57.87/58.01/59.22 58.94/58.88/58.86/58.32 +0.39 %

No slower cell beyond run spread. The 8K decode gain comes mostly from one slow base run; the paths are the same.
Load time is level at server granularity: the tile jobs were CPU work during load.

Checks:

  • zig build test exit 0; the new host test passes.
  • lean 0 new; zig fmt clean; files 600 lines or fewer. No kernel changes.

No refusal test: the change adds no refusal; nothing new is refused, and no path is taken away.

Not run here: a tensor-unit Mac. Its path is unchanged, since tiled() is true there.

x86 CI (Linux, -Dfixed-cpu full set on b3b1dd6): 742/745 steps, 9,597 of 9,674 tests pass. The one failure is cli_config_test (serve --config: expand reads the file...), which fails the same way on main on that box (see #3350); this PR touches no server code. tools/pr_check.py: lean 341 vs 341, 0 new; zig fmt --check clean.

Proposed CHANGELOG line

  • Nemotron on Macs without tensor units no longer builds the lane tiles its kernels never read, saving about 1 GiB of
    GPU memory for Nemotron 3.5 Lightning. Replies and speed are unchanged.

3d57a76 (review fix): retile writes lane tiles only when the Linear has them and always rewrites the row copy, so a slide commit (TF_SLIDE_EDIT=1 --slide, shared down projection) on a Mac without tensor units no longer unwraps absent tiles. Regression: a device test (host-stub guarded, weights_test.zig) commits to a row-only 4/64 Linear and checks its row buffer equals the edited codes; with b3b1dd6's retile it crashes (SIGSEGV, 861/863 steps), with the fix 863/863 steps, 9,110 passed / 94 skipped. lean 341 vs 341; zig fmt clean. The x86 CI row above is on b3b1dd6; the fix touches only weights.zig's retile and a device test.

ff5bf5a (review fix, tensor-unit Macs on main's path): on M5 every changed branch already evaluated as on main (Builder.rows=false, so tiled() holds and every 4/64 projection has tiles), but two things still differed: Linear had a new lane field (one word more on every Linear, passed by value through each encode call), and the MTP eh was built ahead of enorm/hnorm, so its tile buffers and tile job were allocated and queued in a new order. lane() is now derived (tiles != null first, the old test), Linear has exactly main's fields, and eh is built in main's place with pin set and reset around it. With tensor units the struct layout, allocation order, tile jobs and every branch are main's; the retile guard only adds if (lin.tiles), always true there. Pin test (device, host-stub guarded): rows=false on the 4/64 fixture gives 3 tile jobs, 6 tile buffers, tiles on every projection, no row copy. We have no tensor-unit Mac, so the M5 cell's recovery is not shown here, and we can't say which of the two caused the 3.4 %.

No-tensor-unit receipts (M3 Pro 36 GB, not an M4 Pro), Nemotron 3.5 Lightning 30B-A3B MLX 4-bit, main d6c4cce vs ff5bf5a:

  • Memory: load line 19.9 GiB kept wired -> 18.9 GiB (8K window, --parallel 4); footprint peak GPU 20 -> 19 GB in all 12 MTP runs.
  • Replies byte-identical to main: plain greedy and seeded at 7,805 and 26,636 prompt tokens, resumed turn == fresh, concurrency 1 == 4; four-stream MTP (MTP + copies, --parallel 4, 128 tokens) sampled (T=1, seed 7+i) and greedy: one set of 4 hashes a mode over all 12 runs, main and head identical.
  • Four-stream MTP speed, A-B-B-A x3, fresh server a run: sampled median 44.30 (main) vs 44.08 tok/s (-0.5 %, the head's range inside main's); greedy 44.85 vs 44.73 (-0.3 %, overlapping). Our own 4 x 3K-token code prompts; ashhart's hash-map prompt not known here.
  • Suite 863/863 steps; the 31 Nemotron/slide host steps 149/149 native and -Dfixed-cpu; lean 0 new; zig fmt clean.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

FIXES. @jschmied, the native and Metal builds pass, and the row-only loader tests pass. One edit path still needs fixing.

P2 at weights.zig:507: Builder.tiled() now permits a 4/64 projection with rows present and tiles absent, but retile still unwraps tiles. TF_SLIDE_EDIT=1 with --slide reaches this through the shared down projection's commit. An actual-function host regression compiles and crashes at that unwrap. Please skip missing tiles while updating the row copy, and keep a row-only commit regression.

  • Synthena (Ash's Agent)

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Fixed in 3d57a76: retile skips missing tiles and still rewrites the row copy. A device regression commits to a row-only 4/64 projection; it crashes on the old retile (SIGSEGV) and passes now (863/863 steps). Body updated to the new head.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@jschmied DEVICE. The row-only retile regression now passes. On M5, all 80 full 64-token replies match main, greedy and seeded, plain and four-stream MTP.

The sampled four-stream hash-map cell is 138.589 -> 133.908 tok/s, 3.38% slower, with disjoint ranges. The no-tensor-unit memory and inference check still needs M1-M4 hardware; the M5 control cannot qualify it.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@jschmied, to make the ask above explicit: this change is meant to leave tensor-unit Macs alone, but on our M5 Ultra the sampled four-stream cell drops 3.4% (138.6 to 133.9 tok/s, with no overlap between runs). Please find what reaches the M5 path. If the retile is meant for Macs without tensor units only, gating it on tensorUnits() would keep M5 on main's code. Then post the M1-M4 numbers from your M4 Pro (memory and the same exact-reply check), since we have no Nemotron checkpoint on a pre-M5 Mac. Tokens are all equal on M5, so this is only about speed.

  • Synthena (Ash's Agent)

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Fixed in ff5bf5a. Two things in this PR still reached tensor-unit Macs, although every changed branch evaluated as on main there: Linear had gained a lane field (one word more on every Linear passed through each encode call), and the MTP eh was built ahead of its norms, so its tiles were allocated and queued in a new order. lane() is now derived (tiles first), Linear has main's fields, and eh is built in main's place. With tensor units the build is main's, and a device test pins it (rows=false: 3 tile jobs, 6 tile buffers, no row copy). We have no tensor-unit Mac, so we can't show the M5 cell back at 138.6 or say which of the two caused it; please re-run it at ff5bf5a. Don't land until it's level.

The no-tensor-unit numbers are from an M3 Pro 36 GB, not an M4 Pro. Against main d6c4cce: 18.9 GiB kept wired instead of 19.9 (peak GPU 19 GB vs 20). Replies are byte-identical: greedy and seeded at 7.8K and 26.6K, resumed == fresh, c1 == c4, and four-stream MTP sampled and greedy in all 12 A-B-B-A runs. Four-stream MTP speed is level: sampled median 44.08 vs 44.30 tok/s (-0.5 %, the head's range inside main's), greedy 44.73 vs 44.85. Body updated to the new head.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

DEVICE. @jschmied, the restored Linear layout and MTP build order check out, and the row-only retile and allocation regressions pass. On an M5 Ultra, all 80 full replies remain exact across greedy and sampled requests, plain solo and four-stream MTP.

The previously slower sampled four-stream cell is now 137.912 versus 137.295 tok/s, a 0.45% difference with overlapping ranges. No measured decode cell has disjoint slower ranges. We will run the row-only memory, long-prompt, MTP and resume checks on an M3 Ultra on our side. CI is green at this head; those checks remain before landing.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@jschmied, the M3 Ultra check is in, at head ff5bf5a against its base, on a 60-core M3 Ultra (no tensor units) with the Nemotron 3.5 Lightning 4-bit checkpoint. Prompt passes from 2K to 64K tokens at starts 0, 5,000 and 10,000, the stream sweep and the chat cells with resumed turns all read level, and the token rows are equal across every run (0 of 20 differ). The two builds sit within 0.1% of each other in every prompt cell.

With the M5 result from our last reply and CI green, this is READY: it goes in the landing queue.

  • Synthena (Ash's Agent)

jschmied and others added 4 commits November 16, 2026 12:06
… reads: about 1 GiB less

Every 4/64 dense projection got lane tiles, and their CPU tile jobs, on every Mac. Without tensor units every
linear also has its row layout, and each tile reader tries the row kernels first, so the tiles were never read.
The exception is the MTP head's eh, which coopParts reads directly.
- Linear.lane marks a projection the lane kernels can take. The kernel choices that keyed on tiles (simd_bits
  pipelines, prompt chunks' MLX qmm, the mixers' qkv) now key on it, so every path picks the kernel it did before.
- Builder.tiled() builds tiles only with tensor units, or for the pinned eh.
On Nemotron 3.5 Lightning the load keeps 17.8 GiB wired, not 18.8; replies are unchanged.
…ites its rows and skips the tiles

Without tensor units a 4/64 projection has rows and no tiles (Builder.tiled), but retile unwrapped them, so
TF_SLIDE_EDIT=1 --slide crashed committing the shared down projection. retile now writes tiles only where they exist.
A device test commits to a row-only projection and checks its row copy; on the old retile it crashes.
…ly as on main

Linear.lane was a field, so every Linear grew by a word on every Mac, and the MTP eh was built before the head's
norms to set pin, so tensor-unit chips allocated and queued its tiles in a new order. lane() is now derived (tiles
first, then 4/64 rows where none are built), and eh is built in main's place with pin set around it. A device test
pins the tensor-unit build: three 4/64 projections give three tile jobs, six tile buffers and no row copy.
@ashhart
ashhart force-pushed the nemotron-metal-rows branch from ff5bf5a to b0a48cc Compare November 16, 2026 12:13
@ashhart
ashhart merged commit e86a0be into ashhart:main Nov 16, 2026
8 of 22 checks passed
@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

2 participants