mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1536] serve: reuse a reply's own token ids on the next turn, keep the tokens drained after a budget stop (opt-in STRATA_REPLY_REUSE) #3516
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#3516
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/1536
Author: @zsariboga
Created: 10/8/2026
Status: 🔄 Open
Base:
main← Head:pr-reply-reuse📝 Commits (1)
1de969bserve: reuse a reply's own token ids on the next turn, keep the tokens drained after a budget stop (opt-in STRATA_REPLY_REUSE)📊 Changes
5 files changed (+208 additions, -0 deletions)
View changed files
📝
docs/DETAILS.md(+9 -0)📝
serve/server.py(+37 -0)📝
serve/test_prompt_encoder.py(+64 -0)📝
serve/test_server.py(+50 -0)📝
tools/strata_tokenizer.py(+48 -0)📄 Description
Rebased on #1852's
PromptEncoder(the encoder now onmain), as asked. The branch is one commit onmain(477ac13c). It no longer depends on #1455.What it changes
Everything new is opt-in behind
STRATA_REPLY_REUSE=1. With the variable unset, every prompt is a fresh encode and the server behaves exactly asmaindoes.PromptEncoder.remember_reply(prompt_ids, gen_ids)(tools/strata_tokenizer.py, +48 lines). After a reply, the server keeps the prompt plus the reply's own ids as one encoder entry._straddles).encode, a prompt that shares the text past the reply's start may cut at those boundaries without themax_special_len - 1margin. The engine holds those ids, and the text from the cut on is encoded afresh.serve/server.py). The engine sends a few tokens after the budget's STOP before it sees it, and keeps them in its session. They are now collected while draining (StrataEngine.drained). With the switch, they join the thinking when they are plain text (no stop token, no<, no split character), so the wrap-up continuation extends the session instead of reading the thinking again.STRATA_PROMPT_DUMPdiagnosis and the raised encoder limits are gone. #1852's encoder has no such limits.Why
In agent sessions the engine often read a whole reply again on the next turn, although the reply's state was still in its session. The model writes some text in pieces BPE would merge (Turkish letters, digits, code), so the next turn's fresh encode leaves the engine's ids at the first such piece. A reply has no checkpoint inside it, so the engine went back to the turn's start. One real case: 364 tokens reused and 1903 read, where about 885 could have been reused.
Measured (the previous version, 0.1.40.3)
Setup: RTX 5070 Ti Laptop 12 GB, Core Ultra 7 255HX, 64 GB DDR5-5600, Windows 11, Swift 1.5 abliterated IQ3_XXS, opencode.
Not re-measured end to end on this rebase. The unit tests below check the encoder and the budget path. I run the same encoder change on 0.1.45 locally.
Tests
serve/test_prompt_encoder.pyReplyReuse(4 new, with a small BPE vocabulary where 'ab' / 'abc' / ' a' merge):serve/test_server.pyThinkingBudget(3 new):python -m unittest discover -s serve -t . -p "test_*.py"(Windows): 855 tests, one failure. It istest_keepawaketest_service_holds_for_the_whole_request_including_early_close, which also failed on unchangedmainhere and passes when run on its own (timing).Python only: no engine, HIP or SYCL file is touched.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.