[PR #4199] [CLOSED] [Engine] dsv41: batched serving (M1, M4-M6, M2 step) - one pass for the whole batch, 2x aggregate at 16 slots #4945

Closed
opened 2026-11-07 16:31:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 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+)

  • 73f1a7d dsv41: decode scheduler core (M1 of docs/DSV41_BATCHING.md)
  • 8a6db6f dsv41: batched-KV block tables (M2 groundwork)
  • 6e97e5f dsv41: short-first admission of queued requests in the serve loop (M1)
  • 0117fe7 dsv41: batch plan - scheduler step to per-run KV blocks (M2)
  • 82ecc40 dsv41: admit the shortest of all queued requests, and --admit-order (M1)
  • 18631ff docs(dsv41): the burst-interleaving path and its switch cost
  • 9abe6f6 dsv41: parked-state bank for burst interleaving (Path B)
  • 6633ea6 dsv41: accept --burst (0: off) for the burst-interleaving path
  • c3ee6b1 serve: chunked round-robin bookkeeping (Path B2 of the batching design)
  • e15ec77 serve: 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 asks max_tokens: 262144 (256K) and leaves after it has read its
share; thinking is off, so the tokens counted are the answer's.

clients engine wall first token per client handovers aggregate
3 stock (no --batch): the server's FIFO 14.55 s 0.50 / 5.81 / 10.84 s 2 / 900 61.9 tok/s
3 this branch, --batch 3 14.43 s 0.31 / 0.76 / 1.04 s 167 / 900 62.4 tok/s
16 stock (no --batch) 27.35 s within 25.28 s (last: 25.93 s) 15 / 1600 58.5 tok/s
16 this branch, --batch 16 31.08 s within 4.15 s 219 / 1600 51.5 tok/s

The 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 1048576 and every client was answered.

slots (sequences) wall first tokens within handovers aggregate each client
3 (4) 14.43 s 0.74 s 167 / 900 62.4 tok/s 20.8-21.1 tok/s
6 (7) 20.46 s 1.44 s 181 / 1200 58.7 tok/s ~9.8 tok/s
8 (9) 14.74 s 1.96 s 119 / 800 54.3 tok/s ~7.0 tok/s
10 (11) 18.50 s 2.50 s 133 / 1000 54.1 tok/s ~5.5 tok/s
12 (13) 22.12 s 2.95 s 167 / 1200 54.3 tok/s ~4.6 tok/s
16 (17) 31.08 s 4.15 s 219 / 1600 51.5 tok/s ~3.3 tok/s

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:

16 slots, 1M context wall aggregate note
--slot-burst 32 31.14 s 51.4 tok/s no gain, first token 9.45 s against 4.15
STRATA_DS4_BATCH_NOSPEC=1 36.52 s 43.8 tok/s the drafter is worth 5.4 s here - keep it on
--experts 5 28.67 s 55.8 tok/s 17 % less expert traffic a token

The 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 5 where the last expert is not worth it. Warming helps only the
first 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 in
one window ("parallel": N). Same box, same client, --max-context 262144 and every request asks
max_tokens: 131072.

parallel clients wall first tokens within handovers aggregate expert cache
1 3 4.11 s 2.87 s 2 / 300 73.0 tok/s -
4 4 7.78 s 1.87 s 364 / 400 51.4 tok/s 96 %
8 8 20.69 s 6.11 s 769 / 800 38.7 tok/s 84 %

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 its
expert tier and it refuses), where parallel 1 took 5.99 s for three clients (50.1 tok/s) and parallel 4 12.92 s for
four (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 cells
that 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's concurrency gained slots (a slot's busy flag), busy and waiting
(requests admitted but holding no slot). Measured with two slots and three clients at 8K: in_flight=3 slots=BB busy=2 waiting=1, then B. and .. as they finish; the page carries the panel's seven elements and the three clients answered
in 5.16 s with 164 handovers.

5. Status: what is in this branch, and what is not

In, tested, and measured:

  • M1 - per-sequence state (rings, compressed tables, the compressors' partial groups, positions and tokens), the live
    slots (STRATA_DS4_BATCH_LIVE), and the scheduler that takes the model a slot a turn.
  • M2 - the per-sequence regions and the per-row pass: absolute selection rows, AttnRows in its explicit form, the
    per-row chunk path (StepRows through layer_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 8 is clamped to 256 at load and chunk_rows takes 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: a pos_rows that pointed at pageable host memory, and a per-row ring write that read the block after its own. The
    decode side's plumbing is in too: Run
    carries the descriptor, forward_chunks builds one chunk of T rows from it, the Engram rows are read per row, and
    forward_rows is the entry.
  • M4 - the BGEN/BADM/BT/BDONE/BSTOP protocol, --batch N, and the server's batched streaming path: three clients over
    HTTP, every one answered.
  • M5 - the numbers above, and the parameters computed rather than written: INFO batch_* (a sequence's tables, the
    room left, the count it allows, the experts the cards hold, from the pack's geometry and cudaMemGetInfo), the burst
    measured 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, the
    experts 13190 -> 14809 of 15360 in VRAM.
  • M6 - the monitor's parallel view (section 4).

Not in yet: the single-launch decode step itself - the serve loop calling forward_rows once for all the active slots
and 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 2 and --tp 4 both collapse to one member a group), so a layer's compressed rows are written on another device
and 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's forward_par/forward_serial and layer(), with every
    per-position piece taken from the row itself: finish's pos_rows rope, the row's own ring block in the window
    buffer, its own compressor group, its own rows of the compressed tables (one finish a row, at the row's own position
    and 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_i with kv_base(sr, seq)).
  • the cross-group hand-off for a pass's rows: the rows a pass completes are staged in row order (a pass a chunk), the
    readers place them in their own copies, and every device's work is finished before the next pass stages.
  • finish's pos_rows indexes the query, not the row (pos_rows[v / vpp]). A step's q carries vpp = NHL rows
    a 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 are
    sized 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.
  • two races on buffers reused within a pass, both fixed: the window path's staging had no acknowledgement (a reader's
    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 run
against the bursts of its own slot count (batch_step_bench.py --ref):

slots bursts, tok/s step, tok/s gain tokens
2 43.0 59.9 +39 % the reference's, bit for bit
4 43.2 77.6 +80 % the reference's, bit for bit
8 43.3 88.6 +105 % the reference's, bit for bit
16 43.4 86.7 +100 % differs - see below

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 deadlocked
on 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) plus
cmp_hash.py/cmp_num.py over the per-layer hashes of row 0 (DS4_STEPCHECK=2).

Tests

  • serve.test_server: Ran 348 tests, OK
  • tools/dsv41/batch_probe.py (two slots): all checks passed
  • tools/dsv41/batch_step_bench.py, same_probe.py, steprows_check.py
  • docs/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.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4199 **Author:** [@suifei](https://github.com/suifei) **Created:** 10/26/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/dsv41-batch-m1` --- ### 📝 Commits (10+) - [`73f1a7d`](https://github.com/Niko1221/Strata/commit/73f1a7dc9dcf2534b109704c1facaec5273cc57e) dsv41: decode scheduler core (M1 of docs/DSV41_BATCHING.md) - [`8a6db6f`](https://github.com/Niko1221/Strata/commit/8a6db6f2638fad3346a0e23989d2173499701e71) dsv41: batched-KV block tables (M2 groundwork) - [`6e97e5f`](https://github.com/Niko1221/Strata/commit/6e97e5f035316a3bb8a8b7a860409cb6152b6938) dsv41: short-first admission of queued requests in the serve loop (M1) - [`0117fe7`](https://github.com/Niko1221/Strata/commit/0117fe7f95eb7610c01dc62f30b7ee0c493da00e) dsv41: batch plan - scheduler step to per-run KV blocks (M2) - [`82ecc40`](https://github.com/Niko1221/Strata/commit/82ecc409de819953febff6be48c86d47131ec130) dsv41: admit the shortest of all queued requests, and --admit-order (M1) - [`18631ff`](https://github.com/Niko1221/Strata/commit/18631ff8c01acb53b0d48209a531255625ac6256) docs(dsv41): the burst-interleaving path and its switch cost - [`9abe6f6`](https://github.com/Niko1221/Strata/commit/9abe6f6935639c05b177c54afce61fbeaea50af6) dsv41: parked-state bank for burst interleaving (Path B) - [`6633ea6`](https://github.com/Niko1221/Strata/commit/6633ea6c429b9fe52dd456b569647c7632724519) dsv41: accept --burst (0: off) for the burst-interleaving path - [`c3ee6b1`](https://github.com/Niko1221/Strata/commit/c3ee6b172ed3bfa1d04290dfce587e75eae4d8dc) serve: chunked round-robin bookkeeping (Path B2 of the batching design) - [`e15ec77`](https://github.com/Niko1221/Strata/commit/e15ec772cb58b1a57bae09cab71e1ff95fe4bf3c) serve: round-robin over burst cursors, against a fake engine ### 📊 Changes **61 files changed** (+10455 additions, -2536 deletions) <details> <summary>View changed files</summary> 📝 `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_ </details> ### 📄 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 asks `max_tokens: 262144` (256K) and leaves after it has read its share; thinking is off, so the tokens counted are the answer's. | clients | engine | wall | first token per client | handovers | aggregate | |---:|---|---:|---|---:|---:| | 3 | stock (no `--batch`): the server's FIFO | 14.55 s | 0.50 / 5.81 / 10.84 s | 2 / 900 | 61.9 tok/s | | 3 | this branch, `--batch 3` | 14.43 s | 0.31 / 0.76 / 1.04 s | 167 / 900 | 62.4 tok/s | | 16 | stock (no `--batch`) | 27.35 s | within 25.28 s (last: 25.93 s) | 15 / 1600 | 58.5 tok/s | | 16 | this branch, `--batch 16` | 31.08 s | within 4.15 s | 219 / 1600 | 51.5 tok/s | The 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 1048576` and every client was answered. | slots (sequences) | wall | first tokens within | handovers | aggregate | each client | |---:|---:|---:|---:|---:|---:| | 3 (4) | 14.43 s | 0.74 s | 167 / 900 | 62.4 tok/s | 20.8-21.1 tok/s | | 6 (7) | 20.46 s | 1.44 s | 181 / 1200 | 58.7 tok/s | ~9.8 tok/s | | 8 (9) | 14.74 s | 1.96 s | 119 / 800 | 54.3 tok/s | ~7.0 tok/s | | 10 (11) | 18.50 s | 2.50 s | 133 / 1000 | 54.1 tok/s | ~5.5 tok/s | | 12 (13) | 22.12 s | 2.95 s | 167 / 1200 | 54.3 tok/s | ~4.6 tok/s | | 16 (17) | 31.08 s | 4.15 s | 219 / 1600 | 51.5 tok/s | ~3.3 tok/s | **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: | 16 slots, 1M context | wall | aggregate | note | |---|---:|---:|---| | `--slot-burst 32` | 31.14 s | 51.4 tok/s | no gain, first token 9.45 s against 4.15 | | `STRATA_DS4_BATCH_NOSPEC=1` | 36.52 s | 43.8 tok/s | the drafter is worth 5.4 s here - keep it on | | `--experts 5` | 28.67 s | 55.8 tok/s | 17 % less expert traffic a token | The 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 5` where the last expert is not worth it. Warming helps only the first 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 in one window (`"parallel": N`). Same box, same client, `--max-context 262144` and every request asks `max_tokens: 131072`. | parallel | clients | wall | first tokens within | handovers | aggregate | expert cache | |---:|---:|---:|---:|---:|---:|---:| | 1 | 3 | 4.11 s | 2.87 s | 2 / 300 | 73.0 tok/s | - | | 4 | 4 | 7.78 s | 1.87 s | 364 / 400 | 51.4 tok/s | 96 % | | 8 | 8 | 20.69 s | 6.11 s | 769 / 800 | 38.7 tok/s | 84 % | 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 its expert tier and it refuses), where `parallel 1` took 5.99 s for three clients (50.1 tok/s) and `parallel 4` 12.92 s for four (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 cells that 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`'s `concurrency` gained `slots` (a slot's busy flag), `busy` and `waiting` (requests admitted but holding no slot). Measured with two slots and three clients at 8K: `in_flight=3 slots=BB busy=2 waiting=1`, then `B.` and `..` as they finish; the page carries the panel's seven elements and the three clients answered in 5.16 s with 164 handovers. ## 5. Status: what is in this branch, and what is not **In, tested, and measured:** * M1 - per-sequence state (rings, compressed tables, the compressors' partial groups, positions and tokens), the live slots (`STRATA_DS4_BATCH_LIVE`), and the scheduler that takes the model a slot a turn. * M2 - the per-sequence regions and the per-row pass: absolute selection rows, `AttnRows` in its explicit form, the per-row chunk path (`StepRows` through `layer_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 8` is clamped to 256 at load and `chunk_rows` takes 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: a `pos_rows` that pointed at pageable host memory, and a per-row ring write that read the block after its own. The decode side's plumbing is in too: `Run` carries the descriptor, `forward_chunks` builds one chunk of T rows from it, the Engram rows are read per row, and `forward_rows` is the entry. * M4 - the BGEN/BADM/BT/BDONE/BSTOP protocol, `--batch N`, and the server's batched streaming path: three clients over HTTP, every one answered. * M5 - the numbers above, and the parameters computed rather than written: `INFO batch_*` (a sequence's tables, the room left, the count it allows, the experts the cards hold, from the pack's geometry and `cudaMemGetInfo`), the burst measured 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, the experts 13190 -> 14809 of 15360 in VRAM. * M6 - the monitor's parallel view (section 4). **Not in yet:** the single-launch decode step itself - the serve loop calling `forward_rows` once for all the active slots and 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 2` and `--tp 4` both collapse to one member a group), so a layer's compressed rows are written on another device and 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's `forward_par`/`forward_serial` and `layer()`, with every per-position piece taken from the row itself: `finish`'s `pos_rows` rope, the row's own ring block in the window buffer, its own compressor group, its own rows of the compressed tables (one `finish` a row, at the row's own position and 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_i` with `kv_base(sr, seq)`). * the cross-group hand-off for a pass's rows: the rows a pass completes are staged in row order (a pass a chunk), the readers place them in their own copies, and every device's work is finished before the next pass stages. * `finish`'s `pos_rows` indexes the **query**, not the row (`pos_rows[v / vpp]`). A step's `q` carries `vpp = NHL` rows a 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 are sized 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. * two races on buffers reused within a pass, both fixed: the window path's staging had no acknowledgement (a reader's 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 run against the bursts of its own slot count (`batch_step_bench.py --ref`): | slots | bursts, tok/s | step, tok/s | gain | tokens | |---:|---:|---:|---:|---| | 2 | 43.0 | 59.9 | +39 % | the reference's, bit for bit | | 4 | 43.2 | 77.6 | +80 % | the reference's, bit for bit | | 8 | 43.3 | 88.6 | +105 % | the reference's, bit for bit | | 16 | 43.4 | 86.7 | +100 % | differs - see below | 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 deadlocked on 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) plus `cmp_hash.py`/`cmp_num.py` over the per-layer hashes of row 0 (`DS4_STEPCHECK=2`). ## Tests * `serve.test_server`: **Ran 348 tests, OK** * `tools/dsv41/batch_probe.py` (two slots): all checks passed * `tools/dsv41/batch_step_bench.py`, `same_probe.py`, `steprows_check.py` * `docs/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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:31:31 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4945
No description provided.