Skip to content

fix - fix qwen35 moe reasoning parser#812

Closed
alibaba-miji wants to merge 1 commit intomainfrom
feature/qwen35_moe_hot_fix
Closed

fix - fix qwen35 moe reasoning parser#812
alibaba-miji wants to merge 1 commit intomainfrom
feature/qwen35_moe_hot_fix

Conversation

@alibaba-miji
Copy link
Copy Markdown
Collaborator

@alibaba-miji alibaba-miji commented Mar 20, 2026

default set thinking mode = True for qwen35 moe

@alibaba-miji alibaba-miji requested a review from LLLLKKKK as a code owner March 20, 2026 17:11
@LLLLKKKK
Copy link
Copy Markdown
Collaborator

Code Review: PR #812 — fix - fix qwen35 moe reasoning parser

Thanks for the fix! Qwen3.5 MoE models definitely need reasoning parsing enabled by default. Here are my findings:

1. [Bug] Accidental trailing characters (reasoning_tool_base_renderer.py:119)

The comment change adds two trailing middle-dot characters (··, U+00B7):

-            # logprobs模式下使用普通StreamStatus
+            # logprobs模式下使用普通StreamStatus··

This looks unintentional — should be reverted.

2. [Performance] render_chat() called N times redundantly

_create_reasoning_parser() calls self.render_chat(request) which does full Jinja2 rendering + tokenizer encoding. In _create_status_list, this runs inside a list comprehension for _ in range(n), so when n > 1 the same expensive call repeats with identical results. Consider hoisting it out of the loop:

detector = self._create_detector(request)
reasoning_parser = self._create_reasoning_parser(request)
return [
    ReasoningToolStreamStatus(request, detector, reasoning_parser)
    for _ in range(n)
]

3. [Correctness] Exception fallback may be too conservative

except Exception as e:
    logging.error(f"Failed to render chat in _create_reasoning_parser: {e}")
return ReasoningParser(model_type="qwen3")

Since Qwen3.5 templates "always append <think>", the safer fallback on render failure would be qwen3-thinking (force_reasoning=True). With qwen3 as fallback, if rendering fails the <think>...</think> output won't be parsed as reasoning and will leak into normal response content.

4. [Testing] No tests added

No unit tests for the new in_think_mode() or _create_reasoning_parser() overrides. Recommend adding tests to verify:

  • in_think_mode returns True by default, False when thinking disabled
  • _create_reasoning_parser returns correct parser type based on rendered prompt
  • Fallback behavior on exception

Positive notes

  • @override decorator correctly used on both new methods
  • in_think_mode pattern is consistent with QwenRenderer.in_think_mode
  • Core logic is sound — the dynamic qwen3-thinking vs qwen3 selection based on prompt suffix is a clean approach

Automated review by CI bot — 2026-03-21

@alibaba-miji alibaba-miji force-pushed the feature/qwen35_moe_hot_fix branch from a563866 to 7c7f6a8 Compare March 21, 2026 03:17
@LLLLKKKK
Copy link
Copy Markdown
Collaborator

🤖 AI Code Review — PR #812 fix - fix qwen35 moe reasoning parser

概述

Qwen3CoderRenderer(服务 qwen35_moe / qwen35_dense / qwen3_coder_moe)添加 reasoning parser 支持。Qwen3.5 chat template 默认追加 <think>,但之前 renderer 缺少对应的 reasoning 解析逻辑,导致 thinking 内容无法正确提取。

改动包括:

  • 新增 in_think_mode override:除非 disable_thinking() 显式为 True,否则默认开启 thinking
  • 新增 _create_reasoning_parser override:根据渲染后的 prompt 是否以 think_start_tag 结尾,选择 qwen3-thinking(force_reasoning)或 qwen3 模式

建议改进

P1: 缺少单元测试

PR 没有为新增的 in_think_mode_create_reasoning_parser 添加测试。建议至少覆盖:

  • in_think_modedisable_thinking=True/False/None 时的返回值
  • _create_reasoning_parser 在 think 模式下返回正确的 model_type(qwen3 vs qwen3-thinking
  • _create_reasoning_parserrender_chat 抛异常时的 fallback 行为

P2: 代码重复

_create_reasoning_parserQwenReasoningToolRenderer._create_reasoning_parserqwen_reasoning_tool_renderer.py:44-59)几乎完全相同。建议提取到基类 ReasoningToolBaseRenderer 作为默认实现,或提取为共享 helper,避免两处维护。

P2: in_think_mode 忽略 self.think_mode 配置

新的 in_think_mode 完全忽略了 self.think_mode(来自 generate_env_config)。如果运维通过配置显式关闭 think_mode,该 override 仍会返回 True。这与 QwenRenderer.in_think_mode 是同样的模式,属于项目惯例,风险可控,但建议在 docstring 中明确说明。

总结

小而必要的 bugfix,逻辑正确,与已有的 QwenReasoningToolRenderer 模式一致。主要建议是补充测试和减少代码重复。

@alibaba-miji alibaba-miji deleted the feature/qwen35_moe_hot_fix branch March 23, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants