Conversation
… decoding Adds DeepSeek-V4 tool-calling to mlx_lm.server: - DSML tool-call parser and Python chat template (chat_templates/deepseek_v4.py, tool_parsers/deepseek_v4.py), handling the model's truncated `</|DSML|inv>` close tag and the `<`-vs-`</` token boundary. - A DeepSeek standard-format tool-call parser (V3/V3.1/R1/V4) in tool_parsers/deepseek_v3.py. - Grammar-constrained decoding (tool_grammar.py + server.py) that forces the DSML tool-call structure so a quantization-degraded model cannot corrupt the structural keywords, with tool_choice auto/required/named and think-block awareness. Tests cover the parser, chat template, and grammar. The grammar tests drive the phase machine with a synthetic byte-level tokenizer that reproduces the DeepSeek DSML token boundaries (`</` as a single token; `|DSML|`, `<think>` and `</think>` as special tokens), so they run without the model files.
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.
DeepSeek-V4 tool calling for
mlx_lm.server, stacked on the base model (ml-explore#1797). Preview so maintainers can see it coming; not proposed for merge yet.Three parts:
chat_templates/deepseek_v4.py,tool_parsers/deepseek_v4.py) — handles the model's truncated</|DSML|inv>close tag and the<-vs-</token boundary.tool_parsers/deepseek_v3.py.tool_grammar.py+server.py) that forces the DSML structure so a quantization-degraded model cannot corrupt the keywords, withtool_choiceauto/required/named and think-block awareness.Tests cover the parser, chat template, and grammar (25 pass). The grammar tests drive the phase machine with a synthetic byte-level tokenizer reproducing the DeepSeek DSML token boundaries, so they run without the model files.