fix(reasoning): auto-select kimi_k25 for Kimi-K2.6/K2.7 - #1917
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe parser factory maps ChangesKimi-K2 parser automapping
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request adds pattern registration for kimi-k2.6 and kimi-k2.7 to reuse the kimi_k25 reasoning format, along with a comprehensive test suite for the Kimi K2 family automapping. The reviewer suggested a great improvement to simplify the registration by using a single pattern "kimi-k2." to match all current and future Kimi K2.x models (K2.5+) using substring matching.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| registry.register_pattern("kimi-k2.5", "kimi_k25"); | ||
| registry.register_pattern("kimi-k2.6", "kimi_k25"); // K2.6/K2.7 share the K2.5 <think> template | ||
| registry.register_pattern("kimi-k2.7", "kimi_k25"); |
There was a problem hiding this comment.
Instead of registering individual patterns for each minor version of the Kimi K2 family (e.g., kimi-k2.5, kimi-k2.6, kimi-k2.7), we can register a single pattern kimi-k2. to match all current and future Kimi K2.x models. Since the matching logic uses substring matching (contains), this single pattern will correctly match Kimi-K2.5, Kimi-K2.6, Kimi-K2.7, and any future versions (like Kimi-K2.8), while avoiding matching kimi-k2-thinking or kimi-k2-instruct which do not contain a dot after k2.
| registry.register_pattern("kimi-k2.5", "kimi_k25"); | |
| registry.register_pattern("kimi-k2.6", "kimi_k25"); // K2.6/K2.7 share the K2.5 <think> template | |
| registry.register_pattern("kimi-k2.7", "kimi_k25"); | |
| registry.register_pattern("kimi-k2.", "kimi_k25"); // Kimi K2.x models (K2.5+) share the <think> template |
Kimi-K2.6 and K2.7 use the same chat template family as K2.5 (<think>/</think> delimiters, <think> prefilled when thinking is on), but had no auto-select pattern, so they fell through to the legacy unicode 'kimi' parser (◁think▷) and mis-split reasoning. Map both to kimi_k25, matching K2.5. The .-versioned patterns don't match kimi-k2-instruct, which stays on the legacy unicode parser. Signed-off-by: key4ng <rukeyang@gmail.com>
41860aa to
60136fd
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60136fd543
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| registry.register_pattern("kimi-k2-thinking", "kimi_thinking"); | ||
| registry.register_pattern("kimi-k2.5", "kimi_k25"); | ||
| registry.register_pattern("kimi-k2.6", "kimi_k25"); // K2.6/K2.7 share the K2.5 <think> template | ||
| registry.register_pattern("kimi-k2.7", "kimi_k25"); |
There was a problem hiding this comment.
Map K2.7 to a prefilled-think parser
For auto-detected moonshotai/Kimi-K2.7-Code requests with separate_reasoning, this selects kimi_k25, whose parser does not start in reasoning mode; the gateway only calls mark_reasoning_started() when should_mark_reasoning_started() sees a thinking toggle (ThinkingToggle::None => false), but the K2.7-Code template pre-fills <think> unconditionally and has no toggle (HF template). The generated text therefore starts after the prefilled token, e.g. reasoning</think>answer, and BaseReasoningParser treats it as normal text unless it was already marked or sees <think> in the output, so reasoning still leaks into content despite this new auto-map.
Useful? React with 👍 / 👎.
|
Hi @key4ng, this PR has merge conflicts that must be resolved before it can be merged. Please rebase your branch: git fetch origin main
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease |
Description
Problem
Kimi-K2.6andKimi-K2.7have no reasoning-parser auto-select pattern. Reasoning-parser auto-selection matches the model id against registered patterns with a first-match substring check, so these SKUs fell through to the generickimientry — the legacy Kimi-K2-Instruct parser that expects unicode◁think▷/◁/think▷delimiters.K2.6/K2.7 actually use
<think>/</think>(the same chat-template family as K2.5, with<think>prefilled into the generation prompt when thinking is on). So for any deployment relying on--reasoning-parserauto-detection, K2.6/K2.7 reasoning was mis-split intocontent.Solution
Add explicit
kimi-k2.6/kimi-k2.7→kimi_k25patterns, matching the existingkimi-k2.5mapping (all three share the same template). The.-versioned patterns do not matchkimi-k2-instruct, which stays on the legacy unicode parser;kimi-k2-thinkingcontinues to map tokimi_thinking.Note: this only affects name-based auto-selection. Deployments that pass
--reasoning-parserexplicitly (e.g. the nightly A/B) are unaffected.Changes
crates/reasoning_parser/src/factory.rs: registerkimi-k2.6andkimi-k2.7→kimi_k25.test_kimi_k2_family_automaplocking the full K2 family mapping.Test Plan
factory.create(model).model_type()for the auto-select path:moonshotai/Kimi-K2.5kimi_k25kimi_k25moonshotai/Kimi-K2.6kimi(legacy ◁think▷)kimi_k25moonshotai/Kimi-K2.7-Codekimi(legacy ◁think▷)kimi_k25moonshotai/Kimi-K2-Thinkingkimi_thinkingkimi_thinkingmoonshotai/Kimi-K2-InstructkimikimiChecklist
cargo +nightly fmtpassescargo clippy --all-targets --all-features -- -D warningspasses🤖 Generated with Claude Code
Summary by CodeRabbit