Skip to content

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
bertholomus:deepseek-v41-tp2from
willjriley:feat/dsv41-resume-anywhere
Closed

willjriley wants to merge 1 commit into
bertholomus:deepseek-v41-tp2from
willjriley:feat/dsv41-resume-anywhere

Conversation

@willjriley

Copy link
Copy Markdown

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 - window with replay), so every turn re-reads the tail of the previous prompt and the
whole 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):

  • A kept prompt also keeps full snapshots at its prompt's end and at its reply's end: every layer's window ring (the
    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.
  • _match may pick a full snapshot anywhere below the prompt's last row; boundary snapshots keep today's limit.
  • prefill_steps may start anywhere and then follows the PREFILL_CHUNK grid, so boundary snapshots stay on it.
  • A kept prompt holds only its newest 3 full snapshots (otherwise a long conversation accumulates two per turn).
  • With the flag off nothing changes: our explicit-seed replies were byte-identical to the same build without the patch.

Why it holds together on V4.1, as far as we can tell: _compress already handles an unaligned start (compress ratios
are 0/1/2 against the 64-row positional store); every drafter absorb sets absorbed, so draft()'s assertion holds
after a resume; a decode round's absorb runs before _finish, so the reply-end drafter rings are current; and snap(e)
runs after the chunk's forward, replay rows included.

Measurements (flag off vs on; synthetic rows on the same build)

off on
Synthetic agent session, 107k context, 1,000-token replies, small tool results: median wait 2.03 s 0.41 s
Same, rows processed per turn (median) 1,896 37
280k context, ~1.2k-token tool results: median wait 3.15 s 2.06 s
Real agent session, ~660k context, thinking on: median wait (off = the same conversation earlier that day) 2.45 s 0.47 s
Real session: turns that resumed at the reply's end - 24 / 27
Overnight real agent sessions, with the streaming fix below: turns that resumed at the reply's end - 324 / 326
Same night: total wait before first tokens (off = estimated from the same turns) ~802 s 326 s
Same night: whole session time (off = estimated) ~2,572 s 2,096 s (19% less)
Decode tok/s (synthetic) 74.8 75.6
Draft acceptance (synthetic) 0.688 0.679
Fresh 111k-token prefill (on ran second) 67.3 s 64.9 s
  • The cost is exactly the guarantee: a resumed turn's rows come from decoding rather than from a prompt chunk, so its
    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.
  • Generation speed doesn't change; only the wait before the first token does. On the high-effort session the whole task
    was an estimated ~11% faster (the off figure is modeled from that session's earlier turns), because generation
    dominates.
  • The 3 misses on the real session had one cause, outside this patch: with tools, the server streams the whitespace
    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).
  • Quality, flag on vs off (same seeds, engine otherwise idle): tool-eval-bench v2.7.0 90/100 vs 90/100 (one 5-turn chain
    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

  • A test. If the approach is welcome, we'll add one that fails before and passes after: a continued turn resumes at
    the reply's end with the flag on, and replies stay byte-identical with it off.
  • Naming. TF_DS_RESUME_ANYWHERE and the snapshot cap TF_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.

…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]>
@bertholomus

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants