Skip to content

Nemotron: shared rounds hold four rows a lane, up to 128, so 32 and 64 sessions scale - #518

Closed
BobClawblaw wants to merge 1 commit into
ashhart:mainfrom
BobClawblaw:nemotron-batch-rows
Closed

BobClawblaw wants to merge 1 commit into
ashhart:mainfrom
BobClawblaw:nemotron-batch-rows

Conversation

@BobClawblaw

Copy link
Copy Markdown
Contributor

Help-list item 3 in ZIG-PREVIEW: the native Nemotron server's shared round held at most 32 rows, so past 32 sessions it stopped scaling, and at 32 drafting sessions it was already splitting rounds or starving them of draft rows.

What changes

  • zig/src/native/metal.zig: batch_rows follows --parallel: four rows a lane, 64 at least, 128 at most. Up to --parallel 16 that is the 64-row forward the engine already allocated for (max_lanes), so nothing changes there, including memory. At 32 and 64 lanes each drafting stream keeps rows for its drafts.
  • zig/src/families/nemotron/state.zig: max_rows 64 → 128 (the forward's buffers, the per-forward host arrays). replay_rows and max_lanes stay 64: a lone stream's window is unchanged.
  • zig/src/families/nemotron/timing.zig: the startup sweep times shared rounds up to batch_rows (64 caches instead of 16), so the planner prices 64- and 128-row rounds from measurements instead of a straight line past 32.

Three lines of code. No kernel changes; every kernel already took its row count from the dispatch.

Cost

Each row past 64 is one more Mamba state slot: 2 MiB a Mamba layer, 47 MiB across Lightning's 23. --parallel 64 takes about 2.9 GiB more than before; --parallel 8 (the default) the same as before. The sweep adds a few 128-row forwards to startup.

Speed

M5 Ultra (256 GB, macOS 27.0.1), Zig 0.17.0, Metal Toolchain 27A266a, Lightning at d9d758fb, --context 32768 --prompt-cache-gib 0 --no-thinking --temperature 0, 256 tokens a reply, tools/bench_concurrent.py --alone --serial. main (f8fe17d) against this branch, servers alternated, two rounds each, --parallel 64 on both:

Sessions Code, main Code, this PR Chat, main Chat, this PR
8 935-944 tok/s 944-953 712-721 713-717
32 780-795 958-1,019 741-755 843
64 779-795 968-1,006 740-753 847-849

One stream (tools/bench_openai.py): 505 / 347 tok/s on main, 501-505 / 346-347 here.

A flat 64-row cap, measured on the way as a separate build, gave 917-943 on code at 32 sessions but only 825-832 at 64 (chat 822-844 and 781-787): most of the 32-session gain, a quarter of the 64-session one. 64 sessions need two rows each to keep drafting, hence 128.

The final binary's own run (--parallel 8, 32, 64 in turn): --parallel 8 948 / 718 tok/s at 8 sessions and 503 / 345 alone; --parallel 32 979 / 821 at 32; --parallel 64 1,033 / 849 at 64 (code / chat).

Exactness

  • Every concurrent reply equaled its request run alone, and every solo run equaled "draft": false: 1,152 replies in the 32/64-row run, 2,496 in the three-way, 428 in the final binary's run, 0 unequal, 0 failed.
  • zig build test test-golden -Dcpu=apple_m1: passes (312/319 golden, 0 unexpected differences, the same allocator leak traces from the golden checker as main).
  • Lean checker: 512 problems, the baseline.

Docs

ZIG-PREVIEW (sessions paragraph, known gaps, help item 3 now points past 128 rows at the slot pool and the expert kernels' cost per row), and a "Shared rounds on the Zig engine" section in the Nemotron recipe with the table above.

Independent of #497, #499 and #502 (no overlapping hunks; the recipe gets a new section at the end).

🤖 Generated with Claude Code

…4 sessions scale

The native server's shared round held at most 32 rows, so past 32 sessions it stopped scaling and at 32 drafting
sessions it was already splitting rounds. batch_rows now follows --parallel: four rows a lane, 64 at least (what the
engine always allocated for a lone stream's lanes) and 128 at most. state.max_rows goes to 128 for the forward's
buffers; the startup sweep times shared rounds up to that width so the planner prices them from measurements.

M5 Ultra, --parallel 64, main against this: 64 sessions 779-795 -> 968-1,033 tok/s on code and 740-753 -> 847-849
on chat; 32 sessions 780-795 -> 958-1,019 and 741-755 -> 821-843; 8 sessions and one stream unchanged. Every
concurrent reply equaled its solo run and every solo run equaled "draft": false (4,076 replies over the runs).
Each row past 64 costs a Mamba state slot, 47 MiB; --parallel 64 takes about 2.9 GiB more, --parallel 8 the same.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @BobClawblaw. A three-line change measured with care, and the flat 64-row build you tried on the way showed
why 128 was needed.

It's on main as 6cb537422, under your name. Main had rewritten the window-cost timing to keep its costs per build, so
your wider timing caches went into the new measure. Our follow-up 6b32b2adc makes the row bounds explicit, now that
batch_rows can reach max_rows: Metal.init refuses a wider batch_rows, and verify and draft refuse more windows
than their arrays hold.

On an M3 Ultra, with distinct prompts, every concurrent reply equalled its solo run at --parallel 8, 32, 64 and
128, twice each, and solo equalled "draft": false. 64 sessions went from 376 to 396 tok/s in all (409 with #502), 32 from
374 to 385. --parallel 32 and 64 took 3.0 GiB more, and --parallel 8 the same as before.

We re-made the commits without their AI-tool trailer lines, which main's history doesn't carry, so GitHub shows this PR as closed rather than merged. The commit is yours.

@ashhart ashhart closed this Oct 10, 2026
eleqtrizit pushed a commit to eleqtrizit/TensorFold that referenced this pull request Oct 10, 2026
…'s per-stream arrays

Lands ashhart#518 on main. Its wider timing caches went into 1.0.3's cached measure() when the commit
applied. batch_rows now reaches st.max_rows (128), so verify's and draft's per-stream arrays have no
headroom left. The lane core picks no more streams than rows, so no round asks for more today; now
Metal.init refuses a batch_rows past st.max_rows, and verify and draft refuse more windows than
their arrays hold instead of writing past them.
eleqtrizit pushed a commit to eleqtrizit/TensorFold that referenced this pull request Oct 10, 2026
…hhart#518

Lands ashhart#502 on main beside ashhart#518: a shared round can now hold 128 rows, so the routed-expert checker
bit-checks and times every pass shape at 128 rows too. Layer 0's routing copy is sized by the
widest width.
eleqtrizit pushed a commit to eleqtrizit/TensorFold that referenced this pull request Oct 10, 2026
@BobClawblaw
BobClawblaw deleted the nemotron-batch-rows branch October 15, 2026 15:21
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…'s per-stream arrays

Lands ashhart#518 on main. Its wider timing caches went into 1.0.3's cached measure() when the commit
applied. batch_rows now reaches st.max_rows (128), so verify's and draft's per-stream arrays have no
headroom left. The lane core picks no more streams than rows, so no round asks for more today; now
Metal.init refuses a batch_rows past st.max_rows, and verify and draft refuse more windows than
their arrays hold instead of writing past them.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…hhart#518

Lands ashhart#502 on main beside ashhart#518: a shared round can now hold 128 rows, so the routed-expert checker
bit-checks and times every pass shape at 128 rows too. Layer 0's routing copy is sized by the
widest width.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
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