Repository navigation
mtmd: add mtmd_tokenize_from_parts() - #28250
Conversation
|
tests are all passed |
|
/bot review |
Automated code reviewStatic review of Blocking (point 1) Per-part
Either split the flag per part (add_bos/add_eos) or document precisely that per-part Will slow the review (point 2) No test exercises the new public API. (point 3) Input validation in Nits (point 4) Near-identical names for different things: public (point 5) (point 6) (point 7) Scope checks that pass: linked issue exists (#28249), the change is self-contained, reuses the existing This review was generated automatically by pi coding agent using |
* add mtmd_tokenize_from_parts * use it in mtmd-cli * move add_special to call level
* add mtmd_tokenize_from_parts * use it in mtmd-cli * move add_special to call level
* add mtmd_tokenize_from_parts * use it in mtmd-cli * move add_special to call level
* add mtmd_tokenize_from_parts * use it in mtmd-cli * move add_special to call level
* add mtmd_tokenize_from_parts * use it in mtmd-cli * move add_special to call level
…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]>
…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]>
…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]>
…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]>
…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]>
Overview
Target support jinja's input marking: #28249
Add
mtmd_tokenize_from_parts()for fine-control per-segment tokenization (for example, one segment can be marked asparse_special, while other doesn't)Requirements