Repository navigation
[Fix] kimi-k3: Validate message-level tools and let a forced call override JSON response_format - #48481
Merged
Conversation
… forced tool call replace a json response_format grammar
There was a problem hiding this comment.
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.
…on grammar instead of popping it
Collaborator
Author
|
/tag-and-rerun-ci |
Collaborator
Author
|
/rerun-test test_openai_function_calling.py test_openai_server.py test_constrained_decoding_spec_reasoning.py test_kimi_k3_b300.py |
Contributor
|
🚀 🚀 🚀 🚀 |
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.
Motivation
Two Kimi-K3 request shapes are handled differently from the Kimi-K3 API:
response_formatis rejected. For every model,tool_choice: "required"or a named function plusresponse_formatreturns 400, because both constraints cannot be honored. The Kimi-K3 encoding rendersresponse_formatinto the prompt, so the forced call can take the grammar and the request can be served.Both changes apply only to the Kimi-K3 encoding (
chat_encoding_spec == "kimi_k3"). Other models and encodings are unchanged.Modifications
serving_chat.py:_validate_kimi_k3_message_tools, called from_validate_requestfor the Kimi-K3 encoding. A message that declares tools must be a system or developer message without content, each tool must havetype: "function", and each name must match[A-Za-z_][A-Za-z0-9_-]{0,255}. A violation returns 400 through the existing error path. Missing fields, duplicate names and tool messages withouttool_call_idwere already rejected and are unchanged.protocol.py:ChatCompletionRequestrecords which raw messages carried a non-emptytools(_message_tools_indices), since the user-message model drops the field. It validates nothing.to_sampling_params: when a forced tool call meets ajson_object/json_schemaresponse_formatand the renderer statesresponse_formatin the prompt (the existingrenderer_handles_response_format, true only for Kimi-K3), the tool-call constraint replaces the JSON grammar. regex, ebnf andstructural_tagconflicts still return 400, and so does every other encoding.Tests
test_kimi_k3_rejects_message_tools_the_encoding_cannot_render: a table of 12 requests, run with the encoding unset and with Kimi-K3. Each case is rejected only under Kimi-K3; with the encoding unset everything is accepted, including root-role message tools.test_kimi_k3_forced_tool_call_overrides_json_response_format: under Kimi-K3,required+json_objectand a named tool +json_schemaare accepted with the tool-call grammar and no JSON grammar, and the encoder still receivesresponse_format; a regex conflict is still 400; a non-Kimi-K3 encoding is still 400.test/registered/unit/entrypoints/openai/gives the same results as main apart from the two new tests.Accuracy Tests
Kimi-K3, 8x B300, TP8, with this change and the Kimi-K3
tool_choicegrammar fix (#48480): a request-conformance suite for Kimi-K3 API behavior passes its message-level tool cases (10 cases, streaming and non-streaming) and the forced tool call +json_objectprompt-token case, which failed on main. Prompt-token cases: 74/74. Strict tool-call schema cases: 428/428.Speed Tests and Profiling
Request validation only.
CI States
Latest PR Test (Base): 🚫 Run #41944363877
Latest PR Test (Extra): ❌ Run #41944363781
Latest PR Test (AMD ROCm 10): 🚫 Run #41944363964
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: