Repository navigation
lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) - #1503
lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492)#1503jschmied wants to merge 7 commits into
Conversation
fcd8014 to
f31a350
Compare
|
Thanks @jschmied. Leasing from the core pool and keeping states at chat marks is the shape we want, and checking the census after every drain is a nice touch. With #1492's commits on main, both of your commits apply cleanly. One thing must change before this leaves draft. A cold chat turn that keeps a state is 50 ms slower than on #1492 (1.27 s against 1.22 s), and the prompt cache is on by default. Each kept state is a new device allocation ( To your questions:
Then we'll serve it on a GB10:
|
f31a350 to
0506d9c
Compare
|
Thanks @ashhart. Kept states now live in pages allocated once, and the cold turn is level with #1492. The branch is rebased onto the new #1492; the head is
|
0506d9c to
10f3274
Compare
|
Thanks @jschmied. The 27 Oct ask is answered. Kept states lease from one arena allocated inside the prompt-cache budget ( |
|
/atc exchange e068a93c3878cdda3f5978d7f707b52e86b07c7cabdabdb7aa899f0bf87303fe |
10f3274 to
858187d
Compare
|
Thanks @ashhart. Rebased onto main now that #1492 has landed. The head is What moved to fit main:
Checks on the new head, served on a GB10 against main:
Ready for the cells from your 27 Oct note. |
|
Thanks @jschmied, that's the fix. With the copies on the snapshot side stream, the first token's draw and host read come before anything waits on a keep, and the cold cell is now level (−3.2 ms, 9 of 24 slower). The Since this changes stream ordering on the keep and restore paths, we'll give the events one more careful read before it lands. Main is frozen for the 1.2.7 release right now, so it goes in the queue just after.
|
|
Thanks @jschmied. We read the keep and restore events through once more on
A suggestion for a later PR, not this one: the host test covers the fork and the restore fence, but not the five places the prompt stream waits before writing. A small test there, or one helper all five go through, would stop a future writer from skipping the wait. CI is green and it merges cleanly with main. It's queued to land.
|
|
@ashhart the follow-up you suggested in 6806587680 is #2989: |
…m leasing The kernels already read keys and values through a slot's page table, so the pool changes only what the table holds and how large the arena is; no kernel changes. A page is 512 positions of the ten attention layers' keys and values (10 MiB, 20 KiB a token); the conv states stay a fixed part a slot (240 KiB). - Loaded.layout with engine_paged, as Dory's: the plan sets a window of pages aside for the first stream; each stream leases its prompt, its reply and one verify window at its prompt pass and gives them back when it ends. A request that cannot lease waits (LaneMemory); fits is the host's admission. - Model.attach makes the arena and the tables and conv states of the slots the plan names; forward refuses rows past a slot's pages. The idle server logs the pool's census. - TENSORFOLD_LFM2_KV_PAGES=0 keeps every stream's own window of pages, made at open. Served on the GB10 at --parallel 8, 16k: drafted == plain and concurrent == solo, also with 8 long prompts on a 52-page pool where the last waits for pages; the replies equal the fixed pages' ones.
…the pages' rows through its position A state at `at` is the slot's conv states and its keys and values at positions [0, at) of the ten attention layers: one copy a run of consecutive whole pages, then the last page's rows a layer's keys and values. It is copied behind the chunk that ends at the mark and restored into the new stream's leased pages before its next chunk, so a later turn's pass starts at its history. Lookahead 0, as the other headless families. States live in 2 MiB snapshot pages allocated once at startup inside the prompt-cache budget (`snap_ready`), as GLM's: a keep or a restore leases or reads pages and allocates nothing, and a dropped state's pages go back to the pool at once (every copy that reads or writes them is queued on the backend's one stream). The store counts held and spare pages through `snap_charged` / `snap_spare` / `snap_reuses`.
…dds no pass A chat mark inside a prompt chunk ended the chunk there, and every extra prompt pass reads the weights once more: a cold 10k chat turn, whose two marks sit in its last chunk, ran 12 passes instead of 10. Now up to four marks inside a chunk are tapped instead: the conv kernel runs once more on each mark's last row alone, writing the same y and that row's conv states into the model's tap buffer, and the keep copies those states with the K/V rows before the mark. The pass goes on to its grid line; a fifth mark still ends it. The kernel is unchanged.
…fuse anything but 0 or 1
…irst token doesn't wait for them
5506906 to
2ffe07e
Compare
|
@jschmied main moved under this and it conflicted with main, so the landing train left it out. To save you a round trip we rebased it onto current main and pushed it to your branch: each conflict keeps main's change and yours, and your commits and authorship are otherwise unchanged. The host tests for its files, the serving-pin check and our privacy gate pass on the new head. It goes back in the landing queue once its CI is green. No other asks.
|
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
|
Thank you @jschmied. All seven of this PR's commits are on main under your name (83ad23d through 65cebea), with #2989's
|
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
…base docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5, pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2. nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
Part of #1488. On main
673a34b3b; the head is550690618, seven commits. The cold-turn loss is gone on this head: paired −3.2 ms against main, slower in 9 of 24 runs.What
LFM2.5-24B-A2B on CUDA, step 2: attention pages from the shared CUDA KV pool, and the prompt cache.
c79d8700bPool pages. The 10 attention layers' K/V live in pages of the corekv_pool(512 positions, 10 MiB a page), Dory's shape.forwardrefuses rows past a slot's pages.Layout.ofRows, 10 layers of 2 KiB a row), so the load line shows them (Roadmap: one paged KV pool and a radix prompt cache for every family #2444 C2).TENSORFOLD_LFM2_KV_PAGES=0keeps lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492's fixed pages per stream. It is read through the profile registry likeTENSORFOLD_SPARK25_KV_PAGES(class identical,0reported), listed indocs/profiles.md.62ac19fb3Prompt cache. A kept state is the slot's conv states plus K/V rows[0, at)of the 10 layers.cuda_snapshot_pages.zigdoes. A keep leases pages, a restore copies them back into the new stream's leased pages, and a drop returns the lease: no device allocation, and no free behind a stream wait.lfm2_moejoins the familiesTENSORFOLD_PROMPT_CACHE_KEEP_OTHERSapplies to (profile.cuda_cache), ascuda_keep_others_testrequires of every family withsnap_save.29b65c56dKeeps add no prompt pass. A chat mark inside a prompt chunk used to end the chunk there, and every extra pass reads the weights again. A cold 10k chat turn has two marks in its last chunk, so it ran 12 passes instead of 10.yand that row's conv states into a tap buffer, and the keep copies those with the K/V rows before the mark. The kernel is unchanged.9d2a41dd1Docs. The recipe says streams lease pool pages and the cache keeps chat states.1a2612c77Env flag.TENSORFOLD_LFM2_KV_PAGESis a.flagrow inenvironment.zig, read throughenvironment.value; anything but0or1is refused by name.c2f48eddcLoad line. Option (c): the arena stays allocated once, and the startup line says so:a 43.9 GiB prompt cache, reserved at load. LFM2'snativedeclaressnap_reserved; the shared line incuda_kv_pool.textappends the words only for a family that declares it, so no other family's line changes. The LFM2-MoE pool test pins both texts.550690618Keeps off the first-token path. A keep's copies run on the snapshot pages' own stream (cuda_snap.Side), so a cold turn's first token never waits for them.readyon the prompt stream after the chunk that wrote the state. The side stream waits for it, copies, and recordsdone.doneon the device, never on the host, and only before its next write of what a keep reads: a forward, a commit, a slot cleared (Lfm.settle). A restore also waits before it reads snapshot pages (snap.restore). The first token's draw and its host read come before any of these, so they don't wait.flashnext/cuda_batch_side.zig: a stream with fork and join events). GLM (glm/cuda_snapshots.zig) and Qwen3.5 (qwen3_5/cuda_reuse.zig) copy on the prompt stream and synchronize, so their order was the one to move away from.14 files, +881 / −53 against main.
Proposed CHANGELOG line, under Unreleased: "LFM2.5-24B-A2B on CUDA leases its attention pages from the shared KV pool and keeps chat states in the prompt cache, in pages allocated once inside its budget and reserved at load, copied beside the first token;
TENSORFOLD_LFM2_KV_PAGES=0keeps fixed pages per stream (#1503, part of #1488)."Verification (GB10, real weights, served, against main
673a34b3b)Every row is on
550690618unless it names another head.zig/src/families/lfm2_moe/cuda_snap.zig:340): a fake driver logs each copy, event record and wait by stream.doneon the prompt stream before the sampler; the keep's copies come after the side stream waited forready; the restore's copies come after the prompt stream waited for the lastdone.:365), a restore without the fence (:372), and copies before the side stream waited for the pass (:380).saveitself, with the copies on the prompt stream, the test fails at:366(17 of 18 pass); restored, 18 of 18 pass.8595a92c8,zig/src/native/cuda_kv_pool.zig:578) is rewritten in62ac19fb3: this PR gives LFM2-MoEsnap_save, so the test now checks the default cache still plans throughbudgetOfand the store holds what the plan set aside.a 43.9 GiB prompt cache, reserved at load(the same with fixed pages); MemAvailable after ready 55.5 GiB (99.7 GiB with the cache off).TENSORFOLD_LFM2_KV_PAGES=0), with a 0.1 GiB cache that evicts, and under pool pressure. After a restart the greedy replies equal main's again.TENSORFOLD_CUDA_MEMORY_LIMIT_GB=14.0the pool has 72 pages. 8 prompts of about 6k tokens at once wait for pages (10.0 s against 2.29 s on the full pool), and every reply equals its solo run.kv pool idle: promised 0, free 520 + store 0 == total 520(72 of 72 under pressure), with no bad lines in any arm.test-lfm2-moe-cuda-host,test-kv-pool,test-cuda-host.zig build -Dfixed-cpu test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths,check-native-cuda-host compile-cuda-tests.zig fmt --check build.zig zig,git diff --check,cuda_common_check(0 violations; no.cu/.cuhchange),lean_check(386 against main's 386, 0 new),pr_check(0 errors).Speed (GB10, against main, cold A-B-B-A, paired per prompt)
The same six cold 9,231-token chat turns run on every server, each keeping two states. The page cache is dropped before each start. Paired means each head server against the mean of its two adjacent mains.
5506906187302b556b(the same code before a comment-only amend)7302b556b7302b556bc2f48eddc(copies in line)c2f48eddcc2f48eddc--prompt-cache-gib 0c2f48eddcMain drifts up to 24 ms between the first and last server of a cell, so a single cell resolves about 5 ms. With the copies in line, every cell was slower: 3 to 8 ms in these cells, and 13.7 and 18 ms in earlier rounds that included drift. With the copies on their own stream, no cell is clearly slower.
The warm turn and decode rows from the earlier round (warm turn 1.24 s → 0.10 s TTFT at 10,141 cached tokens; plain decode at 1/4/8 streams level) are from the pre-rebase head
858187d75. A warm turn restores on the prompt stream afterdone, as before.Not in this PR
warm_quiet): its own PR.