Skip to content

[None][fix] Responses: detokenize for the parsers as chat completions does - #21072

Merged
JunyiXu-nv merged 1 commit into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyix-fix-responses-special-token-decoding
Oct 30, 2026
Merged

JunyiXu-nv merged 1 commit into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyix-fix-responses-special-token-decoding

Conversation

@JunyiXu-nv

@JunyiXu-nv JunyiXu-nv commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Chat completions sets the detokenizer up for the configured parsers (_configure_parser_special_token_decoding):

  • a reasoning or tool parser that reads special tokens gets them kept (skip_special_tokens=False), the tool parser only when the request has tools;
  • Kimi-K3's parsers also get them without spaces in between (spaces_between_special_tokens=False), because K3 writes tag names between special tokens.

/v1/responses never applied it. Its requests were detokenized with the defaults, special tokens dropped and spaced:

  • Kimi-K3: <|open|>tools<|sep|> arrives as <|open|> tools <|sep|> or loses its tokens. The tool parser never matches, and every tool call reaches the client as message text.
  • DeepSeek DSML parsers (deepseek_v32, deepseek_v4, deepseek_v41): their markup is not dropped, so calls still parse. The end-of-sentence token is dropped from the decoded text, where chat keeps it and the parser removes it. Anything that reads the raw text after decoding sees two different texts for the same output, depending on the endpoint.

This PR applies the same setup on /v1/responses, after the request is preprocessed, for non-Harmony models. has_tools covers tools a client sends in an additional_tools input item too, since those are moved into tools when the request is parsed. The Harmony path is unchanged.

Test Coverage

tests/unittest/llmapi/apps/test_tool_parsers.py (CPU, in l0_cpu.yml), TestConfigureParserSpecialTokenDecoding::test_the_responses_route_applies_it: drives OpenAIServer.openai_responses up to the engine submission and checks the sampling params it submits:

  • kimi_k3 reasoning and tool parsers, with tools: special tokens kept, no spaces;
  • kimi_k3 reasoning parser without tools: the same, since the reasoning parser applies to every request;
  • deepseek_v32 tool parser with tools: special tokens kept, spacing unchanged;
  • deepseek_v32 without tools, and no parser: unchanged.

Three of these cases fail on main's code. On a build of current main, test_tool_parsers.py, test_responses_store_replay.py and test_responses_input_preprocess.py pass: 1043 tests, against 1038 on main.

PR Checklist

  • PR description clearly explains what and why.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

🤖 Generated with Claude Code

Dev Engineer Review

For non-Harmony /v1/responses requests, the server now applies parser-specific special-token decoding after request preprocessing. This aligns Responses behavior with chat completions while leaving the Harmony path unchanged. No review findings or severity counts were supplied.

QA Engineer Review

The change adds a parameterized Responses-route test in tests/unittest/llmapi/apps/test_tool_parsers.py. It checks parser-specific skip_special_tokens and spaces_between_special_tokens settings across Kimi-K3, DeepSeek V3.2, tool-presence, and no-parser cases. The test file is listed in tests/integration/test_lists/test-db/l0_cpu.yml. No manual-QA list entry or test execution results were supplied. Coverage verdict: sufficient for the decoding settings covered by the test.

Per-File QA Perspective

  • tensorrt_llm/serve/openai_server.py — Verify that non-Harmony Responses requests pass the configured parser and tool-presence context into decoding setup after preprocessing. Confirm that Harmony requests retain their existing behavior.
  • tests/unittest/llmapi/apps/test_tool_parsers.py — The new parameterized route test verifies generation receives expected special-token settings for Kimi-K3 and DeepSeek V3.2 cases, including requests with and without tools. The file is listed in the CI test-db/l0_cpu.yml list.

… does

The Responses route never applied the parsers' special-token decoding that
chat completions applies (_configure_parser_special_token_decoding): parsers
that read special tokens need them kept, and Kimi-K3's also need them
without spaces in between. Without it, Kimi-K3 behind /v1/responses gets
<|open|>tools<|sep|> as <|open|> tools <|sep|>, its tool parser never
matches, and every tool call reaches the client as message text. For the
DeepSeek DSML parsers the end-of-sentence token was dropped from the
decoded text where chat keeps it.

Signed-off-by: JunyiXu-nv <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7587cc8 and d6fd0a9.

Files selected for processing: 2
  • tensorrt_llm/serve/openai_server.py
  • tests/unittest/llmapi/apps/test_tool_parsers.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

The Responses API now sets special-token decoding options for non-Harmony requests based on configured parsers and tool presence. A parameterized test checks the resulting settings across five configurations.

Changes

Responses API token decoding

Layer / File(s) Summary
Configure and verify decoding settings
tensorrt_llm/serve/openai_server.py, tests/unittest/llmapi/apps/test_tool_parsers.py
Non-Harmony Responses API requests configure special-token decoding based on parser settings and tool presence. The mocked route test checks the settings across five configurations.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to d6fd0

The Responses decoding change has no identified issue that should block merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title follows the required [None][fix] format and clearly describes the Responses API parser detokenization fix.
Description check Passed The description explains the issue, solution, affected parser behavior, test coverage, and checklist status. It provides sufficient context for review.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80800 [ run ] triggered by Bot. Commit: d6fd0a9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80800 [ run ] completed with state SUCCESS. Commit: d6fd0a9
/LLM/main/L0_MergeRequest_PR pipeline #66537 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Either:

  • Wait for the PR to be fully approved — the label is added automatically once approval is complete. Having unresolved open comments is fine, or
  • If needed, ask a member of NVIDIA/trt-llm-ci-approvers to add the label manually.
    Then re-trigger CI with the same bot command (no rebase needed).

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@github-actions

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81560 [ run ] triggered by Bot. Commit: d6fd0a9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81560 [ run ] completed with state SUCCESS. Commit: d6fd0a9
/LLM/main/L0_MergeRequest_PR pipeline #67228 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants