Repository navigation
Add Qwen4 support with shared Qwen3.5 XML tool-call format - #208
Open
SearchSavior wants to merge 3 commits into
Open
SearchSavior wants to merge 3 commits into
SearchSavior wants to merge 3 commits into
Conversation
openvino.genai master maps model_type qwen4_moe onto the existing QWEN4_EXP pipeline (9b9c388). OpenArc changes needed on top of that: - Requires the OpenVINO nightly stack (2027.0.0 dev) from the parent commit; 2026.5 only knows qwen4_exp. - Vision token + default tool parser for Qwen4MoeForConditionalGeneration and Qwen4ExpForConditionalGeneration (Qwen3.5 vocab, Qwen3-VL processor, Qwen3.5 XML tool-call format). - Qwen4's tokenizer marks <tool_call>, </tool_call>, <think>, </think> as special=True (special=False in Qwen3.5), so every plain decode dropped them and reasoning/tool calls could not be parsed. Add qwen35.decode_keeping_tags() and use it on all qwen35 decode paths: Qwen35ToolCallStreamer (now intercepts the think tags by ID as well), ChunkStreamer, non-streaming LLM, and non-streaming VLM (token IDs collected with a TokenCollector streamer). Output is unchanged for Qwen3.5. - Thinking detection honours Qwen4's reasoning_effort="off" (the template pre-closes <think></think>); centralised in is_thinking_enabled(). - Docs: Qwen4-MoE export/usage notes. Verified end to end on a tiny random qwen4_moe export (optimum-intel main, transformers 5.27.dev) through OVGenAI_VLM with images, tools, streaming, non-streaming and MTP speculative decoding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011SRNHAAfJZyJdP14L19u1c
reasoning_effort is read only by the Qwen4-MoE chat template ("off"
pre-closes <think></think>). Qwen3.5, Qwen3/Nemotron (hermes) and Gemma4
templates ignore it and keep thinking, so treating reasoning_effort="off"
as "thinking off" for every model disabled reasoning splitting while the
model was still reasoning (reasoning streamed as content).
- New ToolCallParser "qwen4": same XML parsing as qwen35 (served by the
qwen35 module, QWEN_XML_PARSERS); only its thinking switch differs.
- is_thinking_enabled(kwargs, tool_call_parser) honours reasoning_effort
only for qwen4; every other parser reads enable_thinking alone.
- Qwen4MoeForConditionalGeneration defaults to qwen4.
Qwen4ExpForConditionalGeneration (Qwen3.8-Flash-Next) stays qwen35: its
reasoning_effort (xhigh|medium|low) only tunes the system prompt.
- CLI choices, route/contract text and docs list qwen4.
- Tests: parser-aware thinking matrix, streamer + route coverage showing
reasoning_effort="off" splits reasoning for qwen35 but not for qwen4.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011SRNHAAfJZyJdP14L19u1c
SearchSavior
force-pushed
the
ccr-768908a6-4w3kid
branch
from
December 4, 2026 06:50
e97bcc5 to
67659c1
Compare
SearchSavior
changed the base branch from
main
to
claude/openvino-nightly-index
December 4, 2026 06:50
Per the Qwen4 model card, enable_thinking=False is equivalent to reasoning_effort="off", so there is no Qwen4-specific thinking switch to track. OpenArc should not interpret template kwargs beyond what it does for every other parser (enable_thinking), so: - Remove the qwen4 tool_call_parser (enum, CLI choice, route mapping, QWEN_XML_PARSERS) and the parser-aware is_thinking_enabled() helper; thinking detection is back to main's inline enable_thinking reads. - Qwen4MoeForConditionalGeneration defaults to qwen35. - Docs: turn thinking off with enable_thinking=false; reasoning_effort is passed through to the template untouched. decode_keeping_tags() stays: Qwen4 marks <think>/<tool_call> special=True, so qwen35 decode paths still need it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011SRNHAAfJZyJdP14L19u1c
This branch has not been deployed
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
This PR adds support for Qwen4 models (Qwen4-MoE and Qwen4-Exp) which share the Qwen3.5 XML tool-call format but mark protocol tags as special tokens. The key challenge is that Qwen4 tokenizers mark
<tool_call>,</tool_call>,<think>, and</think>as special=True, causing standard decode to drop them. This PR introduces infrastructure to preserve these tags during decoding while still stripping true specials like<|im_end|>.Key Changes
Protocol tag preservation: Added
protocol_tag_ids()anddecode_keeping_tags()functions inqwen35.pyto detect and restore protocol tag text by token ID, working for both Qwen3.5 (special=False) and Qwen4 (special=True) tokenizers.Streamer updates: Modified
ChunkStreamerto usedecode_keeping_tags()for qwen35-parser requests, and updatedQwen35ToolCallStreamerto use the new protocol tag detection instead of hardcoding tool boundary IDs.VLM support: Added
TokenCollectorstreamer for VLM non-streaming requests and updated bothllm.pyandvlm.pyto usedecode_keeping_tags()for qwen35 parser output.Thinking: No Qwen4-specific handling. Per the model card,
enable_thinking=Falseis equivalent toreasoning_effort="off", so Qwen4 uses theqwen35parser and OpenArc reads onlyenable_thinking, as for every other parser.reasoning_effortpasses through to the template untouched.Model registration: Updated
resolve_vlm_type.pyandcli/utils.pyto recognize Qwen4 architectures and map them to the qwen35 tool-call parser.Documentation: Added Qwen4-MoE model documentation including export instructions, tool-call/thinking configuration, and MTP speculative decoding support.
Implementation Details
The solution preserves protocol tag text by intercepting tokens at the ID level before decoding. When a protocol tag token is encountered, its text is inserted directly rather than decoded, preventing UTF-8 boundary issues. This approach works transparently for both Qwen3.5 and Qwen4 since the tag IDs are identical across both versions.
https://claude.ai/code/session_011SRNHAAfJZyJdP14L19u1c
Generated by Claude Code