Repository navigation
feat(qwen3_5 cuda): --checkpoint-slots sets the prompt states the 27B's concurrent decoder keeps - #125
Closed
nood-co1 wants to merge 1 commit into
Closed
feat(qwen3_5 cuda): --checkpoint-slots sets the prompt states the 27B's concurrent decoder keeps#125nood-co1 wants to merge 1 commit into
nood-co1 wants to merge 1 commit into
Conversation
…'s concurrent decoder keeps With --parallel 2 or more, the concurrent decoder keeps KEEP = 3 prompt states. When a main agent and its sub-agent share the server, their calls add states in turn, and each conversation's prompt end is evicted before its next call; the next call then resumes from an earlier message start. --checkpoint-slots now sets that count for Qwen3.8-27B on CUDA (default 3, unchanged). The startup estimate already holds each kept state against the window (stream_geometry), so a larger count leaves a smaller window, and the startup line names it. One stream keeps its 4 states in one attention buffer, so --checkpoint-slots without --parallel 2 is refused before any download, as is a count below 1.
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)
Owner
|
This is a useful knob and a clean change. We measured it on a GB10 with the 27B and DFlash2, --parallel 2, replaying two alternating agent conversations, 12 calls and 163k prompt tokens: the default three kept states let each conversation resume only from its first turn, and --checkpoint-slots 6 let each resume from its latest, so 28% fewer prompt tokens were prefilled, 75,259 to 54,062, and the median time to first token fell from 3.91 s to 2.38 s, for 0.60 GiB more at startup, with every reply identical by token sha. On 0.6.0 one GPU's caches grow with use, so we updated the help and the GPU test's startup line, and the README names the CUDA meaning; without the flag it behaves exactly as next-0.6.0. |
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With
--parallelabove one, Qwen3.8-27B's concurrent decoder keepsKEEP = 3prompt states (Q/engine.py:10). When two conversations share the server, their calls add states in turn, and each conversation's prompt-end state is evicted before its next call. The next call then resumes from an earlier message start and prefills the rest again.This PR lets
--checkpoint-slots, the existing option for cached conversation prefixes, set that count for the 27B on CUDA. The default stays 3. The startup estimate already charges each kept state against the window (stream_geometry), so a larger count leaves a smaller window, and the startup line now names the count.Why
Q/issrc/tensorfold/families/qwen3_5/cuda/. References are atmain(9cd52ab, 0.5.0).MultiDecoderkeeps states in aPrefixCache(keep): a message start at leastMIN_GAPpast the resumed prefix, and the prompt end one token early (Q/multi.py:137-195). Pastkeep, the oldest state never resumed from leaves first (cuda/streams.py,PrefixCache.add).keep = 3, the main conversation's prompt end has left by the time its next call arrives. That call resumes from the last state it still shares: in our logs, a message start 6,024 tokens in, or the 5,470-token system block.Q/engine.py:_drop_extensions). There a larger count does not help, so this PR leaves one stream as it is.We measured it on our own agent traffic, not a public benchmark. A DeepSeek Harness coding agent ran 3 sessions over three public repositories (attrs, itsdangerous, requests), each with a sub-agent. That gave 55 requests (52 main calls and 3 title calls) and 997,402 prompt tokens. We replayed that recorded log twice at its recorded arrival times, each body capped at its recorded reply length, against the same build on one DGX Spark with
--parallel 2:--checkpoint-slotsAt 6 slots, 4 of the 52 main calls resumed from a longer state and none from a shorter one. The 6-slot arm ran second, so part of its TTFT gain may be warm-up. A replay model of the store, using 0.5.0's own
PrefixCache,resume_points,MIN_GAPandentry_end, agrees in direction: 209,319 and 196,316 tokens at 3 and 6 slots. It matches the livecachedon 47 and 51 of the 52 calls.Each kept state costs a window of keys and values. On one GB10 at a 131,072-token window, two streams with 3 kept states are estimated at 74.87 GiB within 104.09 GiB, and each further state at about 8 GiB (16 attention layers × 131,072 × 4 heads × 256 × keys and values × 2 bytes). 6 fits there; 8 does not. So this is the operator's choice.
Change
Q/engine.py:Qwen27Engine(..., keep=None).NonekeepsKEEP(3). The count goes tostream_geometry, to the drafter's geometry (kept=keep + 1), and toMultiDecoder(keep=...). With--tp 2it joins the settings both ranks must share. The startup line reads2 streams of N prompt/reply tokens, K prompt states kept.families/qwen3_5/__init__.py:CUDA_CHECKPOINT_SLOTS = True;cuda_enginepassescheckpoint_slotsaskeep.cli.py:_serve_cudapasses--checkpoint-slotsto families that declareCUDA_CHECKPOINT_SLOTS. The help names the 27B's use.serve_options.py: for the 27B on CUDA,--checkpoint-slotsbelow 1 is refused before any download. So is--checkpoint-slotswhere the effective stream count is one:auto, and any number_parallelturns into 1, such as1,01,+1,0and-1. Other families and backends are unchanged. The MLX server keeps its own meaning, and other CUDA engines still do not read the option.Tests
Host: macOS, Python 3.13, PyTorch 2.11.0 CPU.
tests/test_cuda_cli.py:--parallel, and1,01,+1,0,-1), and below 1.--parallel 2, and on MLX.cuda_enginehands it toQwen27Engineaskeep, andNonewithout it.tests/test_cuda_parallel_admission.py: two ranks started with different counts refuse to start (a new case oftest_two_ranks_with_different_streams_or_context_refuse_to_start).tests/cuda/test_qwen27_checkpoint_slots.py(GPU): two two-stream engines at 8,192 tokens, the default andkeep=5. The decoder keeps 3, then 5. The startup line names the count, and the startup estimate is larger with 5.Without the change (
main's four source files), 10 of the 13 new host cases intests/test_cuda_cli.pyfail. The 3 that pass are the two allowed-combination cases and the case where a family does not declare the option. The new two-rank case fails without the count in the handshake.testswithouttests/cudaandtests/test_qwen4_exp_prefill.py, whose indexer-kernel tests abort the interpreter on this Mac onmaintoo),main(9cd52ab)The same 15 ids fail on both, none in a file this PR changes.
ruff checkon the changed files finds only the two findingsmainalready has inQ/engine.py(a lambda assignment and an unusedresult).GPU status
One DGX Spark (GB10), the
tensorfold-benchimage (PyTorch 2.13.0a0, CUDA 13.3),TORCH_CUDA_ARCH_LIST=12.1, Qwen3.8-27B MLX 4-bit with the DFlash2 drafter, on 0.5.0. The GPU runs used d649f74. 38e1891 adds only the count to the two-rank handshake and its host case, which one-GPU runs do not execute.tests/cuda/test_qwen27_checkpoint_slots.py: 1 passed (62 s).--parallel 2 --context 131072:2 streams of 131072 prompt/reply tokens, 3 prompt states kept, estimate 74.87 GiB within 104.09 GiB;2 streams of 131072 prompt/reply tokens, 6 prompt states kept, estimate 99.41 GiB within 104.15 GiB.NV_ERR_NO_MEMORYor out-of-memory line in either arm."draft": falseall gave the same tokens. A tenth was stopped by our client's time bound before it ended.Submitted by an agent from Blockbrain Labs (https://x.com/blockbrain_labs, https://github.com/blockbrain-ai).