Repository navigation
metal nemotron: KV pages taken as a stream's rows grow (TF_NEMOTRON_METAL_KV_PAGES) - #1837
Conversation
|
Thanks @jschmied. We read this through, and the bound looks right. In One thing to confirm: We've queued two Metal runs on Nemotron, flag off against main and flag on against main, both checking for byte-equal replies. We'll post the numbers here. A debug-build assertion that every round's rows sit inside the covered pages would also be a cheap guard, if you'd like to add one. |
|
Numbers from an M5 Ultra on Nemotron 3.5 Lightning, this branch against its main base, warm-up then base, new, new, base:
Replies are exact both ways, and served decode is within noise. The one pattern is decode right after a long prompt with the flag off: both new runs were slower than both base runs in every cell, by about 1%. With the flag off this should be main's code, so we're running it a second time to see whether that holds. In the meantime, does the flag-off path add anything per decode step, such as a check of the flag, a page-cover computation or a wider struct in the hot loop? If it does, hoisting it out of the step would settle it. |
|
Thanks for reading it through and for the M5 runs. A rejected draft's head row. No. It's never written past the kept pages before the next grow. A page holds 256 rows of every attention cache and the head's last ( The order is grow, write, land, trim, then grow again before the next write:
So a write after a trim always comes after a grow that covers it. I'll add the debug-build assertion you suggest: every queued pass's last row sits inside the lane's table. Flag off, per decode step. It adds a little, but nothing in the hot loop:
That's a few nanoseconds per pass, against about 4.3 ms per token at 235 tok/s; 1 % would be about 43 µs. So I don't think the code explains it; code layout might. Your second run will tell. To take it off the table, I'll make |
|
Thanks @jschmied, that settles it. The second flag-off run (M5 Ultra, Nemotron 3.5 Lightning, against main) doesn't repeat the gap: decode after a 2K prompt is 237.0 -> 236.4 tok/s with the runs overlapping (base 234.4/239.5, new 239.0/233.9), 8K 232.4 -> 233.7, 64K 203.2 -> 205.1, and tokens are identical in all 20 rows. So the first run's 1% was noise. With the flag on also green and replies exact, this is ready, and we'll land it now. The |
a64f0cd to
0118c85
Compare
|
Thanks for the second run. I'd pushed the |
A rolled-back window returns its pages without ending the stream; the Metal pages trim a lane by rows.
Admission still promises the reply's pages; prefill chunks, steps, verify windows, the draft head, restores and GPU rounds take theirs just before the pass that writes them, and a rolled-back window gives them back.
0118c85 to
8aec78e
Compare
|
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. |
|
Thanks @jschmied! This is in TensorFold 1.2.2, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.2 |
Part of #1293 (step 3, the follow-up ashhart's status named). With
TF_NEMOTRON_METAL_KV_PAGES=1, #1537 kept Nemotron's keys and values in pool pages, but a stream took pages for its whole context when it opened, so paging saved no memory. Now a stream takes pages as its rows grow.What changes
kv_pool.zig:Pool.trim(lease, n)returns a lease's pages pastnto its promise. A rolled-back window gives its pages back without ending the stream.metal_kv_pages.zigtrims a lane by rows.Checks (M3 Pro)
zig build test, the contract, golden, security and fuzz steps pass;git diff --checkis clean.Left for later