Skip to content

lanes: shared rounds price plain overhead apart from drafted rows (refs #2605) - #2687

Merged
ashhart merged 16 commits into
mainfrom
lead/s368-pricing-r2
Nov 16, 2026
Merged

ashhart merged 16 commits into
mainfrom
lead/s368-pricing-r2

Conversation

@ashhart

@ashhart ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

What this changes

The lane core's depth rule prices a shared round (several streams in one forward) from one fitted overhead. A plain round (no drafts) and a drafted round paid the same overhead, so on hosts where drafted rows cost more per row than plain ones, sampled drafted rounds were underpriced. #2605 shows the result on HIP: sampled chat at 4 streams on Qwen3.6-35B-A3B was 6% faster with --mtp-drafts 0.

Shared rounds now measure plain overhead on its own, refresh it with bounded plain rounds, and fit row costs from both plain and drafted widths. Until a plain observation exists, the rule keeps main's depth choices and timing. Verify widths no longer pay twice for held drafts. Families that set a separate shared head price (GLM, shared_step_ms) keep it on the new paths.

Only how many drafts a round asks for changes. Every reply's tokens are unchanged, since acceptance never depends on the price.

Checks

  • zig build test-lane-api-host passes on this head. zig fmt --check, the lean check (no new problems), and files at most 600 lines.
  • Each new rule has a test that fails without it.
  • Served A/B, main against this branch, tokens equal:
    • Metal, Flash Next MLX 4-bit on an M3 Ultra: 1 to 8 streams, chat and code, temperature 0 and 1, three runs each, level within run-to-run spread.
    • CUDA, Qwen3.6-35B-A3B with MTP on a GB10: level.

Needs

The gain is expected on HIP, where #2605 was measured, and we have no HIP machine. @AbrahamCete, could you run #2605's cell on this head: sampled chat at 4 streams, drafts on against --mtp-drafts 0 and against main? That decides it.

Refs #2605.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

/atc depends 2777

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

This lands after #2777, which lets a learned row cost fall below the table. When I rebase this onto main, shared_price's row excess (max(0, ...)) gets the same rule: a fall that clears the noise test lowers the price, bounded at the plain width.

  • Synthena (Ash's Agent)

@AbrahamCete

Copy link
Copy Markdown
Contributor

@ashhart the gfx1151 run of #2605's cell on 09eeab351. Arms: M, its merge-base on main f3df2d323 (it holds #2652 and #2661); D, the head with default drafts; N, the head with --mtp-drafts 0. Qwen3.6-35B-A3B-MLX-4bit-MTP, one fresh server a run (serve --parallel 4 --context 4096 --prompt-cache-gib 0) in the order M D N N D M; bench_concurrent --tokens 256 --reps 3 at temperature 1.0 then 0, 1 then 4 streams. Tokens are equal in every cell across the three arms.

Aggregate tok/s, both runs of each arm:

prompt, T, streams M (main) D (head) N (head, no drafts) D vs M D vs N
chat, 1.0, 1 95.8, 95.5 97.6, 96.8 82.1, 81.9 +1.6% +18.5%
chat, 1.0, 4 160.4, 161.2 154.7, 160.5 164.4, 163.9 -2.0% -4.0%
code, 1.0, 1 107.8, 107.3 108.6, 107.0 82.1, 81.8 +0.2% +31.5%
code, 1.0, 4 170.2, 164.4 166.3, 169.1 155.9, 155.6 +0.2% +7.7%
chat, 0, 1 94.2, 98.0 99.7, 98.2 84.5, 84.5 +3.0% +17.1%
chat, 0, 4 200.3, 202.7 203.5, 202.9 200.2, 199.9 +0.8% +1.6%
code, 0, 1 122.9, 122.1 122.8, 122.2 97.5, 97.6 +0.0% +25.6%
code, 0, 4 228.1, 241.3 228.5, 227.2 224.1, 224.0 -2.9% +1.7%

So on this GPU the head is level with main inside the run spread (main's own two runs differ by up to 5.6%), and the issue's cell does not close: sampled chat at 4 streams is still faster without drafts, by 4.0% on the head. On main today the same gap is 2.0%, and it was 6.0% when the issue was opened.

What the rounds did in the sampled 4-stream window (rounds of four streams, code and chat together, by how long they took; here a plain round takes 24.2 ms, an 8-row round about 38.5 ms and a 16-row round about 59 ms):

run rounds under 30 ms 30-48 ms 48-70 ms mean ms
M1 900 534 (38% of round time) 49 (6%) 317 (56%) 36.9
M2 773 3 (0.3%) 673 (82%) 97 (17%) 41.0
D1 703 11 (0.9%) 515 (65%) 177 (34%) 43.3
D2 718 6 (0.5%) 494 (60%) 218 (40%) 44.6
N1 1,524 1,511 (98%) 4 (0.4%) 9 (1.3%) 24.2
N2 1,524 1,512 (98%) 3 (0.3%) 9 (1.3%) 24.2

The head runs a plain round now and then (11 and 6 of about 710) and settles on drafting in both runs, with a third or more of the round time in the 16-row rounds. Main's two runs settle differently from each other, one mostly on plain and 16-row rounds and the other on 8-row rounds, and land on the same tok/s.

With two runs an arm I'd read ±3% as spread. Only D against N on sampled chat at 4 streams has both runs of one arm below both of the other. I can repeat this on the rebased head once #2777 is in, and attach the lane traces, serve logs and summaries if they help.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Thanks @AbrahamCete, this is the run that decides it, and the round histograms are exactly what we needed.

Our reading:

  • No regression. The head is level with main inside the spread of main's own two runs, and tokens are equal in every cell across all three arms.
  • The cell doesn't close. Sampled chat at 4 streams is still 4.0% faster with drafts off, and that's the only cell where both runs of one arm sit below both runs of the other. So this head doesn't do what it set out to do on your GPU, and we won't land it as it stands.
  • Where the price goes wrong. At four streams an 8-row round takes about 38.5 ms against 24.2 ms for a plain round, so it only pays when each stream gains about 1.6 tokens a round from one draft, roughly 59% acceptance. Sampled chat at 1.0 likely sits below that, yet D1 and D2 settle on drafted rounds and run a plain round only 11 and 6 times out of about 710. The rule is either pricing drafted rows too low on this GPU or holding too high an acceptance estimate for those streams.

Yes please to the lane traces, D1, D2 and N1 if you still have them. The rule's priced round time against the measured one, and each stream's acceptance estimate next to its real accepted count, will show which of the two is off. The serve logs help too. Nothing else is needed from you for now.

This waits on #2777, which lets a learned row cost move off the table's value. Once that's on main we'll rebase, correct whichever side the traces point to, and ask you for one more run of this same cell.

  • Synthena (Ash's Agent)

@AbrahamCete

Copy link
Copy Markdown
Contributor

@ashhart the traces and logs: https://gist.github.com/AbrahamCete/ca9edeeb15f6b479ff06d4ea94a620ab

  • ab-trace-{D1,D2,N1}.jsonl are the lane traces of the whole server run, and ab-windows.txt gives each window's start and end on the same clock.
  • ab-serve-{D1,D2,N1}.log are the serve logs; each done line has the request's rounds and accepted=a/d.
  • The summaries I quoted from are there too, plus ab-accept.txt (below).

One limit before you read them: the trace holds what ran, not what the rule expected. Its lines are submit, fill and round, with times, the stream count and a row range. It has no priced round time and no acceptance estimate, and it doesn't record a round's drafted rows either; I told the 8-row and 16-row rounds apart by their duration. So these files give the measured side only.

The measured side for the sampled 4-stream window, from the done lines:

run prompt accepted/drafted drafted a stream-round tokens a stream-round
D1 chat 1206/2035 (0.59) 1.10 1.65
D2 chat 1249/2099 (0.60) 1.16 1.69
D1 code 1587/2578 (0.62) 1.75 2.08
D2 code 1684/2775 (0.61) 2.01 2.23
M1 chat 452/869 (0.52) 0.33 1.18
M2 chat 1226/2024 (0.61) 1.10 1.67

So chat on the head accepts 0.59 to 0.60 of what it drafts, right at the break-even you worked out, and gains 1.65 to 1.69 tokens a stream-round.

For the priced side I can run the cell once more on a build that prints, at each decision, the rule's price for the plain and the drafted options and each stream's acceptance estimate. If you'd rather choose what gets printed, push a debug commit or name the values in depth.zig and shared_price.zig, and I'll run exactly that.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

@AbrahamCete thank you, these lined up cleanly. With the windows file, each rep's done rounds match the trace's stream-rounds exactly, so the counts below are solid.

The traces point at the price, and at its plain side.

This head prices a plain round from its own trial rounds. The first comes at a stream count's 64th round, then another whenever the price is 256 rounds old, and each moves the price a fifth of the way. At four sampled streams your first trial landed in the code half and took 28.6 ms (D1) and 29.4 ms (D2). N's plain code rounds at that point took about 24.2 ms. It was the server's first all-plain four-row round, so a one-off cost fits. The later trials, in chat, took 21.8 to 25.0 ms. At a fifth per trial, though, the plain price averaged about 27.0 ms (D1) and 28.1 ms (D2) through chat, against the 23.3 ms N measures.

The drafted side looks right. A round in the 8-row bucket took 38.1 ms in both runs, and the rule's price for it should come out within a few percent of that. That part assumes the load-time table matches the token-per-row timings you posted on #2605, and I can't check that from the trace.

So the line moved. At 38.1 against 23.3 ms, one draft per stream pays above about 0.63 acceptance. Against the plain price the rule held, it pays above 0.35 to 0.41. Your chat drafts land at 0.59 to 0.60, below the real line and well above the one the rule saw.

Acceptance is off only at the start of each request. 97 of the 99 sixteen-row rounds in chat fall in a request's first 30 rounds. Each new stream starts from the default estimates (0.85, 0.75, 0.70) and takes a couple of dozen rounds to come down to about 0.6. That's 16 to 18% of chat's four-stream time, a smaller cost than the plain price.

#2777 doesn't change this, since Qwen3.6 on HIP doesn't learn row costs.

The fix we have in mind is small. A stream count's first plain trial becomes a warm-up, and each later trial replaces the stale price instead of moving it a fifth. Only how many drafts a round asks for changes, and replies stay the same.

When it's up, one more run of this cell (M, D and N at 1 and 4 streams, greedy and sampled) would settle it. And yes please to printing the priced side. We'll push a commit that prints, for each shared round, the trial flag, the rows and draft depths, the rule's plain and per-row prices, and each stream's acceptance estimates, plus the load-time cost table and head step at start. That will check the drafted-side figures above, which I could only infer.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

@AbrahamCete the fix from your traces is on this branch (ef572a5cb0), plus the price log you offered to run.

  • The fix (zig/src/core/lanes/shared_price.zig): a stream count's first plain trial is a warm-up and its sample is dropped, and each later trial replaces the plain price instead of moving it a fifth of the way. Natural plain rounds still blend as before, and drafted rounds feed only the drafted side. Only how many drafts a round asks for changes, so replies stay identical. In a host fake built from your trace (the first all-plain four-stream round 4 ms slow, an 8-row round 1.63x plain, 0.6 acceptance), the old head drafted on all 307 settled rounds. This one moves the four streams to plain rounds once the second trial lands (0 of 495 draft). Where drafting clearly wins, it keeps drafting.
  • The log: TF_SHARED_PRICE_LOG=1 prints one line per shared round, with the trial flag, rows and draft depths, the plain and per-row prices, and each stream's acceptance estimates, plus the cost table at start.

Could you rerun #2605's cell on this head when your GPU is free? That's M, D and N as before, at 1 and 4 streams, greedy and sampled, with TF_SHARED_PRICE_LOG=1 on one D run. If sampled chat at four streams now matches or beats --mtp-drafts 0, with the other cells level, this is done. It still lands after #2777.

  • Synthena (Ash's Agent)

@AbrahamCete

Copy link
Copy Markdown
Contributor

@ashhart the rerun of #2605's cell on ef572a5cb, same setup as before: M is the merge-base f3df2d323, D the head with default drafts, N the head with --mtp-drafts 0; Qwen3.6-35B-A3B-MLX-4bit-MTP, one fresh server a run in the order M D N N D M, then one more D run with TF_SHARED_PRICE_LOG=1 (kept out of the D columns).

Short version: tokens are equal in every cell and the head is level with main. By aggregate_tps, sampled chat at four streams is still 3.4% behind no drafts (it was 4.0% on 09eeab351). By steady_tps it is 1.0% ahead, and it already was on 09eeab351 (+0.8%). On this GPU the gap in that cell is the ragged end of the batch, not the rounds the rule picks.

aggregate_tps, both runs of each arm:

prompt, T, streams M (main) D (head) N (head, no drafts) D vs M D vs N
chat, 1.0, 1 98.5, 97.2 93.4, 100.8 81.9, 81.8 -0.8% +18.6%
chat, 1.0, 4 151.5, 157.3 159.1, 158.4 164.5, 164.1 +2.8% -3.4%
code, 1.0, 1 107.8, 107.1 106.9, 107.1 81.7, 81.7 -0.4% +31.0%
code, 1.0, 4 170.2, 164.3 169.9, 166.9 156.1, 155.9 +0.7% +7.9%
chat, 0, 1 98.1, 99.6 99.6, 100.5 83.9, 83.8 +1.2% +19.3%
chat, 0, 4 202.1, 201.9 203.4, 200.7 200.5, 199.9 +0.0% +0.9%
code, 0, 1 122.6, 123.7 122.3, 123.0 97.1, 97.3 -0.4% +26.2%
code, 0, 4 243.7, 240.5 229.5, 243.9 224.5, 224.1 -2.2% +5.5%

steady_tps (every stream live) at four streams, same runs:

prompt, T M D N D vs N
chat, 1.0 169.4, 168.7 173.4, 171.9 171.1, 170.7 +1.0%
code, 1.0 179.9, 177.8 180.5, 175.5 160.2, 160.1 +11.1%
chat, 0 211.8, 212.0 213.5, 210.6 210.1, 209.5 +1.1%
code, 0 252.1, 248.7 236.8, 252.3 231.1, 230.7 +5.9%

Why the two disagree. Without drafts the four streams make a token a round each and all end on the same round. With drafts they drift apart, and the batch's makespan is its slowest stream's. Sampled chat at four streams, when each request of a rep got its last token (seconds after the batch's first):

run rep 1 rep 2 rep 3 all four live
D1 5.38, 5.81, 6.20, 6.59 5.56, 5.93, 6.24, 6.44 5.37, 5.69, 6.28, 6.49 78-82% of the makespan
D2 5.58, 5.79, 6.28, 6.52 5.37, 5.61, 6.18, 6.76 5.58, 5.92, 6.38, 6.43 76-83%
N1 6.27, 6.27, 6.27, 6.27 6.28, 6.29, 6.29, 6.29 6.28, 6.28, 6.28, 6.28 96%
N2 6.29, 6.29, 6.29, 6.29 6.28, 6.28, 6.28, 6.28 6.29, 6.29, 6.29, 6.29 96%

So with drafts the first two requests finish 0.4 to 0.9 s sooner than without, the third about level, and the fourth 0.2 to 0.5 s later. aggregate_tps divides by that last one.

What the price log shows (the logged D run, four sampled streams, 746 priced rounds):

  • The prices match the clock once they are in. In the chat reps a plain round takes 24.8 ms (the log reads forward 22.00 plus plain 2.1 to 2.7), an 8-row round 37.7 ms and a 16-row round 52.4 ms.
  • The rule's pick is right inside a full-width round. It drafts one deep on most chat rounds: 299 of 417 are 8-row rounds, 71 are plain, 26 are 16-row. Accepted over drafted on chat is 0.60, so an 8-row round makes 6.4 tokens in 37.7 ms, about 170 tok/s, against 161 for a plain round.
  • The first 128 rounds run unpriced. The first trial (the 64th round) is dropped and the second (the 128th) sets the price, 3.23 ms. Until then the rule drafts three deep: 117 of those 128 rounds are of more than 8 rows, 59.7 ms on average. Here the code reps come first and absorb them, and code still wins.
  • Three streams never get a price in this window (64 rounds), and two streams get one late (94 rounds), so the tails run on the original rule.

Which number should decide the cell is your call. If it is aggregate_tps, what is left is how the batch ends, and I can measure any shape you prefer, for example longer requests or requests that arrive as others finish.

The summaries, the per-prompt acceptance table and the price log are here: https://gist.github.com/AbrahamCete/ba0f7b52e29d02e96c78a8a7e31fe6bb

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner Author

@AbrahamCete thanks, that settles it. In a batch whose requests all start together, steady_tps decides drafts against no drafts. It measures the rounds the rule picks. At four streams, aggregate_tps also counts the uneven end of a batch launched at once, which serving with requests arriving on their own doesn't have. Your finish times show the average request finishing sooner with drafts (about 6.0 s against 6.28 s).

By that measure, sampled chat at four streams is 1.0% ahead of --mtp-drafts 0, tokens are equal everywhere, and the head is level with main in every cell, so this is done. It's queued to land after #2777.

The price log also points at the next win: the rounds before the first price (the first 128, three deep at 59.7 ms) and streams that never get a price in a short window. Pricing within the first few rounds would help short requests. That's a follow-up if you want it, not a condition here.

  • Synthena (Ash's Agent)

@AbrahamCete

Copy link
Copy Markdown
Contributor

Thanks. I'll take the early-price follow-up once #2828's PR is up: a price within the first few rounds, and one for the stream counts that only show up at the end of a batch. I'll open an issue for it then and claim it there, unless you'd rather open it yourselves.

@ashhart
ashhart force-pushed the lead/s368-pricing-r2 branch from ef572a5 to 84dcf66 Compare November 11, 2026 23:15
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main eab305db0, now 84dcf66e7. It conflicted with bb267e6 ("a learned row cost may fall below the table, and learning rounds reach the width they measure") in four lane files. Both rules are kept: the learned-cost lowering, bounded at the streams' plain width, with its measure-the-width rounds, and this PR's separate pricing of plain overhead and drafted rows. The lanes host tests pass, including both changes' own, and a test fails if either rule is dropped. It goes back in the queue once CI is green.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/s368-pricing-r2 branch from 84dcf66 to 1677522 Compare November 13, 2026 15:27
ashhart added a commit that referenced this pull request Nov 15, 2026
ashhart added a commit that referenced this pull request Nov 15, 2026
#2687 made Engine.askDrafts public so shared_round.zig could call it,
and proposal_batch_host.zig refuses a public askDrafts at compile time
(draft internals must stay private). The engine now passes its private
draft call to shared_round.run instead.
A stream count's first all-plain trial pays one-off costs, and blending
each later trial a fifth of the way kept that slow sample in the plain
price for hundreds of rounds, so near-even drafts kept drafting. The
first trial is now a warm-up whose sample is dropped (the existing
allocator stays in charge until the next trial, `every` rounds on), and
each later trial replaces the plain point. Natural plain rounds still
blend as before; `due` is unchanged.
Off unless TF_SHARED_PRICE_LOG=1. A common-scope environment.zig row
refuses any other text by name when a server starts, and the lane core
reads it through the same parser at an engine's first priced shared
round, which then logs the load-time shared forward costs and head
steps. Each priced shared round after that logs one line: its trial
flag, rows, time, the forward's table time, each stream's verified
drafts and next depth, the plain and row prices the depths were chosen
by, and each stream's acceptance estimates. Nothing it logs feeds back
into a decision.
Keep the measured plain intercept while the row learner owns its signed slope.
Exercise both prices, the plain-width floor and all three measuring allocators.

Refs #2605.
#2687 made Engine.askDrafts public so shared_round.zig could call it,
and proposal_batch_host.zig refuses a public askDrafts at compile time
(draft internals must stay private). The engine now passes its private
draft call to shared_round.run instead.
@ashhart
ashhart force-pushed the lead/s368-pricing-r2 branch from 1cdcb03 to 36b7827 Compare November 16, 2026 00:01
@ashhart
ashhart merged commit 9c11d43 into main Nov 16, 2026
12 of 20 checks passed
ashhart added a commit that referenced this pull request Nov 16, 2026
#2687 made Engine.askDrafts public so shared_round.zig could call it,
and proposal_batch_host.zig refuses a public askDrafts at compile time
(draft internals must stay private). The engine now passes its private
draft call to shared_round.run instead.
@ashhart
ashhart deleted the lead/s368-pricing-r2 branch November 16, 2026 00:01
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