You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[CUDA] prefix retention does not engage on the CUDA lane: re-sending an identical context still costs a full prefill #98
What works well on this lane (measured on the same box): prefill ~1,597 tok/s at a 1K prompt and ~2,339 tok/s at ~4K; 4 concurrent streams aggregate 92.7 tok/s with every reply equal to its solo run; and 0.3.6.3 lets a full 262144 window fit on CUDA (0.3.6.1 refused 262144 and capped out at ~226,981).
What does not work: prefix retention across turns. With a real multi-turn conversation (each turn appending ~25 tokens), every turn pays a full prefill — and re-sending a byte-identical context costs exactly as much as a fresh one:
turn
prompt_tokens
prefill wall (max_tokens=1)
1
15,061
6.37 s
2
15,086
6.39 s
3
15,112
6.44 s
control: resend the identical context
15,123
6.44 s
15,061 tokens ÷ 6.44 s ≈ 2,340 tok/s, i.e. the full prefill rate — no reuse. The same shape holds at ~2.3K (1.11 → 1.14 s per turn, and 1.15 s for the identical resend). The server log contains no snapshot / prefix / checkpoint lines at all during these runs, so the retention machinery appears not to engage on this lane.
Why it matters to us.#68 added the retention + spill + --checkpoint-slots machinery and validated it on MLX (its notes say tests/cuda was not run); #72 describes exactly our shape — a shared system block with only the ~20-token tails prefilled. Our workload is a fixed ~20K system prompt with pure-append turns (a coding agent loop). On this box, llama.cpp reuses that prefix at 0.10 s TTFT for the same shape, and that single property is what currently keeps us on the other engine for multi-turn work; TensorFold's prefill is ~3x faster per turn, so if retention worked here it would be the better engine outright.
Ask
Is prefix retention supposed to work on the CUDA lane today (i.e. are we missing a flag, or should --prompt-cache-gib / --checkpoint-slots / --snapshot-dir apply here as they do on MLX)?
If it is MLX-only for now, is CUDA retention on the roadmap? We are happy to run test builds and report numbers — including the multi-turn control test above, which is cheap to reproduce.
Happy to provide the launch script and raw logs if useful.
Reproduced on a second DGX Spark (GB10), container nvcr.io/nvidia/pytorch:26.07-py3. Default tensorfold serve, so no--checkpoint-slots, --prompt-cache-gib or --snapshot-dir (your launch line has them, we did not test with them). One request at a time, temperature 0, 32 output tokens. The same 11,053-token prompt sent three times in a row. Released 0.3.7 and 0.4.0 (pip). main is 0.5.0 now, not run by us.
Model
version
prefill run 1 / 2 / 3
cached in the engine block, run 2 / 3
Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP
0.3.7
4.74 / 4.57 / 4.56 s
0 / 0
Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP
0.4.0
4.89 / 5.96 / 5.86 s
0 / 0
Vontra/Qwen3.8-27B-MLX-4bit + DFlash2
0.3.7
7.32 / 0.11 / 0.11 s
11,048 / 11,052
Vontra/Qwen3.8-27B-MLX-4bit + DFlash2
0.4.0
6.96 / 0.11 / 0.11 s
11,048 / 11,052
The token hash is identical across the three runs on every row. So an identical resend is fully re-prefilled on Flash Next (the lane in this issue) and resumes on the 27B.
This matches the code. On the 27B, the 0.3.6.3 changelog says the entry is kept one token before the prompt's end (entry_end in families/qwen3_5/cuda/engine.py), so a resend is a strict prefix of a cached entry. On Flash Next (families/qwen4_exp/cuda/engine.py on main at 9cd52ab), _decode remembers the full prompt (self._remember(list(prompt), ...), line 288) and _resume requires len(ids) < len(prompt) (line 241), so an identical prompt can never hit. Reading only, not tested as a fix: keeping the Flash Next entry at len(prompt) - 1, like the 27B does. GLM-5.3-Flash and Qwen3.6 MoE store the full prompt too according to the code, we did not measure them.
Thanks for catching this. An identical resend on CUDA was prefilling the whole prompt again, because the kept state sat at the full length, and 0.6.0 now keeps that state one token early on Flash Next, Qwen3.6, Nemotron and GLM, with the replies matching a fresh run. On Flash Next, an 18.7k-token prompt, the resend went from 8.3 s to 0.08 s and a thinking-on next turn from 8.4 s to 0.14 s, on one stream and at four streams. Qwen3.6's repeat of a 2k raw prompt went from 0.26 s to 0.04 s, Nemotron's raw 8k resend from 1.05 s to 0.03 s, and its 64k chat resend from 11.18 s to 0.11 s. GLM's resend went from 0.98 s to 0.04-0.07 s, and a thinking-on next turn from 0.61 s to 0.32 s. Flash Next's fix is @benthecarman's #124, and this is in 0.6.0, out tonight.
Activity
docs: triage notes for parked upstream issues (ashhart#85, ashhart#87, …
Nipale-ai commentedon Sep 30, 2026
Reproduced on a second DGX Spark (GB10), container
nvcr.io/nvidia/pytorch:26.07-py3. Defaulttensorfold serve, so no--checkpoint-slots,--prompt-cache-gibor--snapshot-dir(your launch line has them, we did not test with them). One request at a time, temperature 0, 32 output tokens. The same 11,053-token prompt sent three times in a row. Released 0.3.7 and 0.4.0 (pip).mainis 0.5.0 now, not run by us.cachedin the engine block, run 2 / 3Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTPVontra/Qwen3.8-Flash-Next-MLX-4bit-MTPVontra/Qwen3.8-27B-MLX-4bit+ DFlash2Vontra/Qwen3.8-27B-MLX-4bit+ DFlash2The token hash is identical across the three runs on every row. So an identical resend is fully re-prefilled on Flash Next (the lane in this issue) and resumes on the 27B.
This matches the code. On the 27B, the 0.3.6.3 changelog says the entry is kept one token before the prompt's end (
entry_endinfamilies/qwen3_5/cuda/engine.py), so a resend is a strict prefix of a cached entry. On Flash Next (families/qwen4_exp/cuda/engine.pyonmainat 9cd52ab),_decoderemembers the full prompt (self._remember(list(prompt), ...), line 288) and_resumerequireslen(ids) < len(prompt)(line 241), so an identical prompt can never hit. Reading only, not tested as a fix: keeping the Flash Next entry atlen(prompt) - 1, like the 27B does. GLM-5.3-Flash and Qwen3.6 MoE store the full prompt too according to the code, we did not measure them.Raw request rows and engine blocks are in our field-report repo: https://github.com/Nipale-ai/local-llm-field-reports/tree/main/reports/2026-09-30-tensorfold-issue98-prefix-retention (that report covers 0.3.7; the 0.4.0 rows can be added on request). Happy to test a branch on the Spark.
Runs and write-up by AI agents working for Niklas Lenz (Devin, Claude).
feat: Mac prompts fill side by side (#90), exact CUDA token probabili…
fix(glm cuda): GLM-5.3 keeps prompt prefixes inside the KDA chain (#98)…
fix(glm): the MTP head stays beside DFlash2 by default; TF_GLM_MTP=au…
feat(cuda): RTX 40 cards (compute capability 8.9); a kept GLM prompt …
ashhart commentedon Sep 30, 2026
Thanks for catching this. An identical resend on CUDA was prefilling the whole prompt again, because the kept state sat at the full length, and 0.6.0 now keeps that state one token early on Flash Next, Qwen3.6, Nemotron and GLM, with the replies matching a fresh run. On Flash Next, an 18.7k-token prompt, the resend went from 8.3 s to 0.08 s and a thinking-on next turn from 8.4 s to 0.14 s, on one stream and at four streams. Qwen3.6's repeat of a 2k raw prompt went from 0.26 s to 0.04 s, Nemotron's raw 8k resend from 1.05 s to 0.03 s, and its 64k chat resend from 11.18 s to 0.11 s. GLM's resend went from 0.98 s to 0.04-0.07 s, and a thinking-on next turn from 0.61 s to 0.32 s. Flash Next's fix is @benthecarman's #124, and this is in 0.6.0, out tonight.
Nipale-ai commentedon Oct 1, 2026
Correction: the Qwen3.6 MoE engine also keeps prefixes at message boundaries, so my note on it was incomplete. I have not measured either family.
feat: Mac prompts fill side by side (#90), exact CUDA token probabili…
fix(glm cuda): GLM-5.3 keeps prompt prefixes inside the KDA chain (#98)…
fix(glm): the MTP head stays beside DFlash2 by default; TF_GLM_MTP=au…
feat(cuda): RTX 40 cards (compute capability 8.9); a kept GLM prompt …