deepseek_v32 chat template: accept wrapper-injected kwargs#1
Open
lixiangnlp wants to merge 1 commit into
Open
Conversation
`TokenizerWrapper.apply_chat_template` injects `enable_thinking=...` into every call (set from `has_thinking`) and may also forward `tokenize=` / other kwargs. The current `apply_chat_template` hands these through to `encode_messages`, which only accepts a fixed set of arguments and raises `TypeError` on anything else. Map `enable_thinking` -> `thinking_mode` (with `thinking_mode` winning if explicitly set), and filter kwargs down to the set `encode_messages` understands. Also strip the trailing `<|Assistant|></think>` marker when `add_generation_prompt=False` and `enable_thinking=False`, mirroring the existing `<|Assistant|><think>` strip for the thinking case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
TokenizerWrapper.apply_chat_template(inmlx_lm/tokenizer_utils.py) setskwargs[\"enable_thinking\"] = self.has_thinkingon every call and may alsoforward
tokenize=and similar kwargs through to a registered chat-templatemodule.
mlx_lm/chat_templates/deepseek_v32.py:apply_chat_templatecurrentlyhands
**kwargsstraight toencode_messages, which only accepts a fixedset of named arguments — so the very first call from the wrapper raises:
```
TypeError: encode_messages() got an unexpected keyword argument 'enable_thinking'
```
This means anyone setting `chat_template_type: "deepseek_v32"` in
`tokenizer_config.json` today is dead in the water before generating a token.
Changes
with `thinking_mode` winning if both are set.
(`thinking_mode`, `context`, `drop_thinking`, `add_default_bos_token`,
`tools`).
`add_generation_prompt=False` and `enable_thinking=False`, mirroring the
existing `<|Assistant|>` strip for the thinking case.
Tests
New `tests/test_chat_templates.py` covering:
```
$ python -m unittest tests.test_chat_templates
.....
Ran 5 tests in 0.000s
OK
```
Notes
This is independent of the V4 forward-pass work happening on this branch —
it's a pre-existing latent bug in the `chat_template_type` integration that
becomes load-bearing once anything actually wires `deepseek_v32` as a
fallback (see follow-up PR for fallback-by-model-type).