mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2050] [CLOSED] batch-groups: a cold prompt read no longer pauses every stream for its whole length, longest pause 12.2 -> 4.2 s on 2x RTX 5090 (opt-in) #3829
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3829
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2050
Author: @SuperDistance
Created: 10/12/2026
Status: ❌ Closed
Base:
main← Head:pr/piped-read-interleave📝 Commits (3)
3271f31batch-groups: decode and give way between the pieces of a prompt read (opt-in, STRATA_PIPED_READ_PIECE)2ee4a03batch-groups: the piece lines count the rows the slots decoded when they finish meanwhile5e2e6b4batch-groups: the stall watchdog stays on for a read in pieces after the slots go idle📊 Changes
5 files changed (+445 additions, -3 deletions)
View changed files
📝
docs/BATCHING.md(+69 -1)📝
include/strata/program/batch_read.hpp(+31 -0)📝
src/program/generate.cpp(+93 -2)📝
tests/program/batch_read_test.cpp(+26 -0)➕
tools/piped_read_join_bench.py(+226 -0)📄 Description
Title
Issue: Related: #1906 (streams stop for a whole prompt read with
--batch-groups> 1; its question 3 asks whybatch_read_piecereturns 0 for pipelined groups; the full re-reads it also reports are a separate matter) and #1603 (a comment there reports the same stop: a 160K read with--batch-groups autoleft the other slot at 0.03 tok/s; the hang in its title is a separate matter). #1504 (closed) readin pieces on
--batch-groups 1only and left the pipelined path out; its thread asked for the follow-up TTFT during a45K read, measured below. Nearby: #1441 (
--prefill-pipechunk sizes; pieces here are whole chunks of any size).Searched 2026-10-12 for
batch_read_piece,piped,pipelined,BYIELD,batch-groups,DECODE_SHAREandstall.Motivation
I run Strata on 2x RTX 5090 (
--batch-groups 2) as the backend for Hermes agents doing development work. Each time a newagent joins, its first request is a long cold prompt (system prompt, tools, repository context), and every agent that is
already decoding stops until that prompt has been read. With several agents at work this happens often, so the running
streams keep stalling for seconds and their tokens per second swing between full speed and zero.
This change lets a cold prompt join smoothly: the running streams keep getting tokens while it is read, and the new
agent's first token comes a little later in exchange. Like an incremental garbage collector, it turns one long
stop-the-world pause into several short ones; the total time paused stays about the same.
Summary
Why it matters: with a layer split and
--batch-groups> 1, a prompt is read in onesp.run. Every decoding slotwaits for the whole prompt,
STRATA_BATCH_DECODE_SHAREhas no effect, andBYIELDis never taken. On one GPU the slotsalready decode between a prompt's chunks, and a short request can take over a long read.
How:
STRATA_PIPED_READ_PIECE=Nreads the prompt in pieces of N tokens (whole chunks, 1 to 32). Each piece is onepipelined run, so only its end drains the pipeline. At each piece's end:
BYIELDcode (the drained pipelineis what a give-way needs);
STRATA_BATCH_DECODE_SHAREx the piece's time, capped and floored bySTRATA_PIPED_DECODE_MAX_MS/STRATA_PIPED_DECODE_MIN_MS.A read that starts right after another such read gives the slots one decode budget first. Unset: one run, as before.
Measured on 2x RTX 5090 (Swift 1.5 IQ3_S, split 25,
--batch 6 --batch-groups 2 --resident-experts, k8v4, 262K,--kv-resident 32768): v0.1.43 vs this change, both built here, a fresh engine per run,STRATA_PIPED_DECODE_MAX_MS=400.Release and 32K: median of 5 interleaved pairs (ABBA); 16K: one run.
Four streams decoding while two cold prompts join (64K, then 32K 6 s later):
Nothing decoding, a cold 45K prompt (#1504's test, median of 3):
The 32K pause was lower in 5 of 5 pairs. Total time paused counts gaps over 0.5 s (mean of the four streams).
Where upstream's default is better: throughput and the long prompt's TTFT. Each piece ends with a drained pipeline:
the joining prompts' TTFT is 27% longer with 32K pieces (73% with 16K), the token rate is 4% lower (within run-to-run
spread), and an idle 45K read takes 12% longer (25% with 16K), since pieces are also taken when nothing decodes. Leave it
off when aggregate tokens or one client's long prompts matter most; turn it on when a multi-second stall is worse than a
later first token. Single-chunk pieces would cost the read the most (#1504's "65% longer read").
Next to #2326: #2326 reads the prompt on a thread of its own beside the decoding, instead of in pieces. Where it can
run it does better (longest pause 0.97 s against 4.6 s), but it stays off with the GGUF read in place (setup's mode for
Unsloth's files when RAM is short), the helper caches,
--pcie-mode dmaand prompts with pictures. There, and on hostswhere the CPU is the limit (these pieces used 4.7 cores during a read against 16.6 for #2326), this change is the option.
It pays off least with a coarse prompt chunk: each piece costs one pipeline fill, about 7.5 s with superniker's
26,624-token chunks. The two don't depend on each other; with both in, #2326 reads where it can and the pieces apply
elsewhere.
What changed
include/strata/program/batch_read.hpp(header-only):piped_read_piece(),piped_decode_budget_ms(),piped_read_lead_in().src/program/generate.cpp,read_part: the piecewise read on the pipelined path; at each piece's end the existingBSTOP/BYIELDhandling, thenpump(true)for the budget andpipe_drain(); the lead-in; one stderr line per pieceand lead-in. Unset:
batch_read_piece()as before.tests/program/batch_read_test.cpp: each new function (rounding, the 32-chunk cap, chunk 0, cap and floor, lead-in).docs/BATCHING.md: the opt-in's section, and how to runbatch_interleave_test.pyon pipelined groups.tools/piped_read_join_bench.py(new, stdlib only): the scenarios above (--scenarios two_joiners,followup,read_alone --repeat N) and--determinism.Extra Notes
Text equality: upstream's
tools/batch_interleave_test.pypasses every step with 16K pieces: C's 40K read goes inthree pieces while A and B decode, D gives way at 16,384 tokens (
YIELDED 2 16384) while E is admitted, and every requestequals its solo tokens. The release fails step 4 (D never gives way). Settings:
--long 40000 --pcie-frac 0 --adapt-every 1000000 --no-prefill-borrow, plus--batch 4 --batch-groups 2(3 slots make one group) and noconversation cache (it would restore D in step 4). With the variables unset, both builds gave the same SHA-256 for six
greedy answers, twice each, under
--prompt-cache 0 --adapt-swaps 0 --pcie-frac 0(DETAILS.md), and ran at the samespeed (45K read alone 5.66 vs 5.69 s, median of 3; two-joiner pause 12.2 s on both). Text equality, not bit-exactness, and
greedy only.
Run-to-run spread: the longest pause was 12.16-12.23 s for the release in all five runs and 4.19-4.22 s for 32K in
four. In the fifth, the 64K prompt's first piece took 9.3 s instead of 3.95 s before any slot decoded (so not this
change's code), giving a 9.5 s pause and 13.5 / 13.9 s TTFTs; it stays in the medians. Token rate ranged 169-180 tok/s
(release) and 136-174 tok/s (32K).
Built on one Windows 11 PC: CUDA 13.0 (VS 2022,
-DCMAKE_CUDA_ARCHITECTURES=120 -DSTRATA_PORTABLE=ON) and HIP viatools\hip\build_windows.bat tests(ROCm 10.2.0a20260930, gfx1100).batch_read_testpasses on both andbatch_groups_teston HIP; the only new warnings are the MSVCgetenvnotes the file's otherstd::getenvcalls alsoprint. SYCL is untouched: it builds its own
sycl/src/program/generate.cppand never includesbatch_read.hpp. Threecommits, rebased onto v0.1.44.1 (
296b59d2); the numbers above are from v0.1.43.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.