[Bug]: gemma4 reasoning parser returns reasoning as content on requests without tools; reasoning_content keeps the thought label
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- python
- Domain
- backend-api-design
Research direction
Start with Gemma4ReasoningParser and compare its raw-token handling with MuseSparkReasoningParser and KimiK3ReasoningParser. The issue names tests/unittest/llmapi/test_reasoning_parser.py for regression tests; check the linked pull request for work already underway. Done means reasoning is separated from content without the thought label, including when streaming.
Written by the indexing model from the issue text.
Description
System Info
TensorRT-LLM main (3f692ac). This is serving-layer logic only, so it reproduces on CPU with the google/gemma-4-E4B-it tokenizer.
Who can help?
No response
Information
- The official example scripts
- My own modified scripts
Reproduction
trtllm-serve with a Gemma 4 model and --reasoning_parser gemma4 (or auto, which maps gemma4 to it). Send a chat request with chat_template_kwargs: {"enable_thinking": true} and no tools.
<|channel> and <channel|> are special tokens in the Gemma 4 tokenizer. The request keeps the default skip_special_tokens=True, and Gemma4ReasoningParser does not set needs_raw_special_tokens. So _configure_parser_special_token_decoding leaves the default in place and the detokenizer removes both markers:
from transformers import AutoTokenizer
from tensorrt_llm.llmapi.reasoning_parser import ReasoningParserFactory
tok = AutoTokenizer.from_pretrained("google/gemma-4-E4B-it")
ids = tok.encode("<|channel>thought\nThe user wants 2+2.<channel|>4", add_special_tokens=False)
text = tok.decode(ids, skip_special_tokens=True) # what the server decodes
print(repr(text)) # 'thought\nThe user wants 2+2.4'
r = ReasoningParserFactory.create_reasoning_parser("gemma4").parse(text)
print(repr(r.content), repr(r.reasoning_content)) # 'thought\nThe user wants 2+2.4' ''
print(ReasoningParserFactory.needs_raw_special_tokens("gemma4")) # False
Expected behavior
content == "4". reasoning_content holds the reasoning.
actual behavior
- Without tools: the whole reasoning block, plus its
thoughtlabel, is returned ascontent, glued to the answer, andreasoning_contentis empty. With tools it works only because the Gemma 4 tool parser setsneeds_raw_special_tokens. - With tools (raw tokens kept):
reasoning_contentstarts with the channel label ("thought\nThe user wants..."). In a tool-call loop the Gemma 4 chat template replays that turn's reasoning as'<|channel>thought\n' + reasoning_content + '\n<channel|>'. The next prompt therefore contains<|channel>thought\nthought\n..., which the model never produced: an off-distribution prompt and a prefix-cache miss at every tool step. vLLM's Gemma 4 parser strips this label (_strip_thought_label).
additional notes
Fix:
- Set
needs_raw_special_tokens = TrueonGemma4ReasoningParser.MuseSparkReasoningParserandKimiK3ReasoningParseralready do this for the same reason. - Drop a leading
thought\nfrom each channel body inparseandparse_delta. While streaming, a partial label split across deltas is held back.
A PR with regression tests in tests/unittest/llmapi/test_reasoning_parser.py follows.
A related gap that the PR does not change: after a tool response with enable_thinking=True, the template's generation prompt ends with <|channel>thought\n. The completion then starts inside the channel, but Gemma4ReasoningParser always starts outside reasoning. That reasoning is still returned as content up to <channel|>. Fixing it needs the prompt-tail resolution (resolves_thinking_from_prompt) that other parsers use, so I left it for a separate change.
Before submitting a new issue...
- Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
- Dominant language
- Python
- Stars
- 15.2k
- Forks
- 3k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 477
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/TensorRT-LLM
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.xPossibly taken @NimaVaziri claimed this today. OpenPytorch
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NVIDIA/TensorRT-LLM#23406 ·
Maintainers usually reply within 1 day
-
Inference runtime Windows
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
NVIDIA/TensorRT-LLM#23394 ·
Maintainers usually reply within 1 day
-
[Bug]: MMLU subsampling changes when evaluators are interleavedPossibly taken @LeNeLeNeWo claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NVIDIA/TensorRT-LLM#23273 ·
Maintainers usually reply within 1 day
-
Trace-replay Pareto window includes the drain when sessions finish out of admission orderPossibly taken @sbeierle claimed this 3 days ago. OpenTesting
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
NVIDIA/TensorRT-LLM#23077 ·
Maintainers usually reply within 1 day
-
LongBench V2 blog command breaks on inline comments after continuationsPossibly taken @ddlw claimed this 25 days ago. OpenDoc
Difficulty 1/5 Under an hour Newbie friendliness 91/100
NVIDIA/TensorRT-LLM#21879 ·
Maintainers usually reply within 1 day
All issues in NVIDIA/TensorRT-LLM
Similar issues
-
[Resource]: SpaicelyOpenresource-submission validation-passed
Difficulty 1/5 Under an hour Newbie friendliness 68/100
hesreallyhim/awesome-claude-code#3875 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
bvis/aegis-hass#725 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stampOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
#1643 unrecoverable split: 1 digest with a 403 — two earlier captures of the same URL are real 200sOpen
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Robin-IA/Congressional-Letters-Dev#1684 ·
Maintainers usually reply within 1 day