Skip to content

[https://nvbugs/6060281][fix] Treat whitespace-only content in nano-v3 reasoning swap#12912

Merged
tijyojwad merged 1 commit into
NVIDIA:mainfrom
tijyojwad:fix/nvbug-6060281-whitespace-reasoning-fallback
Apr 13, 2026
Merged

[https://nvbugs/6060281][fix] Treat whitespace-only content in nano-v3 reasoning swap#12912
tijyojwad merged 1 commit into
NVIDIA:mainfrom
tijyojwad:fix/nvbug-6060281-whitespace-reasoning-fallback

Conversation

@tijyojwad

@tijyojwad tijyojwad commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

…(6060281)

When chat_template_kwargs enables force_nonempty_content, NemotronV3ReasoningParser promotes reasoning into content if the parsed content string is empty. Apply the same fallback when content is only whitespace (e.g. a lone newline after the closing think tag), matching the non-whitespace empty case.

Add unit coverage for newline- and space-only trailing content.

Made-with: Cursor

Summary by CodeRabbit

Bug Fixes

  • Improved reasoning content parsing to properly handle cases where content contains only whitespace or newlines.
  • Enhanced content validation logic to ensure consistent behavior when processing empty or whitespace-only text segments.

Description

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

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

…(6060281)

When chat_template_kwargs enables force_nonempty_content, NemotronV3ReasoningParser
promotes reasoning into content if the parsed content string is empty. Apply the
same fallback when content is only whitespace (e.g. a lone newline after the
closing think tag), matching the non-whitespace empty case.

Add unit coverage for newline- and space-only trailing content.

Signed-off-by: tijyojwad <1127155+tijyojwad@users.noreply.github.com>
Made-with: Cursor
@tijyojwad
tijyojwad requested a review from a team as a code owner April 10, 2026 02:39
@tijyojwad
tijyojwad requested a review from hchings April 10, 2026 02:39
@tijyojwad

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@coderabbitai

coderabbitai Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Updated the reasoning parser to treat whitespace-only content after closing tags as empty, enabling proper reasoning-to-content swaps. Added corresponding test cases to verify this edge case handling.

Changes

Cohort / File(s) Summary
Reasoning Parser Logic
tensorrt_llm/llmapi/reasoning_parser.py
Modified _maybe_swap_content method to normalize result.content and check content.strip() instead of raw content, ensuring content with only whitespace/newlines triggers the reasoning-to-content swap.
Parser Tests
tests/unittest/llmapi/test_reasoning_parser.py
Extended test_nano_v3_reasoning_parser parametrized test with two new cases covering whitespace-only content scenarios (newline and spaces/tabs).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the issue (whitespace-only content not triggering the swap) and solution, with test coverage mentioned; however, the Description and Test Coverage sections of the template are not fully filled out as standalone sections.
Title check ✅ Passed The title accurately describes the main change: treating whitespace-only content in the nano-v3 reasoning parser's swap logic, which is the core purpose of the modifications to both the implementation and tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42623 [ run ] triggered by Bot. Commit: 59f7c6c Link to invocation

@tijyojwad
tijyojwad requested review from 2ez4bz and LinPoly and removed request for hchings April 10, 2026 14:54
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #42623 [ run ] completed with state SUCCESS. Commit: 59f7c6c
/LLM/main/L0_MergeRequest_PR pipeline #33341 completed with status: 'SUCCESS'

CI Report

Link to invocation

@2ez4bz 2ez4bz changed the title [https://nvbugspro.nvidia.com/bug/6060281][fix] Treat whitespace-only content in nano-v3 reasoning swap … [https://nvbugs/6060281][fix] Treat whitespace-only content in nano-v3 reasoning swap … Apr 10, 2026
@2ez4bz 2ez4bz changed the title [https://nvbugs/6060281][fix] Treat whitespace-only content in nano-v3 reasoning swap … [https://nvbugs/6060281][fix] Treat whitespace-only content in nano-v3 reasoning swap Apr 10, 2026
Comment thread tensorrt_llm/llmapi/reasoning_parser.py
@tijyojwad
tijyojwad merged commit 293b1c9 into NVIDIA:main Apr 13, 2026
10 of 12 checks passed
chienchunhung pushed a commit to chienchunhung/TensorRT-LLM that referenced this pull request Apr 16, 2026
…3 reasoning swap (NVIDIA#12912)

Signed-off-by: tijyojwad <1127155+tijyojwad@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants