Repository navigation
qwen27 metal: srpt counts a reply that is still reasoning by its answer quota plus the reasoning left - #3371
Conversation
|
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.
|
|
@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.
|
|
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
|
b80de85 to
d4afe56
Compare
|
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.
|
d4afe56 to
9f22819
Compare
…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
…between two one-line declarations)
e7b7cd7 to
0779090
Compare
|
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. |
What this changes
With
--thinking-reserve, srpt counted a reply that is still reasoning asmax_tokens + reservetokens, 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 thanbudgetLeft(); until the first think block has closed, and for requests with thinking off or without--thinking-reserve, the count isbudgetLeft()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).--thinking-reserve, a reasoning reply never counts as short, so srpt lets a long prompt take the GPU and the reply's decode drops ~95 % #3270 (direction 1 and direction 3's documentation note, as agreed in the issue).atc overlap --json(atc 0.9.6, withATC_READ_ONLY=1), run in this tree on 2026-11-14 between 18:09 and 18:11 CET, base main2ba55ec7d, this head9711bc030. The plain run stopped at its limits (complete: false;otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit) with 8 overlaps, all clean. So I ranoverlap --pulls, six at a time, over the 60 open pull requests that touch one of this change's five files (listed at 18:09 CET): 52 clean, 8 conflicts, 0 unknown. One batch reportedpullFilesLimitfor tp ranks: every byte after the key proof crosses the bootstrap, fate and plan links in sealed records #3101, which atc lists as clean;git merge-treeof tp ranks: every byte after the key proof crosses the bootstrap, fate and plan links in sealed records #3101 is clean with this head and with main. For each of the 8 conflicts,git merge-treeshowsdocs/api.mdas the one file of this change that conflicts. ocr: GLM-OCR reader on /v1/ocr (#2440 step 3) #2572, ocr: POST /ocr in LiteParse's contract (#2440 step 4) #2573, ocr: POST /ocr in docTR's contract (#2440 step 5) #2574, ocr: POST /ocr in PaddleX's contract (#2440 step 6) #2575, native: Qwen3.5-2B on CUDA attests the execution witness's first path, every weight byte read once the server is ready #2956 and streams: return_progress sends a prompt pass's progress before the first token #3216 have the same conflicts in that file with main as it stands (the same hunks there with and without this change). lfm3: add native Metal vision support above the text decoder #1502 and dsv41 metal: prompts in pieces between the other streams' rounds (stacked on #1720) #2950 conflict in that file only with this change, in one hunk each: both edit one of the two lines ofdocs/api.mdthat this change adds a sentence to. That is not resolved here; whichever lands later has to keep both edits.Checks on this head
changelog: #3371 under Unreleased,CHANGELOG.mdonly) on 9711bc0 (the code commit, 2bea8ef87 put on main 2ba55ec). The tests below and the atc run above ran on 9711bc0. Main has no## Unreleasedheading after the 1.2.9 release, so the second commit adds it above## 1.2.9, as 93d77e5 did above 1.2.8.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 3371on b80de85: merge base 2ba55ec, 6 changed files, lean 341 vs 341, 0 new; 0 errors, 0 warnings.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 allon 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 zigandgit diff --check origin/main: clean. No existing test was changed. Five tests are new, inzig/src/core/lane_host_srpt.zig; they callSrpt.estimate,Srpt.thought,Srpt.seenand the newreplyTokens(srpt, ...), so none compiles on main.TENSORFOLD_PREFILL_ORDER=srptand--thinking-reserve, which this reaches too (not measured there, only on the one Mac);zig build dev-tools(notf-*tool callsreplyTokens, the one signature this changes: searched the tree); Metal device checks beyond those inzig build test(the change touches no kernel).Receipt
/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 todocs/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 samegit patch-id), and the checks above ran on it. The reply'smax_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: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
lendsallows. 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: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 fromdeliverPendingtoo).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.Seeded with "What is 17 times 23? Show the steps.",
max_tokens 2000, two runs a side: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_tokens199,900, 2,000 and 500,ignore_eos) are not rerun: with no reasoning the estimate isbudgetLeft(), 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,3f45a3b2b82bfor seeds 1 to 4).Srptis read from the environment in the lane host, so any lane host box withTENSORFOLD_PREFILL_ORDER=srpt(Qwen3.8-27B on Metal by default) and--thinking-reserve. Run on Qwen3.8-27B on Metal only.-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-4bitat 22d8d538 andz-lab/Qwen3.8-27B-DFlash2at 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 86400added (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.thinking_budgetis not treated differently by the estimate, and was not run.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: scheduling only, no arithmetic changes. In both cells below every request'stoken_sha256is 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.token_sha256main / brancha1758c1d356d/a1758c1d356d2fc420d3f99e/2fc420d3f99ea1758c1d356d/a1758c1d356da1758c1d356d/a1758c1d356d2fc420d3f99e/2fc420d3f99etoken_sha256equal.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.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.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 2000row). 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.mdstates the interaction where srpt and--thinking-reserveare 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.seenandreplyTokens(srpt, ...), so none compiles on main. One pins that a reasoning stream under a reserve counts asbudgetLeft()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.