mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2326] [CLOSED] batch-groups: read a cold prompt beside the decoding slots, stall 11.9 -> 0.8 s, same work 6.4% sooner (opt-in) #3984
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#3984
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/2326
Author: @SuperDistance
Created: 10/13/2026
Status: ❌ Closed
Base:
main← Head:pr/piped-concurrent-read📝 Commits (7)
d304ee2PleTable: a lock around its reader state, so two threads can use one table57ee849batch-groups: read a prompt beside the decoding slots on a thread of its own (opt-in, experimental STRATA_PIPED_CONCURRENT)cb5a9f7batch-groups: the concurrent read allocates nothing on its threads, keeps its checks and the watchdog, and waits on a launch3c9d48cdocs/BATCHING.md: reading beside the decoding slots, and what it measured106c271batch-groups: --remote-expert-opt without a helper cache does not keep the concurrent read off67bc65cbatch-groups: the concurrent read's threads do not share the host thread's core on Linuxfcf93bdverify: the Mac build keeps the default stream priority (no priority calls in its CUDA shim)📊 Changes
16 files changed (+1018 additions, -90 deletions)
View changed files
📝
docs/BATCHING.md(+96 -0)📝
include/strata/core/expert_source.hpp(+8 -5)📝
include/strata/core/mtp.hpp(+4 -0)📝
include/strata/core/pinned_ring.hpp(+35 -0)📝
include/strata/core/verify.hpp(+24 -5)📝
include/strata/platform/aux_cpus.hpp(+64 -0)📝
include/strata/prefill/prefill.hpp(+12 -0)📝
include/strata/program/batch_read.hpp(+26 -0)📝
src/core/expert_source.cpp(+2 -2)📝
src/core/mtp.cpp(+41 -8)📝
src/core/verify.cpp(+96 -35)📝
src/kernels/ngram.cpp(+10 -0)📝
src/prefill/prefill.cpp(+23 -0)📝
src/program/generate.cpp(+323 -34)📝
tests/program/batch_read_test.cpp(+28 -1)➕
tools/piped_read_join_bench.py(+226 -0)📄 Description
Title
Issue: Related: #2275, #1906 and #1603 (on the pipelined groups every decoding stream stops for a whole prompt read),
and #2050 (the other approach, reads in pieces; this PR does not depend on it).
Motivation
I run Strata as the backend for coding agents on 2x RTX 5090. Every new agent starts with a long cold prompt, and with
--batch-groups> 1 every agent that is already decoding stops until that prompt is read.vLLM and SGLang avoid this with chunked prefill: a new prompt's chunks share batches with the running requests' decode
steps. #2050 brought the time-sliced form of that here (the read in pieces, taking turns with decode windows), but
every turn drains the pipeline, so the new prompt waits longer, and with a coarse chunk one piece is still about 21 s
of reading (superniker on #2050). Strata's prompt path and its decode windows use different kernels and buffers, so
they cannot share one forward pass, but they can run at the same time on the same GPUs. That is this PR.
Summary
With
STRATA_PIPED_CONCURRENT=1(opt-in, experimental) a cold prompt is read on a thread of its own while the slotgroups keep decoding. With the variable unset nothing changes: main's tokens (SHA-256 equal) at main's speed.
On 2x RTX 5090, four streams decoding while a 64K and a 32K cold prompt join:
The whole workload finishes sooner because the GPUs stay busier during a read; on main they sit partly idle while every
stream waits. The price is the joining prompt's own first token, which comes 20-47% later.
How it works
pump) and takesBSTOPandBYIELDmeanwhile.allocated or freed on the read's threads (everything is sized before the read starts).
BYIELDends the read at its next chunk, and the part read waits in a slot, as #656's give-way does.the host thread's one-core mask; Windows' CPU Sets are not inherited).
Where the two rules come from, and what an independent review found
Two hangs turned up while building this, both read from the engine's stall dumps against its PDB. Both had #31's
shape: the main thread waited for the CUDA driver's lock in
cudaSetDevicewhile the lock's holder waited for the GPU(a
cudaFreein the drafter's prompt pass, then cuBLASLt's lazy load of a GEMM module), and a window on that GPUwaited for its doorbell. A doorbell served by a thread that never calls CUDA cannot be held up that way. An independent
review then found five more things, fixed in the third commit: configurations where serving a doorbell does call CUDA
(the mode is now off there), #1996's pinned upload rings growing mid-read (now reserved first), a window that would
never finish going unnoticed, the watchdog switching itself off when the last slot finished mid-read, and a rare race
that could serve a new window with the previous one's row count.
How to review
src/program/generate.cpp,read_part: the block underif (piped && pr_conc && req_imgs.empty()), thenpump'stwo changes (the watchdog during a read, the launch that wakes the doorbell thread).
src/core/verify.cpp:batch_serveisbatch_poll's per-layer service moved out unchanged.concurrent_read_off(batch_read.hpp, tested inbatch_read_test)lists the configurations where the mode stays off.
Results
Measured on 2x RTX 5090 (Swift 1.5 IQ3_S, split 25,
--batch 6 --batch-groups 2), engines built from maina0116b27.reads against 509 (main 293).
overlap.
about a sixth of its speed, the streams keep 22-29% of their rate instead of almost none, and the engine uses 16.6
cores against 6.3. VRAM stays flat.
a 105K conversation.
no error; memory stayed flat.
ed4773eb, #2050's bench): a cold 32K join stops the streams 0.7 s against6.1-6.5 s on main and 2.9-3.1 s with #2050's 16K pieces, and they emit 925-1,065 tokens during it against 222-229
and 814-860. The first version kept the read's threads on the host thread's core there (6.1 rows/s on blange48's
4x RTX 5080); the sixth commit fixes that.
stall and no hang.
Tables and method
Against #2050 (a cold 59.6K prompt at 6 s and a 33.7K one at 12 s, the same prompts in every arm):
With a second prompt under half the first one's length (72.4K and 28.1K), the long read gives way at its next chunk by
#656's rule, here at 57,344 of 72,368 tokens: the short prompt gained little (7.4 against main's 7.1 s) and the long
one waited for it (17.2 against 8.3 s). A rule that compares what is left to read, as @blange48 carries on #2170, would
skip a give-way that late; that belongs in its own PR.
The same work, sooner. The four streams send the same prompts in every run, greedy, and their answers came out the
same length (3,828-3,899 tokens on main, 3,831-3,865 here). Finishing time is the last stream's last token. Order main,
this mode, this mode, main. Both arms decode at about 330 tok/s before the joins; main then stops the streams for about
12.8 s, while this mode keeps them near 90 tok/s through a 15.7 s read, which puts it 1.5-2 s ahead. GPU busy is
nvidia-smi's utilization every 100 ms during the read period. The gain depends on how much of the time is spentreading; with no reads there is none.
Host contention (the cold 64K prompt read alone, then beside the decoding streams; read speeds from the engine's
line for the whole request):
16 GB cards (
--vram-reserve-mib 16600 --kv-resident 16384): the streams' rate during the reads 0.9 -> 52.9 tok/s,all four done 70.6 -> 63.8 s, GPUs busy 80% -> 92%, the joining prompts' first token 9.5 / 10.1 -> 15.8 / 21.1 s.
A weaker host (16 GB cards, experts from the mapped file, AVX2, 6 pool workers,
--batch 2): a stream's longeststop 11.1 -> 0.41 s beside a 64K read and 20.3 -> 0.64 s beside a 127K one, the prompt's first token +4-7%.
Linux (WSL2, Ubuntu 24.04, the same machine and engine, all builds on main
ed4773ebwith #2050's commits appliedfor its arm;
piped_read_join_bench.py's cold32k, followup and two_joiners; the n-gram table in RAM in every arm, sinceWSL's disk reads it about 7x slower; 2-3 runs each):
The slots decoded 24-37 rows/s during a 30K+ read with the first version and 95-127 with the fix.
Exactness. With the usual settings near-tie tokens flip a little more often than on main (the prompt path borrows
some of the decode's GPU expert slots, and those experts run on the CPU kernels, which round differently). With
--pcie-frac 0 --adapt-swaps 0 --prompt-cache 0 --no-prefill-borrowthis mode's two runs were byte-identical for allthree answers; release's two runs with the same settings still differed. In
batch_interleave_test.py --long 40000every request equaled its solo tokens in two runs of three; the third had a near tie that flips on main as well. With
the variable unset, six greedy answers' SHA-256 equal main's in two engine starts each.
Load. The hour: four streams, cold joins of 4-128K every 4-15 s, short questions, follow-ups, clients leaving
mid-read; GPU0's VRAM grew 82 MiB over 80 minutes (in my local testing an engine grew 44 MiB in its first hours and
then held). My local testing ran v0.1.43 with #2050 and this ported; against the 20 hours before it on #2050's pieces,
the slowest tenth of long reads fell from 15.8 to 7.5 s, but the workload differed, so that is not a controlled A/B.
Costs and limits
BYIELD).--pcie-mode dma, the helper caches (--expert-cache-device1..3), anexpert source that recycles its buffers (the GGUF in place, unbuffered,
STRATA_IO_PREFETCH),STRATA_FS_SLOTS,STRATA_PREFILL_HELPandSTRATA_SPLIT_MTP_BATCH(--remote-expert-optwithout a helper cache does not count).Prompts with pictures are read the usual way.
What changed
src/program/generate.cpp: the concurrent read, the doorbell thread and the log lines;pumpkeeps the watchdog onduring a read and wakes the doorbell thread at a launch.
src/core/verify.cpp,include/strata/core/verify.hpp:batch_serve(shared withbatch_poll) andset_external_serve; the window state as atomics; the windows' streams at high priority under the opt-in.src/prefill/prefill.cpp,include/strata/prefill/prefill.hpp:stop_at_chunk,reserve_uploads.src/core/mtp.cpp,include/strata/core/mtp.hpp:reserve_prefill.include/strata/core/pinned_ring.hpp:PinnedRing::reserve.src/kernels/ngram.cpp: a lock inPleTable.src/core/expert_source.cppand its header: atomic read counters.include/strata/program/batch_read.hpp,tests/program/batch_read_test.cpp:concurrent_read_offand its test.include/strata/platform/aux_cpus.hpp:place_off_hostandrelease_host_inheritors(Linux), the read's threadsoff the host thread's core.
docs/BATCHING.md: the section and the tables.tools/piped_read_join_bench.py: #2050's measuring client,unchanged.
Extra Notes
both in, this mode reads where it can run and #2050's pieces cover the rest. The pieces suit configurations where this
mode stays off and cost the host less; this mode keeps the streams going and the read at full speed.
296b59d2), where it builds and its unit test passes; the Windows numbers above arefrom
a0116b27, the Linux ones fromed4773eb.batch_read_testpasseson all three. SYCL is not built here.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.