Repository navigation
flashnext cuda: size the rows-store staging permit from the served window - #5501
Conversation
|
Thanks for fixing the large kept-state staging and small-window loading, @shantanugoel. The new served-window method also enables context-sized cache probes. With conversation learning enabled and an accepted context of 1–13 tokens, the probe takes fewer than seven input tokens and then subtracts seven to form its cache mark, causing an underflow before prefill. At 14 or 15 tokens the mark is zero, which Flash Next cannot keep, so initialization still fails instead of honoring the small context. Please keep the staging size based on the served window, but handle contexts below 16 with a valid probe or by skipping that probe. Boundary coverage for contexts 1, 8, 14, 15 and 16 would protect the fix.
|
|
Thanks, confirmed. Below 16 the probe either underflows (1–13) or marks row 0 (14, 15), and declaring Fixed in
|
|
A CUDA data point for this change, in case it helps review. tensorfold-native 1.3.5 on CUDA sm_120 (one RTX PRO 6000 Blackwell), a Flash-Next family TFQ3 checkpoint with vision, Synthetic repro: a 39,143-token prompt (system message of filler words, one user turn), thinking off,
Our long chat sessions run 80K-100K tokens, so on CUDA spill currently never covers them. Sizing the permit from the served window, as this PR does, is exactly what we need. Happy to run a build of this branch against the same repro and report the before and after. |
…o contexts under 16 load
6d7dd98 to
e9d46b8
Compare
|
Thank you @shantanugoel. 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
Flash Next on CUDA opens its rows store with no served window, so the staging permit stays at 1 GiB: a kept state with more unwritten rows than that (about 31K tokens with the MTP head's rows, 35K without) is skipped with
StagingFull, and after a restart the prompt prefills again. Its kept-state view now declarescontext, as Dory, Gemma 4 and Spark2.5 do, so core sizes the permit to one state at the served window, within the RAM store's budget. This is the CUDA counterpart of #5400.The same declaration bounds the identity probe to half the window, so
--learn-conversationsnow loads at small contexts, wheremainstops withPromptTooLong. Below 16 tokens the window leaves no mark to keep, so the shared probe is skipped (probe seed as its hash, no measured rate).main(51fee3ca7), three commits: the change (b7b66bcba), its changelog line (lines/5501.txt) and the small-context guard (6d7dd9899). The receipt was measured on the change before its rebase (headbd1aa092con89375de45); the two patches are identical (git patch-id), and between the bases the only change in the code it reaches is a comment innative/cuda_kv_pool.zig.atc overlap --json(v0.9.6, read-only, 2026-11-28T10:41Z,origin/mainf6e27fc40): the repository-wide run reports no overlaps but is incomplete (its pull-request and time limits).--pulls 4526,5415,5457is complete: flashnext cuda: opt-in routed plan without the shared expert's empty item (TF_FLASHNEXT_ROUTED_PLAN) #5415 and rows: slice write-behind gathers under a per-file staging cap #5457 clean; flashnext cuda: opt-in multi-CTA HC writeback and norm for decode windows #4526 conflicts incuda_disk.zig, one block both with this head and withmainalone (git merge-tree). The head merges cleanly with thatmain. rows: slice write-behind gathers under a per-file staging cap #5457 (draft) slices the gather described below and keepslongestfor evictions.Checks on this head
6d7dd9899. It adds the guard innative/cuda_kept.zigand its test to3d1a70d9c. On this head:test-host2,809/2,815 steps, 14,480 passed, 85 skipped, 1 failed (the same one; 390 of 1,143 test steps reused from cache);test-golden fuzz-cortheon8/8 steps; lean 93 and 93;test-cuda-kept-host23/23, where the new boundary test panics (integer overflow) without the guard. The receipt below was not re-measured: at 262,144 tokens the guard is not taken.python3 tools/zig/lean_check.py, on the base and on this head: 93 and 93, 0 new.tools/pr_check.py --base origin/main --pr 5501: 0 errors; warnings are three inherited import cycles and no Unreleased bullet inCHANGELOG.md(the line is inlines/5501.txt).CUDA kept: Flash Next's permit takes a state at its served window whole, within the RAM store's budget: fails onmain(expected 262144, found 0), passes with the change (checked on89375de45;zig build test-cuda-kept-host: 22/22).b7b66bcba,zig build -Dfixed-cpu test-host --test-timeout 20m: 2,809/2,815 steps; 32,658 passed, 204 skipped, 1 failed (6 of 1,173 test steps were reused from cache and aren't in these counts). The one failure,Flash Next memory: pack phases … allocation peak(697,244 bytes against the recorded 601,023), also fails on unmodifiedmainat89375de45, and its file is unchanged since.b7b66bcba,zig build test-golden fuzz-cortheon: 33/33.zig fmt --check build.zig zig,git diff --check: clean.dev-tools(macOS). No kernel changes.Receipt
--parallel 2 --prompt-cache-gib 10 --learn-conversations, greedy, 64 tokens):mainStagingFull)StagingFull)Cost: large saves now happen, and each pauses replies once. The state is gathered to host memory on the engine thread. Longest gap between chunks of a reply decoding at that moment:
main(skips)The staged bytes (at most one state at the window, capped by the RAM store's budget; 7,450 MiB at 249,999 tokens) are pageable memory outside the CUDA budget, the question raised on #2337; on a GB10 it is the same memory. Lowest host
MemAvailableover a run saving 163,839- and 249,999-token states, 13 GiB reserve: 23.6 GiB onmain, 16.3 GiB here.--learn-conversationsor--spill-gib.89375de45, headbd1aa092c; Zig 0.17.0, nvcc 13.0.88,-Dgpu=spark; DGX Spark (GB10, sm_121, 128 GB unified), Ubuntu 24.04.5, driver 580.178.04;nvidia/Qwen3.8-Flash-Next-FP4-Local@b9ce18a6, its own MTP head.--context 262144 --max-tokens 32768 --thinking --vision --vision-max-images 50 --learn-gib 200 --learn-daily-gib 150 --learn-min-free-gib 8,TENSORFOLD_MEMORY_RESERVE_GIB=13,TENSORFOLD_RESTORE_PREFETCH_GIB=4.--learn-conversationson one GB10,--context 4096(loads and writes states; no restart at that size) and, on6d7dd9899, contexts 1, 8, 14, 15 and 16 (all load; a completion answers at 16;main89375de45stops at 8 and 16 withPromptTooLong). Not run:--spill-gib(an eviction can't wait for the permit, so one arriving during another large write is still skipped), other CUDA GPUs.--tprefuses--learn-conversationsfor this family.bench_concurrent.py --levels 1,2 --alone --serial --temperatures 0 --tokens 256 --reps 3: 0 unequal, 0 failed (concurrent against solo, drafted against"draft": false); all 90 token hashes equalmain's. The replies resumed from disk after restart have thetoken_shaofmain's cold replies (e5a60f8ef459,d5567ce88931).bench_openai.py, 256 tokens, medians of 3): code 83.95 → 84.12 tok/s, chat 50.53 → 50.47. Two streams, aggregate: code 145.8 → 145.7, chat 92.3 → 92.2. These don't include the one-off pause above.bench_cache.py; every row uncached, hashes equal; seconds to first token,main→ branch):Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.--drafter, no slower than without it, greedy and sampled (steady decode is level; a large save now pauses replies once, above; greedy only, no--drafter).