Skip to content

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
mainfrom
lead/dsv41-metal-trees
Closed

ashhart wants to merge 2 commits into
mainfrom
lead/dsv41-metal-trees

Conversation

@ashhart

@ashhart ashhart commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

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=2 to 4) ended a reply after a few tokens. The Metal verify target never supported tree windows: windowGroup refused any window whose rows weren't one chain (error.TreeWindow), and keep refused 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: TreeWindow at token 46 of 48.

The fix is in the verify logic only, no kernel changes (new metal/tree.zig):

  • The tree splits into chains: one from row 0, and one from each row that isn't its parent's first child.
  • Chain 0 runs on the stream's slot. Each other chain runs on a shadow slot holding the stream's state below the window, in the same launch.
  • A shadow is copied whole the first time, then only the positions committed since.
  • A row run again in front of a branch must choose the same token as on its own chain, or the window errors out.
  • When the kept path is a shadow's chain, the two slot states trade places, so the slot ends exactly as the accepted chain would leave it, and the drafter is pointed at the kept rows.
  • target.zig's launch now takes explicit runs. serve_lanes.Model gains a trees override so tests set the knobs without the environment.
  • Shadows are allocated on the first tree window only: one slot at the context limit each (about 355 MB at 131,072).

Tests:

  • New zig/tests/dsv41_metal/tree_test.zig builds 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.
  • New served case (g) runs one and two siblings: drafted == "draft": false == serial, full reply length.
  • test-dsv41-metal, the Metal package unit tests (14/14) and test-dsv41-draft (137/137) pass on an M5 Max; test-dsv41-metal-serve passes 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.

arm greedy sampled "draft": false prose greedy prose sampled
off 89.3 72.7 51.5 66.7 57.4
TREE=2 89.2 72.5 51.5 66.7 57.2
TREE=3 89.2 72.3 51.4 66.6 57.2

_DUP_MS and _ROWS changed 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.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/dsv41-metal-trees branch from cb235b2 to bd64767 Compare November 14, 2026 12:18
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
ashhart force-pushed the lead/dsv41-metal-trees branch from bd64767 to 18cf706 Compare November 14, 2026 15:09
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
ashhart force-pushed the lead/dsv41-metal-trees branch from 18cf706 to 8eb884f Compare November 15, 2026 11:18
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.
@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Landed on main with #3384, which was stacked on it: its commits are on main as 1b5f9c2 and 0955fe3, and its files on main equal this PR's head. Closing as landed.

  • Synthena (Ash's Agent)

@ashhart ashhart closed this Nov 15, 2026
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.

1 participant