Skip to content

feat(dsv41): --learn-conversations - TP2 conversation states spill to disk - #64

Open
0xWhiteMage wants to merge 2 commits into
bertholomus:deepseek-v41-zig-tp2from
0xWhiteMage:feat/dsv41-learn-spill
Open

0xWhiteMage wants to merge 2 commits into
bertholomus:deepseek-v41-zig-tp2from
0xWhiteMage:feat/dsv41-learn-spill

Conversation

@0xWhiteMage

Copy link
Copy Markdown

Summary

Gives dsv41 (DeepSeek-V4.1 TP2 lanes) support for --learn-conversations: kept conversation/prompt states spill to disk through the shared rows.Rows store, on both ranks, instead of being silently lost when the GPU prompt cache evicts them.

Before this change, --learn-conversations was refused for the dsv41 family ("Nemotron only"), and every long-context conversation state lived GPU-resident only — on a 1M-token context service, a handful of sessions evicts an earlier session's entire state, so its next turn pays a complete re-prefill.

Measured on two DGX Spark GB10 nodes over the dual-rail RoCE fabric, ~1M context, 8 streams:

Probe Before After
~979K-token prompt, re-sent after two intervening ~900K sessions 458 s full re-prefill 2.4 s — 841 MiB read back in 373 ms, resumes at token 978,944

How it works

Since #56 a dsv41 Snap owns one contiguous packed prefix (buf) per rank — the substrate this change serializes:

  • families/dsv41/disk.zig (new): a rows.Image over the packed prefix — parts, gather (DeviceBuffer → host), blank, scatter (host → new snapshot), whole (refuses to serialize an incomplete state). Each rank's half additionally lands under ds41-<rows-key>.snap, written atomically via .part + rename, verified by header magic/version + payload checksum on load — partial/corrupt files are rejected.
  • lanes.zig: Snap carries the disk key stamped by the rows writer (tag_disk); the TP2 follower mirrors disk persist/load/forget over the existing framed wire protocol, so rank 0's store and rank 1's halves commit or fail as a unit.
  • native.zig / native/cuda.zig: the snapshot vtable gains rows + tag_disk; the host attaches rows.Rows to the prompt-cache store when --learn-conversations is set.
  • native/cuda_refusal.zig: dsv41 leaves the Nemotron-only gate. The flag remains strictly opt-in — with it unset, the resident-cache path is byte-for-byte unchanged.
  • core (prompt_cache.zig, rows_write.zig, rows_read.zig): a tag_disk vtable hook so the rows writer can stamp a state's disk key before the peer half's file is named.

Design follows the GLM family's existing multi-rank learned-state persistence (per-rank halves, atomic writes, peer lockstep) — the same contract, applied to dsv41's lanes wire protocol.

Dependencies

Stacks on #56 (fix/dsv41-independent-prefix-snapshots, @rhattala): the packed-prefix Snap.buf this serializes does not exist before it. Rebased onto deepseek-v41-zig-tp2 @ ea64a87 with #56's commit included for CI/review; it drops out cleanly once #56 merges.

Testing

  • Two-rank TP2 service on real hardware: --learn-conversations --learn-dir /spill --learn-gib 64
  • A→B→C→A′ probe: state written on keep, evicted under pressure, recalled from disk on next turn (read 978944 tokens from disk, cached_tokens=978944)
  • Both ranks' halves written and restored (rank-1 ds41-*.snap files verified)
  • Output identical vs resident path — decoded continuation coherent
  • Corrupt/partial .snap rejection (checksum path — exercised by construction, synthetic test welcome)

Credit

@bertholomus

Copy link
Copy Markdown
Owner

Thank you @0xWhiteMage for this, and for the measurements and the clear write-up. In one line: dsv41 joins --learn-conversations, with kept conversation states spilling to disk on both ranks through the shared rows store.

We are checking how it should land: it builds on #56, which is still open, and its order against the other open pull requests on deepseek-v41-zig-tp2. We will reply in this thread.

@bertholomus bertholomus added enhancement New feature or request needs-decision labels Nov 23, 2026
@bertholomus

Copy link
Copy Markdown
Owner

Thank you @0xWhiteMage. We are keeping the PR open; the merge waits on three things.

  1. Order. This builds on open fix(dsv41): retain complete packed prefix backing in prompt snapshots #56: fix(dsv41): retain complete packed prefix backing in prompt snapshots #56 lands first, and this then rebases onto the new tip of deepseek-v41-zig-tp2.
  2. Commit 4a88288 lists the bot account as author and carries AI attribution lines. Could you rewrite it with you as author and no attribution lines? 06351c4 keeps its own author.
  3. The default-path receipt. The wire format between ranks changes, so both ranks need this build. We have not run the node check; no date set. Please post equal token hashes on the default path (--learn-conversations unset), in the two-node served layout, on the exact head — after the rebase and the rewrite.

@devin-ai-integration
devin-ai-integration Bot force-pushed the feat/dsv41-learn-spill branch 2 times, most recently from 04efd34 to eaf8b0a Compare November 24, 2026 08:02
@0xWhiteMage

Copy link
Copy Markdown
Author

Done, waiting on #56! Thanks for the notes and double checks, @bertholomus!

… disk

A dsv41 snapshot is one contiguous packed prefix per rank since
fix/dsv41-independent-prefix-snapshots (PR ashhart#56); this makes every kept
conversation state eligible for the shared rows store's disk persistence
instead of being lost on prompt-cache eviction.

- families/dsv41/disk.zig: a rows.Image over the packed prefix (parts/
  gather/blank/scatter/whole) plus each rank's half under
  ds41-<rows-key>.snap, written atomically through a .part file and
  verified by a header magic + payload checksum on load.
- lanes.zig: Snap carries the stamped disk key (tag_disk), the follower
  mirrors disk persist/load/forget over the existing wire protocol, and
  rank 0 coordinates so both halves commit or neither does.
- native.zig / native/cuda.zig: the snapshot vtable gains the rows image
  and tag_disk; the native host attaches rows.Rows when
  --learn-conversations is set.
- native/cuda_refusal.zig: dsv41 leaves the Nemotron-only gate for
  --learn-conversations; the flag stays opt-in.
- core: the snapshots vtable's tag_disk hook lets the rows writer stamp
  a state's disk key before the peer half is named.

Design follows the GLM family's existing multi-rank learned-state
persistence (per-rank halves, atomic files, peer lockstep), built on
the packed-prefix snapshot substrate of PR ashhart#56.

Measured on two DGX Spark GB10s over dual-rail RoCE: a ~979K-token
conversation restored from disk in ~2.4 s (841 MiB read in 373 ms)
where the same prompt previously paid a ~458 s full re-prefill after
two intervening ~900K-token sessions evicted it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants