Skip to content

XPU Qwen3.8-27B: a lone DFlash2 stream draws its tree's width from the lane rule's lone pricing - #3052

Open
Mirrdhyn wants to merge 27 commits into
ashhart:mainfrom
hygurlabs:xpu-lone-tree-width
Open

Mirrdhyn wants to merge 27 commits into
ashhart:mainfrom
hygurlabs:xpu-lone-tree-width

Conversation

@Mirrdhyn

@Mirrdhyn Mirrdhyn commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2897.

A stream served alone with the DFlash2 drafter (--parallel 1) went through LaneHost.lone to XpuLanes.alone, which
verified a fixed 15-node tree every round. At long context 16 verified rows each read the whole context, so a smaller
tree is faster with the same tokens (#2897). This takes that choice through lone_costs, as CUDA's lone round does:

  • alone grows the tree to cap = min(XPU_TREE, 15) on the host (drafter_tree.grow: lattice, noise, best-first
    tree, now also each draft's own log-chance), prices it with lone_costs.choose (prices, allocateDrafts, then
    probe/trial), the one copy of the sequence that windows.zig also calls for an engine lone window, except
    least_rows 2 where windows.zig uses 0, and verifies only the first w drafts (settle). A tree of w nodes is the
    first w pops of the 15-node tree and a child pops after its parent, so the prefix keeps every parent and the accepted
    path is the wide path cut at w.
  • Chances come from Landing.chance(sampled, own) x parent, as cuda_draft.zig does (xpu_dflash2.chances), updated
    with observeTree on the verified prefix. They are not on the Drafter vtable: Drafted reads
    vtable.chances only when facts.chances or tree_nodes > 0, and XPU sets neither.
  • The whole round (lattice, tree, width, verify, the drafter's taps, synchronized at the end) is timed and goes to the
    stream's depth.ms through Rule.observeCost, then lone_costs.observe (dflash2.measured). The first round
    (prefill-to-decode switch) and the first round after a cold drafter-context restart in resumeLone are not samples.
  • A stream files its calibration in Engine.lone_kept when its lone loop ends, at the end or at the hand-over to the
    engine (dflash2.retain, deferred in XpuLanes.alone), and seed starts the next stream of the band from it.
  • XPU_TREE is a cap. Below 2 nodes the width is fixed and nothing is learned (as before).
  • Facts: lone_cost_tile = 4; probes every 4 rows from row 2 (1, 5, 9, 13, 15 drafts).

What the core lacked, and what this extends (small, and CUDA's behaviour is unchanged):

  1. Rule.costs wrote the stream's own table only under plain_guard. XPU leaves plain_guard false so that a shared
    round is not held at 0 drafts. A Who.lone mark (set by lone_costs.marked) now makes Rule.costs use the
    stream's own table for a lone round priced by lone_costs, which XPU's lone driver does (xpu_dflash2.zig).
    lone_costs.enabled still requires plain_guard, as on main, so engine rounds keep main's pricing on every backend
    and shared rounds do not change.
  2. probe started at 1 row, i.e. a draft-less window. Without plain_guard no round is drafted with nothing, so it
    starts at 2 rows (CUDA's schedule with plain_guard, tile 16, is unchanged: lone_costs_test.zig still passes).
  3. lanes.lone_costs is exported so a native backend can call it.
  4. priceOf prices every width from a least-squares line over the sampled widths' excess on the startup model once
    three widths are sampled; with fewer it copies the nearest sample, as before. One round's timing varies by more than
    an extra draft row costs, so a single sample no longer prices a whole group of widths. Only the lone XPU tree asks
    for the line (line = true in xpu_dflash2.width); the engine's lone window passes false and keeps estimate's
    per-width pricing, so main's shared-lane tests are unchanged.
  5. windows.allocate calls lone_costs.choose for a lone window; the shared rounds' counts moved unchanged into a
    sharedCounts helper, to stay within the line budget.

Engine rounds: an engine round of a single live stream (a hand-over from the driver, or a request the lone driver
refuses through lane_host_lone.takes) is priced as on main and writes no lone table. An earlier head of this PR
dropped plain_guard from enabled and priced those rounds too; item 6 in the discussion shows what that won and lost,
and why it was put back.

Exactness: the width only sets how many drafts are verified; the walk keeps the target's own pick (greedy ties to the
lower id, sampled picks keyed by (seed, position, id)).

Measured on one Arc Pro B70 (PCIe 5.0 x16), main 7fb9fc661 and the head c36b7391e (the head's binary differs from
that tree by the wording of one doc comment), with no local patch: zig/src/xpu/rt.zig is main's in both binaries.
Receipt: docs/receipts/xpu-qwen27-lone-tree-width, with every request. The same token_sha256 in each cell across
main's fixed trees of 15, 7 and 3 nodes and the head (greedy 34 to 121,022 tokens, and seeded at 34 and 121,022). Decode
tok/s, the median of 3 requests after a warm-up, a fresh server for each pass; main with XPU_TREE 15 / 7 / 3, the head
with no XPU_TREE:

prompt tokens mode main 15 main 7 main 3 head (nodes a round) head / best fixed
34 greedy 140.5 132.1 91.4 140.4 (13.0) 0.999
34 seeded 154.0 102.2 159.1 (12.0) 1.033
28,946 greedy 36.3 47.5 52.8 53.0 (4.1) 1.003
58,543 greedy 25.7 36.7 43.8 44.7 (3.4) 1.019
121,022 greedy 13.3 21.4 27.5 29.5 (2.3) 1.072
121,022 seeded 14.1 27.5 28.9 (2.5) 1.053

The spread between the 3 requests is 0.1 % or less in main's cells and 2 to 5 % in the head's. Repeat passes of main's 3
and 15 reproduce the first by 0.1 % or less.

  • At 34 tokens the head matches the 15-node tree. On this main the best fixed tree is 3 nodes from 28,946 tokens on;
    the head is +0.3 %, +1.9 % and +7.2 % over it at 28,946, 58,543 and 121,022 tokens, and 1.46, 1.74 and 2.22 times
    main's default of 15 nodes.
  • The first request of each context band on a fresh server is still cold, as designed (48.3 tok/s at 28,946 tokens and
    24.3 at 121,022, against 53.0 and 29.5 afterwards), since the band's prices are not sampled yet; the next request of
    the band starts from the calibration the previous one filed.

Tests: zig build test-shared-lane-regressions-host passes 449 with 1 skip and zig build test-draft-xpu-host passes 21
on the head. New host tests: the width follows the band's measured rounds; XPU_TREE caps; a w-node tree is the prefix
of the 15-node one and the tokens are equal at widths 1 to 15, greedy and seeded; the lone test files its calibration
through dflash2.retain, as the driver does; with enough widths sampled one noisy timing does not move its neighbours'
prices; lone pricing without plain_guard. The host tests drive width/measured directly: none calls
XpuLanes.alone, so the loop's wiring is covered by the device runs and the tables above only. The receipt's device
tests and kernel contract were not rerun on this head; no kernel file changed.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. This is what #2897 asked for: the lone tree's width now comes from lone_costs, and XPU_TREE stays a cap. The deep cells are a big win, 1.58 to 2.04 times main from 28,946 to 121,022 tokens, with one hash per prompt. The exactness argument holds: a tree of w nodes is the first w pops of the 15-node tree (grown and settle in zig/src/xpu/drafter_tree.zig), and the walk keeps the target's own pick. The receipt is thorough, and it helps that it says plainly where the branch falls short.

We also checked who else the core change reaches. lone_costs.enabled (zig/src/core/lanes/lone_costs.zig:15) still needs lone_cost_tile > 0 and a head plan. On main, only Qwen3.5 on CUDA sets a tile, and both of its drafters set plain_guard, so CUDA keeps its current path.

Before it can land

  1. The 34-token cell. The branch is 3.6% below main there (136.14 against 141.23 tok/s). Short prompts are the common case, so we can't land a loss there. XPU (B70) Qwen3.8-27B: on code at 121,022 prompt tokens, drafted decode is slower than plain decode #2897 set the bar at or above the best fixed tree at each depth. Your own log points two ways:

    • The table prices 15 nodes at 43.0 ms from one trial, and 14 nodes at 39.8 ms from many rounds. A width priced from one timing, or from the warm-up's first rounds, shouldn't hold the stream off the cap.
    • A 14-node round on the branch takes 40.4 ms; a 15-node round on main takes 40.1 ms. So part of the gap may be the per-round sync (zig/src/native/xpu_lanes.zig:545) and the host pricing, not only the width. Please measure that overhead on its own.

    The first request in each band also pays the width trials (120 tok/s at 34 tokens). Every fresh server pays that, so please show it beside main's first request.

  2. Rebase. The branch is 136 commits behind main. It conflicts in CHANGELOG.md and zig/src/native/draft_sources_xpu_test.zig, so CI hasn't run. It also conflicts with xpu: serve logprobs and top_logprobs on Qwen3.8-27B #3051, which we'd land first; its Note hook then moves into your walk. With xpu: a sampled Qwen3.8-27B row draws from a top-k kept on the card #2895 and xpu: serve logprobs and top_logprobs on Qwen3.8-27B #3051 in, your 24 lines would take xpu_lanes.zig past 600, and xpu: serve logprobs and top_logprobs on Qwen3.8-27B #3051 is moving its logprob code out to make room.

  3. Sampled speed. The speed table is greedy only. Please add main against the branch at temperature 1.0, seeded, at 34 and 121,022 tokens. You already have these runs for the hashes.

  4. Engine rounds and more streams. A single-stream engine round is now priced from the stream's own table with least_rows 0 (zig/src/core/lanes/engine.zig:234, zig/src/core/lanes/windows.zig:285), so it can pick no drafts. Please post main against the branch for one request the lone driver refuses, such as a structured-output or tool-call request, greedy and sampled. Please add one cell at --parallel 2 or wider. Both need equal hashes.

  5. Two clocks, one table. The driver times the lattice, tree, verify and taps. The engine's round times flush, verify and the late draft. Both write the same keys and share Engine.lone_kept by band (xpu_lanes.zig:522, engine.zig:595). Please keep them apart, or measure the offset and show it doesn't change the choice.

  6. One copy of the pricing. width() (zig/src/native/xpu_dflash2.zig:39-58) repeats the sequence at windows.zig:275-292: seed, prices, allocateDrafts, probe and trial. It also resets the core's round arena from the backend (xpu_dflash2.zig:47). Please move that sequence into one lone_costs function that both call, with least_rows as a parameter, so the two copies can't drift. As XPU (B70) Qwen3.8-27B: on code at 121,022 prompt tokens, drafted decode is slower than plain decode #2897 said, the core is the place to extend.

  7. An existing test. zig/src/core/lanes/lone_costs_test.zig:105 adds s.rounds += 8 to a CUDA test. Please say why. If it makes the check stronger (past the deadline rather than before it), please confirm it also passes on main.

  8. Changelog. Please end the line with (#3052, refs #2897), and update the 34-token figure once item 1 is fixed.

  • Synthena (Ash's Agent)

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Measurements for items 1, 3 and 4, and where item 1 stands. Nothing is pushed yet. I don't have a fix for item 1 (details below), and the 34-token figure in the changelog waits on it. The rest does not: the rebase after #3051 (the Note hook into walk, the line budget, CI), the two clocks, one copy of the pricing in lone_costs, the explanation of s.rounds += 8, and the changelog suffix come with the next push.

All runs: one Arc Pro B70, this branch's parent 52c8f51e7 against its head d71c69445 (not rebased onto current main yet), the receipt's server flags (--parallel 1 --context 132096 --prompt-cache-gib 0), DFlash2, up to 256 new tokens. Every token_sha256 below is equal between the parent and the branch.

Item 1: the 34-token cell

Greedy, 5 fresh servers a side, 4 timed requests each after one warmup.

tok/s, median of 20 ms a round
parent 141.51 40.04
branch, the rule 139.21 (−1.6 %; −2.1 % as the median of the 5 servers' medians, 138.60) 39.21
branch, width forced to 15 141.44 40.07
branch, forced to 15, no pricing, no bookkeeping, no sync 141.51 40.04

The receipt's −3.6 % (136.14 against 141.23) is the same card at 02e26dd51, two passes of three requests. The only change under zig/ since that commit is a comment, so I read 136.14 against 139.21 as protocol and run-to-run spread.

  • Overhead. A probe around the sync at xpu_lanes.zig:545 records 329 µs, but that call is a second synchronize: settle already waits in verifyTree and commitPath (qwen27.zig:488, :521). Removing the sync, the pricing and the bookkeeping moves the round mean from 40.054 ms to 40.040 (σ 0.63, n = 860), so the probe's 329 µs is not time added to the round. width() takes 0.7 µs a round. Forced to 15 nodes with all of it left in, the branch is 141.44 tok/s against 141.51. So the loss is the widths the rule picks, not the sync or the host pricing.
  • 14 against 15 nodes. Forced widths, mean round: 14 nodes, 39.63 ms on the branch (n = 880, σ 0.63) and 39.61 on the parent (XPU_TREE=14); 15 nodes on the parent, 40.05. The receipt's 40.4 ms was 14-node rounds chosen by the rule at 02e26dd51 (40.42, σ 1.37, n = 156).
  • Prices. In this run's steady price table at 34 tokens, 15 nodes is 40.2 ms, close to its forced round (40.1). The widths from 9 to 14 are priced 3 to 6 ms above their forced rounds: 9 nodes at 41.2 against 37.8, 11 at 44.7 against 38.5, 12 at 44.9 against 38.9, 13 at 42.1 against 39.3, 14 at 43.1 against 39.7; 7 nodes is priced at 37.0, its forced round. On steady rounds the rule never picks 11, 12 or 14, picks 13 (the derived best) in 3 % of rounds and 9 in 5 %.
  • First request of a fresh server: parent 128.21 tok/s, branch 120.40 (−6.1 %). Over the 5 servers' first requests (250 rounds) the rule tries 13 widths, 1 and 4 to 15.
  • What the rule picks, and what a fixed tree would give. A tree of w nodes is the first w pops of the 15-node tree, so a round verified at 15 gives exactly what each narrower tree would have accepted in it. I logged that for every round at 34, 7,588, 28,946, 58,543 and 121,022 tokens (checked against rounds actually run at each forced width: identical tokens in all 2,104 matched rounds), and timed rounds at each forced width and depth. Round time is smooth, about 0.4 ms a node at 34 tokens and 21 ms a node at 121,022.
    • Derived tok/s (accepted tokens over round time, not the served rate; the served 15-node tree is 141.51): at 34 tokens, 11 to 15 nodes span 140.2 to 141.0, best 13 at 141.0, 15 at 140.5. At 7,588 the best fixed width is 6 (69.2); 15 is 59.6 and the rule 68.3. At 28,946 the best is 3 or 4; at 58,543 and 121,022 it is 3.
    • On steady rounds at 34 tokens the rule picks 15 nodes in 74 % of rounds and 7 in 16 %. Its expected tokens are not biased toward the narrow trees: on the rounds forced to 15 at 34 tokens (n = 132), expected over accepted runs from 0.95 to 0.99 across widths, 0.971 at 7 nodes and 0.992 at 15.
  • Rules tried offline, on resampled rounds (this does not model how landing learns under each rule). Shrinking each round's expected tokens toward their running mean, with smoothed prices and a minimum of observations, reaches the 34-token plateau and stays above the best fixed tree at 28,946 and 58,543, but misses it by about 1 % at 7,588 and 121,022. One width per context band, from the measured acceptance, does not repair 34 tokens and gives up several tok/s at 28,946 and 58,543. None of the variants is at or above the best fixed tree at every depth.

So I don't have a rule that meets #2897's bar yet. Forcing 15 removes the served loss at 34 tokens, and 15 sits on that plateau (0.4 % under the derived best), but it is far from the best at 7,588, and nothing is measured between those two depths. Sampled, the simulation puts the rule above the cap at 34 tokens (161.7 against 159.2, best fixed 160.2 at 14 nodes) while the served item 3 cell is 0.991, so a cutoff would need its own sampled cells too. Would you review a cutoff in lone_costs (the cap below some context, the per-round rule above it, with measurements on both sides of the cutoff), or would you rather have a change to the per-round estimate, held to the best fixed tree at every depth?

Item 3: sampled

Temperature 1.0, top_k 20, top_p 0.95, seed 7. 5 fresh servers a side, alternating, one warmup and one timed request.

prompt tokens parent branch ratio
34 150.32 (150.19 to 150.34) 148.94 (148.77 to 153.62) 0.991
121,022 10.10 19.09 1.89

Item 4: requests the lone driver refuses, and more streams

The lone driver refuses "draft": false, a JSON schema, tool_choice: "required" and a thinking budget (lane_host_lone.zig:18, the XPU flags at xpu.zig:166); an instrumented build logged no lone-driver round for them. Sixteen engine-round cells (those four, greedy and sampled with seed 7, a short prompt and about 8K tokens): every hash equal. Plain and JSON-schema greedy cells are at 1.000 to 1.003; tool and thinking cells run from 0.94 to 1.11 in both directions and JSON-schema sampled at about 8K is 0.970. These rates were not alternated, and I read the scatter as noise without having shown it. logprobs is refused with HTTP 400 on both sides, since this branch predates #3051.

total tok/s, prefill included parent branch
--parallel 2, two requests at once (34 and 7,588 tokens) 62.42 63.92
--parallel 4, four at once (34 to 30,966 tokens) 20.43 20.40

At both batch sizes each request's hash equals the parent's and equals the same request sent alone.

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. The new runs isolate the overhead, add sampled and engine-round coverage, and keep the hashes equal. The short-prompt gate is still open. These items remain:

  1. zig/src/native/xpu_dflash2.zig:39: fix the width choice under XPU (B70) Qwen3.8-27B: on code at 121,022 prompt tokens, drafted decode is slower than plain decode #2897's best-fixed-tree gate. At 34 tokens it still gives 139.21 versus 141.51 tok/s, and 120.40 versus 128.21 on the first request. A context cutoff needs agreement and measurements on both sides.
  2. zig/src/native/xpu_lanes.zig:522 and zig/src/core/lanes/engine.zig:595: separate the two clocks' calibration tables, or measure their offset and show it leaves choices unchanged.
  3. zig/src/native/xpu_dflash2.zig:39 and zig/src/core/lanes/windows.zig:284: move the shared selection sequence into lone_costs, taking least_rows; remove the backend's arena reset.
  4. zig/src/native/draft_sources_xpu_test.zig:4: after xpu: serve logprobs and top_logprobs on Qwen3.8-27B #3051 lands, resolve the integration, carry its Note hook into walk, and keep the affected modules within 600 lines.
  5. zig/src/core/lanes/lone_costs_test.zig:105: explain s.rounds += 8 and confirm the strengthened check passes on main.
  6. zig/src/core/lanes/engine.zig:234: repeat the slower engine-only request cells with alternating main/head runs; the posted scatter doesn't yet establish noise.
  7. zig/src/native/xpu_dflash2_lone_test.zig:171: run zig fmt; remove the trailing whitespace in docs/receipts/xpu-qwen27-lone-tree-width/exp/scatter-rule.patch:8 too.
  8. CHANGELOG.md:7: update the short-prompt figure once fixed and end the line with (#3052, refs #2897).
  • Synthena (Ash's Agent)

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

@ashhart, where this stands, and why I'm holding the width tuning.

Profiling the verify round at 58,543 tokens (details on #2543): of the 205 ms of profiled GPU time in a 16-row round (15 drafted nodes plus the pending token), 146 ms is attn_decode, 9.1 ms a row, because each tree row reads the prefix on its own. With #2595's grid order a row costs about 35 % less. So at long context the width this PR prices sits on a kernel that is about to change; whether the best fixed tree moves there is not measured. #2799 changes the merge, and on drafted rounds it measured level, so I am not counting on it to move the width.

The short-prompt gate does not depend on those kernels. Local changes, not pushed, bring the 34-token cell to 0.999 of main timed and 1.005 on the first request; 7,588 tokens is still under the best fixed tree (0.958 timed, 0.906 on the first request).

Unless you prefer otherwise, I'll do the non-kernel items from your 14 Nov list now, and finish item 1 once #2595 is in, measured on top of it. For that item I'd also change the approach: our forced-width rounds fit A + B·L + (c + k·L)·R with a 0.7 ms mean absolute error on the averages (2.7 ms at the worst point), which is enough to price widths without trials at long context; on the flat short-prompt band 1 ms is several nodes, so that gate keeps its own check.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn, that plan works for us. Please go ahead with items 2 to 5 now; item 4 still waits on #3051. Item 1 can follow #2595 and be measured on top of it.

For item 1, pricing widths from the fitted cost model is fine at long context. The gate itself stays measured: the 34-token and 7,588-token cells against the best fixed tree, timed and on the first request, at or above it in both. The 7,588-token cell is still under (0.958 timed, 0.906 on the first request), so it needs to close too, not only the short prompt.

  • Synthena

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

@ashhart, items 2, 3, 5 and 7 are in, one commit each on top of d71c69445. Item 4 waits for #3051 and item 1 for #2595, as agreed.

  • 2 (xpu_lanes.zig:522, engine.zig:595), bec308952: the engine keeps one calibration table per clock (lone_kept[clock], backend or wall). A stream that changes clock files its samples under the old clock, through keep's usual rules (nothing is filed after a shared round or from an empty table), then seeds from the new clock's table with fresh probe deadlines. The exits (release, detach and the lone driver's defer) file under the stream's own clock. Three new tests in xpu_dflash2_lone_test.zig cover a crossing, the exits and a detach. engine.zig stays at 600 lines.
  • 3 (xpu_dflash2.zig:39, windows.zig:284), 695278b6e: the shared sequence (prices, allocateDrafts, the tile probe and its trial) is one function, lone_costs.choose(e, a, p, chances, least_rows). The engine passes 0 and the XPU backend 2, and each caller hands it the arguments its own copy used. The backend's arena reset is gone; its temporaries sit in a 2 KiB fixed buffer. The existing lone tests pass unchanged (test-lane-api-host, test-draft-xpu-host). What can change a choice is item 2: after a clock change, the stream reseeds from the other clock's table.
  • 5 (lone_costs_test.zig:105, now :108), 47d19b3ff: in the loop, 8 rounds reaches the first deadline (cost_probe_after, the default Cooldown.spacing), so a width is owed. After the plan is cut to 16 tokens, observing width 17 moves cost_probe_after 8 rounds on; without the added step, the final null would only be that gate. With it the deadline has passed, and null means nothing is owed. That added step alone, applied to main eeeb02650, passes (test-lane-api-host 636/636).
  • 7 (xpu_dflash2_lone_test.zig:171, scatter-rule.patch:8), d91eff6e9: zig fmt on the lone test, and the trailing space in the patch removed.

Lean stays at 386 and zig fmt --check zig/src is clean. The lone_kept line in engine.zig, which the clock split had lengthened, is back under 120 columns.

The branch still conflicts with main, as d71c69445 did (CHANGELOG.md, draft_sources_xpu_test.zig), and now also in windows.zig; I will resolve all three with item 4, in the rebase after #3051.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. The four commits cover items 2, 3, 5 and 7 as we asked. With one calibration table per clock, and prepare filing a stream's samples under its old clock before it reseeds, the backend and wall times stay apart. lone_costs.choose(e, a, p, chances, least_rows) now holds the only copy of the selection sequence, and the backend's arena reset is gone. The note on s.rounds += 8 explains the test, and it helps that the added step also passes on main.

Two items don't wait on #3051 or #2595:

  • Item 6 (zig/src/core/lanes/engine.zig:234): we left this out of our 16 Nov summary, sorry. A single-stream engine round on XPU is now priced from the stream's own table with least_rows 0, so it can pick a round with no draft. Please rerun the slower engine-only cells from 13 Nov (tool call, thinking budget, and JSON schema sampled at about 8K tokens) with main and the head alternating, at least 3 runs a side, so we can tell noise from a loss.
  • Item 8 (CHANGELOG.md:7): please end the line with (#3052, refs #2897). The short-prompt figure can follow item 1.

Item 1 stays as agreed: after #2595, the 34-token and 7,588-token cells at or above the best fixed tree, timed and on the first request of a fresh server, with equal hashes. For the rebase after #3051, one note on zig/src/core/lanes/windows.zig: main now prices shared rounds through verifyPrice on the same allocateDrafts call your choose branch splits, so that path needs to survive for the shared case. In draft_sources_xpu_test.zig, please keep both xpu_dflash2_depth_test.zig and your lone test.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

On 695278b6, zig build test-lane-api-host test-draft-xpu-host -Dcpu=apple_m1 -j5 --summary all passed 611/611 on Apple Silicon with Zig 0.17.0. These cover the host planner and adapter tests. I did not run XpuLanes.alone on an Intel GPU or repeat the 8K timing cases.

The logprob prerequisite (#3051) is now on main through #3722 (a3853e9b9), which is an ancestor of 9ba855b3. The current trial merge still has eight conflicts and #2595 is open. In the test import hunk, keep main's depth and logprob tests (xpu_dflash2_depth_test.zig, xpu_logrow.zig) together with this PR's xpu_dflash2_lone_test.zig so the host gate still covers all three cases after integration.

Igor Lessio - AIFLOW LABS

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Rebased onto main 4c616e63d, which has #3051 through #3722; head 25015ad09. This covers item 4, and item 8 is the last commit.

Item 4

  • draft_sources_xpu_test.zig keeps main's xpu_dflash2_depth_test.zig, xpu_logrow.zig and xpu_sampled_topk_test.zig, plus this PR's xpu_dflash2_lone_test.zig.
  • xpu: serve logprobs and top_logprobs on Qwen3.8-27B #3051's Note hook is carried into walk, follow, settle and treeRound in drafter_tree.zig. It fires at path place 0 and after each descent, as on main.
  • In windows.zig, shared rounds still take the verifyPrice / allocateDrafts path, now in a small sharedCounts helper. Only a lone stream goes through lone_costs.choose.
  • Every touched module is within 600 lines. xpu_lanes.zig and stream.zig are at 600.

Two changes you have not reviewed yet

  1. lone_kept is now indexed [clock][mode][band]. Main's new lone_copy.zig, lone_copy_price_test.zig and lone_copy_sampled_test.zig assumed [mode][band], so they now read lone_kept[0], the backend clock. Copy pricing only runs when lone_cost_tile == 0, so it never shares a table with the XPU wall clock.
  2. To keep xpu_lanes.zig within 600 lines, xpu: serve logprobs and top_logprobs on Qwen3.8-27B #3051's round-landing block (drafted and accepted counts, landed tokens, s.commit) moved from there into dflash2.land in xpu_dflash2.zig, beside a new dflash2.lone. The one change is that the caller now passes the logprob rows, or none, where the block chose them inline.

Checks

  • zig build test-lane-api-host test-draft-xpu-host passes 730/730 on an aarch64 host.
  • zig fmt --check zig/src is clean.
  • tools/pr_check.py --pr 3052 reports 0 errors and 0 warnings, lean 168 vs 168.

No GPU cell was rerun for the rebase. Items 6 and 1 still need the B70.

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Item 6, measured on card 0 (PCIe 5.0 x16), with two changes it led to. Token hashes are equal in every cell, side against side and server against server.

What item 6 found. The six cells (tool call with tool_choice required, thinking budget, JSON schema, each at ~8K and short) all run engine rounds: the lone driver refuses those requests, and the trace shows one engine allocation per round. So they measure this PR's removal of plain_guard from lone_costs.enabled, which puts XPU engine streams on their own price table. At 25015ad09 that wins two ~8K cells (JSON 1.074, tool call 1.042 over main) and loses the thinking cell (0.947) and two short ones (thinking 0.913, JSON 0.893). The short losses come from the table: one round's timing varies by 1.6 to 2.7 ms against 0.4 to 0.5 ms per extra draft row, a single raw sample is copied to the unmeasured widths, and the kept table carries it through the request.

The two changes, pushed as two commits on top of 25015ad09:

  1. estimate prices every width from a least-squares line over the sampled widths' excess on the startup model once three widths are sampled, instead of copying the nearest sample.
  2. plain_guard is back in lone_costs.enabled, so engine rounds keep main's behaviour and the PR's pricing applies to the lone driver only.

Engine cells, main (M) against the new head (G), five servers a side alternating, median decode tok/s:

Cell G/M
JSON schema, ~8K, sampled 1.001
thinking budget, ~8K, greedy 0.961 (M's own servers span 59.1 to 66.5)
tool call, ~8K, greedy 0.999
JSON schema, short, sampled 0.995
thinking, short, greedy 1.000
tool call, short, greedy 1.000

Lone-driver cells (greedy, bench_tree.py), three fresh servers a side alternating M / 25015ad09 (H) / G, one cold request and three timed per depth; warm tok/s, median of the per-server medians:

Prompt tokens M tok/s H/M G/M
34 140.84 0.943 0.999
7,588 58.87 1.127 1.140
28,946 29.43 1.547 1.572
58,543 19.73 1.744 1.776
121,022 9.83 2.120 2.170

plain_guard alone (without change 1) gives the same deep figures as H and 0.962 at 34 tokens, so change 1 is what brings the 34-token cell back to main.

Still open: the first request of a fresh server at 34 tokens is below main in every variant (G 0.937, H 0.959, three samples each): it pays the width trials. The ~8K wins of the engine-round pricing are given up with change 2; I would rather keep the engine rounds at main than ship the short-reply losses. Change 1 sits in estimate, which CUDA shares: the host tests pass (730/730), but I have not run it on a CUDA card.

Checks on the new head: zig fmt --check clean, pr_check 0 errors, lean 168 vs 168, zig build test-lane-api-host test-draft-xpu-host 730/730.

@ashhart
ashhart force-pushed the xpu-lone-tree-width branch from 957e383 to a2ed926 Compare November 21, 2026 23:17
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Hello,

Main has changed how a stream served alone is priced. It no longer keeps separate copy-pricing tables for a lone stream, so that part of your change could not be carried over. What does carry over is the tree width: a lone stream is still marked as lone, its own measured round times still price the width, and a width is still fitted from a line over the sampled widths. Shared rounds and engine rounds keep main's pricing, unchanged.

The numbers in your receipt were measured on an older base and with a local, uncommitted VRAM-guard patch. They no longer describe this rebased result. Please re-measure on current main: the widths chosen at 34, 28,946, 58,543 and 121,022 prompt tokens, the exact reply tokens at each width (greedy and seeded), and decode tokens per second against the fixed 15, 7 and 3 node trees. Then tell us whether the shortfall at 34 tokens and the gains at long prompts still hold.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

The trial merge of a2ed92677 into main 1eed88bb0 applies cleanly. On M5 Max with Zig 0.17.0, test-shared-lane-regressions-host fails to compile in lone_costs_test.zig. The head restored the two-dimensional Engine.lone_kept shape, but four fixtures still index it as three-dimensional or pass &e.lone_kept[0] where slot expects the whole table.

I switched those fixture lookups to own.slot(&e.lone_kept, &stream) in the local trial. That gets the suite running. The shared-lane target then passes 432 tests, skips one, and fails four. The earliest concrete failure in the phase-lock fixture is expected 105 versus observed 1. The noisy-neighbour, plain-guard-disabled, and same-width recovery assertions also fail. Main alone passes all 434 executed shared-lane tests with one skip.

zig build test-shared-lane-regressions-host test-draft-xpu-host \
  test-qwen27-config-xpu-host test-qwen27-prompt-tail-xpu-host \
  -Dcpu=apple_m1 -j4 --summary all

All three XPU host targets pass with the fixture edit. The remaining failures need a decision about the intended width and recovery policy before adjusting those assertions. This check used host fixtures.

Igor Lessio - AIFLOW LABS

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Re-measured on current main (7fb9fc661) as asked, on one Arc Pro B70 (PCIe 5.0 x16), with no local patch: zig/src/xpu/rt.zig is main's in both binaries.

A fix first. On the rebased head, the lone stream lost its calibration at the end of every request. a2ed92677 dropped the retain defer from XpuLanes.alone, and nothing replaced it on that path: a per-round log shows every request starting with no samples. Every request then started from the empty-context startup table (1 29.9, 8 32.7, 16 34.2 ms by rows), opened with 15-node trees and repeated the width trials. At 28,946 tokens a row really costs about 4.1 ms. c36b7391e puts the call back as dflash2.retain, deferred in XpuLanes.alone, and the lone test goes through it instead of calling keep by hand, which is how the test missed it. Once warm, the price table matches the measured round within about 1 ms, and the predicted tokens a round match the observed ones (2.92 against 2.99).

Two more commits on the branch:

  • 12fd5014f: the line over sampled widths is now used only by the lone XPU tree. Before, it sat in lone_costs.estimate, which the engine's lone path shares, and it broke two of main's shared-lane tests (the phase-lock and same-width recovery ones). windows.zig passes false, xpu_dflash2.width passes true, and main's tests are unchanged.
  • The fixture lookups now index the two-dimensional lone_kept.
    test-shared-lane-regressions-host passes 449 with 1 skip, and test-draft-xpu-host passes 21, on the head and on a trial merge into current main.

Numbers. Decode tok/s, the median of 3 requests after a warm-up, with a fresh server for each pass. Main runs the fixed XPU_TREE trees, and the head runs with no XPU_TREE. The reply tokens are identical at every width and in both modes, in each cell: the same token_sha256 across the head and main's 15, 7 and 3.

prompt tokens mode main 15 main 7 main 3 head (nodes a round) head / best fixed
34 greedy 140.5 132.1 91.5 140.4 (13.0) 0.999
34 seeded 154.0 102.2 159.1 (12.0) 1.033
28,946 greedy 36.3 47.5 52.8 53.0 (4.1) 1.003
58,543 greedy 25.7 36.8 43.8 44.7 (3.4) 1.019
121,022 greedy 13.3 21.4 27.5 29.5 (2.3) 1.072
121,022 seeded 14.1 27.5 28.9 (2.5) 1.053

The spread between the 3 requests is under 1 % in main's cells and up to 5 % in the head's. Second passes of main's 3 and 15 reproduce them within 0.1 %.

So, on current main:

  • The shortfall at 34 tokens is gone. It came from the cold start too, and the head now matches the 15-node tree. For reference, the rebased head before c36b7391e measured 132.6 there.
  • The long-prompt gains hold: +0.3 %, +1.9 % and +7.2 % over the best fixed tree. Main's attention is much faster than at the old receipt (fixed 3 at 121,022 went from 20.5 to 27.5), so the best fixed tree is now 3 nodes from 28,946 tokens on, and the head's lead is smaller there.

The first request of each context band is still cold, as designed (48.3 tok/s at 28,946 and 24.3 at 121,022). The receipt in docs/receipts/xpu-qwen27-lone-tree-width/ is updated with these runs.

# Conflicts:
#	CHANGELOG.md
@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Merged main (af42d4e17) after posting: a CHANGELOG conflict only, and the host targets pass (473 of 474, 1 skipped). The measured binary is c36b7391e.

# Conflicts:
#	zig/src/core/lanes/lone_costs.zig
@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Merged main (6e44558d7) again: one conflict in lanes/lone_costs.zig, where main's keepCopies/seedCopies and this branch's choose were added side by side; both are kept unchanged. On the merge, test-shared-lane-regressions-host passes 486 of 487 (1 skipped), test-draft-xpu-host 21 of 21, and zig build test passes.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn for restoring calibration retention, narrowing the fitted-line change, and publishing the raw request records. The fresh first-request acceptance cells are still open.

The receipt's first 34-token request is 121.457 tok/s with adaptive widths versus 127.125 tok/s with the fixed 15-node tree, about 4.5% slower, although their token hashes match. The warmed median does not answer the separate first-request criterion. The receipt also has no 7,588-token request.

Please adjust the cold-probing policy so the first request meets the agreed bar, or call out the cold-start tradeoff explicitly for a decision. Then provide 34-token and 7,588-token results against the fixed 15/7/3-node trees, with at least three fresh alternating servers per side and no preceding warm-up. Equal token hashes and adaptive speed at or above the best fixed tree are still the acceptance criteria. The current merged head needs a fresh run too.

  • Synthena

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Cold first request, as asked: fresh servers, the first request measured with no warm-up, three servers per arm in alternating order (ABCD/DCBA/ABCD), against the fixed 15-, 7- and 3-node trees. The 34- and 7,588-token prompts are joined by 28,946 and 121,022. Everything ran on one B70 (card 0). The head is 48e6f4d89 (main 683c66fe3 merged); main 683c66fe3 runs the fixed trees with XPU_TREE. The receipt section is "First request with a context prior".

Policy change: a band with no retained calibration now draws a fixed prior through its first request, with no probes:

  • 15 nodes under 2,048 prompt tokens (the drafter's window plus one);
  • 7 nodes in band 0 (under 8,192);
  • 3 nodes beyond.

Those rounds are retained, and the next request probes and adapts as before. A --draft-tree or XPU_TREE cap below the prior wins.

prompt adaptive fixed 15 fixed 7 fixed 3 adaptive / best fixed adaptive / fixed 15
34 126.93 127.15 119.90 84.84 0.998 0.998
7,588 67.16 59.16 67.28 57.98 0.998 1.135
28,946 50.09 35.40 45.75 50.32 0.995 1.415
121,022 26.86 13.13 20.93 26.89 0.999 2.045

Median tok/s of three fresh servers. Each prompt gives one token_sha256 across its 12 cells. The adaptive first request draws exactly the best fixed tree's nodes and rounds: 15.00, 7.00, 3.00 and 3.00 nodes a round; 45, 77, 95 and 95 rounds.

Where it falls short: the bar is "at or above the best fixed tree", and the adaptive median sits 0.1 to 0.5 % below it at every depth. With identical trees, that gap is the lone path's per-round work: choosing the width, measuring and pricing the round. I have not isolated it. At 28,946 it is outside the spread between servers (50.08-50.09 against 50.31-50.33).

Why the prior: without it, the first request probed widths 1, 5, 9 and 13 one round each. At depth those rounds are expensive. The first series in the receipt, run on 599d8a56e with the same design, shows the first request at 0.975, 0.950 and 0.876 of the best fixed tree at 7,588, 28,946 and 121,022.

Limits: the prior values (15/7/3) and the edges (2,048/8,192) come from this card and these four depths. Where the 7-node tree stops beating the 3-node tree, somewhere between 8,192 and 28,946, is not measured.

Host tests on the head: test-shared-lane-regressions-host 513/514 (1 skipped), test-draft-xpu-host 22/22.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. The fresh-server series answers the missing 7,588-token and cold-start measurements, and the measured runtime matches this head. The prior now keeps the first request at the best fixed width, with equal token hashes.

The remaining gate is throughput: all four medians are still below the best fixed tree. At 28,946 tokens, 50.08–50.09 versus 50.31–50.33 tok/s has no overlap in the reported runs. Please isolate and remove that remaining overhead, or leave the documented tradeoff for an explicit maintainer decision. The 2,048/8,192 boundaries and mixed prompt lengths within one calibration band also need coverage before generalizing the prior. The shared pricing and retention fixes remain intact.

  • Synthena

This branch has not been deployed

No deployments
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.

3 participants