Skip to content

feat(server): alias enable_thinking to bare thinking for deepseek_v32 - #579

Merged
inureyes merged 1 commit into
mainfrom
feat/issue-512-deepseek-v32-thinking-alias
Jul 1, 2026
Merged

inureyes merged 1 commit into
mainfrom
feat/issue-512-deepseek-v32-thinking-alias

Conversation

@inureyes

@inureyes inureyes commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Investigation issue #512 speculated that DeepSeek-V3.2 (deepseek_v32) gates its chat template's reasoning toggle via a thinking_mode variable with "thinking"/"chat" string values. Direct verification against the real templates shows a different variable than either the issue's guess or mlxcel's current enable_thinking passthrough, 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-Exp assets/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 bare thinking boolean ({%- if not thinking %}{{'</think>'}}{%- else %}{{'<think>'}}{%- endif %}). It is not thinking_mode, and it is not enable_thinking either. mlxcel only ever populates enable_thinking in the Jinja context, so thinking is always undefined on this template family and the guard pins it to false regardless of what a caller asks for.
  • GLM-5.2 (glm_moe_dsa, the other checkpoint named in the issue) ships its own chat_template.jinja (https://huggingface.co/zai-org/GLM-5.2/blob/main/chat_template.jinja) that already reads the conventional enable_thinking kwarg 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.
  • The mlx-community DeepSeek-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.json has no chat_template field, and no standalone chat_template.jinja file), 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: added ChatTemplateProcessor::wants_bare_thinking_alias, which detects the not thinking is defined idiom in the loaded template source. build_template_context now takes a bare_thinking_alias: bool parameter and, when the flag is set, mirrors the fully-resolved enable_thinking value (request override, or the server's tokenizer-derived default) into a thinking key, unless the caller already supplied an explicit thinking kwarg (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 generic enable_thinking passthrough is unchanged for every other model.
  • docs/supported-models.md: documents the new alias behavior under a "thinking alias for the DeepSeek-V3.2 (deepseek_v32) chat template" section.
  • Seven new unit tests in 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-style enable_thinking template), the true/false alias mapping, the tokenizer-derived-default path, the explicit thinking kwarg override, and parity through the raw-JSON apply_raw_with_kwargs path.

Test plan

  • cargo check --lib --tests --features metal,accelerate
  • cargo test --release --features metal,accelerate server::chat_template — 81 passed, 0 failed, 1 pre-existing ignored (test_all_local_model_templates_render, requires a local models/ checkout)
  • cargo fmt --all -- --check

Closes #512

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.
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:low Low priority status:done Completed labels Jul 1, 2026
@inureyes
inureyes merged commit da96994 into main Jul 1, 2026
4 checks passed
@inureyes
inureyes deleted the feat/issue-512-deepseek-v32-thinking-alias branch July 1, 2026 11:39
@inureyes inureyes self-assigned this Jul 1, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:low Low priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(server): map enable_thinking -> thinking_mode for the DeepSeek-V3.2 chat template

1 participant