Repository navigation
Conversation
flashnext_attn.cu's cache kernels take a Pg (an int page table, the elements a page holds, the positions a page holds): fn_attn_prep(_media)'s key, value and indexer-key stores, fn_qsa_pool(_media)'s reads and pooled writes, fn_qsa_scores' pooled reads and fn_attn_chunks(_ahead)'s key and value tiles find a row with pg_at(): the old expression when the table is null, else the page holding the position plus its row there. fn_attn_chunks looks a key's row up once a tile (key_at, beside key_ids), the pool once a block of four. A page of n positions holds, for each attention layer, its keys, values and indexer keys of n positions and the pooled rows of their n / 4 blocks (cuda_pages.zig); a cache pointer is its layer's part of page 0. Only addresses change, never a sum's order, so paged caches give contiguous bytes at any page size that holds whole blocks. Without our glue (a captured Triton set) a page table is refused. TF_FLASHNEXT_KV_PAGE_TEST=n gives each stream's caches one buffer read through a reversed table of n-position pages (checks only). Prompt-cache saves and restores copy page runs into the same layout, so kept states move between paged and contiguous caches. tf-cuda-test flashnext-pages (also in kernel-contract): six cases, cached lengths to 9000, pages of 16, 48, 128, 256 and 512 positions, two streams shuffled through one arena: queries, indexer queries, block scores, dense and sparse attention rows, the stores and pooled rows equal contiguous over three repeats; attention rows within a float64 bound; guards intact. Red: a swapped table over placed pages, a planted row. Records: the sm_80..121 registers and static bytes of the kernels that moved (nvcc 13.0). GB10, nvidia/Qwen3.8-Flash-Next-FP4-Local, --parallel 4 --context 40960, --no-drafts, ABAB against main: c=1 23.51/23.49 and 23.55/23.44 tok/s against 23.46/23.40 and 23.38/23.48; 8k 5.97-6.91 s against 6.03-7.00 s, 31k 25.64/25.74 s against 25.67/26.01 s; replies equal (3 chats, three ~8k, one 31k). Page test 16: the same bytes, 23.56/23.38 tok/s, 31k 26.08 s. With MTP drafts: drafted == plain 8/8, concurrent == solo 8/8, resumed == fresh (7,147 cached tokens restored into pages), equal to contiguous.
|
Thanks @jschmied for the page table, for keeping every sum in its old order so paged bytes equal contiguous ones, and for the swapped-table and planted-row controls. While this was open we built a Flash Next page pool of our own on the KV pool line for the next release, along the same lines as your Qwen pages; since yours came first, we'll take this PR and #1170 as the base, kept as yours, and fold what ours adds in a separate commit on top. That commit also threads the page table through the attention paths main has gained since your base ( - Synthema, Ash's AI Assistant. |
Carried onto main: zig/src/core/contract/flashnext_tile_records.zig:13 retains #1217's fn_gdn_fused record (384 threads and 82496 shared bytes), while :14 keeps #1169's measured qsa_tile register counts of 218 on sm_120 and sm_121. The paging entry-point records in flashnext_pages_pending.zig stay as authored. Both registrations describe kernels present on this line; neither record replaces the other.
|
Landed on main in 93a215b..35e46c0, with your records under your authorship plus the maintainer fix-ups. Thank you. Measured with the whole group (#1139, #1140, #1143, #1147, #1164, #1169, #1171 and #1170's Flash Next slice) against main on GB10s:
- Synthema, Ash's AI Assistant. |
Branch
fn-paged-kvf23b5ab5onmaind1018b31. Part of #781's follow-ups (other families on the core pool).What this changes
The seven
flashnext_attn.cukernels that touch a stream's caches now take aPgargument: an int page table, theelements in a page, and the positions in a page. They are
fn_attn_prep(_media),fn_qsa_pool(_media),fn_qsa_scoresandfn_attn_chunks(_ahead).pg_at()finds each row:A page of n positions holds, for each attention layer:
A cache pointer is its layer's part of page 0 (layout in
cuda_pages.zig). Only addresses change; no sum changesorder. So paged caches give the contiguous bytes at any page size that holds whole blocks.
TF_FLASHNEXT_KV_PAGE_TEST=nreads each stream's caches through a reversed table of n-position pages. It is forchecks only.
fn_attn_chunkslooks up a key's row once per tile (key_atin shared memory, besidekey_ids), and the pool kernelonce per block of four; the contiguous path pays one uniform branch.
Receipt
Environment: TensorFold
maind1018b31plus this branch; one DGX Spark (GB10, sm_121, CUDA 13.0, nvcc 13.0.88);nvidia/Qwen3.8-Flash-Next-FP4-Local@b9ce18a6.Kernel contract:
tf-cuda-test flashnext-pages, also run insidekernel-contract.one arena.
attention rows, the stores, and the pooled rows.
override set still needs regenerating with nvcc 13.2, which is not on this box.
Served, greedy,
--parallel 4 --context 40960 --no-drafts, ABAB againstmain(c=1 tok/s code/chat, TTFT):The page test's first version (one page-table lookup per 16-byte load) cost +3-4 % at 31k; one lookup per key per tile
removes that.
Gates with MTP drafts, page test 16, compared with contiguous:
Tests: full
zig build test -Dnvcc=/usr/local/cuda/bin/nvccexit 0,zig fmt --checkclean, lean check 0 newfindings;
kernel-contract: 85/85 kernels pass gates 1-4, 7 controls red (exit 1 only frommain's 877 limitproblems).
Gotchas
TF_FLASHNEXT_KV_PAGE_TESTuses pages here. The pool itself is the stacked follow-up, Flash Next CUDA: the streams beside the first take KV pages from the core pool #1170.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. Allthree were measured on the page test.