Repository navigation
Conversation
…nger take a picture's place (Niko1221#150 follow-up) The markers are special tokens only where the template writes them for an image item. The same strings in a message's text (an agent reading chat_template.jinja, a tool result quoting it) became the same special ids, so text with <|vision_start|><|image_pad|> before a picture took that picture's embeddings, every later picture moved up one and the last real marker became text - every count still matched. On 0.1.39 this takes Niko1221#537's path: the vision markers join <think> / </think> as literal tags (frontend.VISION_TAGS), swapped for private-use marks before the template and encoded as text through the tokenizer's plain spans. A pair of markers cut apart across text parts is refused ("the prompt and its images do not match") instead of shifting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio
Author
|
Closing: this went into 0.1.40 from #554 (see the comment there). It was reopened here only because my old fork had gone private; thank you for taking it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #554. GitHub closed it on 2026-10-05, when my fork was made private by mistake: that took the fork out of the network for good, so it can no longer open pull requests. This is the same branch and commit (
1273345), opened from a new fork; the discussion and the measurements are in #554.Service.prepare()renders the chat template and tokenizes the whole prompt withparse_special=True. The template writes<|vision_start|><|image_pad|><|vision_end|>for each image item, and the #150 guard turns only an<|image_pad|>not preceded by<|vision_start|>back into text.Message text that contains the whole marker pair becomes the same special ids as a real image. That happens with an agent reading
serve/chat_template.jinja, these docs, or a tool result quoting them. If such text comes before a real picture:The counts still match, so nothing reports it. With Claude Code reading a repository and a screenshot in one conversation, this is an ordinary case.
Fix (
serve/server.py,Service.prompt_ids()):parse_special=False) tokens. The pieces between placeholders are tokenized as before, since a special token split the text there anyway.count_tokensuses the same ids.Test
test_the_whole_marker_in_text_before_images: each picture's rows follow its own marker, and the text keeps its literal tokens. Without the fix it finds 3vision_startwhere 2 belong. The #150 test is unchanged. Serve tests: 173 OK (7 skipped).This touches the first lines of
prepare(), as #529 does; whichever goes in second needs a one-line rebase.🤖 Generated with Claude Code
https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio