[Feature][Frontend] Add granite_thinking_parser reasoning parser for Granite 4.2 (#55957)
Signed-off-by: Yousaf shah <yousaf.shah@gmail.com> Co-authored-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
@@ -34,6 +34,7 @@ class Sample:
|
||||
tools: list[dict] | None = None
|
||||
chat_template_kwargs: dict | None = None
|
||||
prompt_token_ids: list[int] | None = None
|
||||
content_lstrip: str | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -327,7 +327,18 @@ _TOOL_CALL_SAMPLES = [
|
||||
def _tool_suppression_expectations(
|
||||
sample, think_end: str, tool_start: str, *, include_tool_block: bool
|
||||
) -> tuple[str, str]:
|
||||
"""Expected (reasoning, content) when tool calls are not extracted.
|
||||
reasoning, content = _raw_tool_suppression_expectations(
|
||||
sample, think_end, tool_start, include_tool_block=include_tool_block
|
||||
)
|
||||
if sample.content_lstrip:
|
||||
content = content.lstrip(sample.content_lstrip)
|
||||
return reasoning, content
|
||||
|
||||
|
||||
def _raw_tool_suppression_expectations(
|
||||
sample, think_end: str, tool_start: str, *, include_tool_block: bool
|
||||
) -> tuple[str, str]:
|
||||
"""Expected (reasoning, content) from the raw token text.
|
||||
|
||||
With ``include_tool_block=True`` (skip_tool_parsing / reasoning
|
||||
adapter first pass), tool terminal text is preserved as content so
|
||||
|
||||
@@ -15,7 +15,7 @@ from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, replace
|
||||
from typing import Any
|
||||
|
||||
from tests.parser.engine.replay_harness import (
|
||||
@@ -35,6 +35,7 @@ from vllm.parser.engine.registered_adapters import (
|
||||
Gemma4Parser,
|
||||
Glm47MoeParser,
|
||||
GraniteParser,
|
||||
GraniteThinkingParser,
|
||||
InklingParser,
|
||||
KimiK2Parser,
|
||||
MinimaxM2Parser,
|
||||
@@ -594,6 +595,30 @@ def _build_nemotron_v3(scenario: Scenario, validate: bool = True) -> Sample:
|
||||
)
|
||||
|
||||
|
||||
def _build_granite_thinking(scenario: Scenario, validate: bool = True) -> Sample:
|
||||
"""Granite 4.2: the Nemotron V3 grammar plus leading-newline stripping on
|
||||
content after ``</think>``."""
|
||||
sample = _build_qwen3(
|
||||
scenario,
|
||||
name="granite_thinking_parser",
|
||||
parser_cls=GraniteThinkingParser,
|
||||
strip_trailing_ws=True,
|
||||
validate=False,
|
||||
)
|
||||
sample = replace(
|
||||
sample,
|
||||
expected_content=(
|
||||
sample.expected_content.lstrip("\n")
|
||||
if sample.expected_content
|
||||
else sample.expected_content
|
||||
),
|
||||
content_lstrip="\n",
|
||||
)
|
||||
if validate:
|
||||
_validate_sample(sample, GraniteThinkingParser)
|
||||
return sample
|
||||
|
||||
|
||||
# ── Seed-OSS (Qwen3 XML grammar with Seed wrapper tokens) ────────────
|
||||
|
||||
_SEED_OSS_VOCAB: dict[str, int] = {
|
||||
@@ -1136,6 +1161,7 @@ _BUILDERS: dict[str, Any] = {
|
||||
"granite": _build_granite,
|
||||
"minimax_m2": _build_minimax_m2,
|
||||
"nemotron_v3": _build_nemotron_v3,
|
||||
"granite_thinking_parser": _build_granite_thinking,
|
||||
"seed_oss": _build_seed_oss,
|
||||
"glm47_moe": _build_glm47_moe,
|
||||
"kimi_k2": _build_kimi_k2,
|
||||
|
||||
Reference in New Issue
Block a user