Skip to content

fix(qwen4_exp cuda): resume identical resends and thinking turns - #124

Closed
benthecarman wants to merge 1 commit into
ashhart:mainfrom
benthecarman:investigate-testing-5090-5060-spark
Closed

benthecarman wants to merge 1 commit into
ashhart:mainfrom
benthecarman:investigate-testing-5090-5060-spark

Conversation

@benthecarman

@benthecarman benthecarman commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #98.

Flash Next kept each prompt's state at its end, and a resume needs a strictly shorter prefix. So an identical
resend, or a next turn with thinking on (which renders the last prompt token differently), always prefilled in
full. This keeps the entry at len(prompt) - 1, as the 27B does, for one stream, --parallel and --tp 2.

One DGX Spark, Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP, 11.7K-token prompt, time to first token:

main this PR
Same prompt again 5.2 s 0.07 s
Next turn, thinking on 5.2 s 0.13 s
Next turn, thinking off 0.20 s 0.20 s

The same holds with --parallel 4, and every reply equals its "draft": false reply. The kept state is taken
inside the chunk that holds it, as the 27B's prefill does, so a prompt costs no extra forward.

Kept entries ended at the prompt's end, and a resume needs a strictly
shorter prefix, so an identical resend or a next turn with thinking on
(which renders the last prompt token differently) always prefilled in
full. Keep the entry at len(prompt) - 1, as the 27B engine does, cut
inside the chunk that holds it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Arminova

Copy link
Copy Markdown
Contributor

I tested this branch (326fe7f) against main (9cd52ab) on one DGX Spark (GB10). Both ran from source on the same NGC PyTorch 26.07 based image: Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP, --parallel 5 --context 262144 --kv-dtype int8 --mtp-drafts 6 --mtp-confidence 0.60 --ple-on-ssd --thinking, temperature 0.

Each case is a two-turn chat. Turn 1 is a document of N tokens plus a question. Turn 2 sends turn 1's reply back, reasoning stripped as clients do, plus a new question. Times are the server's prefill_s: the median of 3 runs up to 64k, one run at 128k and 200k.

context turn 1, main turn 1, this PR turn 2, main turn 2, this PR cached, this PR
2k 0.92 s 0.91 s 0.93 s 0.130 s 1,992
16k 7.08 s 7.01 s 7.11 s 0.132 s 15,785
64k 30.74 s 30.58 s 30.81 s 0.134 s 65,225
128k 66.95 s 66.76 s 66.96 s 0.139 s 131,169
200k 112.50 s 112.75 s 112.54 s 0.141 s 206,920
  • On main, turn 2 had cached 0 at every size. The cold prefill is the same on both, so the kept point costs nothing.
  • On the resumed turn, a fact placed at about 80% depth came back correctly at every size from 2k to 200k.
  • The same 11,162-token prompt sent four times in a row took 5.14 s, then 0.064, 0.060 and 0.061 s, with cached 11,161 each time. A regenerate after that resumed too, and so did the next turn after it.
  • On this branch, tests/cuda/test_flashnext_multi.py, tests/test_cuda_ignore_eos_engines.py and the prefix and resume tests in tests/cuda/test_flashnext_forward.py (-k "prefix_reuse or chunks_and_resumes or kept_one_token or family_hook") pass, 60 of 60. I didn't test --tp 2, since I have one GPU.

A test worth adding: the same prompt twice in a row after a hit. When a request resumes from exactly its kept point (keep_at == begin), the entry has to be stored again at len(prompt) - 1. I made an independent version of this fix (#143, now closed) that stored the whole prompt in that case. After that, every other identical resend missed: hit, miss, hit, miss. This PR gets it right (e.kept = resume if keep_at == begin). But test_flashnext_multi.py and test_prefix_reuse_and_the_serial_switch send the repeated prompt only once after a hit, and my version passed both of them. A third identical request would catch it, for example in test_flashnext_multi.py:

same = run(longer, 10)       # the same prompt again: all but its last token kept
assert same.cached == len(longer) - 1 and same.out == warm.out
again = run(longer, 10)      # and again: the point it resumed from is kept once more
assert again.cached == len(longer) - 1 and again.out == warm.out

The same extra request would fit in test_prefix_reuse_and_the_serial_switch and test_flashnext_tp.py.

ashhart added a commit that referenced this pull request Sep 30, 2026
…t resends resume (#124), streamed tool calls (#114)

- CUDA prompts take bf16 activations by default; --prefill-fp8 restores FP8 prompts; both ranks agree on the precision;
  block-scaled FP8 checkpoints load (#126)
- Flash Next keeps each prompt's state one token early, so identical resends and next thinking turns resume (#124)
- Tool-call arguments stream as they are written on the CUDA server (#114)
- Before M5, Flash Next hyper-connection projections of 8+ rows run in 8-row tiles with the per-row bits
- --checkpoint-slots on CUDA (#125)
@ashhart

ashhart commented Sep 30, 2026

Copy link
Copy Markdown
Owner

We measured your fix, ported to 0.6.0's prompt passes, on a GB10 with Flash Next and an 18.7k-token prompt: an identical resend's time to first token fell 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 --parallel 4 alike, and every reply is identical to before and to a fresh prefill without drafts. On 0.6.0 prompts also fill packed passes that can share a decode round's forward, so we added the same one-token-early cut there, with a test. Arminova's GB10 run of the branch showed the gap at long context, with turn 2 at 200k going from 112.5 s to 0.141 s, and Arminova's hit-miss-hit observation became the third identical-resend test.

@ashhart ashhart closed this Sep 30, 2026
@benthecarman
benthecarman deleted the investigate-testing-5090-5060-spark branch September 30, 2026 21:33
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…t resends resume (ashhart#124), streamed tool calls (#114)

- CUDA prompts take bf16 activations by default; --prefill-fp8 restores FP8 prompts; both ranks agree on the precision;
  block-scaled FP8 checkpoints load (ashhart#126)
- Flash Next keeps each prompt's state one token early, so identical resends and next thinking turns resume (ashhart#124)
- Tool-call arguments stream as they are written on the CUDA server (#114)
- Before M5, Flash Next hyper-connection projections of 8+ rows run in 8-row tiles with the per-row bits
- --checkpoint-slots on CUDA (ashhart#125)
wojo added a commit to wojo/TensorFold that referenced this pull request Oct 25, 2026
…e, lifted from the DeepSeek port)

Spill v2's family-neutral, GPU-free store, the DeepSeek port's core/spill/ as
it stands on that port's engine, lifted onto v1.0.7 (whose direct_io has the
same API): kept states in 2,048-token blocks that turns and forks of a
conversation share (the id chain salted with the lineage names them, so a
later turn writes only its own blocks), small per-point sections, writes
staged through the write-at-keep ring (a kill keeps only fully published
points), recovery at open, reads through read slots with all-rank presence and
validation, and room made by conversation (issue ashhart#122) under a cap, a disk
floor, a quota and a turn bound.

- The namespace prefix is the family's (Config.prefix; GLM's is glm-spill-),
  and open prunes only that family's other builds, names of exactly
  <prefix><16 hex>, so GLM and DeepSeek can share one spill folder.
- Kept although GLM uses only the first (with KV sharding) and not yet the
  second: owner-sharded layouts (a part-salted lineage, a foreign part's
  block size) and picture points (manifest version 3); a text point is
  written as version 2.

Switch: none (a library). Nothing calls it before the GLM tier (the spill
blocks patch): with no store opened nothing changes, and Zig's lazy analysis
leaves it out of the server binary. Tests: the DeepSeek store's tests (format,
recovery, crash points, lineage, eviction, concurrent reads) plus a GLM-shaped
check of grid turns, the family prune and prefix refusals; its mutants are
caught.

Measured on the pair: under the GLM tier in round 2's image (g2; the spill
blocks patch says what).

Credits: Robert Wojciechowski (GitHub @wojo, X @rwojo); spill v2's block store
design (2,048-token blocks, lineage, the write-at-keep ring, release and fsync
order): BadAd84 (https://github.com/BadAd84),
MiaAI-Lab/GLM-5.3-Flash-EXL3-2x-DGX-Sparks-TensorFold#118; GLM patches 0088
and 0110, MiaAI-Lab/GLM-5.3-Flash-EXL3-2x-DGX-Sparks-TensorFold#78 and ashhart#124.
@ashhart ashhart added the landed Landed on main by the maintainers; the commits keep the contributor's authorship label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CUDA] prefix retention does not engage on the CUDA lane: re-sending an identical context still costs a full prefill

3 participants