mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2527] [Engine] Keep conversations in pipelined batch slots (1/3): active-row windows, park=, cache-aware placement behind a policy interface #4095
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#4095
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/2527
Author: @andyhrc
Created: 10/15/2026
Status: 🔄 Open
Base:
main← Head:pr/slot-mechanism📝 Commits (10+)
8d634bcbatch: STRATA_PIPELINE_ACTIVE_ROWS=1 - a pipelined group's window runs its active slots only, so an idle slot keeps its conversation (opt-in)da5a462batch: park=B keeps the main session's conversation in an idle slot before a different request replaces it (with STRATA_PIPELINE_ACTIVE_ROWS=1)2b64831serve: STRATA_SLOT_CACHE_AFFINITY=1 - place batch requests by what the slots hold, with the placement policy as an interface (serve/slot_policy.py)82ba0f4serve: the allocation event and a slot's live row show this request's own placement plan023edc2serve: /metrics live.solo_* clear when the solo request endsd926b13serve: no protection wait - place() always answers a free slot2d9b685serve: no PARK_MIN_TOKENS - a park is not cut off by lengthf89de46batch, serve: park=B tells another conversation by the main session's last turn, not by half of it17fad48serve: a continued request's record keeps its first read's cache source and placement hintc7edf14serve: test_cache_trace imports serve.* by name, so it also loads when serve/ is discovered on its own📊 Changes
16 files changed (+931 additions, -38 deletions)
View changed files
📝
CMakeLists.txt(+3 -0)📝
docs/BATCHING.md(+82 -1)📝
include/strata/core/verify.hpp(+2 -0)➕
include/strata/program/pipeline_rows.hpp(+16 -0)➕
serve/cache_trace.py(+18 -0)📝
serve/server.py(+321 -18)➕
serve/slot_policy.py(+76 -0)➕
serve/test_cache_trace.py(+29 -0)📝
serve/test_parallel.py(+30 -2)📝
serve/test_parallel_yield.py(+28 -0)📝
serve/test_slot_alloc.py(+164 -1)📝
src/core/verify.cpp(+7 -2)📝
src/program/generate.cpp(+86 -10)📝
sycl/include/strata/core/verify.hpp(+2 -0)📝
sycl/src/core/verify.cpp(+8 -4)➕
tests/core/pipeline_rows_test.cpp(+59 -0)📄 Description
Problem and result
On a layer split with
--batch, conversations are lost between turns in two ways. First, a pipelined group's window runsevery slot up to its last active one, so an idle slot below an active one becomes a pad row and loses its state. Second, a
long conversation on the solo path is overwritten by the next, unrelated request. Agent clients (Claude Code, Codex) send
long conversations in many short turns, with short side requests in between. On our server that meant re-reading tens of
thousands of tokens on a large share of turns.
The engine log of 2026-10-09 to 2026-10-14 (3 x RTX A4000 16 GB layer split,
--batch3-6 in 3 groups, two peopleusing Claude Code and Codex) had 3,027 prompts of 8K tokens or more. 538 of them reused less than half of their previous
turn, and 40.7M prompt tokens were read again. The causes below are classified by prompt lengths; the log has no content,
so this is a heuristic:
At about 2,900 tok/s for long prompts on this machine, the first two rows are about three hours of prompt reading.
With this PR and the policy of #2528, the next turn of a 37,359-token conversation after a side request reused 37,352
tokens and took about 1 s, instead of 0 tokens and 14 s. The greedy output after the restore was the same.
Everything is opt-in. With every variable unset, the engine's output and the generation path are unchanged.
Related discussion
There is no issue. This PR was opened on 2026-10-14 and closed in the 0.2.0-beta tracker reset; it is rebased on current
mainhere. This is part 1 of 3:serve/slot_policy.pyis aninterface only: its policy functions raise
NotImplementedError.serve/slot_policy.py.Each later branch contains the earlier ones' commits. Merge in that order. With all three merged, the code is what we run
in production (plus a few local-only diagnostics we do not propose). If you prefer other rules than ours, merge this PR
and write your own
serve/slot_policy.pyagainst the interface; the server side does not change.I can open an issue for the scope first if you prefer.
Approach
STRATA_PIPELINE_ACTIVE_ROWS=1. A pipelined group's window lists only its active slots(
include/strata/program/pipeline_rows.hpp,Verifier::batch_launch_rowsfor CUDA and SYCL). There is no pad row, soan idle slot keeps its conversation; the engine prints
INFO slot_padding_safe=1. After a prompt's restore it printsCACHE_SOURCE <slot or -1> <tokens>. The test istests/core/pipeline_rows_test.cpp, registered in CMake.park=B(INFO slot_park=1 turn_token=<id>, with the variable above). A prompt counts as anotherconversation when it does not share what the main session holds up to its last turn, the last
<|im_start|>. (Twochats of one client share a long system prompt; a next turn without the reply's thinking shares the history.) For such
a prompt, the engine first copies the main session's conversation into idle slot B and says
PARKED B <tokens>. Theserver's claim uses the same test.
STRATA_SLOT_CACHE_AFFINITY=1.pick_slotasksslot_policy.place(), which always answers a free slot. A request waitsonly when every slot is busy, as before.
slot_policy.park_destination()before sendingpark=.slot_padding_safe=1, the server tracks fromBADM/BT/BDONEwhich idle slot a later window haspadded over.
/metricsgains:live.cache_events, the last 96 placement eventsX-Forwarded-For)live.solo_*and per-slot cache fieldsSTRATA_CACHE_TRACE=1adds a per-request snapshot of what each slot shared with the prompt (serve/cache_trace.py,lengths only).
cache source and placement hint. This last part is new since the previous review: before it, a 207K prompt's
record could show a 214K placement hint.
The interface in
serve/slot_policy.pyhasplace,park_destination,cache_state,superseded_slots,reliable_flagsandconfigure/settings; the docstrings state the contract. Without a policy,STRATA_SLOT_CACHE_AFFINITY=1andSTRATA_CACHE_TRACE=1raiseNotImplementedError. The new/metricsfields arepresent with the variables unset too (additive only). If you prefer them behind a variable, say so.
Rebase on
main(5e8a4cca, v0.2.7). One hand merge: v0.2.7 addsSTRATA_PIPED_MTP(#4121,--batch-mtp), which packs a group's rows too (each active slot's token, then its drafts). The two sharePGroup::rows: a window is built as #4121's when that is on, else from the active rows, else as the old span, and launched in the same order.Verifier::batch_launch_rowsnow has two overloads (#4121's deferred-commit one takes(rows, S, hbase, ...), this PR's(base, S, rows, ...))./metricslive.cache_eventsandlive.slot_policysit beside the newlive.split_serve. The rest stays where earlier rebases placed it:PGroup::activecounts the packed rows, andstage_in_flightis recorded before either launch.carries
request_idandprompt_readas well as the client address.serve/test_parallel.py/serve/test_parallel_yield.pynow holds their neighbours.Validation
Passed:
pr/slot-mechanismatc7edf14a, onmain5e8a4cca(v0.2.7). The serve tests were run on this head; the GPU runs name their own revision. Ubuntu, AMD EPYC 7543,3 x RTX A4000 16 GB, CUDA 13.3.
python3is the repository's.venv.python -m unittest discover -s serve -t .on this branch: 1229 tests OK (38 skipped).requirements.txt, thentools/minimal_server_smoke.pyandpython -m unittest discover -s serve -p 'test_*.py'): smoke OK, 1229 tests OK (38 skipped). The previous head failed there onserve/test_cache_trace.py's relative imports (fine with-t .); this PR's last commit fixes them.cmake -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86 -DSTRATA_BUILD_TESTS=ON, Release), andpipeline_rows_testpassed. On v0.2.7: this head's native CUDA buildpassed (sm_86, Release), and
pipeline_rows_testpassed (built from our production tree: this stack + local-only diagnostics).58eef307on v0.2.1.1, which contains this PR, with its own engine andserve/server.py; repeated with our v0.2.7 production build, below).Setup: Qwen3.8-Flash-Next IQ3_S, 200K context, int8 K/V,
--batch 6in 3 groups,STRATA_PIPELINE_ACTIVE_ROWS=1 STRATA_SLOT_CACHE_AFFINITY=1 STRATA_CACHE_TRACE=1. Results: an agent conversation (27,348 tokens) took the main session between classifier queries. Each time, the classifier transcript it displaced was parked into an idle slot first (PARKED, 43-44K tokens in 167-231 ms). Each of its next five turns found it in the slot that kept it: 27,341 tokens reused in 0.73-0.76 s, where the first read took 10.4 s. With a thinking chat and four other conversations on the 6 slots, the reuse was the same, token for token, as on 0.1.45.5e8a4cca, its own engine andserve/server.py) with the deployed switches repeated the run on 2026-10-28. S: 13.8, 14.5, 1.21, 1.40, 1.65, 1.80 s; B: 0.54, 0.97, 1.09, 1.30, 1.61, 1.75 s; the thinking chat's next turn reused 19,176 tokens in 0.58 s, and the other conversations reused the same tokens as on v0.2.1.3. Throughput (tools/serve_load.py, temperature 0, one run each on two fresh engines, on the build before #2843's last commit, which changes only a give-back): 67.6 / 63.0 tok/s with one client (1,024 tokens), 190.7 / 191.5 tok/s total with 6 clients x 2,048 tokens (v0.2.2: 64.3 / 193.7).since 2026-10-15.
Failed:
None observed. (The previous revision's note about
serve.test_responses.NoLeakedSamplerfailing on main here no longer applies: the whole suite passes.)Not run:
STRATA_PIPELINE_ACTIVE_ROWSon 0.2.x. On 0.1.44.1 (the same binary off / on,tools/serve_load.py,6 clients x 2048 tokens, one run each) it measured 177.4 / 173.5 tok/s, inside the run-to-run spread (173.9-178.2).
STRATA_PIPED_MTP(the latter builds the window then). We do not run--batch-mtp: on this machine it was slower (6 clients: 88.6 against 170.9 tok/s on 0.1.45).Limits
prefix, whatever the placement does. #2843 handles the case where only the end is rewritten.
--batchwithout them (one GPU, or--batch-groups 1) keeps its currentslot choice.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.