mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #931] [CLOSED] serve: control-token text inside a message stays text (<|im_end|> in a file no longer ends the turn) #2922
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#2922
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/931
Author: @asp345
Created: 10/5/2026
Status: ❌ Closed
Base:
main← Head:serve-control-token-text📝 Commits (3)
1c3df53serve: a control token's text in a message is encoded as text (<|im_start|>, <|im_end|>, <|endoftext|>, ...)9959073serve: control literals are marked longest first; the server reads the tokenizer's list directlyafe2706serve: mark_literals and unmark_literals, the names of what they now do📊 Changes
4 files changed (+131 additions, -33 deletions)
View changed files
📝
serve/frontend.py(+37 -28)📝
serve/server.py(+11 -4)📝
serve/test_server.py(+82 -1)📝
tools/strata_tokenizer.py(+1 -0)📄 Description
The problem
The server renders the chat template and then tokenizes the whole prompt with control tokens parsed. So when a message contains the text
<|im_end|>or<|im_start|>, that text becomes the real token.Take a user message that includes these lines, for example from a file or a web page an agent read:
The model does not see those characters. It sees the user turn end, a real system turn, and a new user turn.
Two things go wrong:
IM_END = "<|im_end|>", it answersIM_END = "and stops.0.1.39 already fixed this for
<think>and</think>(#537). #554 proposes the same for the four vision markers. This PR does it for every control token.The change
It reuses #537's mechanism and adds no new one.
Tokenizer.control_tokenslists the tokenizer's control tokens (GGUF token type 3). Qwen3.8-Flash-Next has 27.literal_tags()gives each of them a private-use mark, next to the marks of the think tags.mark_think_literals()andunmark_think_literals()take that table and are renamedmark_literals()andunmark_literals(), since they no longer handle only the think tags. The server passes the table inencode_prompt().The table is ordered longest first, as the tokenizer's own matching is. A control token whose text sits inside a longer one is then handled whatever the vocabulary's order. This model's 27 do not nest.
The result: only the control tokens the template writes are control tokens. A prompt without such text gets exactly the same token ids as before.
Measured
Both arms use the same 0.1.39 engine build. Only the server code differs: upstream's against this branch. Qwen3.8-Flash-Next IQ3_XXS, one RTX 3060 12 GB, greedy, thinking off.
How to read it:
print("<|endoftext|>")came back asprint("Hello, World!").No change where none is expected:
Relation to #554
#554 uses the same mechanism for
<|vision_start|>,<|image_pad|>,<|vision_end|>and<|video_pad|>, with a fixed table. This PR takes the list from the tokenizer, so those four are included. Both PRs touch the same lines inserve/frontend.py, so whichever goes in second needs a small rebase. #554 also adds a check that the prompt and its images match. That check is not part of this PR.One leftover: the older guard in
prepare()that turns a stray<|image_pad|>back into text (#150) can no longer trigger from message text with this change. I left it in place because #554 edits the same block.Not covered
<tool_call>,</tool_call>,<tool_response>and</tool_response>(token type 4) inside message text still become their tokens. The chat template itself looks for<tool_response>in message content, and I have not measured this case, so I left it alone.Test
LiteralControlTokensinserve/test_server.py(6 tests) fails on 0.1.39 and passes with this change.serve.test_server: 145 tests pass. The other serve test modules give the same results as on 0.1.39.serve.test_responseshas one error,test_json_schema_text_format. It is the same on 0.1.39 without this change.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.