Skip to content

Nemotron on Metal: warm turns, so a long follow-up resumes past the previous prompt - #3190

Open
ashhart wants to merge 2 commits into
mainfrom
lead/nemotron-metal-warm-turns
Open

ashhart wants to merge 2 commits into
mainfrom
lead/nemotron-metal-warm-turns

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Fixes #3108.

Nemotron on Metal turns on warm turns. When a reply ends, the lane host waits 150 ms of quiet, then prefills the reply as the next turn will render it, so a follow-up resumes from the kept state instead of prefilling again. It saves the Mamba state and the MTP head exactly as a fresh prefill leaves them, and only at the existing planned cuts, so no new cut points or arithmetic. Two commits:

  1. Warm reply states at the existing planned cuts (native/planned_warm.zig, native/metal.zig, the Nemotron prompt loop); cache 0 still turns it off.
  2. Background chunks yield: each warm chunk is landed before the next is queued, and cancel and yield are checked between chunks, so a foreground arrival waits at most for the chunk already on the GPU. Foreground keeps its one-chunk lookahead. An opt-in trace adds warm begin and end events.

Measured on an M5 Ultra (Nemotron 3.5 Lightning MLX 4-bit with its MTP head; A B B A, warm-ups dropped; 960 replies, 1,068,032 tokens):

  • Exact: every reply byte-equal to a fresh cache-off main solo reply, greedy and seeded, 1 and 4 streams, with and without MTP drafts.
  • First long follow-up (9,216-token prompt): resumes 8,192 rows, TTFT 0.164 s against 1.020 s on main.
  • A same-chat follow-up arriving during a warm pass: TTFT 24-69 ms faster than main (it still waits 795-851 ms for the warm chunk already submitted, which main spends prefilling).
  • Short replies: same cached counts and TTFT as main (no legal cut inside a 128-token reply).
  • Cold TTFT and decode: inside main's range on every draw and draft setting.

Host tests: the warm lane host and prompt-flight tests (7 changed-flight tests); two planted controls fail and pass when restored. Not checked: M1-M4, CUDA, an unrelated prompt arriving during a warm chunk.

  • Synthena (Ash's Agent)

Enable idle reply passes only with a prompt cache, retaining the MTP
one-token lookahead and the next request's existing chunk cuts. Give an
immediate request a quiet interval, then yield between prompt chunks
without releasing an in-flight command buffer early.

Trace warm pass boundaries under TF_LANE_TRACE so arrivals during a pass
can be distinguished from arrivals before it. Test cache-off policy,
planned marks, yield/cancel precedence and owned flight completion.

Fixes #3108
@ashhart
ashhart force-pushed the lead/nemotron-metal-warm-turns branch from bec5480 to 8329aea Compare November 18, 2026 14:35
@Spectre056

Copy link
Copy Markdown

I can add an M5 Max leg next to your M5 Ultra rows: Apple M5 Max (40-core GPU), 128 GB, macOS build 26B131, Zig 0.17.0.

Plan, against the "done when" list in #3108, base main against this PR's head:

  • A five-turn chat that sends each reply back: cached tokens past each reply's end, and time to first token against main.
  • Replies against a fresh prefill and a cache-off server, with and without MTP drafts, greedy and seeded, at 1 and 4 streams.
  • A request sent the moment a reply ends, timed, to show it doesn't wait on the warm pass.
  • Cold prompt and decode cells against main, arms alternated A B B A.

Same model as your rows (Nemotron 3.5 Lightning MLX 4-bit with its MTP head) unless you'd prefer another. It would run in the next few days; tell me if the head is about to move or if there's a narrower cell you'd rather have.

@Spectre056

Copy link
Copy Markdown

M5 Max leg, against the "done when" list in #3108.

  • Apple M5 Max (40-core GPU, tensor units), 128 GB, macOS build 26B131.
  • Base is the merge base 8cbef977, fix is this head 8329aea3, both built with Zig 0.17.0 using zig build native -Dcpu=apple_m1 -Dversion=1.2.9. The two trees differ in exactly this PR's 11 files.
  • TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit @ d9d758fb with mtp-4bit.safetensors. Server flags --context 49152 --parallel 4 --no-thinking with the default prompt cache (33.3 GiB), and --prompt-cache-gib 0 for the references.
  • Requests are streamed chat with ignore_eos so every reply has a set length. Greedy means temperature 0; seeded means temperature 1.0, top_p 0.95, seed 7. Serial means "draft": false.
  • Arms alternated base, fix, fix, base. Each value is the mean of the two pass medians, with the range over all samples.

On this host the startup line is prompt chunks of up to 8,192 tokens, cut at replies 256+ tokens apart. A turn already resumes at its own assistant header on main, so the warm pass adds a state only where a reply crosses the next 8,192-row line. I sized the cells to that. In the five-turn chat each reply ends 64 tokens past the next line (8,196-8,207 tokens), and each user turn is about 30 tokens.

Five-turn chat, each reply sent back:

turn prompt previous prompt ends cached, main cached, fix TTFT main TTFT fix
2 8,292-8,299 50-54 0 8,192 1.593 s (1.587–1.596) 0.078 (0.069–0.083)
3 16,481-16,484 8,292-8,299 8,192 16,384 1.730 0.091
4 24,672-24,691 16,481-16,484 16,384 24,576 1.858 0.095
5 32,862-32,879 24,672-24,691 24,576 32,768 1.986 0.105

With the recipe's shape (a 9.1K-token system prompt and 96-token replies), turns 2-5 have the same cached counts and TTFT as main, 0.092-0.123 s on both.

A follow-up after an 8.2K-token reply:

sent after the reply cached, main / fix TTFT main TTFT fix
at once (gap under 1 ms) 0 / 0 1.559 s (1.558–1.560) 1.561 (1.557–1.567)
0.2 s, warm pass running 0 / 8,192 1.572–1.597 1.537–1.542
3 s, engine idle 0 / 8,192 1.596–1.599 0.081–0.082

After a 16.4K-token reply, with the reply ending 64 past 16,384:

sent after the reply cached, main / fix TTFT main TTFT fix
0.2 s, warm pass running 0 / 0 3.217 s (3.211–3.225) 4.657 (4.647–4.668)
3 s, engine idle 0 / 16,384 3.203 (3.189–3.218) 0.074 (0.072–0.075)

In that case the warm pass's only mark is 16,384, past its first 8,192-row chunk. A follow-up that arrives during the first chunk waits about 1.45 s for it to land and then finds no kept state, so it is 1.44 s slower than main (4 of 4 samples). A 17,237-token turn in the 0.2 s cell above did the same (4.78 against 3.32 s).

Token equality: each conversation is two turns: a reply ending past 8,192, then a 256-token follow-up. There are 4 conversations per mode and stream count, in greedy MTP, greedy serial, seeded MTP and seeded serial, solo and four at once.

  • With the cache on, all 64 replies equal both cache-off main and cache-off fix. Solo, every turn 2 resumed 8,192 or 16,384 rows from the warm state.
  • Four in lockstep rarely kept a warm state in time (13 of 16 turn 2s resumed 0). So I added a four-stream set with a 10 s pause: 32 of 32 equal, with 7 of 16 turn 2s resumed from a warm state.
  • Every timing turn has one hash across base and fix (76 of 76), and MTP equals serial in the decode cells.

Cold and decode: cold prompts at 2K, 8K, 16K and 32K come in at 0.427 / 1.550 / 3.149 / 6.736 s on main against 0.426 / 1.551 / 3.148 / 6.740 s here, about 4,840-5,300 tok/s on both. Decode at 512 tokens: prose 290.9 against 287.9 tok/s with MTP and 188.4 against 188.6 serial; code 307.5 against 307.7 and 188.3 against 188.5. Every cell is inside main's range.

Against "done when" on the M5:

  • Cached tokens past each reply's end and lower TTFT in a five-turn chat: TTFT yes, 19-21x lower on every follow-up when the replies cross an 8,192-row line. Cached tokens pass the previous prompt on every turn but stop 64 tokens short of the reply's end, at the planned cut, so it is past the previous prompt, as the title says, rather than past the reply. With replies under about 8K tokens, it is the same as main.
  • Byte-identical to a fresh prefill and a cache-off server, with and without MTP, greedy and seeded, at 1 and 4 streams: yes.
  • A request sent the moment a reply ends doesn't wait on the warm pass: yes, 1.561 against 1.559 s. One arriving a little later, mid-chunk, does wait. It comes out 35-57 ms ahead of main when that chunk ends at the kept mark, but 1.44 s behind when the mark is past the first chunk.
  • Cold prompts and decode level with main: yes.

Receipts (commands, prompts, raw per-request data with token ids and hashes, server logs, lane traces) available on request.

This branch has not been deployed

No deployments
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.

Nemotron on Metal: warm turns, so a follow-up resumes past the previous reply

2 participants