Repository navigation
feat(server): alias enable_thinking to bare thinking for deepseek_v32 - #579
Merged
Merged
Conversation
The upstream deepseek-ai/DeepSeek-V3.2-Exp chat template gates its <think> block on a bare `thinking` boolean rather than the conventional `enable_thinking` kwarg mlxcel forwards by default, so toggling reasoning previously had no effect on that template family (verified directly against https://huggingface.co/deepseek-ai/DeepSeek-V3.2-Exp/blob/main/assets/chat_template.jinja, which declares `{% if not thinking is defined %}{% set thinking = false %}{% endif %}` and later branches on the bare `thinking` value, never `enable_thinking`). ChatTemplateProcessor now detects the `not thinking is defined` idiom in the loaded template source (wants_bare_thinking_alias) and, when present, mirrors the fully-resolved enable_thinking value (request override, or the server default) into a `thinking` key in the Jinja context. An explicit `thinking` entry in chat_template_kwargs still overrides the derived alias. Detection is based on the template text, not the model architecture name, so it is data-driven and covers any future template that adopts the same idiom without a per-checkpoint hard-code. Also verified GLM-5.2 (glm_moe_dsa), the other model this issue named: its chat template already reads `enable_thinking` directly (`enable_thinking is not defined`), so it is unaffected and needs no change. Added seven unit tests covering detection (including a negative case against the GLM-5.2 shape), the true/false alias mapping, the tokenizer-derived default path, the explicit-override escape hatch, and the raw-JSON apply path. Documented the behavior in docs/supported-models.md.
4 tasks
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…lablup#579) The upstream deepseek-ai/DeepSeek-V3.2-Exp chat template gates its <think> block on a bare `thinking` boolean rather than the conventional `enable_thinking` kwarg mlxcel forwards by default, so toggling reasoning previously had no effect on that template family (verified directly against https://huggingface.co/deepseek-ai/DeepSeek-V3.2-Exp/blob/main/assets/chat_template.jinja, which declares `{% if not thinking is defined %}{% set thinking = false %}{% endif %}` and later branches on the bare `thinking` value, never `enable_thinking`). ChatTemplateProcessor now detects the `not thinking is defined` idiom in the loaded template source (wants_bare_thinking_alias) and, when present, mirrors the fully-resolved enable_thinking value (request override, or the server default) into a `thinking` key in the Jinja context. An explicit `thinking` entry in chat_template_kwargs still overrides the derived alias. Detection is based on the template text, not the model architecture name, so it is data-driven and covers any future template that adopts the same idiom without a per-checkpoint hard-code. Also verified GLM-5.2 (glm_moe_dsa), the other model this issue named: its chat template already reads `enable_thinking` directly (`enable_thinking is not defined`), so it is unaffected and needs no change. Added seven unit tests covering detection (including a negative case against the GLM-5.2 shape), the true/false alias mapping, the tokenizer-derived default path, the explicit-override escape hatch, and the raw-JSON apply path. Documented the behavior in docs/supported-models.md.
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
Investigation issue #512 speculated that DeepSeek-V3.2 (
deepseek_v32) gates its chat template's reasoning toggle via athinking_modevariable with"thinking"/"chat"string values. Direct verification against the real templates shows a different variable than either the issue's guess or mlxcel's currentenable_thinkingpassthrough, so this is a real gap, just with a corrected variable name and shape.Verification finding
Fetched directly (not summarized) from the authoritative sources:
deepseek-ai/DeepSeek-V3.2-Expassets/chat_template.jinja(https://huggingface.co/deepseek-ai/DeepSeek-V3.2-Exp/blob/main/assets/chat_template.jinja) declares{% if not thinking is defined %}{% set thinking = false %}{% endif %}and later branches on the barethinkingboolean ({%- if not thinking %}{{'</think>'}}{%- else %}{{'<think>'}}{%- endif %}). It is notthinking_mode, and it is notenable_thinkingeither. mlxcel only ever populatesenable_thinkingin the Jinja context, sothinkingis always undefined on this template family and the guard pins it tofalseregardless of what a caller asks for.glm_moe_dsa, the other checkpoint named in the issue) ships its ownchat_template.jinja(https://huggingface.co/zai-org/GLM-5.2/blob/main/chat_template.jinja) that already reads the conventionalenable_thinkingkwarg directly ({%- if (enable_thinking is not defined or enable_thinking) ... -%},{{- '<think></think>' if (enable_thinking is defined and not enable_thinking) else '<think>' -}}). This family needs no change.mlx-communityDeepSeek-V3.2 exports checked (DeepSeek-V3.2-4bit,DeepSeek-V3.2-Speciale-4bit,DeepSeek-V3.2-mlx-5bit) currently ship no chat template at all (tokenizer_config.jsonhas nochat_templatefield, and no standalonechat_template.jinjafile), so today's public exports don't yet expose this specific gap in the field, but the upstream/model-native template does, and a fixed export (or the upstream repo copied locally) would hit it immediately.What changed
src/server/chat_template.rs: addedChatTemplateProcessor::wants_bare_thinking_alias, which detects thenot thinking is definedidiom in the loaded template source.build_template_contextnow takes abare_thinking_alias: boolparameter and, when the flag is set, mirrors the fully-resolvedenable_thinkingvalue (request override, or the server's tokenizer-derived default) into athinkingkey, unless the caller already supplied an explicitthinkingkwarg (which always wins). Detection is based on the template text, not a hard-coded model/architecture name, so any future template adopting the same idiom is covered automatically, and the genericenable_thinkingpassthrough is unchanged for every other model.docs/supported-models.md: documents the new alias behavior under a "thinkingalias for the DeepSeek-V3.2 (deepseek_v32) chat template" section.src/server/chat_template.rs: detection (positive on a trimmed DeepSeek-V3.2-shaped template, negative on the GLM-5.2 shape, on the default template, and on a Qwen3-styleenable_thinkingtemplate), the true/false alias mapping, the tokenizer-derived-default path, the explicitthinkingkwarg override, and parity through the raw-JSONapply_raw_with_kwargspath.Test plan
cargo check --lib --tests --features metal,acceleratecargo test --release --features metal,accelerate server::chat_template— 81 passed, 0 failed, 1 pre-existing ignored (test_all_local_model_templates_render, requires a localmodels/checkout)cargo fmt --all -- --checkCloses #512