[Bug]: gemma4 reasoning parser returns reasoning as content on requests without tools; reasoning_content keeps the thought label
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 15.2k
- 派生
- 3k
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 477
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NVIDIA/TensorRT-LLM 的其他 Issue
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.x可能已有人在做 @NimaVaziri 今天认领。 未关闭Pytorch
难度 2/5 1-3 小时 新手友好度 78/100
NVIDIA/TensorRT-LLM#23406 ·
维护者通常 1 天内回复
-
Inference runtime Windows
难度 2/5 1-3 小时 新手友好度 65/100
NVIDIA/TensorRT-LLM#23394 ·
维护者通常 1 天内回复
-
[Bug]: MMLU subsampling changes when evaluators are interleaved可能已有人在做 @LeNeLeNeWo 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
NVIDIA/TensorRT-LLM#23273 ·
维护者通常 1 天内回复
-
Trace-replay Pareto window includes the drain when sessions finish out of admission order可能已有人在做 @sbeierle 于 3 天前认领。 未关闭Testing
难度 2/5 1-3 小时 新手友好度 86/100
NVIDIA/TensorRT-LLM#23077 ·
维护者通常 1 天内回复
-
LongBench V2 blog command breaks on inline comments after continuations可能已有人在做 @ddlw 于 25 天前认领。 未关闭Doc
难度 1/5 1 小时以内 新手友好度 91/100
NVIDIA/TensorRT-LLM#21879 ·
维护者通常 1 天内回复
查看 NVIDIA/TensorRT-LLM 的全部 Issue
相似的 Issue
-
resource-submission validation-passed
难度 1/5 1 小时以内 新手友好度 68/100
hesreallyhim/awesome-claude-code#3875 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 77/100
bvis/aegis-hass#725 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stamp未关闭
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
#1643 unrecoverable split: 1 digest with a 403 — two earlier captures of the same URL are real 200s未关闭
难度 2/5 1-3 小时 新手友好度 66/100
Robin-IA/Congressional-Letters-Dev#1684 ·
维护者通常 1 天内回复