Repository navigation
server : accumulate generated text and tokens as parse input - #29876
Merged
Merged
Conversation
pwilkin
reviewed
Oct 3, 2026
| input.append(piece, tokens[i]); | ||
| } | ||
| if (input.text != text) { | ||
| // the pieces do not give back the same text, keep the text without tokens |
Member
There was a problem hiding this comment.
I think we should print a warning here so we can figure out what the reason behind the discrepancy is.
Contributor
Author
There was a problem hiding this comment.
Hmm, I don't think that's necessary. It will generate a warning on every request, and if this is an issue it should be caught when writing the parser since parsing the generation prompt would fail if token based but it falls back to text.
pwilkin
approved these changes
Oct 3, 2026
pwilkin
left a comment
Member
There was a problem hiding this comment.
Looks OK to me, looking forward to this one :)
ngxson
approved these changes
Oct 4, 2026
auRose94
pushed a commit
to auRose94/llama.cpp
that referenced
this pull request
Oct 28, 2026
…g#29876) * server : collect text and token input * common : add a tokenize helper that aligns tokens with bytes * common : simplify tokenize logic
1 task
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 14, 2026
…nd in the parsed output Input: the server tokenized the rendered chat prompt as one string with parse_special, so a file the agent read and sent back as a tool result turned "</think>", "<tool_call>", "<|im_end|>" into the special tokens. llama_tokenize_with_literals() takes byte ranges in which no special token is matched, not even a user-defined one (Qwen's <think> and <tool_call> are USER_DEFINED and match even with parse_special = false). The text runs between real special tokens are still tokenized as a whole, so the tokens across the part borders are those of the whole text. The jinja input marking (ggml-org#30389) gives the ranges; tokenize_chat_prompt() follows the shape of the open upstream PR ggml-org#32033 (--chat-input-special / --no-chat-input-special), also for the count-tokens endpoints and mtmd (mtmd_tokenize_from_parts joins adjacent text parts and passes the literal ranges). Fork default: disabled, client text is text; a request may set "chat_input_special". Output: with the vocab's special token table, a PEG literal or until delimiter that names a special token matches only that token id in the generated tokens (ggml-org#29876), so "</think>" or "<tool_call>" written as ordinary tokens in reasoning or content no longer cuts it. A small stand-in for the token-aware parsing of the open upstream PR ggml-org#29307. Text without tokens parses as before. Refs: mkyt docs/decisions.md P6-50, P6-51; ggml-org#28249, ggml-org#32033, ggml-org#29307, ggml-org#29876, ggml-org#30389, ggml-org#28250. Co-Authored-By: Claude Opus 5.5 <[email protected]>
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 17, 2026
…nd in the parsed output Input: the server tokenized the rendered chat prompt as one string with parse_special, so a file the agent read and sent back as a tool result turned "</think>", "<tool_call>", "<|im_end|>" into the special tokens. llama_tokenize_with_literals() takes byte ranges in which no special token is matched, not even a user-defined one (Qwen's <think> and <tool_call> are USER_DEFINED and match even with parse_special = false). The text runs between real special tokens are still tokenized as a whole, so the tokens across the part borders are those of the whole text. The jinja input marking (ggml-org#30389) gives the ranges; tokenize_chat_prompt() follows the shape of the open upstream PR ggml-org#32033 (--chat-input-special / --no-chat-input-special), also for the count-tokens endpoints and mtmd (mtmd_tokenize_from_parts joins adjacent text parts and passes the literal ranges). Fork default: disabled, client text is text; a request may set "chat_input_special". Output: with the vocab's special token table, a PEG literal or until delimiter that names a special token matches only that token id in the generated tokens (ggml-org#29876), so "</think>" or "<tool_call>" written as ordinary tokens in reasoning or content no longer cuts it. A small stand-in for the token-aware parsing of the open upstream PR ggml-org#29307. Text without tokens parses as before. Refs: mkyt docs/decisions.md P6-50, P6-51; ggml-org#28249, ggml-org#32033, ggml-org#29307, ggml-org#29876, ggml-org#30389, ggml-org#28250. Co-Authored-By: Claude Opus 5.5 <[email protected]>
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 19, 2026
…nd in the parsed output Input: the server tokenized the rendered chat prompt as one string with parse_special, so a file the agent read and sent back as a tool result turned "</think>", "<tool_call>", "<|im_end|>" into the special tokens. llama_tokenize_with_literals() takes byte ranges in which no special token is matched, not even a user-defined one (Qwen's <think> and <tool_call> are USER_DEFINED and match even with parse_special = false). The text runs between real special tokens are still tokenized as a whole, so the tokens across the part borders are those of the whole text. The jinja input marking (ggml-org#30389) gives the ranges; tokenize_chat_prompt() follows the shape of the open upstream PR ggml-org#32033 (--chat-input-special / --no-chat-input-special), also for the count-tokens endpoints and mtmd (mtmd_tokenize_from_parts joins adjacent text parts and passes the literal ranges). Fork default: disabled, client text is text; a request may set "chat_input_special". Output: with the vocab's special token table, a PEG literal or until delimiter that names a special token matches only that token id in the generated tokens (ggml-org#29876), so "</think>" or "<tool_call>" written as ordinary tokens in reasoning or content no longer cuts it. A small stand-in for the token-aware parsing of the open upstream PR ggml-org#29307. Text without tokens parses as before. Refs: mkyt docs/decisions.md P6-50, P6-51; ggml-org#28249, ggml-org#32033, ggml-org#29307, ggml-org#29876, ggml-org#30389, ggml-org#28250. Co-Authored-By: Claude Opus 5.5 <[email protected]>
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 19, 2026
…nd in the parsed output Input: the server tokenized the rendered chat prompt as one string with parse_special, so a file the agent read and sent back as a tool result turned "</think>", "<tool_call>", "<|im_end|>" into the special tokens. llama_tokenize_with_literals() takes byte ranges in which no special token is matched, not even a user-defined one (Qwen's <think> and <tool_call> are USER_DEFINED and match even with parse_special = false). The text runs between real special tokens are still tokenized as a whole, so the tokens across the part borders are those of the whole text. The jinja input marking (ggml-org#30389) gives the ranges; tokenize_chat_prompt() follows the shape of the open upstream PR ggml-org#32033 (--chat-input-special / --no-chat-input-special), also for the count-tokens endpoints and mtmd (mtmd_tokenize_from_parts joins adjacent text parts and passes the literal ranges). Fork default: disabled, client text is text; a request may set "chat_input_special". Output: with the vocab's special token table, a PEG literal or until delimiter that names a special token matches only that token id in the generated tokens (ggml-org#29876), so "</think>" or "<tool_call>" written as ordinary tokens in reasoning or content no longer cuts it. A small stand-in for the token-aware parsing of the open upstream PR ggml-org#29307. Text without tokens parses as before. Refs: mkyt docs/decisions.md P6-50, P6-51; ggml-org#28249, ggml-org#32033, ggml-org#29307, ggml-org#29876, ggml-org#30389, ggml-org#28250. Co-Authored-By: Claude Opus 5.5 <[email protected]>
thefallentree
added a commit
to thefallentree/llama.cpp-gp100
that referenced
this pull request
Nov 20, 2026
…nd in the parsed output Input: the server tokenized the rendered chat prompt as one string with parse_special, so a file the agent read and sent back as a tool result turned "</think>", "<tool_call>", "<|im_end|>" into the special tokens. llama_tokenize_with_literals() takes byte ranges in which no special token is matched, not even a user-defined one (Qwen's <think> and <tool_call> are USER_DEFINED and match even with parse_special = false). The text runs between real special tokens are still tokenized as a whole, so the tokens across the part borders are those of the whole text. The jinja input marking (ggml-org#30389) gives the ranges; tokenize_chat_prompt() follows the shape of the open upstream PR ggml-org#32033 (--chat-input-special / --no-chat-input-special), also for the count-tokens endpoints and mtmd (mtmd_tokenize_from_parts joins adjacent text parts and passes the literal ranges). Fork default: disabled, client text is text; a request may set "chat_input_special". Output: with the vocab's special token table, a PEG literal or until delimiter that names a special token matches only that token id in the generated tokens (ggml-org#29876), so "</think>" or "<tool_call>" written as ordinary tokens in reasoning or content no longer cuts it. A small stand-in for the token-aware parsing of the open upstream PR ggml-org#29307. Text without tokens parses as before. Refs: mkyt docs/decisions.md P6-50, P6-51; ggml-org#28249, ggml-org#32033, ggml-org#29307, ggml-org#29876, ggml-org#30389, ggml-org#28250. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Overview
I am working on implementing token-aware parsing in #29307. Before I mark that ready, I want to submit PRs for changes that touch different components so all the stakeholders can agree.
This PR implements
common_chat_inputstruct to accumulate the generated text and tokens to feed into the parser. It uses two arrays, where each token id is present at the start of the token's bytes. This structure is to ensure that lookup during parsing happen inO(1).Requirements