mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #559] [CLOSED] Several conversations at once: batch slots, a pipelined layer split, per-stage dense weights #2689
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#2689
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/559
Author: @blange48
Created: 10/2/2026
Status: ❌ Closed
Base:
main← Head:multi-sequence-batching📝 Commits (10+)
ba707d8Several conversations at once: batch slots, pipelined layer split, per-stage dense weightsc67052cserver: a client that stops reading early keeps the engine in stepe11166bConversation parking with --layer-split220ccbbTests and docs: parking with a layer split, tools/parking_test.py, a Testing sectionf67bf51Parking with a layer split: the draft ring once, every stage's K/V reused, checkpoints moved not copied537588fParking with a layer split: the draft ring with the last stage, on its GPU; guards; trim logbd400f7Layer split comment: KV streaming and images do run across a splitf0c61d3Speculative batch, step 1: rows per slot in batch windows and commits (set_batch_rows; 1 = unchanged)6840647Speculative batch, step 2: MtpDrafter::clone_from (a drafter per slot sharing the weights) and copy_kv_from72774f2Speculative batch, step 3: --batch-spec N (MTP drafts in batch windows, a drafter per slot)📊 Changes
22 files changed (+3119 additions, -133 deletions)
View changed files
➕
docs/BATCHING.md(+148 -0)📝
docs/DETAILS.md(+23 -3)📝
docs/MULTI_GPU.md(+5 -0)📝
include/strata/core/conversation_cache.hpp(+69 -3)📝
include/strata/core/conversation_snapshot.hpp(+17 -0)📝
include/strata/core/mtp.hpp(+15 -0)📝
include/strata/core/native_dense.hpp(+3 -1)📝
include/strata/core/verify.hpp(+88 -0)➕
serve/prometheus.py(+153 -0)📝
serve/server.py(+295 -9)➕
serve/test_prometheus.py(+181 -0)📝
src/core/conversation_cache_test.cpp(+92 -0)📝
src/core/conversation_snapshot_test.cpp(+41 -0)📝
src/core/conversation_state.cpp(+45 -18)📝
src/core/mtp.cpp(+75 -10)📝
src/core/native_dense.cpp(+8 -2)📝
src/core/verify.cpp(+559 -52)📝
src/program/generate.cpp(+709 -35)➕
tools/autoconfig.py(+303 -0)➕
tools/batch_test.py(+154 -0)...and 2 more files
📄 Description
Several conversations at once: batch slots, a pipelined layer split, per-stage dense weights
Strata serves one request at a time today (#465, #249): with several clients everything queues. This PR lets one
engine process decode several conversations together, opt-in, without changing anything when the new options
are absent. Full description in the new
docs/BATCHING.md.What it adds
1. Batch windows in the verifier (
--batch N, 2..8) -include/strata/core/verify.hpp,src/core/verify.cppsis slots, at its own position,reading and writing its own state, which lives in its own
SessionState(carved withsession_initlike thestage's own session: same layer range, same
max_cells).record_windowloop over the slots: the GDN conv history and recurrence(
gdn_conv_l2_multi/gdn_step_norm_multion each slot's state, one row each), the QSA K/V append, indexerappend, block selection and attention on each slot's
QsaState, and the PLE history. Everything that is per rowalready - hyper-connections, the dense projections, the router, the shared expert, the routed experts on the GPU
and the CPU pool, the head - runs once over the S rows, so the weights are read once per window for all of them.
that needs no host decision.
init_slots,run_slots/commit_slots(synchronous), andbatch_launch/batch_poll(asynchronous,for the pipeline below). Graphs are captured per (first slot, count).
window's Philox(seed, position).
2. A pipelined layer split (
--batch-groups G) -src/program/generate.cppslots, a batch window over one group is launched on one stage with its commit right behind it on the stage's
stream, and one host thread serves the rings of every stage that has a window in flight (
batch_polldoes notblock). Stage k then runs group g while stage k+1 runs group g-1.
3. Per-stage dense weights (
--trim-stage-weights) -src/program/generate.cpp,src/core/native_dense.cpp--layer-split, every GPU loaded the whole model's dense weights although it runs a quarter ofthe layers. With the option, each GPU skips the
blk.<l>.tensors outside its range, both in the pack(
WeightTable::load's skip list) and in the native projections (NativeDense::loadtakes a layer range). The VRAMgoes back to the expert cache. Useful without
--batchtoo.4. The engine protocol and the server -
src/program/generate.cpp,serve/server.pyBGEN <slot> <max_new> [keys] <ids>(andBGENI) reads the prompt through the usual path as aGEN 1(promptcache, checkpoints, images), then copies the state into the slot with the existing
conversation_checkpoint_save/restoreandconversation_kv_save/restoreon every stage, and answersBADM <slot> 1|0. Slots streamBT <slot> <id>and end withBDONE <slot> ...;BSTOP <slot>ends one.Between batch windows the engine reads its input without blocking.
StrataEngine.generate_batched) runs concurrent requests in the slots when the engine has--batch:a request alone takes the solo path (MTP drafts, the fastest single stream); when another one arrives, it is
STOPped and continues in a slot with its prompt plus what it generated (the prompt cache holds exactly that), and
the newcomer is admitted next to it. The request FIFO is bypassed in this mode.
5. A client that stops reading early (second commit) -
serve/server.pyrequest is STOPped and read to its DONE, an admission to its BADM, and a slot is BSTOPped and freed only at its
BDONE. Without it the engine went on writing the abandoned answer and the next request read it as its own (seen
with an agent client: the previous answer came back).
tools/early_close_test.pyreproduces it;STRATA_BATCH_TRACE=1logs the control lines.6. Conversation parking with
--layer-split(third commit, by @crazyaimachine, from their comment below) -include/strata/core/conversation_cache.hpp,src/program/generate.cppand put back together on restore; every stage image is validated before anything is overwritten; the guard that
rejected parking with a split is removed.
follow-ups token-identical to the conversation that never left (without parking: 3.4 / 6.8 s to re-read them).
Through the HTTP server, two long conversations alternating: follow-ups at 0.53 / 0.46 s to the first token
instead of 3.9 / 5.7 s.
8. The parking follow-ups (fifth commit), the open points from that comment:
conversation_snapshot_*take aconst QsaState* draft,nullptrfor an image without it (the later stages);ConversationKvReuse::stages), so a conversation parked again copies onlywhat changed on every stage - 141 MB reused on the second park of a 9K-token conversation in
parking_test.py;conversation_checkpoints_split/_merge), not copied;conversation_cache_test(split/merge round trip without copies, refused misalignments, per-stagereuse) and
conversation_snapshot_test(draft-less images: estimate, validation both ways, exactness,incremental reuse) - 4,191 and 2,155 checks passing.
9. The draft ring with the last stage (sixth commit): the draft layer's K/V lives on the last stage's GPU (the
drafter is loaded there), so it is now saved, restored and verified with that stage's image under that device, not
with stage 0's on GPU 0 (where the ring-restore kernel ran against another GPU's memory - #653 places it the same
way). Also: parking with a split on one GPU (
--split-device 0) is refused at start, the whole-session validaterefuses a split image, and
--trim-stage-weightslogs each GPU's layers. Re-verified on 4 GPUs withSTRATA_SNAPSHOT_VERIFY=1: follow-up identical, draft ring read back, 141 MB of K/V reused on the second park.10. MTP drafts in batch windows and active-slot group windows (by @crazyaimachine, 9 commits from their
comment below, applied unchanged):
a pipelined group window holds its slots only up to the last active one, instead of every slot of the group
(idle slots ran pad rows through every layer);
--batch-spec N: MTP drafts in batch windows (rows per slot, a drafter per slot sharing the weights, per-slotn_keepcommits, rows chosen per group window, drafts while at most--batch-spec-max-activeslots are active),and the n-gram rows read token by token (a drift found on the way).
Re-verified on 4 GPUs: 8 slots identical to solo, 3 slots with
--batch-spec 2identical, parking identical(141 MB of K/V reused on the second park). Through the HTTP server (T=0.7, 300 tokens):
--batch-spec 2(reserve 2000 MiB)--batch-specneeds room for the slot drafters (at 262K context, 8 drafters did not fit in 700 MiB ofreserve on 16 GB cards); the larger reserve costs expert residency, so on this machine it does not pay.
11.
tools/autoconfig.py: the settings above from the machine (GPUs, VRAM, PCIe link, RAM, layer count),with
--calibrateto measure the candidates; on the 4-GPU machine the rules give back the hand-tuned config andname the card on an x8 link. Documented in
docs/BATCHING.md.12.
/metricsfor Prometheus, with vLLM's names (three commits) -serve/prometheus.py,serve/server.py:Accept: text/plain/ openmetrics, or?format=prometheus) gets the text format with vLLM's metricnames (running / waiting, context usage, token and request counters, prefix-cache queries and hits, MTP drafts,
TTFT / inter-token / end-to-end histograms), so dashboards and alerts written for vLLM read Strata; anything else
keeps the JSON;
strata:, named after their JSON key (strata:live_tok_s,strata:gpu_utilper card, ...), so the Monitor tab and Grafana read the same values;--batch, every concurrent request is now recorded (history, totals, latencies): they shared one statusand only the last to finish was counted.
serve/test_prometheus.py(6 tests, one with three requests at once).Documented in
docs/DETAILS.md.7. Tests (fourth commit):
tools/parking_test.py,tools/batch_test.py --keys, and a Testing section indocs/BATCHING.mdlisting the three scripts and how to run them exactly.Rebased on main (engine 0.1.38): the 8-conversation exactness test still passes there.
Correctness
A batch row's arithmetic is the single-token window's, so greedy outputs are the solo outputs:
tools/batch_test.pydecodes the same prompts alone and in batch and compares them token by token. 8 concurrent conversations x 150
tokens: identical to their solo runs, with the synchronous batch and with the pipeline (2 and 4 groups), with
STRATA_IQ_MT_MIN=1and--pcie-frac 0. With a PCIe share, which missed experts go to the GPU depends on thewindow's misses, so the rounding can differ and outputs drift apart after some tokens (as two solo runs with
different windows can) - documented.
Measured
4-GPU layer split (4 x 16 GB, PCIe Gen3), IQ3_S,
--batch 8 --batch-groups 4 --trim-stage-weights, HTTP server,400 tokens per answer, temperature 0.7:
Without the pipeline, 8 slots ran at ~180 tok/s; without
--trim-stage-weights, ~105 tok/s (the cards held 76-85 %of the experts instead of 84-100 %, and the CPU computed the rest for every row).
Not done (yet)
--batch-groupsneeds each stage on its own GPU; the slot sessions take VRAM and pinned RAM like the stage'ssession.
setup.py:tools/autoconfig.pywrites them into a copy of the config.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.