mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
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#4097
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/2528
Author: @andyhrc
Created: 10/15/2026
Status: 🔄 Open
Base:
main← Head:pr/slot-policy📝 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 (+1892 additions, -38 deletions)
View changed files
📝
CMakeLists.txt(+3 -0)📝
docs/BATCHING.md(+149 -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(+331 -18)➕
serve/slot_policy.py(+291 -0)➕
serve/test_cache_trace.py(+44 -0)📝
serve/test_parallel.py(+69 -2)📝
serve/test_parallel_yield.py(+28 -0)📝
serve/test_slot_alloc.py(+779 -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
#2527 lets the server place batch requests by what the slots hold, behind the interface
serve/slot_policy.py. This PRis the policy behind that interface. It decides which idle slot a request runs in, which history to give up, how long a
history is protected, and where the solo path's conversation is parked.
Plain rules cannot tell which history to give up when a new conversation needs a slot and no free slot is without value.
The one used longest ago may be a 90K-token conversation whose user is reading the answer; the newest may be a side
request's 300 tokens. This policy weighs length and age. Every threshold is a parameter in the server config's
"env",so most other behaviours are a matter of setting them.
Result on our machine (3 x RTX A4000 16 GB, Qwen3.8-Flash-Next IQ3_S,
--batch 6in 3 groups):14 s.
versions of the same transcript.
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 2 of 3 and depends on #2527; the branch includes #2527's commits, so review the policycommits after those. #2843 (part 3) builds on it. #2589 is the small counterpart for the path this PR does not
change:
--batchwithout pipelined groups. If you prefer other rules, keep #2527 and replaceserve/slot_policy.py.I can open an issue for the scope first if you prefer.
Approach
STRATA_SLOT_TTL_MAX_SSTRATA_SLOT_EXPIRED_KEEP_SCORESTRATA_SLOT_IDLE_VALUE_ZERO_SSTRATA_SLOT_PARK_VALUE_RATIOSTRATA_SLOT_PARK_MIN_VALUESTRATA_SLOT_PARK_KEPT_SHARESTRATA_SLOT_SIBLING_SHAREProtection by length (piecewise linear):
Retention = (n / 50000)^0.7 x (n / (n + 2000))^2 x (0.25 + 0.75 x freshness), where freshness = 1 - age / TTL,
and 0 once expired. The overwrite score is 1 / (1 + retention). A fresh 50K history is worth about 1, a 500-token one
0.002.
Value after expiry = (n / 50000)^0.7 x (n / (n + 2000))^2 x 0.25 x (1 - x^2), where x = clamp((age - TTL) /
(idle_value_zero_s - TTL), 0, 1).
controls replacement and parking, never cache validity. No timer deletes anything.
Blank slots count as expired and worthless: empty, invalid, or holding a superseded copy.
A continued conversation runs in its own slot or in a blank slot of a less loaded group, never in a slot that
holds another conversation. Near matches count as sources: within 2% of the best, one second of the prompt rate, or
4096 tokens.
An older version of the same conversation (
STRATA_SLOT_SIBLING_SHARE) is replaced in place. Claude Code's safetyclassifier rewrites the end of its transcript every query. Under the rules above, the previous query's slot would still
be protected, so each query would take another slot.
A new conversation takes, in order:
STRATA_SLOT_EXPIRED_KEEP_SCOREA park uses the same order (
reclaim_slot).No wait. When every history is protected, the policy overwrites the least loss at once; losses within 10% are
ranked by group load. An earlier version waited up to 5 s first. With more requests than slots, each wait ran its full
5 s and ended in the same overwrite.
Park. No park when:
STRATA_SLOT_PARK_MIN_VALUE, orSTRATA_SLOT_PARK_KEPT_SHAREof it.Otherwise the destination is, in order:
STRATA_SLOT_PARK_VALUE_RATIOtimes as muchA park never goes into another protected slot. A park keeps the conversation's last use, so it cannot renew its
protection.
Rebase on
main(5e8a4cca, v0.2.7): no conflict; the policy is unchanged.Validation
Passed:
Revision. Branch
pr/slot-policyatdf1d87bd, 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.
Serve suite.
python -m unittest discover -s serve -t .on this branch: 1291 tests OK (38 skipped). Its cases are mainly inserve/test_slot_alloc.py(the policy's own cases, including the production scenarios below),serve/test_parallel.pyand
serve/test_cache_trace.py.The CI job's form ("Minimal serving runtime": a venv with only
requirements.txt, thentools/minimal_server_smoke.pyandpython -m unittest discover -s serve -p 'test_*.py'): smoke OK, 1291 tests OK (38 skipped). The previous head failed there onserve/test_cache_trace.py's relative imports (fine with-t .); the last commit of #2527 fixes them.GPU run. Run on the tip of the stack (#2843's branch at
58eef307on v0.2.1.1, 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,
--batch 6in 3 groups, the deployed settings(
STRATA_SLOT_CACHE_AFFINITY=1,STRATA_SLOT_PARK_MIN_VALUE=0.1, the other thresholds at their defaults). Results:the agent conversation and the classifier chain kept their own slots through six alternations, alone and with a client decoding beside them. Every agent turn reused its 27,341 tokens, and every classifier query from the third on reused 43,340 tokens (#2843's part). With a thinking chat beside four other conversations, the reuse was the same, token for token, as on 0.1.45.
On v0.2.7. Our production build of this stack (plus a few local-only diagnostics, on
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).Earlier GPU checks on 0.1.44.1 (same machine), not repeated on 0.2.x. Conversation A (37K tokens) was parked;
two clients generated 1,500-token answers in a loop; conversations B (9K) and C (7.9K) took turns about every 30 s,
past their protection. Tokens reused on turns 1-3:
This PR accepts the second row: a protected history is not overwritten while an expired one can be. With
STRATA_SLOT_IDLE_VALUE_ZERO_S=150:park_skip,main_low_value)Equivalence check.
place()before and after the shared reclaim order chose the same slot in 200,000 random slottables.
Production. It has run in production 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: no throughput or cache-hit measurement over a working day is claimed for the 30-minute default.
Limits
slot_padding_safe=1, starting a row above a protected idle history costs thathistory's retention too.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.