Repository navigation
DeepSeek-V4.1 on Metal: draft trees run whole replies (shadow-slot branches), still off by default - #3326
Closed
ashhart wants to merge 2 commits into
Closed
DeepSeek-V4.1 on Metal: draft trees run whole replies (shadow-slot branches), still off by default#3326ashhart wants to merge 2 commits into
ashhart wants to merge 2 commits into
Conversation
ashhart
force-pushed
the
lead/dsv41-metal-trees
branch
from
November 14, 2026 12:18
cb235b2 to
bd64767
Compare
ashhart
added a commit
that referenced
this pull request
Nov 14, 2026
…; kept branches copy into the slot Review of #3326: the target held one tree state, so two streams' tree windows in one window call (draft/lanes.zig sends every stream's window together and keeps each after) would overwrite each other's chains and shadow, and the first stream's keep would fail with NotAPath. Each slot now has its own tree window (Tree.open, made on the first tree), and all tree windows of a call are prepared first, then their chains run together, R rows a launch. A chain's shadow is one no pending tree holds (its slot's own first, then a free one, another slot's, or a new one), so trees of one round never share a shadow. A kept sibling no longer swaps slot states: its kept rows (window rows, pool and index-key rows), carries, compressor inputs and taps rows are copied into the slot, so the slot's buffers never change and stay the ones the target joined to the weights' residency owner. A new shadow joins that owner when the target did (Resident.tryAddNow, refused past its load limit) and leaves it before it is freed. Tests: the tree target test also runs two slots' trees in every window call (each choice == serial, each kept row's taps == its chain's) and checks the shadows join and leave the residency owner (the fixture can now open with one); served (h) runs two streams with trees on two slots, overlapping, both buying trees, each == "draft": false == serial.
ashhart
force-pushed
the
lead/dsv41-metal-trees
branch
from
November 14, 2026 15:09
bd64767 to
18cf706
Compare
ashhart
added a commit
that referenced
this pull request
Nov 15, 2026
…; kept branches copy into the slot Review of #3326: the target held one tree state, so two streams' tree windows in one window call (draft/lanes.zig sends every stream's window together and keeps each after) would overwrite each other's chains and shadow, and the first stream's keep would fail with NotAPath. Each slot now has its own tree window (Tree.open, made on the first tree), and all tree windows of a call are prepared first, then their chains run together, R rows a launch. A chain's shadow is one no pending tree holds (its slot's own first, then a free one, another slot's, or a new one), so trees of one round never share a shadow. A kept sibling no longer swaps slot states: its kept rows (window rows, pool and index-key rows), carries, compressor inputs and taps rows are copied into the slot, so the slot's buffers never change and stay the ones the target joined to the weights' residency owner. A new shadow joins that owner when the target did (Resident.tryAddNow, refused past its load limit) and leaves it before it is freed. Tests: the tree target test also runs two slots' trees in every window call (each choice == serial, each kept row's taps == its chain's) and checks the shadows join and leave the residency owner (the fixture can now open with one); served (h) runs two streams with trees on two slots, overlapping, both buying trees, each == "draft": false == serial.
…ame launch TF_DSV41_TREE=2..4 ended served replies after a few tokens on Metal: the target refused every window whose parents were not one chain (TreeWindow) and every keep that was not a prefix. A tree window now splits into chains: one from row 0 and one from each row that is not its parent's first child, with the path before it. Chain 0 runs on the stream's slot; each other chain runs on a shadow slot that equals the slot below the window (copied whole when first bound, then only the positions committed since: window rows, pool and index-key rows, carries), all in one launch. A row run again in front of a branch must choose as on its own chain. A kept path in a shadow's chain trades the two slot states, so the slot holds what the accepted chain would; the taps map points the drafter's ingest at the kept rows. Shadows are made on the first tree window. serve_lanes.Model gains `trees` so tests set the knobs without the environment. New tests: the target test runs trees whose main chain, first or second sibling, or a deeper branch wins, and checks every choice against serial decode, every kept row's taps bit for bit against the path run as a chain, and a cached turn after trees against a fresh one; served (g) runs trees with one and two siblings, drafted == draft:false == serial.
…; kept branches copy into the slot Review of #3326: the target held one tree state, so two streams' tree windows in one window call (draft/lanes.zig sends every stream's window together and keeps each after) would overwrite each other's chains and shadow, and the first stream's keep would fail with NotAPath. Each slot now has its own tree window (Tree.open, made on the first tree), and all tree windows of a call are prepared first, then their chains run together, R rows a launch. A chain's shadow is one no pending tree holds (its slot's own first, then a free one, another slot's, or a new one), so trees of one round never share a shadow. A kept sibling no longer swaps slot states: its kept rows (window rows, pool and index-key rows), carries, compressor inputs and taps rows are copied into the slot, so the slot's buffers never change and stay the ones the target joined to the weights' residency owner. A new shadow joins that owner when the target did (Resident.tryAddNow, refused past its load limit) and leaves it before it is freed. Tests: the tree target test also runs two slots' trees in every window call (each choice == serial, each kept row's taps == its chain's) and checks the shadows join and leave the residency owner (the fixture can now open with one); served (h) runs two streams with trees on two slots, overlapping, both buying trees, each == "draft": false == serial.
ashhart
force-pushed
the
lead/dsv41-metal-trees
branch
from
November 15, 2026 11:18
18cf706 to
8eb884f
Compare
ashhart
added a commit
that referenced
this pull request
Nov 15, 2026
…; kept branches copy into the slot Review of #3326: the target held one tree state, so two streams' tree windows in one window call (draft/lanes.zig sends every stream's window together and keeps each after) would overwrite each other's chains and shadow, and the first stream's keep would fail with NotAPath. Each slot now has its own tree window (Tree.open, made on the first tree), and all tree windows of a call are prepared first, then their chains run together, R rows a launch. A chain's shadow is one no pending tree holds (its slot's own first, then a free one, another slot's, or a new one), so trees of one round never share a shadow. A kept sibling no longer swaps slot states: its kept rows (window rows, pool and index-key rows), carries, compressor inputs and taps rows are copied into the slot, so the slot's buffers never change and stay the ones the target joined to the weights' residency owner. A new shadow joins that owner when the target did (Resident.tryAddNow, refused past its load limit) and leaves it before it is freed. Tests: the tree target test also runs two slots' trees in every window call (each choice == serial, each kept row's taps == its chain's) and checks the shadows join and leave the residency owner (the fixture can now open with one); served (h) runs two streams with trees on two slots, overlapping, both buying trees, each == "draft": false == serial.
ashhart
added a commit
that referenced
this pull request
Nov 15, 2026
…; kept branches copy into the slot Review of #3326: the target held one tree state, so two streams' tree windows in one window call (draft/lanes.zig sends every stream's window together and keeps each after) would overwrite each other's chains and shadow, and the first stream's keep would fail with NotAPath. Each slot now has its own tree window (Tree.open, made on the first tree), and all tree windows of a call are prepared first, then their chains run together, R rows a launch. A chain's shadow is one no pending tree holds (its slot's own first, then a free one, another slot's, or a new one), so trees of one round never share a shadow. A kept sibling no longer swaps slot states: its kept rows (window rows, pool and index-key rows), carries, compressor inputs and taps rows are copied into the slot, so the slot's buffers never change and stay the ones the target joined to the weights' residency owner. A new shadow joins that owner when the target did (Resident.tryAddNow, refused past its load limit) and leaves it before it is freed. Tests: the tree target test also runs two slots' trees in every window call (each choice == serial, each kept row's taps == its chain's) and checks the shadows join and leave the residency owner (the fixture can now open with one); served (h) runs two streams with trees on two slots, overlapping, both buying trees, each == "draft": false == serial.
Owner
Author
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.
Stacked on #3321: both add a field to
Target, so this branch carries #3321's commit and lands after it.DeepSeek-V4.1 on Metal: draft trees (
TF_DSV41_TREE=2to4) ended a reply after a few tokens. The Metal verify target never supported tree windows:windowGrouprefused any window whose rows weren't one chain (error.TreeWindow), andkeeprefused a path that wasn't a prefix. So the lane host failed the stream the first time the planner bought a sibling, after about 4 tokens on the release model. The fixture reproduces it:TreeWindowat token 46 of 48.The fix is in the verify logic only, no kernel changes (new
metal/tree.zig):target.zig's launch now takes explicit runs.serve_lanes.Modelgains atreesoverride so tests set the knobs without the environment.Tests:
zig/tests/dsv41_metal/tree_test.zigbuilds trees where the main chain wins, the first or second sibling wins, a deeper branch wins, or nothing wins. It checks every choice against serial decode (greedy and seeded), every kept row's taps bit for bit against the accepted path run as a chain, and a cached turn after trees against a fresh one: 46 trees, 28 state swaps, all equal."draft": false== serial, full reply length.test-dsv41-metal, the Metal package unit tests (14/14) andtest-dsv41-draft(137/137) pass on an M5 Max;test-dsv41-metal-servepasses on an M5 Ultra. Lean: 0 new.Speed: trees stay off by default. Measured on an M5 Ultra on the decode stack (#3287, #3288, #3292, #3296 and gilby's #2973/#2983), 16 prompts at 512 tokens. Every arm's 48 replies equal the reference.
"draft": falseTREE=2TREE=3_DUP_MSand_ROWSchanged nothing beyond noise.On prose, a sibling won 18.5% of tree rounds and added about +0.22 tokens a tree round (+15%). It cost its own verify row (about 5.7 ms) plus the duplicated pending row the planner prices (+1.8 / +2.9 / +5.8 ms at 3 / 4 / 5 rows), about +23% of the round. First-position siblings would pay only without that pending row (tree attention over staged ancestor KV, kernel work not done here) and at a 25-30% win rate.