Repository navigation
KV pages: one core owner with reservation leases, Nemotron CUDA pilot (#781) - #935
Conversation
…shhart#781) kv_pool.zig holds a family's stream layout (fixed bytes, token bytes, page rows, snapshot slot bytes), the load plan (room less the engine's own sequence, the other streams' fixed parts, snapshot slots and copied KV, then pages) and Pool: page ids, holders, the free list and the promised count. Leases promise, take, cover (with a table write that rolls back on failure), adopt a store's resumed pages, share a kept page and finish. A promise that does not fit asks the store to reclaim before it fails with LaneMemory. prompt_radix.pagesOf gives a Pool to the paged store as its Pages. test-kv-pool: the plan's arithmetic at Nemotron's numbers (a 2,048-token prompt with 4,096 reply tokens reserves 13 pages, 45.5 MiB); every table write and every allocation failing in turn; 300 random admit, keep, resume, finish, cancel and failure runs through prompt_radix with every page's holders checked after each step and all free at the end; a lane host whose second request waits for the first stream's pages, runs once it ends, and fails in words past the whole pool. The fake target gains a reservation hook for this.
… core pool (ashhart#781) The engine keeps its own full-window sequence, graphs and lone fast path as they were; it is counted once, in the model's memory. The other --parallel streams get paged sequences made at load (64 MiB fixed each) whose K and V rows (six attention layers and the MTP head, 7 KiB a token) live in one arena of 512-row pages from kv_pool. A request reserves ceil((prompt + max_tokens + 16) / 512) pages at prefill; the lane host admits it when the engine's own sequence is free or the pool holds its pages, and a promise that fails returns LaneMemory, so it waits. The attention kernels (kv_write, attn_chunk, its prefetching and shared-window copies, the prompt chunk's pattn) take a page table at a fixed device address and the elements between pages; a null table keeps the contiguous rows. The copy store stays, with the MTP lookahead: it copies a paged sequence's rows page by page, its snapshots' Mamba states sit in slots made at load (they replace the spares and the per-save cuMemAlloc), and --prompt-cache-gib is split into those slots and the copied rows' budget, both out of the room before any page. The startup line shows the pool; an idle pool logs promised 0 and free + store == total. TF_KV_PAGES=0 restores a window per stream, TF_KV_PAGES=all puts every stream on pages for checks, TF_KV_POISON=1 fills taken pages with NaN. Checks on GB10 with the MLX 4-bit checkpoint: tf-cuda-test glue (paged kernels byte-equal to contiguous ones, alone and in shared windows, across page edges); tf-cuda-test paged (a paged sequence's prompt pass, decode and states resumed both ways at rows 511-513, 1023-1025, 2047-2049 equal the own sequence's); reuse_served record on a TF_KV_PAGES=all server against replay on a TF_KV_PAGES=0 server with the cache off: 43 of 43 token SHAs equal, and all 44 rows equal main's record; greedy and seeded drafted == plain and concurrent == solo, 24 of 24, equal to main's SHAs; a pool of 54 pages ran three 30-page requests one after another.
There was a problem hiding this comment.
Reviewed a9dfd3846fb0a12d959dc47f3652842081651691 against the first-pilot choices in #781. The core reservation/rollback paths and the CUDA table, sequence-capacity and snapshot-slot wiring look consistent in source. I ran zig build test-kv-pool on an M5 Max with Zig 0.17.0. Astra separately reviewed the core ownership paths and tests.
One small generic Store.most gap is reproducible: the reuses early exit runs before the entry-count limit. With the existing Fake.pooled, most = 1, spare storage available, and two different direct keeps at rows 4 and 6, both saves succeed and the store retains two entries.
The current Nemotron CUDA snapshot adapter has no reuses callback, so this does not demonstrate a memory fault in the pilot. It does violate the new generic count limit.
I put a two-file patch together: require entries.len < most on the reuse exit too, with a regression through the real Store. The test checks one retained entry, one live snapshot, the newer state and exactly one eviction.
| Check | Result |
|---|---|
| New regression on the unchanged PR | Fails: expected 1 entry, found 2 |
| Proposed guard, complete cache/disk test root | 98/98 pass |
test-kv-pool, whole-tree format and whitespace |
Pass |
| Lean | 516 findings against main's 517, 0 new |
Astra also reviewed the fix and test without a remaining source blocker. The proposed patch also passes the complete local zig build test, test-kernel-contract, test-golden and fuzz-cortheon commands, plus whole-tree format and whitespace checks; the goldens have 0 unexpected differences. I have not run a CUDA kernel, model, Super VL, multi-rank or performance test; the device receipts in the description remain the author's measurements.
|
@cwschroeder, thank you. Your patch is in as The only family that sets |
|
Confirmed at I also checked the adapter distinction: |
|
Thank you, @jschmied, the reservation, table-failure and holder-conservation tests make the three #781 pilot choices concrete. We checked 197db0c. The copy store keeps its MTP lookahead, leases sit beside one Pool owner, and the engine's full-window sequence is charged once before planning extra streams. prompt_cache.zig:464 also closes the generic reuses/count-limit case. This is ready for the core and scoped Nemotron pilot landing checks. We will retain paging-off/all/poison, disk recall, record and full-token controls, and run the still-open Super VL, multi-rank and structured-output cells on the integrated source before extending coverage. No new source blocker appeared in this focused ownership read. Posted by Ash's AI Assistant Synthena |
… cap, Module.holds and paged attention changed them The serving-identity pin came with Living Weights pinned against a base without Drama's process-wide allocation cap (cuda/memory.zig), Module.holds (cuda/module.zig) or #935's paged attention (nemotron_attention.cu, prefill_attention.cu and prefill_attention_rows.cuh), so it failed on the first of them. Those files now pin the bytes those reviewed landings left, and cuda/root.zig's approved hash is the Living Weights exports over them. The learning changes it guards are unchanged: every other serving file still has its released bytes or an approved append.
The dense family's pin of its serving CUDA sources failed on prefill_attention.cu, which #935's reviewed paged attention changed (an optional page table and page stride; the contiguous path's arithmetic is the same). Its other twelve pins and the launch argument sequence still match.
… 13.0 and 13.2 from every SM's image Living Weights brought 95 Flash Next and shared training launches and 34 dense ones, and #935 six paging launches, all with zero records that kept the CUDA resource gate red until measured. kernel-contract-limits over every SM's fatbins (sm_80, 86, 89, 120 and 121) gives their usage: nvcc 13.0's go in the records, and the 37 launches 13.2 compiles otherwise (their registers, mostly) join the 13.2 set from registry_learning.zig. Two serving records were zeroed for re-measurement and come back as they were (fn_attn_prep and fn_qsa_pool, whose sources Living Weights did not change), and of the two vision launches in the prefill attention image #935 changed, full_kernel<72>'s record takes its new usage. The pending sets' red tests become checks that every measured record fits every SM, and the per-compiler set test finds overrides among all the audited records.
… lost with the learning records cda734f7d put tf_nemo_attn_chunk_segs's 13.2 usage (78 to 97 registers, 45,568 static bytes) in registry_learning.zig beside the learning launches, so the Living Weights revert dropped it and 13.2's limits marked the launch stale on sm_120 and sm_121. It now sits in paging_pending.zig with the launch's 13.0 record.
|
Thank you, @jschmied, for the page owner, and @cwschroeder for the reuse guard. 1.1.0 includes #935 ( Posted by Ash's AI Assistant Synthena |
…re owner, with leases for the streams beside the engine's own ashhart#935's page owner, reservation leases, rollback and the Nemotron pilot, on this line's kept prompt states: a snapshot is an owned device buffer for tool callers, a borrowed slot for a configured device cache, or a pinned host state on a discrete card that cannot hold the cache asked for (the startup line says which), and device and host copies walk the bound page sequence. Startup reserves a host cache's one staging buffer before it plans the page pool and refuses, naming the bytes it needs and has, when the room is short; keep 0 reserves and allocates nothing. Every paged constructor's cleanup and Pages.deinit drain before an owner is released. The six paging launches and the changed prefill attention image stay unqualified until their records are measured. test-kv-safety-host and test-kv-merge-host run the actual startup, planner and constructors under allocation and completion faults, with the tests named for what they check. Co-authored-by: Christian Schröder <[email protected]>
… cap, Module.holds and paged attention changed them The serving-identity pin came with Living Weights pinned against a base without Drama's process-wide allocation cap (cuda/memory.zig), Module.holds (cuda/module.zig) or ashhart#935's paged attention (nemotron_attention.cu, prefill_attention.cu and prefill_attention_rows.cuh), so it failed on the first of them. Those files now pin the bytes those reviewed landings left, and cuda/root.zig's approved hash is the Living Weights exports over them. The learning changes it guards are unchanged: every other serving file still has its released bytes or an approved append.
…urce The dense family's pin of its serving CUDA sources failed on prefill_attention.cu, which ashhart#935's reviewed paged attention changed (an optional page table and page stride; the contiguous path's arithmetic is the same). Its other twelve pins and the launch argument sequence still match.
… 13.0 and 13.2 from every SM's image Living Weights brought 95 Flash Next and shared training launches and 34 dense ones, and ashhart#935 six paging launches, all with zero records that kept the CUDA resource gate red until measured. kernel-contract-limits over every SM's fatbins (sm_80, 86, 89, 120 and 121) gives their usage: nvcc 13.0's go in the records, and the 37 launches 13.2 compiles otherwise (their registers, mostly) join the 13.2 set from registry_learning.zig. Two serving records were zeroed for re-measurement and come back as they were (fn_attn_prep and fn_qsa_pool, whose sources Living Weights did not change), and of the two vision launches in the prefill attention image ashhart#935 changed, full_kernel<72>'s record takes its new usage. The pending sets' red tests become checks that every measured record fits every SM, and the per-compiler set test finds overrides among all the audited records.
…record, lost with the learning records cda734f7d put tf_nemo_attn_chunk_segs's 13.2 usage (78 to 97 registers, 45,568 static bytes) in registry_learning.zig beside the learning launches, so the Living Weights revert dropped it and 13.2's limits marked the launch stale on sm_120 and sm_121. It now sits in paging_pending.zig with the launch's 13.0 record.
…core pool Every stream made a sequence sized for the window on its first bind, and admission priced every stream at that size: at a 1M window, 12.9 GiB a rank whatever the conversation's length. The family now declares a kv_pool.Layout (ashhart#781), as Nemotron does (ashhart#935): a stream's fixed part and 13,056 bytes a token in pages of 512 rows. The server plans the pool beside the engine's own full-window sequence, counted once, and attach makes the paged sequences and the pages. A request takes the pages of its prompt, its reply and one verify window when it starts and gives them back when it ends; admission waits while the pool lacks them. The prompt cache keeps its copied rows beside the pages. TF_KV_PAGES chooses which streams page. auto, the default, pages from three ranks up and keeps a window each below: on two GB10s the room left after the weights (6 to 9 GiB) is under the default 16 GiB prompt cache, which the plan funds after a page a stream and before any other page, so the pool would hold little more than a page a stream. on pages every stream past the engine's own at any rank count, off (or 0, as for Nemotron) gives every stream a window as before, and all puts every stream on pages for checks, the engine's own sequence left idle. TF_KV_POISON=1 fills a stream's pages with NaN before its rows are written, as for Nemotron. On more than one rank, rank 0 plans by the smallest room and sends the pool's size in a new pool step; every rank makes the same pool, and each stream's begin step carries its page ids, which the other ranks write to their tables without taking pages of their own. A page size that differs between the ranks is refused by name. With --kv-cache fp8 the streams keep their windows: auto does not page, and on and all are refused by name (Fp8OnPages), as the FP8 cache's scales have no place on a page yet.
…core pool Every stream made a sequence sized for the window on its first bind, and admission priced every stream at that size: at a 1M window, 12.9 GiB a rank whatever the conversation's length. The family now declares a kv_pool.Layout (ashhart#781), as Nemotron does (ashhart#935): a stream's fixed part and 13,056 bytes a token in pages of 512 rows. The server plans the pool beside the engine's own full-window sequence, counted once, and attach makes the paged sequences and the pages. A request takes the pages of its prompt, its reply and one verify window when it starts and gives them back when it ends; admission waits while the pool lacks them. The prompt cache keeps its copied rows beside the pages. TF_KV_PAGES chooses which streams page. auto, the default, pages from three ranks up and keeps a window each below: on two GB10s the room left after the weights (6 to 9 GiB) is under the default 16 GiB prompt cache, which the plan funds after a page a stream and before any other page, so the pool would hold little more than a page a stream. on pages every stream past the engine's own at any rank count, off (or 0, as for Nemotron) gives every stream a window as before, and all puts every stream on pages for checks, the engine's own sequence left idle. TF_KV_POISON=1 fills a stream's pages with NaN before its rows are written, as for Nemotron. On more than one rank, rank 0 plans by the smallest room and sends the pool's size in a new pool step; every rank makes the same pool, and each stream's begin step carries its page ids, which the other ranks write to their tables without taking pages of their own. A page size that differs between the ranks is refused by name. With --kv-cache fp8 the streams keep their windows: auto does not page, and on and all are refused by name (Fp8OnPages), as the FP8 cache's scales have no place on a page yet.
…core pool Every stream made a sequence sized for the window on its first bind, and admission priced every stream at that size: at a 1M window, 12.9 GiB a rank whatever the conversation's length. The family now declares a kv_pool.Layout (ashhart#781), as Nemotron does (ashhart#935): a stream's fixed part and 13,056 bytes a token in pages of 512 rows. The server plans the pool beside the engine's own full-window sequence, counted once, and attach makes the paged sequences and the pages. A request takes the pages of its prompt, its reply and one verify window when it starts and gives them back when it ends; admission waits while the pool lacks them. The prompt cache keeps its copied rows beside the pages. TF_KV_PAGES chooses which streams page. auto, the default, pages from three ranks up and keeps a window each below: on two GB10s the room left after the weights (6 to 9 GiB) is under the default 16 GiB prompt cache, which the plan funds after a page a stream and before any other page, so the pool would hold little more than a page a stream. on pages every stream past the engine's own at any rank count, off (or 0, as for Nemotron) gives every stream a window as before, and all puts every stream on pages for checks, the engine's own sequence left idle. TF_KV_POISON=1 fills a stream's pages with NaN before its rows are written, as for Nemotron. On more than one rank, rank 0 plans by the smallest room and sends the pool's size in a new pool step; every rank makes the same pool, and each stream's begin step carries its page ids, which the other ranks write to their tables without taking pages of their own. A page size that differs between the ranks is refused by name. With --kv-cache fp8 the streams keep their windows: auto does not page, and on and all are refused by name (Fp8OnPages), as the FP8 cache's scales have no place on a page yet.
…core pool Every stream made a sequence sized for the window on its first bind, and admission priced every stream at that size: at a 1M window, 12.9 GiB a rank whatever the conversation's length. The family now declares a kv_pool.Layout (#781), as Nemotron does (#935): a stream's fixed part and 13,056 bytes a token in pages of 512 rows. The server plans the pool beside the engine's own full-window sequence, counted once, and attach makes the paged sequences and the pages. A request takes the pages of its prompt, its reply and one verify window when it starts and gives them back when it ends; admission waits while the pool lacks them. The prompt cache keeps its copied rows beside the pages. TF_KV_PAGES chooses which streams page. auto, the default, pages from three ranks up and keeps a window each below: on two GB10s the room left after the weights (6 to 9 GiB) is under the default 16 GiB prompt cache, which the plan funds after a page a stream and before any other page, so the pool would hold little more than a page a stream. on pages every stream past the engine's own at any rank count, off (or 0, as for Nemotron) gives every stream a window as before, and all puts every stream on pages for checks, the engine's own sequence left idle. TF_KV_POISON=1 fills a stream's pages with NaN before its rows are written, as for Nemotron. On more than one rank, rank 0 plans by the smallest room and sends the pool's size in a new pool step; every rank makes the same pool, and each stream's begin step carries its page ids, which the other ranks write to their tables without taking pages of their own. A page size that differs between the ranks is refused by name. With --kv-cache fp8 the streams keep their windows: auto does not page, and on and all are refused by name (Fp8OnPages), as the FP8 cache's scales have no place on a page yet.
The first slice of #781, as agreed there: a model-free core layout and reservation owner, then Nemotron on CUDA. Rebased on main 46a08c1 (1.0.12).
Core (
zig/src/core/kv_pool.zig)Layout: fixed bytes, token bytes, page rows, snapshot slot bytes;need(prompt, max_tokens, window)= pages of prompt + max_tokens + 16.plan: room, less the engine's own sequence (counted once), the other streams' fixed parts, the snapshot slots and the copied-KV budget, then pages. Never more pages than every other stream could hold at once.Pool: page ids, holders, free list and promised count. Leases beside it:promise/unpromise/take/cover(rolls back if the table write fails) /adopt/share/finish. A promise that doesn't fit asks the store to reclaim first, then fails withLaneMemory.prompt_radix.pagesOfhands a Pool to the paged store as itsPages.test-kv-pool: Nemotron's arithmetic (2,048 + 4,096 + 16 rows = 13 pages, 45.5 MiB). Every table write and every allocation fails in turn, and nothing leaks. 300 random admit/keep/resume/finish/cancel/failure runs throughprompt_radix, with every page's holders checked after each step and everything free at the end. A lane host where a second request waits for the first stream's pages and runs when it ends; aLaneMemoryrequeue; past the whole pool alone, it fails in words.Nemotron CUDA
--parallelstreams get paged sequences made at load (64 MiB fixed each). Their K and V rows (6 attention layers + the MTP head, 7 KiB a token) come from one arena of 512-row pages.kv_write,attn_chunk(and its prefetch and shared-window copies) and the prompt chunk'spattnread a page table at a fixed device address. A null table keeps the contiguous rows.cuMemAlloc.--prompt-cache-gibis split into slots and the copied rows' budget, andStore.mostcaps the number of states at the slot count.promised 0, free + store == total; slots free + held == count.TF_KV_PAGES=0: a window per stream, as before.TF_KV_PAGES=all: every stream on pages (for checks; with--parallel 1the one stream keeps the engine's own).TF_KV_POISON=1: NaN in pages a stream takes.--slidekeep a window per stream.What 1.0.12 changed that touches this
prefill_attention.cunow shares one row body (prefill_attention_rows.cuh) betweenpattn_kernel, the tree kernel and the full kernel. The page table goes into that body; the tree and full kernels pass a null table, so LFM2 and the vision towers read contiguous rows as before (lfm2-attentionandlfm2-visionoutput identical to main's).nemotron_h_omni) opens the same Nemotron engine, so its other streams take pages too. Its vision tower and image rows are engine-wide, not per stream, and ranks past 0 of a latent MoE hold no KV. Not run here (no checkpoint on this box).native/cuda.zig(moved tonative/cuda_kv_pool.zig) only applies to a family that declares it.--learn-conversationsreads disk states into a kept state, which takes a snapshot slot. The disk recall now frees a slot first, as the in-memory paths do (new test inrows_test.zig). Its probe at startup takes a slot after the slots are made.--recordwith paged streams: the recorder reads the per-stream hidden rows, which every paged sequence has.Checks (GB10, NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit, main 46a08c1 as reference)
zig build test,test-kv-pool,zig fmt --checkpass. Lean check: 516 problems against main's 517.tf-cuda-test glue: 1,365 of 1,365 comparisons equal, including the paged kernels against contiguous ones, alone and in shared windows, at page edges.tf-cuda-test paged, pages shuffled and NaN-filled: the paged prompt pass and 24 decoded tokens equal the own sequence's. States at 511/512/513, 1023/1024/1025, 2047/2048/2049 and len-5 resume equal to fresh in both directions.tf-cuda-test resumepasses.reuse_served.py recordonTF_KV_PAGES=all TF_KV_POISON=1 --parallel 4, replayed onTF_KV_PAGES=0 --prompt-cache-gib 0: 43 of 43 token SHAs equal.--min-prompt).--parallel 1. All three give main's SHAs.reuse_served.py evict(1 GiB): same rows and SHAs as main. Its 3 expectation failures fail the same way on main.--recordwith paging on: 24 of 24 token SHAs equal to the run without it. The recorded rows equal main's recording byte for byte (36 of 36 streams). Whether a stream's last row is recorded depends on how its verify windows fell, on main too.--learn-conversations: after a restart, turn 2 read 5,255 tokens from disk, and its SHA equals a fresh pass.--parallel 4, two rounds): fibonacci 77.8/78.1 tok/s on main, 78.0/78.1 on this branch; chat 55.1/55.3 vs 55.0/55.2. 4 streams, code: 193.6/225.3 vs 229.4/224.6.structured_served.py.