Repository navigation
kv pool: a window's pages go back once their readers are done, and sliding attention reads through page tables (#2444 P4, step 1) - #3353
Conversation
|
Thanks @laudney, this is a careful first step for P4. Keeping the retire state in its own file behind one field keeps One thing needs a change before this lands:
A question for the next step rather than an ask here: Optional suggestions:
On the receipt: since no served path changes, this step doesn't need main-against-branch numbers. Could you attach the device run's output (the full
|
|
@ashhart thanks for the careful read. Two new commits answer it; the head is now
On Checks on Device test:
|
|
@jschmied, the required change is in and the host tests pin it: a step retires under the forward's token and Your answer on the Nothing to change from us. The next step of #2444 - the Gemma 4 sliding layers on these pages behind the
|
C5 of ashhart#2444: a sliding window gives back the pages behind it while its stream runs. A retired page carries the token of the last forward that may read it until its last holder lets it go, waits pending until settle passes that token, and only then is free; the lease's promise for it comes back at settle, so no count names a page that is not free and no run takes a pending page. The state lives in one field, allocated at a pool's first retire.
P4 of ashhart#2444: a window helper lays a family's sliding layers out as bands in pool pages of its full pages' rows, each band its own table on one page-major lease. Before each forward it retires the pages no kernel can load again and covers the rows ahead, all or nothing, and it hands a keep each band's pages from the window's first loaded row.
P4 of ashhart#2444: the head dim 256 paged attention kernels already start at a window's first key and find each key's page by its absolute position, so the host now admits a window with pages there. Contract cells and a device test show the paged path gives the ring kernel's bits, with NaN in every page below each window, so no kernel reads a page a stream has retired.
Window.step settled its own forward's token before that forward ran, and settle is pool-wide, so it could free another lease's page retired under the same token while that forward might still read it. A step now only retires under its token; the caller settles the token once the forward's work is done, before the window's next step, and the window's promise covers one step's retired pages until then. Tests settle after each forward, show a page retired for forward t staying out of take, runs and available() until settle(t), and show a full pool's credit backed by reclaiming a kept page.
reclaimable() subtracted waiting(), which scanned every page of the pool once any page had been retired. The retire state now keeps a list of the pages that carry a token, each with its place in the list, so waiting() scans only those and a page leaves the list in constant time when its token clears. The scan oracle checks the list and waiting() against a full scan, and the first retire's allocation failures are covered at all five allocations.
e0ea94b to
d16fd18
Compare
|
Thank you @laudney. 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. |
What this changes
P4 of #2444 (sliding windows on pool pages, D4 and C5), its first step: the pool calls, a window helper and the kernel admission a sliding layer needs to keep its rows in pool pages. No family calls them yet, so every path today runs as before.
trimfrom the end)kv.retirement.retire(pool, lease, i, token)gives entryiback now; the page is reused only aftersettle(token), once the last forward that may read it is donesettle, so no count ever names a page that is not free; a page is reused only after the caller settles, once the forward's work is donetake, runs,available(),reclaimable()kv_window.zig, not used yet: bands of sliding layers in pages of the full group's rows (one logical page index for both groups); before each forward it retires the pages no kernel can load under that forward's token, which its caller settles once the forward's work is done, and covers the rows ahead, all or nothing; its promise covers one step's retired pages until that settle; a keep gets each band's pages, a resume places copies at their indexkv_pool.zigkeeps its length (564 lines): the new state lives inkv_pool_retire.zigbehind one field, allocated at a pool's first retire. Before any retire, every freed page goes to the free stack as today.reclaimable()scans only the pages that carry a token, not the whole pool.TF_KV_WINDOWS, then Spark2.5, Dory and Kolibri-1).ff9a4f77bthe window step leavessettleto its caller,e0ea94b6bthe waiting count over marked pages).atc overlap --json: incomplete today (its time and request limits), so the files of all 357 open pull requests were compared and each overlappingkv_pool.zigmerge tried: one-line hunks with flashnext: pool lanes keep their states and draft as pieces on whole pages, no run (#2444 P3, F2) #2898 and flashnext: the MTP head's streams by row through the lease's pages, no per-lane block outside the pool (#2444 P3, F2 part c) #2992 (the landing train; the merged file is 599 lines), qwen3_5 cuda: a pool lane's state as pieces on any whole pages of its lease, no run (#2444 P3, Q3) #2939, GLM on CUDA: owner-only latent rows and owner-computed attention (TF_GLM_KV_SPLIT, #1431 part 2; stacked on #2415) #2935, GLM on CUDA: the prompt history fetch under the latent split (TF_GLM_KV_SPLIT, #1431 part 3; stacked on #2935) #2937, GLM on CUDA: kept states, carries and prompt twins under the latent split (TF_GLM_KV_SPLIT, #1431 part 4; stacked on #2937) #2938 and GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415 (the top import andfinish's loop), none of them hard; this rebases after the train lands.zig/tests/cuda/main.zigchanges one help line; cuda window attention: a decode row merges and computes partials only over chunks it has keys in #3123 (window_attention.zig) merges clean.Checks on this head
zig build test: passed (712 of 712 steps; 3067 tests, 3026 passed, 41 skipped);zig build test-cuda-host: 6711 passed, 31 skipped;zig build test-kv-pool: 93 passed;zig build test-window-rows-host: 9 passed;zig build compile-cuda-tests: builds;zig fmt --check build.zig zigandgit diff --check: clean.zig build test-goldenpassed on 91edde8; the two new commits touch only the pool's retire state and the window helper, which no golden reaches.Receipt
retire,settle,skipor the window helper, and none passes a window with pages, so no served path changes. The pool's shared paths are covered by the host suites above: before any retire,freeOrPendfrees exactly as before and nothing is held.kv_window.zig(no caller yet), the CUDA window attention host checks.Kernel contract
tf_wrows_part_256_pg+tf_wrows_merge_256_pg) and paged prompt rows (tf_wrows_prompt_256_pg,tf_wrows_prompt_256_p32_pg) are now admitted with a window. Cells: decode at 32/16 heads, window 1024, and 16/8 heads, window 512; prompt rows (bf16 P, and P32 with image rows) at 32/16, window 1024; all with pages of 256.SUMMARY(sm_121, filtered towindow_pagesandwindowed paged):16 kernels: 16 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 6 limit problems, exit 1 from the limit problems alone. They are register counts off the records (for example 108 against 110, 62 against 48 fortf_wrows_merge_256_pg) with threads and shared bytes equal: the images were built by nvcc 13.5 and checked against nvcc 13.3's records, and no kernel source changes here. The full output is in the comment below.tf-cuda-test window-pages-512, which now also runswindow_pages_slide_tests.zig): head dim 256 windowed decode over shuffled pages of 256 and 512 (31B's 32/16 at window 1024 with 2 streams, E4B's 8/2 at 512 with 3; rows at the first key, inside the first window, on page and window edges, scattered, the end) and prompt rows, bf16 P and P32 (at 0, across the window, far past it), with NaN in every unused slot and every page wholly below each stream's window: PASS, bit-equal to the ring kernel, so no kernel reads a page a stream has retired.Host: the pool's retire, settle and skip (83 then 93 kv-pool cases): a page waits for its readers with every count and notice exact (checked against a scan of the pages); a page the store keeps is pending when evicted before settle, free when evicted after it, and backed through the reclaim chain when a credit needs it; no take or run gets a pending page; a failed settle grants its credit later and once; each allocation of a retire fails without a change; a share into an empty entry; the window helper's geometry for Gemma 4 31B (5 layers a band, 10 bands, no padding), Kolibri-1 (10, 4, none) and Gemma 4 26B-A4B (2, 13, 20 %), its live bound over a prefill and a decode with the caller settling after each forward, its band tables, keeps, resumes, and failed takes and table writes with exact retries; two leases on one pool, where another lease's page retired for forward t stays out of
take, runs andavailable()while the window steps for forward t, untilsettle(t); and a full pool whose credit at settle reclaims a kept window page from the store. Planting immediate reuse fails four cases; planting a settle inside the window's step fails the two-lease case; planting the old promise fails the prefill case.Checklist