Repository navigation
feat(dsv41): TF_DS_RESUME_ANYWHERE, an opt-in resume at the reply's end (not bit-exact, default off) - #6
Closed
willjriley wants to merge 1 commit into
Conversation
…ot bit-exact, default off) With TF_DS_RESUME_ANYWHERE=1, a kept prompt also keeps full snapshots (every layer's window ring, the compressor inputs and the drafter rings) at the prompt's own end and at its reply's end, and keeps the reply's rows, so a conversation's next turn resumes after the reply and fills only its new rows. Full snapshots may sit inside a later prompt's last window; boundary snapshots keep their old limit. Prompt processing may start anywhere and then follows the PREFILL_CHUNK grid. A kept prompt holds only its newest TF_DS_RESUME_FULL_KEPT (default 3) full snapshots: where it resumed, its prompt's end and its reply's end. Without that cap each turn's two full snapshots (~11 MB each) accumulate under the upper-half rule of _kept_marks (a simulated 300-turn session peaked at ~2.8 GB of snapshots against ~0.9 GB with the flag off). The boundary rules apply to boundary snapshots only, and _covered no longer needs a covered prompt's superseded full snapshots. Replies are not bit-exact with a fresh prefill in this mode, so it is opt-in. Default 0 keeps today's exact behaviour and code paths: with the flag off every snapshot is a boundary one and nothing changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
Thank you @willjriley — and thank you for opening it as a question first; that's exactly right for a change that touches exact output. Honest answer: an opt-in resume that isn't bit-exact doesn't fit the rule this fork keeps (a continued prompt must equal a fresh one), and in maintenance mode we can't carry a second, non-exact resume path. As you suggested, closing it — please do keep it as a local patch. The measurement (1,570 mostly re-read rows and ~44% of turn time before the first token on a ~660k session) is a great writeup of why the kept-window design costs what it costs. Thanks again. |
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.
Opening this as a draft to ask first: CONTRIBUTING asks for an issue before a change that touches exact output, and
issues are off on this fork, so the code comes along to make the question concrete. If an opt-in mode that isn't
bit-exact doesn't fit the rules, please close it and we'll keep it as a local patch.
Thanks for TensorFold. We run
deepseek-v41-tp2(measured on 808eb4a; this branch is on today's 90b68e0) TP=2 on two DGX Sparks with the Mia EXL3 2.9 bpw pack(
TF_DS_KEEP=1,TF_DS_PREFILL_CHUNK=2048,TF_DS_REPLAY=1), mostly for long agent sessions: thinking on, tool calls,a few hundred tokens per reply, contexts of 100k-700k tokens. We know this touches the exact-output rule (a resumed
prompt equals a fresh one), so it's entirely your call.
What we see
An agent turn's prompt is the previous prompt + the previous reply + a tool result. A kept prompt resumes at its last
kept chunk boundary (below
len - windowwith replay), so every turn re-reads the tail of the previous prompt and thewhole previous reply before reaching the new rows. On a real ~660k-token session (thinking on, effort high) that was a
median of 1,570 rows processed per turn, nearly all of them re-read, and 2.45 s before the first token. Replies there
are short tool calls (median ~170 tokens), so waiting for the first token was ~44% of the model's time on those turns.
We understand why it's built this way: a continued prompt's chunks are a fresh prefill's own chunks, so its reply is the
fresh reply.
What this adds (opt-in, default off)
TF_DS_RESUME_ANYWHERE=1(+79/-19 across engine.py and multi.py):decoder half too, under replay), the compressor inputs, and the drafter rings, ~11 MB per rank each. The reply's ids
are kept as keys, so a continuation that sends the reply back unchanged resumes right after it.
_matchmay pick a full snapshot anywhere below the prompt's last row; boundary snapshots keep today's limit.prefill_stepsmay start anywhere and then follows thePREFILL_CHUNKgrid, so boundary snapshots stay on it.Why it holds together on V4.1, as far as we can tell:
_compressalready handles an unaligned start (compress ratiosare 0/1/2 against the 64-row positional store); every drafter
absorbsetsabsorbed, sodraft()'s assertion holdsafter a resume; a decode round's absorb runs before
_finish, so the reply-end drafter rings are current; andsnap(e)runs after the chunk's forward, replay rows included.
Measurements (flag off vs on; synthetic rows on the same build)
reply is not bit-identical to a fresh one (in our A/B the wording diverged after a few words, e.g. "template" vs
"structure"; coherence and grounding unchanged). Fresh prompts stay byte-identical with the flag on.
was an estimated ~11% faster (the off figure is modeled from that session's earlier turns), because generation
dominates.
before a tool-call block as content, while the final message strips it. A client that rebuilds its history from the
stream sends the reply back with extra newlines, so the reply's rows no longer match and the turn falls back to the
prompt-end snapshot (still past the old boundary). That fix stands on its own: fix(server): stream no trailing whitespace before a tool call #5 ("fix(server): stream no
trailing whitespace before a tool call"). With it, the overnight run above resumed at the reply's end on
324 of 326 turns, replies up to 4,287 tokens included; both misses were client-side history edits (an older message
shortened, and an identical retry).
went partial -> pass, one borderline prompt-injection scenario partial -> fail); a separate 130-case safety run had
0 unsafe outcomes with the flag off and 0 with it on; spark-bench v6.8.0 T3 TrueScore 92.4 vs 92.4, with lower latency
(median 2.16 -> 1.97 s).
Not in this draft yet
the reply's end with the flag on, and replies stay byte-identical with it off.
TF_DS_RESUME_ANYWHEREand the snapshot capTF_DS_RESUME_FULL_KEPT(default 3) are easy to change.Question
Would an opt-in, default-off mode like this be welcome? We'd gladly adapt it to your style or flag naming. And if
you see an exact way to get most of this (we looked at smaller chunks and at message-aligned chunk ends; neither paid off
at long context), we'd much rather use that.