Skip to content

feat: gemma4 tool_choice patch on v0.32.0 with upstream xgrammar - #2

Open
oe374kt wants to merge 7 commits into
klang/v0.32.0from
feat/g4-tool-0.32
Open

oe374kt wants to merge 7 commits into
klang/v0.32.0from
feat/g4-tool-0.32

Conversation

@oe374kt

@oe374kt oe374kt commented Oct 28, 2026

Copy link
Copy Markdown

EvansThomas and others added 6 commits October 28, 2026 14:31
Registers a gemma4 xgrammar structural tag that forces the native call syntax, attaches it on both the composed parser path and the unified engine path, and lexes the call markers from text.

Source: klanggames/iac-gcloud images/vllm-gemma4 at ce8e18d76. Upstream: vllm-project#50477, vllm-project#53363.
…a style

Needs the Klang xgrammar fork (EvansThomas/xgrammar, tag klang-gemma-2), which adds style="gemma" to JSONSchemaFormat. Schemas the style cannot drive fall back to a syntax-only tag.

Source: klanggames/iac-gcloud images/vllm-gemma4 at eea31c1ec.
Upstream xgrammar (mlc-ai/xgrammar#923) adds the gemma JSON-schema style but keeps declaration order. Sort properties and object literals like the chat template's dictsort here, so the Klang xgrammar fork is no longer necessary.
vLLM 0.32.0 treats a tool without an explicit strict as non-strict, so its arguments went unconstrained. Restore the 0.28.0 rule for gemma4: unless tool_choice is auto with no strict tool, a tool without strict is constrained, and strict=false stays free.
Upstream xgrammar excludes only the string delimiter from gemma strings, so pass both call markers as excludes. It also compiles patternProperties and non-identifier keys, which the fork rejected, so those schemas now stay constrained.
@oe374kt
oe374kt marked this pull request as ready for review October 29, 2026 14:46
@oe374kt
oe374kt requested a review from EvansThomas October 29, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants