mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1852] [CLOSED] serve: tokenise the prompt from the last shared prefix, not from the start #3719
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#3719
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/1852
Author: @gputier
Created: 10/10/2026
Status: ❌ Closed
Base:
main← Head:pr/prompt-encoder-0.1.41📝 Commits (8)
c73b389serve: the prompt is tokenised from the last shared prefix, not from the start4a1bab0serve: #567's server tests take their reference from a full encode_prompt62ec02dtools: llama.cpp's qwen35 vectors are checked with the qwen35 vocabularye13bb1fserve, tools: #567's tests and ByteTokenizer without repeated code6f6ebc1serve: #567's kept prompts, one per conversation, none refused for the contextda7fa64serve: keep one prompt per engine conversation cache slot401cc50serve: count tokens without storing the prompt in the encoder9b92530serve: size the kept prompts from --conversation-cache-slots on a lazy start too📊 Changes
6 files changed (+776 additions, -14 deletions)
View changed files
📝
SECURITY.md(+3 -1)📝
serve/server.py(+55 -10)➕
serve/test_prompt_encoder.py(+162 -0)📝
serve/test_server.py(+138 -0)📝
tools/strata_tokenizer.py(+120 -1)📝
tools/test_strata_tokenizer.py(+298 -2)📄 Description
This reopens #567 on the new main, as Niko1221 suggested after the history rewrite. It supersedes #567 and closes nothing.
Every request re-encoded the whole conversation before the engine saw it.
PromptEncoderkeeps the last prompts with their ids and resume points, and encodes only the text that follows the longest shared prefix. The ids are the ones a full encode gives, token for token.Changes against #567
Rebased on v0.1.42 (
61b3fb5d). #931's literals (control-token text inside a message stays text) go through the incremental encoder: the shared prefix ends where the two prompts' plain spans first differ. blange48 merged #567 with #931 the same way on port-567, and stays credited as co-author. f346dc6b's piece cache is kept, and the incremental encoder sits on top of it. Upstream'stools/test_strata_tokenizer.pytests are all kept, and ours are added.Two fixes of #567's own behaviour:
--conversation-cache-slots, 4 without it). Token counts (/v1/messages/count_tokens) read the kept prompts without storing one.SECURITY.md now says that the server keeps the text and ids of its last few prompts in memory, and that no endpoint shows them.
Numbers and tests
Measured on v0.1.41 with llama.cpp's qwen35 vocabulary,
Service.encode_promptper turn, 12 measured turns per pass, in a 10-CPU Linux container on an Apple M5 Pro:python -m pytest serve tools/test_strata_tokenizer.py: 598 passed, 18 skipped, 0 failed (v0.1.41 alone: 584 passed, 11 skipped). The 7 extra skips are the qwen35-vocabulary tests, which needSTRATA_TOKENIZERor llama.cpp's vocab file. Fuzz: 2,400 random plain/literal-span cases, incremental against full, and 2,400 random message prompts throughService.encode_promptwith control-token and think text quoted. All equal.Five commits on v0.1.41:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.