Skip to content

feat(lanes): a prompt pass runs in pieces between the other streams' rounds (dsv41) - #29

Merged
bertholomus merged 2 commits into
bertholomus:deepseek-v41-zigfrom
hashd1ve:dsv41-interleave-pr
Oct 19, 2026
Merged

bertholomus merged 2 commits into
bertholomus:deepseek-v41-zigfrom
hashd1ve:dsv41-interleave-pr

Conversation

@hashd1ve

Copy link
Copy Markdown

What this changes

A prompt pass can run in pieces between the other streams' rounds. Before, a pass ran whole inside its admission, so every stream that was decoding stopped until it ended. On two GB10s, a 400K-token prompt (a restarted agent session, or one whose state was gone) held the other sessions for ~4 min.

Builds on #28 (image caching): this branch carries its commit. Review that one first.

  • The interface. Backend.prefill_part is optional: the same pass in pieces of at most N chunks. With TF_FILL_CHUNKS set and another stream decoding, the lane core runs only the first piece at admission. The stream is then filling, and fillStep runs a piece after every TF_FILL_ROUNDS rounds of the live streams (at once when none decodes). When the pass ends, the stream draws its first token and joins the rounds.
  • Short prompts. TF_FILL_FIRST sets the first piece's chunks, so a turn's new tokens within it run whole, as before.
  • Scope. One pass fills at a time: the host admits the next request when it ends. A cancel or an error in a piece ends that request alone. Unset, every pass runs whole as before.
  • dsv41. prefillFn becomes an opening (slot, extent, images, rank 1's fill, the kept state) plus resumable chunks, with the loop's state in Lanes.fill.
  • Why both ranks stay in step. Rank 1 already joins the read-ahead and drops the prompt's ids at any frame that is not the fill's, so both ranks run the same frames in the same order. Rounds leave the fill's view, rings, spans and image rows alone. A chunk takes Engram rows read ahead before a piece's end when they cover it with both layers; they sit in the read-ahead's own buffers, which rounds do not use, and fillBegin invalidates them for each prompt.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: deepseek-v41-zig at 629c524a plus this change. Two DGX Sparks (GB10, 128 GB each), TP=2 over RoCE with both rails, nvcr.io/nvidia/pytorch:26.07-py3. Checkpoint easthambuilds/DeepSeek-V4.1-Flash-1017-EXL3-2.9bpw at 2913ea75. Served with --context 1048576 --parallel 4, drafts and CUDA graphs on. The live checks below ran on our served build, which is this branch plus fix(server): DSML calls read from their own tags in the native server (the native side of #20) #25.

  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: not run. Instead, 12 greedy chat prompts give byte-identical text to the unpatched engine; a ~7K-token prompt resumed from its kept state, and again after another conversation, gives the same reply as fresh; /tokenize ids for 1,500 random conversations are unchanged.

  • Decode speed before and after, from tools/bench_openai.py: not run. The recipe's kit_bench.py decode --set a gives prose 57.0 → 56.9 and structured 104.9 → 104.3 tok/s.

  • Tests run, with pass, fail and skip counts: zig build test (CUDA host tests, aarch64 Linux) on this branch: 222 pass, 0 fail, 0 skip.

  • Prompt speed before and after, from tools/prefill_cold.py: not run. With nothing else decoding, a pass runs whole as before.

  • For this change, on the server: A streams a long greedy reply; B, a new 56,840-token prompt, arrives meanwhile. Then B is sent again (resumed).

    B's first token A's chunks during B's prompt B again
    without this change (whole passes) 28.9 s 0 same reply
    this change (TF_FILL_CHUNKS=1 TF_FILL_ROUNDS=4 TF_FILL_FIRST=4) 32.7 s 100 same reply

    The 3.8 s are the rounds A gets meanwhile. A first version that dropped each piece's read-ahead and read every chunk twice took 38.4 s; the second commit fixes that.

  • New tests (lane host, fake backend), both failing before this change:

    • With a stream decoding, a six-chunk prompt runs in pieces, the decoding stream delivers tokens between every two pieces, and the new reply equals the fake's continuation.
    • A prompt within the first piece runs whole.
  • Not run, and why: Metal (no Mac set up for this branch; the core change is backend-neutral, and only dsv41 offers prefill_part); the three tools above.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (B interleaved = B resumed alone, and resumed = fresh; draft:false not run)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release. (unset or with nothing else decoding the pass runs whole; with a stream decoding it yields to it, 28.9 → 32.7 s above)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@bertholomus

Copy link
Copy Markdown
Owner

Thank you @hashd1ve for this and for the clear measurements. It is tested and ready, but GitHub cannot merge it now that #28 is in (as 3de79d8). Could you rebase it onto deepseek-v41-zig and drop its first commit? It goes in as soon as you do.

…rounds (TF_FILL_CHUNKS, TF_FILL_ROUNDS)

A prompt pass ran whole inside its admission, so every stream that was decoding stopped until it ended: on two GB10s
a 400K-token prompt (a restarted agent session, or one whose state was lost) held the other sessions for ~4 min.

The backend may offer prefill_part, the same pass in pieces of at most N chunks. When it does, TF_FILL_CHUNKS is set
and another stream decodes, the lane core runs only the first piece at admission; the stream is then `filling` and
fillStep runs a piece after every TF_FILL_ROUNDS rounds of the live streams (at once when none decodes), then draws
its first token and joins the rounds. One pass fills at a time: the host admits the next request when it ends. A
cancel or an error in a piece ends that request alone.

dsv41: prefillFn becomes an opening (slot, extent, images, rank 1's fill, the kept state) and resumable chunks; the
chunk loop's state lives in Lanes.fill between pieces. A piece ends with the read-ahead joined and the prompt's ids
gone, as rank 1 does at any other frame, so both ranks run the same frames in the same order; rank 1 reads ahead
again at the next chunk. Rounds leave the fill's view, rings, spans and image rows alone; the Engram read-ahead of a
chunk is redone when none is pending. Unset, every pass runs whole as before.

Test: a lane host with a stream decoding admits a six-chunk prompt; the decoding stream delivers tokens between
every two pieces, and the new reply equals the fake's continuation of its prompt.
… prompt runs whole (TF_FILL_FIRST)

Each piece ended with the next chunk's Engram read-ahead joined, and that chunk, finding no read-ahead pending, read
its rows from the drive again: every chunk of a pass in pieces was read twice, and a 31K-token prompt went at ~1,500
tok/s instead of ~2,100. A chunk now takes rows read ahead that ended before it when they cover it, both layers: they
sit in the read-ahead's own buffers, which rounds leave alone (a round's Engram reads use the host's others). A
prompt's fill invalidates what was read ahead for another, so rows never cross prompts at the same positions.

TF_FILL_FIRST=N: the first piece runs N chunks, so a turn's new tokens within it run whole, as before.

Test: a prompt within the first piece runs whole, the decoding stream waiting for it.
@hashd1ve
hashd1ve force-pushed the dsv41-interleave-pr branch from 70ab7ab to 78152f2 Compare October 19, 2026 15:58
@hashd1ve

Copy link
Copy Markdown
Author

Done: rebased onto deepseek-v41-zig without the first commit. The resulting tree is byte-identical to the one I tested (git diff against the old head is empty).

@bertholomus
bertholomus merged commit 45c25b1 into bertholomus:deepseek-v41-zig Oct 19, 2026
@bertholomus

Copy link
Copy Markdown
Owner

Merged, thank you @hashd1ve! It went in exactly as tested. A long prompt no longer stops the other sessions, and the read-ahead fix keeps the pieces fast. Thanks also for the quick rebase.

bertholomus added a commit that referenced this pull request Oct 21, 2026
…s (TF #29 on TP4), off unless TF_FILL_CHUNKS is set

TF #29 by @hashd1ve (a27d2f0 + 45c25b1 on deepseek-v41-zig) on TP4's 1.0.12 lane core, devchain dsv41tp4 d125.
TF_FILL_CHUNKS=N steps a prompt pass N chunks of 2048 rows at a time (TF_FILL_FIRST: its first step's chunks), and
the lane host runs TF_FILL_ROUNDS (default 4) rounds of the live streams between two steps, so a long prompt no
longer stops the replies that stream meanwhile. Unset, as served, the family hands the lane core the entries it
handed before (no prefill_step), and every pass runs whole as before.

- core: Backend.VTable.prefill_one (a backend that holds one prompt pass at a time: the lane host admits the next
  request once the pass ends, so its kept-state lookup finds what that pass kept); Info.fill_rounds (the rounds
  between two steps of a pass that began); a first step that the pool cannot place yet (ContextFull) while other
  streams run is requeued as admission does. The CUDA wrapper and the recorder forward prefill_one.
- dsv41: #29's family half (the pass state Fill; prefillPart and fillOpen; release ends a pass in pieces; a
  follower's piece after a round reads ahead again; the read-ahead reset at fillBegin and kept when it covers the
  chunk); steps_vt only when TF_FILL_CHUNKS > 0.
- tests: one pass at a time; fill_rounds rounds between two steps; both vtables forward the same entries but the step.

Co-Authored-By: Manrique <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit a24de00c5e5bb8109ab9528c25b399692f74c217)
bertholomus added a commit that referenced this pull request Oct 21, 2026
The kept-states stack of fill29 (a shared prefix no longer stales the first conversation's kept states; prompts with
lane images keep their states, keyed by the images' digests; a resumed prompt skips the vision tower for the images
it holds; TF_FILL_CHUNKS, unset as served) onto zdirdb's candidate ffa2f163 (the shield, structured output, reply
ids, DSML for tool_choice required, the stats line, d143).

Conflicts:
- families/dsv41/lanes.zig: both sides' fields and release; structured output's first_masked and held in whole_vt
  (steps_vt copies it); the grammar's kept first row in prefillPart after the first token's draw (the lane core
  draws it in the same step: open.zig fillStream, opened, drawFirst); both sides' tests.
- server/prompt.zig: the history renders as the prompt does (renderIdsOf with the lane images), so with
  TENSORFOLD_PLAIN_SPECIALS a lane image's placeholder stays the template's in both and #28's history length
  holds; text requests render as before.

Every other file's change against dc464126 (5f1b1cbe + d143) is ffa2f163's against 89872573 (fbee5419 + d143).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
bertholomus added a commit that referenced this pull request Oct 21, 2026
The four-node line that serves DeepSeek-V4.1-Flash-1017 on four GB10 nodes comes in as its own commits since v0.2.0
(22, six of them merges). This merge keeps the branch a fast-forward of its head with pull requests #30 and #31
(b8b115e).

Against v0.2.0:
- A replay cut uploads its rows' positions into the chunk's aligned buffer (a prompt resumed after a kept text prefix
  no longer stops with MissingTritonVariant).
- Kept prompt states: pull request #26 (@hashd1ve), a prefix two conversations share no longer stales the first one's
  kept states; prompts with lane images keep and resume their states, matched by the images' digests (after #28 by
  @hashd1ve), and a resumed prompt skips the vision tower for the images its kept state holds; a kept state the lanes
  would refuse is passed over for an earlier one.
- TENSORFOLD_PLAIN_SPECIALS: a sender's special-token text stays text, and a lane-vision engine's image placeholders
  stay its image tokens.
- Structured output (response_format json_object and json_schema) through libtfgrammar; TENSORFOLD_GRAMMAR_LIB names
  its file.
- tool_choice "required" and a named function write DeepSeek's DSML calls block, and a forced call's marker is always
  its token.
- The served sampler draws top_k off (0 and -1) and any top_k.
- The draft head's chains counted by depth for /metrics, with an optional stats line (TENSORFOLD_STATS_EVERY).
- Off unless set: TF_FILL_CHUNKS (#29 by @hashd1ve, on TP4: a prompt pass in pieces between the other streams'
  rounds) and TENSORFOLD_REPLY_IDS.

Both sides changed zig/src/families/dsv41/model.zig and prompt.zig. model.zig takes both: #30's neighbor gather beside
the served line's changes. prompt.zig keeps the served line's replayCut, which uploads every cut's surviving positions
into the chunk's own buffer; #31 uploads them for small odd cuts and keeps the view otherwise, and the positions are
the same. #31's CPU test follows the served replayCut (one upload for every cut) and passes on it, and
replay_positions.md says so; the v0.2.0 baseline still fails it as the document says. Every other file is one side's:
40 the served line's, 17 this branch's.

With TF_DS_NEIGHBOR_RDMA unset, #30 opens no neighbor gather and every exchange takes the path it took before. Rank
0's startup settings now carry the neighbor mode (48 bytes, 40 before), so every rank runs the same build.

Thanks @swbiggart for #30 and @mrsergiopascal for #31.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
bertholomus added a commit that referenced this pull request Oct 21, 2026
…, forced tool calls, five contributions

The README's fork note adds what the branch serves since v0.3.0: kept prompt states for image turns too, a shared
4,194,304-position window, structured output and forced tool calls in DeepSeek's DSML. NOTICE lists the new files (the
prompt shield's, and the neighbor transport's document and receipts), every upstream file the branch changes against
1.0.12 (16 more since v0.2.0) and the contributions: Manrique's pull requests #26, #28 and #29, Scott Woolsey
Biggart's #30 and mrsergiopascal's #31. ATTRIBUTION.md adds them, the ideas taken from DeepSeek's DeepInfer and from
xgrammar's structural tags, and @den13501's report behind the stream keepalive. The family's section of
THIRD_PARTY_NOTICES.md names libtfgrammar in a deployment's kit.

The fork note also thanks the branch's contributors by name. ATTRIBUTION.md says that the EXL3 kernel code copied
from TensorFold's Python line was written before 0.6.0 and keeps its MIT notice (LICENSES/MIT.txt), and names the
co-authors the commits' trailers name.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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