Skip to content

qwen27 metal: srpt counts a reply that is still reasoning by its answer quota plus the reasoning left - #3371

Merged
ashhart merged 4 commits into
ashhart:mainfrom
Nipale-ai:srpt-reasoning-estimate-3270
Nov 20, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
Nipale-ai:srpt-reasoning-estimate-3270

Conversation

@Nipale-ai

@Nipale-ai Nipale-ai commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

With --thinking-reserve, srpt counted a reply that is still reasoning as max_tokens + reserve tokens, most of the window, so it never let such a reply ahead of a long prompt, and the reply's decode dropped about 95% beside a 110,000-token cold prompt (#3270). While a reply is still reasoning and has an answer quota, srpt now counts it as that quota plus the reasoning it is expected to have left, from a moving average of the think blocks this server has seen close, and never more than budgetLeft(); until the first think block has closed, and for requests with thinking off or without --thinking-reserve, the count is budgetLeft() as on main. A think block joins the average once, also when its reply ends in the round that closes it. Scheduling only: the order changes, no token does.

Once a reply's reasoning has passed the average, its reasoning left is counted as what it has already reasoned (as long again), so the estimate is the answer quota plus the tokens emitted so far, capped at budgetLeft(); it grows with the reply, and past a point the reply no longer goes first and the prompt keeps its lead. A wrong guess costs the prompt no more than srpt already allows: it lends at most a quarter of its own fill time (lends).

Checks on this head

  • Head commit: b80de85 (changelog: #3371 under Unreleased, CHANGELOG.md only) on 9711bc0 (the code commit, 2bea8ef87 put on main 2ba55ec). The tests below and the atc run above ran on 9711bc0. Main has no ## Unreleased heading after the 1.2.9 release, so the second commit adds it above ## 1.2.9, as 93d77e5 did above 1.2.8.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 341 on the base, 341 on this head, 0 new. python3 tools/pr_check.py --base origin/main --pr 3371 on b80de85: merge base 2ba55ec, 6 changed files, lean 341 vs 341, 0 new; 0 errors, 0 warnings.
  • Tests run, with the command and pass, fail and skip counts: zig build test test-lane-api-host test-prefill-service-host test-lane-lone-host test-lane-halt-host test-lane-interrupted-host -Dcpu=apple_m1 --summary all on a fresh cache: 880/880 steps succeeded, 14857 of 14975 tests passed, 118 skipped, 0 failed. zig build test-golden -Dcpu=apple_m1: 5/5 steps succeeded. zig fmt --check build.zig zig and git diff --check origin/main: clean. No existing test was changed. Five tests are new, in zig/src/core/lane_host_srpt.zig; they call Srpt.estimate, Srpt.thought, Srpt.seen and the new replyTokens(srpt, ...), so none compiles on main.
  • CI: all checks pass on this head (fmt, pytest, zig, zig-windows, zig-macos-dev-tools, benchmark-clients on ubuntu-latest and windows-latest, release-paths); host-nightly-linux and host-nightly-macos were skipped.
  • Not run, and why: other chips (no machine); other lane host boxes with TENSORFOLD_PREFILL_ORDER=srpt and --thinking-reserve, which this reaches too (not measured there, only on the one Mac); zig build dev-tools (no tf-* tool calls replyTokens, the one signature this changes: searched the tree); Metal device checks beyond those in zig build test (the change touches no kernel).

Receipt

  • Main against branch: a reasoning chat reply (thinking on, temperature 0) streams while a cold 110,000-token prompt (/v1/completions, max_tokens 1, cached 0) is filled, started once the reply has streamed 20 reasoning chunks. Fresh server for every run, main and branch alternating, prompt seeds 1 to 4, the same flags, built from main e54bd72 and from 2bea8ef87 (that main plus this commit). Main has since moved by 25 commits, to 2ba55ec. One of them, c331d07, adds lines to docs/api.md, none in the paragraphs this change edits; none touches the four Zig files. This head, 9711bc0, is 2bea8ef87 put on that main (the same git patch-id), and the checks above ran on it. The reply's max_tokens: 300 in the first two tables, 2000, the report's value, in the last two. In the rows marked "seeded", every server, main's too, first answered three sampled chat replies (temperature 0.7, thinking on) so that the branch had think blocks to count; the report's setup has none, which is the row "not seeded". Absolute times differ a little between the series (the machine ran slower in the later ones), so compare main and branch within a row.

Seeded with three "What is 17 times 23? Show the steps." replies (82 reasoning tokens each), max_tokens 300, four runs a side:

Binary Reply chunks/s beside the prompt Median Prompt fill s Median
main 2.17, 2.05, 2.02, 1.99 2.04 94.7, 100.2, 101.3, 103.1 100.7
branch 7.33, 7.30, 6.66, 7.23 7.27 117.5, 117.8, 116.1, 119.6 117.7

The reply is 3.6 times faster and the prompt's fill takes 17% longer (+24.2, +17.6, +14.7 and +16.0% against main's run with the same seed), inside the quarter that lends allows. The reply's longest gap stays under 1.3 s.

Reasoning well past the average: seeded with three "What is 2+2?" replies (15 reasoning tokens, 18 in all), so the average is 15, while the measured reply reasons for thousands of tokens; max_tokens 300, four runs a side:

Binary Reply chunks/s beside the prompt Median Prompt fill s Median
main 1.97, 1.95, 1.87, 1.84 1.91 103.8, 105.1, 109.6, 111.4 107.4
branch 7.15, 6.89, 6.66, 6.79 6.84 121.5, 124.7, 129.8, 130.4 127.3

The prompt's fill grows by 17.1, 18.6, 18.5 and 17.1% against main's run with the same seed (18.5% on the medians), never past the quarter. The reply goes first for part of the fill, which fits the code: the estimate (answer quota plus tokens emitted so far) is under a quarter of the fill time left, and the prompt keeps its lead after that. That the average was set: a build of this change before the rebase (the code in the four Zig files is the same), with one extra log line, not part of the branch, logged each of the three 15-token think blocks joining the average (15.0); the same line in an earlier revision of this change, which counted a think block only in a round that still had its stream live, logged none for these replies, because their think block closes in the round that ends the reply. This revision counts them (Srpt.seen, called from deliverPending too).

The report's max_tokens 2000, two runs a side. Not seeded, as in the report: the branch has seen no think block and behaves as main.

Binary Reply chunks/s beside the prompt Prompt fill s
main 1.86, 1.93 110.4, 106.1
branch 1.86, 2.00 110.0, 102.0

Seeded with "What is 17 times 23? Show the steps.", max_tokens 2000, two runs a side:

Binary Reply chunks/s beside the prompt Prompt fill s
main 1.86, 2.03 110.2, 100.9
branch 4.90, 5.31 118.4, 109.0

With the larger answer quota the reply gets less priority (2.6 times) and the prompt's fill grows 7.4 and 8.0%. The report's completions rows (max_tokens 199,900, 2,000 and 500, ignore_eos) are not rerun: with no reasoning the estimate is budgetLeft(), as on main. Alone, the reply streams 35.0 to 36.8 chunks/s on both binaries across these runs, and the cold prompt's hash is equal in every run (2fc420d3f99e, 23d16ccd3da4, b8f77066618d, 3f45a3b2b82b for seeds 1 to 4).

  • Boxes it reaches: Srpt is read from the environment in the lane host, so any lane host box with TENSORFOLD_PREFILL_ORDER=srpt (Qwen3.8-27B on Metal by default) and --thinking-reserve. Run on Qwen3.8-27B on Metal only.
  • New switch? None.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: measured on main e54bd72 and 2bea8ef87 (that main plus this commit); this head is 9711bc0 on main 2ba55ec; Zig 0.17.0, -Dcpu=apple_m1, ReleaseFast engine; Apple M5 Ultra with 256 GiB, Metal, one rank; macOS 27.0.1, Metal toolchain 27.1.266.1; TensorFold/Qwen3.8-27B-MLX-4bit at 22d8d538 and z-lab/Qwen3.8-27B-DFlash2 at 50307d4c as drafter. Server: --drafter z-lab/Qwen3.8-27B-DFlash2 --context 262144 --parallel 2 --max-inflight 8 --max-inflight-per-key 3 --prompt-cache-gib 18 --thinking-reserve 262144, the report's flags with --keep-warm 86400 added (not set: --dashboard, --vision*, --prompt-cache-disk, --spill-gib, --prompt-cache-over-cap, --compact-*, --learn-*). The report's machine has 96 GB, ours 256 GiB.
  • Paths and platforms the change reaches, which I ran and which I could not: ran the lane host on an M5 Ultra. Could not: M1 to M4, other M5 chips, other checkpoints and families. A request with thinking_budget is not treated differently by the estimate, and was not run.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: scheduling only, no arithmetic changes. In both cells below every request's token_sha256 is equal on main and on this branch: the greedy reasoning reply (thinking on, max_tokens 1500, with the reserve; it runs 31,916 tokens), the 110,000-token cold prompt, and, in the first cell, the same reply alone, which also equals the reply beside the prompt on each binary. Not compared with "draft": false.
Cell Request token_sha256 main / branch
seeded with the 17 times 23 replies reply beside the prompt a1758c1d356d / a1758c1d356d
cold prompt 2fc420d3f99e / 2fc420d3f99e
reply alone a1758c1d356d / a1758c1d356d
seeded with the 2+2 replies reply beside the prompt a1758c1d356d / a1758c1d356d
cold prompt 2fc420d3f99e / 2fc420d3f99e
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): the tables above, same machine, checkpoint, flags and prompt seeds, fresh servers, main and branch alternating, with token_sha256 equal.
  • Decode speed before and after, from tools/bench_openai.py: not run; the greedy reply's decode time alone in the exactness cell, 31,916 tokens: 191.04 s on main, 189.37 s on this branch. The alone streams in the tables run 35.0 to 36.8 chunks/s on both.
  • Prompt speed before and after: with no reply running there is nothing for the order to change; measured on an earlier build of this change with the same estimate code (the cold 110,000-token prompt alone, cached 0, seeds 1 and 2): 95.4 and 95.3 s on main, 95.4 and 95.6 s on the branch. Beside a reasoning reply the fill takes 17% longer, as in the first table.
  • Licence of any new weights or drafter, or "n/a": n/a.

Limits. The effect is small when the reasoning is long: a reply past the average think length is expected to reason as long again, so a long proof keeps its priority only while that estimate is under a quarter of the fill time left, as srpt's margin says; a larger answer quota shortens the priority too (the max_tokens 2000 row). Measured on an M5 Ultra only. A fresh server has no think block yet and behaves as main until one has closed, which is why the report's own setup shows no change. The report's clients both send temperature 0, and a lone greedy reply runs in the lone driver, so a think block that closes and ends there is not counted, and on such traffic nothing changes until a sampled reply has reasoned in the lane rounds. The factor of two was chosen in an earlier round of measurements on a previous main, with a test build that read it from an environment variable, against 1.5, 3, 1 and a constant, four runs each; 1.5 gave 8.1 chunks/s for +19% fill, 3 gave 5.1 for +10%, 1 and the constant gave 10.9 and 11.1 for +36% and +39%; 2 gave the best gain per added second and is the simplest. Docs: docs/api.md states the interaction where srpt and --thinking-reserve are described, in both places.

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency. They call the new Srpt.estimate, Srpt.thought, Srpt.seen and replyTokens(srpt, ...), so none compiles on main. One pins that a reasoning stream under a reserve counts as budgetLeft() before the first think block and goes first once the average is set; one that a think block joins the average once; one that a think block closed in the round that ends its reply joins it.

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • 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. Not compared with "draft": false; concurrent equals solo in the hash cell above, and token hashes equal main's.

  • No precision traded for speed. No arithmetic changes.

  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. Greedy decode alone is level; the one slower figure is the prompt's fill beside a reasoning reply (+17%), the order's price, stated above. Sampled and the widest admitted width were not measured.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

DEVICE. @Nipale-ai, the 647 lane-host tests and native/Metal builds pass, with no new lean findings. The once-per-stream reasoning estimate preserves the actual sampling rule and token budget.

We will run the device check on our side: a cold 110K prompt beside a reasoning reply, then short and long reasoning history, checking complete greedy and seeded replies, chunk cadence and TTFT with the reserve and SRPT on and off. The exact-head zig, zig-windows, pytest and fmt CI results are also still needed before landing.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@Nipale-ai DEVICE. On M5, all 70 complete responses stay identical, including the history primers, with zero cached rows.

With short or long reasoning history, the reply falls from about 104.0 to 16.8 seconds and visible fragment cadence rises from 5.28 to 32.73/s. The 110K prompt waits longer for its first token: about 97.1 -> 100.8 seconds, +3.83-3.84%. Cold history stays within main's timing ranges. The short-history reply's first token is 1.75 ms later; p95 streaming gaps still improve from about 549 to 28 ms.

This qualifies the measured fairness tradeoff. Green zig, zig-windows, pytest and fmt at this head are still needed before landing.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @Nipale-ai. We rebased this onto main and ran it on an M5 Ultra. It's exact: all 246 replies match main token for token and text for text, across plain and drafted, solo and concurrent, greedy and sampled, and real cache restores.

Speed is mixed in a way that holds it for now. With a short history at four streams, the change does what it sets out to: the short reply finishes in about 39 s instead of about 111 s, and the fill takes 12.5% longer, which is the trade srpt is for. With a long history at four streams, though, there's no short reply to serve, and it's a plain loss: the fill median goes from 98.13 to 100.82 s (+2.7%), both of the PR's runs are above main's slowest, and the two replies are 0.3-0.5% slower.

The path is Srpt.estimate (zig/src/core/lane_host_srpt.zig:61) feeding the decode-first and lend decision at lane_host_fill.zig:281. Please make that case level with main, so the estimate only changes the order when a shorter reply can actually finish sooner. The rebase onto today's main is ours, and we'll rerun the same cells on your next head.

  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @Nipale-ai. The exactness result is clear, and the short-history four-stream case does what the change sets out to do.

The long-history four-stream case is still a plain loss: with no short reply to serve, the fill is about 2.7% slower and both runs sit above main's slowest. Could you make the estimate change order only when a shorter reply can actually finish sooner, and post the new head? We will rerun the same cells on our side.

  • Synthena

@ashhart
ashhart force-pushed the srpt-reasoning-estimate-3270 branch from d4afe56 to 9f22819 Compare November 20, 2026 00:40
ashhart added a commit to Nipale-ai/TensorFold that referenced this pull request Nov 20, 2026
Nipale-ai and others added 4 commits November 20, 2026 12:44
…er quota plus the reasoning left

With --thinking-reserve a reply that is still reasoning counted as max_tokens plus
the reserve, most of the window, so shortest-remaining-work-first never let it go
ahead of a long prompt. srpt now counts it as its answer quota plus the reasoning
it is expected to have left, from a moving average of the think blocks the server
has seen close, and never more than budgetLeft; until the first block has closed
the count is budgetLeft, as before. Scheduling only: no token changes.

Fixes ashhart#3270
@ashhart
ashhart force-pushed the srpt-reasoning-estimate-3270 branch from e7b7cd7 to 0779090 Compare November 20, 2026 12:45
@ashhart
ashhart merged commit 675ec00 into ashhart:main Nov 20, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @Nipale-ai. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants