mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4199] [CLOSED] [Engine] dsv41: batched serving (M1, M4-M6, M2 step) - one pass for the whole batch, 2x aggregate at 16 slots #4945
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#4945
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/4199
Author: @suifei
Created: 10/26/2026
Status: ❌ Closed
Base:
main← Head:feat/dsv41-batch-m1📝 Commits (10+)
73f1a7ddsv41: decode scheduler core (M1 of docs/DSV41_BATCHING.md)8a6db6fdsv41: batched-KV block tables (M2 groundwork)6e97e5fdsv41: short-first admission of queued requests in the serve loop (M1)0117fe7dsv41: batch plan - scheduler step to per-run KV blocks (M2)82ecc40dsv41: admit the shortest of all queued requests, and --admit-order (M1)18631ffdocs(dsv41): the burst-interleaving path and its switch cost9abe6f6dsv41: parked-state bank for burst interleaving (Path B)6633ea6dsv41: accept --burst (0: off) for the burst-interleaving pathc3ee6b1serve: chunked round-robin bookkeeping (Path B2 of the batching design)e15ec77serve: round-robin over burst cursors, against a fake engine📊 Changes
61 files changed (+10455 additions, -2536 deletions)
View changed files
📝
CMakeLists.txt(+31 -0)➕
docs/DSV41_BATCHING.md(+616 -0)➕
docs/DSV41_HANDOFF.md(+899 -0)➕
serve/burst.py(+84 -0)📝
serve/server.py(+120 -21)➕
serve/test_burst.py(+54 -0)➕
serve/test_burst_roundrobin.py(+61 -0)📝
serve/test_queue_keepalive.py(+57 -0)📝
serve/test_structured.py(+27 -0)📝
serve/web/monitor.html(+6 -1)📝
serve/web/monitor.js(+77 -0)➕
src/dsv41/ds4_batch_attn.hpp(+109 -0)➕
src/dsv41/ds4_batch_kv.hpp(+160 -0)➕
src/dsv41/ds4_batch_plan.hpp(+83 -0)➕
src/dsv41/ds4_batch_proto.hpp(+59 -0)📝
src/dsv41/ds4_kernels.cu(+2244 -2232)📝
src/dsv41/ds4_kernels.cuh(+5 -0)📝
src/dsv41/ds4_main.cpp(+724 -95)📝
src/dsv41/ds4_model.cu(+1309 -186)📝
src/dsv41/ds4_model.hpp(+24 -1)...and 41 more files
📄 Description
dsv41 batching: M1-M6, with the measurements the PR needs
Ready for review. M1, M2's foundations, M4, M5 and M6 are in, tested and measured; the single-launch decode step is
not, and section 5 says what that costs and what it still needs. The two test sections the owner asked for - concurrency
against the engine without batch slots, and how many concurrent requests the L20 holds at the production 1M context with
256K max_tokens - then the same two questions on Qwen3.8-Flash-Next (256K context, 128K max_tokens).
1. Concurrency against the engine without it (real 1M context)
Box: 4 x NVIDIA L20 (46 GB each), the IST-DAS 2.25 bpw pack, the production configuration (
--max-context 1048576,--experts 6,--tp 2, DSpark on). Every request asksmax_tokens: 262144(256K) and leaves after it has read itsshare; thinking is off, so the tokens counted are the answer's.
--batch): the server's FIFO--batch 3--batch)--batch 16The branch changes when a user sees their tokens: the stock engine runs the answers one after the other, so the last
client's first token waits for every answer before it (10.84 s at three clients, 25.93 s at sixteen), while the branch
admits them all at once (0.31-0.76 s at three, 4.15 s at worst at sixteen) and their tokens interleave. At three
clients the aggregate is identical (62.4 against 61.9 tok/s); at sixteen it is 12 % lower, because the slots' KV comes
out of the experts' VRAM. The aggregate itself needs the single-launch step (M2's remainder) and the grouped MoE (M3),
which the routing measurements bound at 1.15-1.28x on this box.
2. How many concurrent requests the L20 holds at 1M context (256K max_tokens)
Every run loaded the model at
--max-context 1048576and every client was answered.Sixteen concurrent requests at the 1M context load and are all answered (17 sequences: the sixteen slots and the
solo one), with 0.59 GB a GPU left. The price is expert residency: a sequence's compressed KV is ~0.54 GB a GPU
(~2.2 GB in all), taken from the experts - 4224 of 4224 experts stay in VRAM with one sequence, 3662 at 13 sequences and
3441 at 17 - and the aggregate drifts from ~62 to ~51 tok/s as the displaced experts are read from RAM. At a 32K
context the same sixteen slots keep every expert (4224 of 4224, the tables 0.30 GB against 9.14 at 1M) and score 57.2
tok/s, so about half of the drift is the displacement and half is what sixteen sequences' passes and working sets cost
by themselves. Capping what one slot may hold (the design's 32K a slot) is the lever that would raise both.
Why sixteen concurrent requests are 13.6 % slower in wall than the stock engine (31.08 against 27.35 s): the engine
says it at load - with one sequence "the experts VRAM leaves over (~0.0 GB) are read in place from the model's files",
with the sixteen slots' seventeen sequences "~13.8 GB". The 1M-context KV is 9.14 GB a GPU for them against 0.54 GB for
one, and the experts it displaces are read per token. The 32K control (all 4224 experts resident) takes 28.0 s for the
same sixteen clients - +2.4 % is the interleaving, ~+11 % the spill. Measured against the 31.08 s baseline:
--slot-burst 32STRATA_DS4_BATCH_NOSPEC=1--experts 5The three levers, in order: the single-launch step (amortise the weights - M2's remainder), a per-slot context cap (the
tables are what displace the experts), and
--experts 5where the last expert is not worth it. Warming helps only thefirst tokens (the pack's cold reads and the empty RAM store after a load), not the steady state.
3. Qwen3.8-Flash-Next: the same two questions (256K context, 128K max_tokens)
The Qwen path (
strata, ISTA-DASLab IQ2_XS, 69 GB) is untouched by this branch; it already decodes several requests inone window (
"parallel": N). Same box, same client,--max-context 262144and every request asksmax_tokens: 131072.It runs normally on this tree, and at 256K four requests are the sweet spot (all admitted at once, first tokens
within 1.87 s, 364 handovers) while one at a time keeps the highest aggregate (73.0 tok/s) at the price of the queue
(the third client waits 2.87 s) - and eight slots cost both (38.7 tok/s, 6.11 s) because the extra KV comes out of the
expert cache. The controls across contexts say the same thing from both sides: at 32K the same batching is a real
aggregate win (25.0 -> 45.6 tok/s, 1.8x, 377 handovers against 2) - what this branch's single-launch step (M2) and
grouped MoE (M3) would buy; at 1M the engine needs
--kv q4_0(with int8 the 1M-token KV leaves no VRAM for itsexpert tier and it refuses), where
parallel 1took 5.99 s for three clients (50.1 tok/s) andparallel 412.92 s forfour (31.0 tok/s, cache 68-78 %). The first case after each load pays the pack's cold reads, so its single-request rates
are the low ones.
4. What else the branch carries: the monitor's parallel view (M6)
The built-in API monitor (
/api-monitor) shows the batch as it runs, in the page's own vocabulary: a row of slot cellsthat light while a slot holds a request, an area chart of requests in flight over four minutes with the session's peak
marked, and four facts (in flight, slots busy, waiting, peak). It draws itself only where the server serves more than one
request at a time, so a single-request deployment looks exactly as it did.
The data is the engine's own -
/v1/status'sconcurrencygainedslots(a slot's busy flag),busyandwaiting(requests admitted but holding no slot). Measured with two slots and three clients at 8K:
in_flight=3 slots=BB busy=2 waiting=1, thenB.and..as they finish; the page carries the panel's seven elements and the three clients answeredin 5.16 s with 164 handovers.
5. Status: what is in this branch, and what is not
In, tested, and measured:
slots (
STRATA_DS4_BATCH_LIVE), and the scheduler that takes the model a slot a turn.AttnRowsin its explicit form, theper-row chunk path (
StepRowsthroughlayer_chunk), proved bit-identical to the contiguous path in process(the same chunk through both paths on the same state, 300 tokens in 38 chunks through every layer, no difference in the rows, the compressed KV or the index keys). Re-running that A/B on the final tree showed it had never reached the per-row branch:
--prefill-chunk 8is clamped to 256 at load andchunk_rowstakes the per-row path only at T <= 16, so both sides ran the same code. Driven at T = 16 the per-row path is ~270x slower than the contiguous one (a 128-token prompt: 857 ms against not finishing in 233 s); one cause is fixed here - the indexer's weight block was rebuilt once a row - and the rest is open. Two faults found on the way are fixed too: apos_rowsthat pointed at pageable host memory, and a per-row ring write that read the block after its own. Thedecode side's plumbing is in too:
Runcarries the descriptor,
forward_chunksbuilds one chunk of T rows from it, the Engram rows are read per row, andforward_rowsis the entry.--batch N, and the server's batched streaming path: three clients overHTTP, every one answered.
INFO batch_*(a sequence's tables, theroom left, the count it allows, the experts the cards hold, from the pack's geometry and
cudaMemGetInfo), the burstmeasured per turn from the switch cost, and a slot's context computed at load, written beside the pack and applied by
the next load (
STRATA_DS4_AUTO=1): at 17 sequences 1M a slot became 373K, the tables 964 -> 344 MB a sequence, theexperts 13190 -> 14809 of 15360 in VRAM.
Not in yet: the single-launch decode step itself - the serve loop calling
forward_rowsonce for all the active slotsand sampling each row (the pieces are in: the descriptor through the chunk path, the per-row Engram reads, the per-row
sampler). What it still needs is measured rather than assumed now: on this box every multi-device run is layer-split
(
--tp 2and--tp 4both collapse to one member a group), so a layer's compressed rows are written on another deviceand the per-row path refuses without a cross-group hand-off (the design note's item 2: one copy of the step's T latent
rows to the owning group, ~32 KB a layer a step); and the per-row chunk path is ~270x slower than the contiguous one at T = 16 (one cause fixed), so it needs a profile pass before the step can rest on it. Until the step lands the engine keeps one pass a sequence, so this branch buys waiting time and
fairness (first tokens within 4.15 s against 25.93 s at sixteen clients) rather than aggregate throughput. That step is also M3's
prerequisite: the grouped GEMM over the step's T routed rows is what would turn the 1.15-1.28x bound (
route_overlap)into the 2-3x the milestone promises.
dsv41: one pass for the whole batch
M2's batched step now runs on the decode path's kernels instead of the chunked prompt path: one pass over T rows, a
token of a sequence each, the same single launch a decode token takes. The chunk path paid ~200 ms of fixed cost a pass
(a device sync after the routing, the bounds over the bus, ~40 kernels a layer); the window path pays ~16 ms.
What changed
forward_rows->forward_step-> the window path'sforward_par/forward_serialandlayer(), with everyper-position piece taken from the row itself:
finish'spos_rowsrope, the row's own ring block in the windowbuffer, its own compressor group, its own rows of the compressed tables (one
finisha row, at the row's own positionand destination), and the indexer a row at a time - its own sequence's region of the index keys, and its own picks
made absolute in that region (
rows_add_iwithkv_base(sr, seq)).readers place them in their own copies, and every device's work is finished before the next pass stages.
finish'spos_rowsindexes the query, not the row (pos_rows[v / vpp]). A step'sqcarriesvpp = NHLrowsa query, so the old indexing read another row's position - and the chunk path's step wrote its compressed rows
unroped (
rd = 0), which is the drift it showed from the third token on.--slot-context N/STRATA_DS4_SLOT_CONTEXT: the tokens a conversation may hold. The pack's compressed tables aresized a sequence by it - 965 MB a sequence at 1M, 30 MB at 32K - which is what keeps the experts in VRAM: at 16
slots and 1M they cost 15.4 GB a GPU and 2170 of 4224 experts go to the host lane (a pass then reads ~27 GB); at 32K,
none do.
copy could still be in flight when the next pass staged), and the serial path staged every row through one pinned
buffer (
replicate); a pass's device is now synced at the end of its work, and a row stages in its own slice.Numbers
Four L20s, 1M max-context, greedy, DSpark off, 64-token prompts, 96 tokens a slot,
--slot-context 32768, each step runagainst the bursts of its own slot count (
batch_step_bench.py --ref):The step's first tokens all arrive at one instant (0.88 s at 2 slots, 3.40 s at 8, 6.75 s at 16 - the last prompt's
read) against the bursts' 0.41 s spread, and at 16 slots nothing goes to the host expert lane.
At 1M with no slot cap (a shorter run, 32 tokens a slot): 2 slots 31.3 -> 39.4 (+26 %, 125 host experts) and 8 slots
31.0 -> 49.1 (+58 %, 984 host experts, 2.6x a slot). The flow streams a step's experts on this path at no cost
(39.4 with it on, 39.5 with
DS4_FLOW=0, the same tokens), which the chunk path's flow could never do - it deadlockedon a step's rows.
Exactness
Bit-identical to the burst path at 2, 4 and 8 slots. Above 8 rows the pass is deterministic and self-consistent but
rounds differently from a one-token decode: in the first pass, layers 0-12 agree to 1e-7 and layer 13 jumps to 1e-2 (an
indexer top-k tie flipping on a 1-ulp difference), which greedy decode then amplifies. Not a race, not a per-row
defect - the harness is
tools/dsv41/same_probe.py(one prompt for every slot, or two alternating) pluscmp_hash.py/cmp_num.pyover the per-layer hashes of row 0 (DS4_STEPCHECK=2).Tests
serve.test_server: Ran 348 tests, OKtools/dsv41/batch_probe.py(two slots): all checks passedtools/dsv41/batch_step_bench.py,same_probe.py,steprows_check.pydocs/DSV41_HANDOFF.md: the whole path - measurements, the dead ends, and the two remaining questions.Debug switches the work left behind, all off by default:
DS4_STEP_CHUNK=1(the chunk path's step, for an A/B),DS4_STEP_SERIAL=1(a pass on one thread,replicate, no staging),DS4_STEP_SYNCROUTE=1(the route on the device,no mailbox),
DS4_STEPCHECK=N(pass shape, per-layer hashes, row-0-vs-row-2 check).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.