From f3aa88d2309523f8438a239a55f59a28179ce5ef Mon Sep 17 00:00:00 2001 From: Wentao Ye <44945378+yewentao256@users.noreply.github.com> Date: Thu, 17 Sep 2026 13:05:52 -0400 Subject: [PATCH] [Kimi K3 Bug] Fix kimi k3 reasoning parser (#57098) Signed-off-by: yewentao256 Co-authored-by: Flora Feng <4florafeng@gmail.com> --- vllm/reasoning/kimi_k3_reasoning_parser.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/vllm/reasoning/kimi_k3_reasoning_parser.py b/vllm/reasoning/kimi_k3_reasoning_parser.py index d3ae2b3abe..e5618d47be 100644 --- a/vllm/reasoning/kimi_k3_reasoning_parser.py +++ b/vllm/reasoning/kimi_k3_reasoning_parser.py @@ -256,11 +256,13 @@ class KimiK3ReasoningParser(ReasoningParser): ) -> tuple[str | None, str | None]: """Split full text into ``(reasoning, rest)`` for the non-streaming path. - Handles three shapes: - * no think channel at all -> ``(None, model_output)`` (all content) + Handles four shapes: + * response opener without think markers -> no think channel; all content * open marker present -> reasoning starts after ``<|open|>think<|sep|>`` * open marker absent but a close marker exists (gen-prefix consumed the open) -> reasoning starts at offset 0 + * neither marker present -> truncated reasoning after a consumed + generation prefix ``rest`` is whatever follows the close marker, fed on to the tool parser. """ if not self._thinking_enabled: @@ -270,11 +272,14 @@ class KimiK3ReasoningParser(ReasoningParser): # reasoning content begins right after think-open (or at start if the # open marker was already consumed as a generation prefix) content_start = m_open.end() if m_open is not None else 0 - # if there is no think channel at all, everything is content - if m_open is None and self._think_close_re.search(model_output) is None: - return None, self._content_after_reasoning(model_output, request) m_close = self._think_close_re.search(model_output, content_start) + if ( + m_open is None + and m_close is None + and self._response_open_re.search(model_output) is not None + ): + return None, self._content_after_reasoning(model_output, request) if m_close is not None: reasoning = model_output[content_start : m_close.start()] rest = model_output[m_close.end() :]