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 12 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:
|
The shared-window chunk and merge bodies move to paged_attn_segs.cuh, included twice by nemotron_attention.cu: Nemotron's head-128 kernels keep their names and SASS, and head 64 adds tf_paged_attn_chunk_segs_64 and tf_paged_attn_merge_segs_64. prefill_attention.cu instantiates pattn_kernel<64, 8, 4, 8> over paged caches. sassid on sm_80/86/89/120/121: 0 functions changed, 15 added.
lfm2_moe.cu holds what the shared operators do not: the short conv over each stream's state with every window row's snapshot, the commit of an accepted row's conv state, and the router (fp32 weights, top-4 of sigmoid + bias, ties to the lower id, a NaN ranked as -inf). Each has a planted control. Launch records cover these kernels and the head-64 paged attention on nvcc 13.0, with one 13.2 override.
The MLX 4-bit checkpoint (embedding at 4, 6 or 8 bits) on the shared affine-4 projections and experts, with prompt chunks of 1024 rows, one-row decode and copy-drafted windows over --parallel streams. The ten attention layers keep their keys and values in 512-position pages, and each stream has its own conv state. There is no drafter and no prompt cache yet.
…ount The gated short conv over each stream's state and the conv-state commit move out of lfm2_moe.cuh into liquid_conv.cuh, templated on the tap count, so LFM3 (7 taps) can take the same bodies as LFM2.5 (3). lfm2_moe.cu keeps the router and instantiates the 3-tap pair as tf_liquid_conv_3 and tf_liquid_commit_3; the controls become tf_ctl_liquid_conv_3 and tf_ctl_liquid_commit_3. cuobjdump -sass on sm_80/86/89/120/121, nvcc 13.0 and 13.2: the moved bodies are identical under their new names, every other function unchanged.
… against float64 tf_paged_attn_chunk_segs_64 with tf_paged_attn_merge_segs_64 and pattn_kernel<64, 8, 4, 8> run over shuffled 512-key pages, decode rows over up to eight streams a launch, and are held head by head to contract_attn's float64 bound. Two controls in contract_controls.cu read the values from the neighbouring lane's dims (decode) and from the neighbouring 8 dims (prompt rows). To build them from the same bodies, nemotron_attention.cu's page and tile helpers move to paged_attn.cuh and prefill_attention.cu's to prefill_attention.cuh; every existing function's SASS is unchanged on sm_80/86/89/120/121 under nvcc 13.0 and 13.2.
… of every top-1 miss ref64.py dequantizes the MLX 4-bit weights exactly and runs the forward in float64; --bf16 adds the engine's bf16 storage points. It checks the CUDA engine's greedy picks on teacher-forced prompt rows and on reply rows; REF64.md lists each miss with the prompt, the position, both tokens and both margins.
The recipe gets a CUDA section (build, serve, revision, GB10 receipt, licence), the README row names one NVIDIA GPU beside the Mac, and the contract's coverage lists LFM2.5's CUDA kernels.
…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.
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
|
Part of #1488. Stacked on #1492 (now on main), and only the last four commits are new here. It stays a draft until #1492 lands, then I'll rebase onto main.
What
LFM2.5-24B-A2B on CUDA, step 2: attention pages from the shared CUDA KV pool, and the prompt cache.
92fc4f0ebPool 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.TENSORFOLD_LFM2_KV_PAGES=0keeps lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492's fixed pages per stream.6ef5d8401Prompt 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.cb823583bKeeps 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 (nsys: 1,920 prompt GEMM launches against lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492's 1,600).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.0506d9c0bDocs. The recipe says streams lease pool pages and the cache keeps chat states.7 files, +647 / −43 against #1492.
Verification (GB10, real weights, served, greedy and sampled)
TENSORFOLD_CUDA_MEMORY_LIMIT_GB=13.6) every reply matches. The 8 long concurrent requests take 7.39 s instead of 6.42 s while they wait for pages.lean_check: 0 new against lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492's head.zig fmt --check zigandzig build testpass.Speed (GB10, against #1492, alternating runs)
I re-measured only the cold turn this round. The warm turn and decode rows are from the previous head, and nothing on their path changed.
The remaining 5 ms on the cold turn is the two 200 MB state copies. A device-to-device copy runs at about 115 GB/s here, so each takes about 1.8 ms.
Not in this PR
warm_quiet): its own PR.