vllm.parser.gemma4 ¶
Gemma4 parser.
Handles channel-based reasoning plus custom tool call format in a single state machine::
<|channel>thought
...reasoning...<channel|>
<|tool_call>call:func_name{key:<|"|>value<|"|>,num:42}<tool_call|>
Classes:
-
Gemma4Parser–Gemma4 parser:
<|channel>reasoning +<|tool_call>
Gemma4Parser ¶
Bases: ParserEngine
Gemma4 parser: <|channel> reasoning + <|tool_call> tool calls in a single engine.
- Strips the
thought\nprefix from reasoning content - Sets
skip_special_tokens=Falseso boundary tokens are visible - Detects
<|tool_call>token as implicit reasoning end
Methods:
-
adjust_initial_state_from_prompt–Pre-initialise the engine to
REASONINGwhen the prompt does -
adjust_request–Keep special tokens when thinking or tool calls need them.
Source code in vllm/parser/gemma4.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
adjust_initial_state_from_prompt(prompt_token_ids) ¶
Pre-initialise the engine to REASONING when the prompt does not already end with reasoning concluded.
This covers the post-tool-response continuation case where the chat
template leaves the prompt ending inside an open ``<|channel>``
block (issue #45834). It is also safe in the common new-turn case
where the model itself emits ``<|channel>`` first: the no-op
``(REASONING, THINK_START)`` transition swallows it, and the
``thought
prefix in the first reasoning chunk is stripped by_events_to_delta`` as it already is in the default flow.
Source code in vllm/parser/gemma4.py
adjust_request(request) ¶
Keep special tokens when thinking or tool calls need them.
skip_special_tokens must stay False when there is something to preserve: reasoning channel tokens (thinking enabled) or tool-call delimiters (tools active). Otherwise keep the default so stray delimiters do not leak into content (e.g. tool_choice="none" with thinking disabled).
Source code in vllm/parser/gemma4.py
_gemma4_arg_converter(raw_args, partial) ¶
Convert Gemma4 custom arg format to a JSON string.
Source code in vllm/parser/gemma4.py
_parse_gemma4_args(args_str, *, partial=False) ¶
Parse Gemma4's custom key:value format into a Python dict.
Format examples::
location:<|"|>Tokyo<|"|>
location:<|"|>San Francisco<|"|>,unit:<|"|>celsius<|"|>
count:42,flag:true
nested:{inner_key:<|"|>val<|"|>}
items:[<|"|>a<|"|>,<|"|>b<|"|>]
Parameters:
-
(args_str¶str) –The raw Gemma4 argument string.
-
(partial¶bool, default:False) –When True (streaming), bare values at end of string are omitted because they may be incomplete and type-unstable (e.g. partial boolean parsed as bare string).
Returns a dict ready for json.dumps().
Source code in vllm/parser/gemma4.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
_strip_partial_delim(value) ¶
Strip a trailing partial STRING_DELIM prefix from value.
Prevents partial delimiters from leaking into the streamed JSON diff.