Skip to content

[Feat] kimi-k3: Read the thinking object and map reasoning effort onto K3 tiers - #48776

Merged
hnyls2002 merged 6 commits into
mainfrom
lsyin/k3-request-validation
Nov 10, 2026
Merged

hnyls2002 merged 6 commits into
mainfrom
lsyin/k3-request-validation

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Port of #48414

Takes the Kimi-K3 request-side changes from #48414: the thinking object, the reasoning-effort tiers, the chat-template-kwarg checks, and bare-string image URLs. The protocol and serving hunks are applied hunk by hunk, and the matching tests come along.

Against the raw port:

  • The branch's protocol-level validator for message-level tools, its tool-name rule, and its "forced tool call drops response_format" change are not ported. Main already has K3-gated versions of all three ([Fix] kimi-k3: Validate message-level tools and let a forced call override JSON response_format #48481), and the branch versions would apply to every model. The branch tests for them (TestMessageLevelTools, the two response_format tests, and the split developer message in an existing test) stay on the branch as well.
  • TestThinkingParam.test_unknown_type_rejected is not ported. thinking stays a plain dict on the request, so an unknown type is rejected only by the K3 serving path, never at parse time. The test fails on the branch too.
  • test_keep_all_accepted is dropped. test_keep_is_accepted covers the same case.

Summary

  • thinking object (protocol.py). thinking.effort outranks reasoning.effort and reasoning_effort. thinking.type: "disabled" turns reasoning off. A thinking object with no type turns it on, unless an effort has already decided the toggle. chat_template_kwargs still overrides all of these.
  • K3 request checks (_validate_kimi_k3_request, called once next to the MiniMax-M3 one). thinking must be an object whose type is enabled, disabled, adaptive, or absent; anything else is a 400. keep and other keys are accepted and ignored. The message-level tool checks main already had move into the same function.
  • Effort tiers. On the K3 path, OpenAI's reasoning-effort tiers map onto K3's levels: minimal/low to low, medium/high to high, and xhigh/ultra/max to max. K3.1 keeps medium as its own tier. No effort is forwarded when thinking is off. A float or unknown effort is a 400; before, it logged a warning and fell back to the encoder default.
  • chat_template_kwargs on K3. add_generation_prompt is dropped, like tokenize. conversation and tools are rejected. A thinking_effort outside the model's tiers is rejected.
  • Bare image URL. "image_url": "<url>" parses as {"url": "<url>"}.

Changes to existing code

  • Every model: the thinking object now sets the reasoning toggle. Before, a client's thinking dict reached only the templates that read it (MiniMax-M3). Now the request normalizer also reads it for every model:
    • thinking.type fills chat_template_kwargs.thinking and enable_thinking (with setdefault, so explicit kwargs still win).
    • thinking.effort becomes reasoning_effort. It is parsed by the same _parse_effort as reasoning.effort, so tiers, numbers, and numeric strings are accepted, and anything else is a 422 naming thinking.effort.
    • For example, {"type": "adaptive"} now turns thinking on for a Qwen3 or DeepSeek template, and MiniMax-M3 now sees thinking.effort as reasoning_effort.
  • Every model: a bare-string image_url is accepted where it was a validation error.
  • Everything else runs only under chat_encoding_spec == "kimi_k3".

Verification

Unit tests, run locally (macOS, CPU, xgrammar 0.2.7 as pinned), on this branch merged with current main:

cd test
python -m pytest -q registered/unit/entrypoints/openai/test_protocol.py
python -m pytest -q registered/unit/entrypoints/openai/test_serving_chat.py
  • test_protocol.py: 63 passed. On main: 50 passed.
  • test_serving_chat.py: 186 passed and 1 failed. On main: 172 passed and the same 1 failed (test_streaming_created_is_stable_across_chunks), because tml-renderers is not installed locally.
  • Every test file under registered/unit/entrypoints/openai, registered/unit/entrypoints/anthropic, and the reasoning-parser tests fails the same 18 cases as main and no others.
  • pre-commit run passes on the changed files.

CI States

Latest PR Test (Base): 🚫 Run #42796650466
Latest PR Test (Extra): ❌ Run #42796650324
Latest PR Test (AMD ROCm 10): ⏳ Run #42796650708

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_protocol.py test_serving_chat.py

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (2 tests): ✅ View workflow run

cd test/ && python3 registered/unit/entrypoints/openai/test_protocol.py  # base-a
cd test/ && python3 registered/unit/entrypoints/openai/test_serving_chat.py  # base-a

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Nov 10, 2026
@hnyls2002
hnyls2002 merged commit 4c08984 into main Nov 10, 2026
105 of 135 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/k3-request-validation branch November 10, 2026 10:32
kpham-sgl added a commit that referenced this pull request Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant