Skip to content

[https://nvbugs/6284101][fix] Fix guided decoding for Harmony parser - #15741

Open
dongfengy wants to merge 2 commits into
NVIDIA:mainfrom
dongfengy:codex/6284101-guided-decoding-harmony
Open

[https://nvbugs/6284101][fix] Fix guided decoding for Harmony parser#15741
dongfengy wants to merge 2 commits into
NVIDIA:mainfrom
dongfengy:codex/6284101-guided-decoding-harmony

Conversation

@dongfengy

@dongfengy dongfengy commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Adds model-aware Harmony guided-decoding adaptation for raw Python LLM.generate().
  • Applies JSON, regex, and grammar constraints after the Harmony final-channel marker.
  • Shares guided-decoding adaptation with the serving path.
  • Adds parser-aware final-content extraction and JSON-mode scoring.
  • Preserves behavior for normal reasoning parsers, llguidance, plain models, and unsupported guides.
  • Adds parsing fallbacks for failures and empty parser output.
  • Adds CPU test-list coverage and removes the GPT-OSS/Eagle3 waiver.
  • No configuration typos or unintended scope changes found.

QA Engineer Review

  • Adds generation-content tests for raw text, Qwen3, non-Harmony parsers, token IDs, and explicit Harmony parsing.
  • Adds sampling-parameter tests for Harmony adaptation, JSON schemas, parser resolution, unsupported guides, plain models, structural tags, and reasoning-parser sequences.
  • Adds unittest/evaluate/test_generation_content.py to tests/integration/test_lists/l0_cpu.yml.
  • Removes TestGPTOSS::test_eagle3_guided_decoding_4gpus[one_model] from tests/integration/test_lists/waives.txt.
  • Test-list entries have valid paths and no reported duplicates.
  • Verdict: sufficient.

Description

Fix guided decoding for the raw Python LLM.generate() path when GPT-OSS uses the Harmony protocol with xgrammar. Caller-provided JSON, regex, and grammar constraints are enriched with model-aware Harmony framing so they apply only after the final-channel marker instead of constraining the reasoning transcript.

The serving path keeps its existing behavior while sharing the same reasoning-parser adapter. JSON-mode evaluation now scores parser-selected final content, covering plain output, explicit Harmony output, and explicit normal reasoning-parser output without guessing a parser for unrelated models.

Raw guided-decoding behavior remains unchanged for normal reasoning parsers and llguidance. This PR does not change the public API.

Test Coverage

  • Post-rebase pre-commit on all changed files: passed on exact head 059d1c9a76.
  • Incremental CUDA 13.2/TensorRT 10.16 SM90+SM100 rebuild on exact head 059d1c9a76: passed.
  • Focused guide-adaptation/final-content units: 46 passed; strict tool-guided construction: 8 passed.
  • Broad affected unit/API/bindings suite: 185 passed, with the same three unrelated upstream Qwen3 auto-detection failures from missing logger methods.
  • Qwen3 raw sync+async: passed with xgrammar and llguidance; Qwen3 100-sample JSON evaluation: 77/100.
  • Llama-3.1-8B guided decoding: xgrammar and llguidance both passed (2 passed, 74/100 each).
  • Exact four-B200 GPT-OSS/Eagle3 regression on 059d1c9a76: passed with JSON accuracy 78/100 and grammar accuracy 96/100 (threshold 50.369).

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • 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.

@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from 558e70c to ab42d37 Compare June 30, 2026 00:09
@dongfengy
dongfengy marked this pull request as ready for review June 30, 2026 00:15
@dongfengy
dongfengy requested a review from a team as a code owner June 30, 2026 00:15
@dongfengy
dongfengy requested a review from zhenhuaw-me June 30, 2026 00:15
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds reasoning-parser-aware guided-decoding adaptation for Harmony and other reasoning formats. Wires the shared adaptation into LLM sampling and OpenAI serving. Adds final-content extraction and reasoning-aware JSON evaluation.

Changes

Reasoning-parser guided decoding and evaluation

Layer / File(s) Summary
Parser resolution and guided-decoding adaptation
tensorrt_llm/llmapi/reasoning_parser.py
Adds Harmony constants, parser resolution, guide conversion, and final-content constraints for supported guided-decoding formats.
Runtime guided-decoding wiring
tensorrt_llm/llmapi/llm.py, tensorrt_llm/serve/openai_protocol.py
Applies parser-specific adaptation during sampling preparation and delegates OpenAI protocol adaptation to the shared helper.
Reasoning-aware content extraction and JSON evaluation
tensorrt_llm/evaluate/interface.py, tensorrt_llm/evaluate/json_mode_eval.py
Extracts final content from generated output and uses configured reasoning parsers during JSON-mode evaluation.
Parser adaptation and extraction validation
tests/unittest/evaluate/test_generation_content.py, tests/unittest/llmapi/test_sampling_params.py, tests/integration/test_lists/test-db/l0_cpu.yml, tests/integration/test_lists/waives.txt
Adds coverage for parser resolution, Harmony constraints, schema handling, unchanged guides, final-content extraction, and CPU test registration.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant LLM
  participant ReasoningParser
  participant JsonModeEval
  Client->>LLM: Submit guided-decoding parameters
  LLM->>ReasoningParser: Resolve and adapt parser framing
  ReasoningParser-->>LLM: Return adapted parameters
  LLM-->>JsonModeEval: Return generated output
  JsonModeEval->>ReasoningParser: Extract final content
  ReasoningParser-->>JsonModeEval: Return parsed content
Loading

Suggested labels: api-compatible

Suggested reviewers: qijune, crazydemo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required ticket and type format and clearly states the main guided-decoding fix for Harmony.
Description check ✅ Passed The description explains the problem and solution, lists relevant test coverage, and includes the required checklist with the review item checked.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/evaluate/interface.py`:
- Around line 90-109: The fallback parsing in interface.py is catching all
Exception in both the harmony adapter path and the ReasoningParserFactory path,
which can mask real bugs. Update the try/except blocks around
get_harmony_adapter().harmony_output_to_openai and parser.parse(text) to catch
only the expected import, parsing, or type-related failures, and leave
unexpected exceptions to surface. Keep the same fallback-to-text behavior, but
narrow the exception handling in these parser paths to the smallest specific set
possible.

In `@tensorrt_llm/evaluate/json_mode_eval.py`:
- Around line 33-48: Add a return type annotation to _load_json_from_generation
in json_mode_eval.py, and if helpful introduce a local alias for the JSON value
type to keep the signature readable. Update the function signature of
_load_json_from_generation (and any related helper typing if needed) so the new
helper is fully annotated per the codebase guidelines.

In `@tests/unittest/evaluate/test_generation_content.py`:
- Around line 1-2: The new test file currently has only an SPDX-only header, but
it needs the repository’s full NVIDIA copyright/license header block. Update the
top-of-file header in test_generation_content.py to match the required NVIDIA
format used elsewhere in the repo, including the year of the latest meaningful
modification and the standard Apache-2.0 license notice.
- Around line 23-42: Add a test in test_generation_content for
extract_final_content_from_generation that combines token_ids with
reasoning_parser="qwen3" and asserts the qwen3 path still wins. Mirror the
existing test_extract_final_content_does_not_guess_harmony_from_tokens setup by
monkeypatching tensorrt_llm.serve.harmony_adapter.get_harmony_adapter to raise
if called, then verify the function returns the expected final content. This
should cover the explicit non-Harmony parser branch even when token_ids are
present and prevent future regressions in extract_final_content_from_generation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 318d2a29-586e-453d-ab59-726c7b606634

📥 Commits

Reviewing files that changed from the base of the PR and between e901627 and ab42d37.

📒 Files selected for processing (7)
  • tensorrt_llm/evaluate/interface.py
  • tensorrt_llm/evaluate/json_mode_eval.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/llmapi/reasoning_parser.py
  • tensorrt_llm/serve/openai_protocol.py
  • tests/unittest/evaluate/test_generation_content.py
  • tests/unittest/llmapi/test_sampling_params.py

Comment thread tensorrt_llm/evaluate/interface.py
Comment thread tensorrt_llm/evaluate/json_mode_eval.py Outdated
Comment thread tests/unittest/evaluate/test_generation_content.py
Comment thread tests/unittest/evaluate/test_generation_content.py
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from ab42d37 to 059d1c9 Compare June 30, 2026 03:00
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

1 similar comment
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56512 [ run ] triggered by Bot. Commit: 059d1c9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56512 [ run ] completed with state SUCCESS. Commit: 059d1c9
/LLM/main/L0_MergeRequest_PR pipeline #45351 completed with status: 'FAILURE'

CI Report

⚠️ 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

CI Agent Failure Analysis

Link to invocation

@dongfengy dongfengy changed the title [https://nvbugs/6284101][fix] fix guided decoding for harmony parser [TRTLLM-13773,https://nvbugs/6284101][fix] fix guided decoding for harmony parser Jun 30, 2026
@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch 2 times, most recently from 0b38f28 to baf824c Compare June 30, 2026 17:31
@dongfengy dongfengy changed the title [TRTLLM-13773,https://nvbugs/6284101][fix] fix guided decoding for harmony parser [https://nvbugs/6284101][fix] Fix guided decoding for Harmony parser Jun 30, 2026
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56678 [ run ] triggered by Bot. Commit: baf824c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56678 [ run ] completed with state ABORTED. Commit: baf824c
/LLM/main/L0_MergeRequest_PR pipeline #45501 completed with status: 'FAILURE'

CI Report

⚠️ 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

CI Agent Failure Analysis

Link to invocation

@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from baf824c to 0dac1c9 Compare June 30, 2026 23:49
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56761 [ run ] triggered by Bot. Commit: 0dac1c9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56761 [ run ] completed with state SUCCESS. Commit: 0dac1c9
/LLM/main/L0_MergeRequest_PR pipeline #45580 completed with status: 'FAILURE'

CI Report

⚠️ 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

CI Agent Failure Analysis

Link to invocation

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56850 [ run ] triggered by Bot. Commit: 0dac1c9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56850 [ run ] completed with state SUCCESS. Commit: 0dac1c9
/LLM/main/L0_MergeRequest_PR pipeline #45661 completed with status: 'FAILURE'

CI Report

⚠️ 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

CI Agent Failure Analysis

Link to invocation

@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from 0dac1c9 to 0cbb805 Compare July 6, 2026 23:43
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57856 [ run ] triggered by Bot. Commit: 0cbb805 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65085 [ run ] triggered by Bot. Commit: 0d9ba14 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65085 [ run ] completed with state SUCCESS. Commit: 0d9ba14
/LLM/main/L0_MergeRequest_PR pipeline #52889 completed with status: 'FAILURE'

CI Report

⚠️ 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

CI Agent Failure Analysis

Link to invocation

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

1 similar comment
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65210 [ run ] triggered by Bot. Commit: 0d9ba14 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65210 [ run ] completed with state FAILURE. Commit: 0d9ba14
/LLM/main/L0_MergeRequest_PR pipeline #52994 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Ask a member of NVIDIA/trt-llm-ci-approvers to add the label, 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

Apply structural guidance only after Harmony enters the final channel. Preserve unconstrained reasoning while keeping JSON and grammar evaluation scoped to final content.

Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from 0d9ba14 to ff0987a Compare August 11, 2026 18:42
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65370 [ run ] triggered by Bot. Commit: ff0987a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65370 [ run ] completed with state SUCCESS. Commit: ff0987a
/LLM/main/L0_MergeRequest_PR pipeline #53133 completed with status: 'FAILURE'

CI Report

⚠️ 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

CI Agent Failure Analysis

Link to invocation

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65431 [ run ] triggered by Bot. Commit: ff0987a Link to invocation

@brnguyen2 brnguyen2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks right and the shared adapter is a real improvement over the duplicated serving logic (it also fixes the latent unbound-content NameError in the old _response_format_to_guided_decoding_params when no guide field matched). Two things should land with this PR so CI actually guards the fix:

  1. waives.txt still skips the regression test. accuracy/test_llm_api_pytorch.py::TestGPTOSS::test_eagle3_guided_decoding_4gpus[one_model] is SKIPped at tests/integration/test_lists/waives.txt:59 (under https://nvbugs/5596343). Since this PR is the fix for that failure (split into 6284101) and the description says the exact 4-GPU regression passed on head, remove the waiver here — otherwise the fixed test stays disabled and nothing in CI covers the bug.

  2. The new unit-test file never runs in CI — see the inline comment on tests/unittest/evaluate/test_generation_content.py.

One scope question worth a sentence in the description or a tracked follow-up: the raw-path adaptation is deliberately gated to xgrammar (resolve_raw_guided_decoding_reasoning_parser at tensorrt_llm/llmapi/reasoning_parser.py:241), so GPT-OSS + llguidance via raw LLM.generate() still applies the guide to the whole transcript. Since structural tags are xgrammar-only that's understandable, but it leaves the original symptom reachable on the other backend — is a follow-up planned, or should llguidance + gpt_oss at least warn?

Comment thread tests/unittest/evaluate/test_generation_content.py
# final output. Add that model-aware framing here so
# xgrammar applies the guide only to Harmony's final
# channel. Other formats preserve the original guide.
sampling_params.guided_decoding = (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reassigns guided_decoding on the caller's own SamplingParams object (generate_async doesn't copy it). After the first request, the user's GuidedDecodingParams(json=...) is silently replaced by an xgrammar structural-tag guide; if they reuse the same SamplingParams against another LLM (e.g. an llguidance-backed one), the structural tag — unsupported there — is what gets submitted, and their original schema is unrecoverable. The existing mutations in this method (end_id, logits processors) are additive; swapping the guide type is observably different. Consider applying the adaptation to a copy, or at least deferring the rewrite to the point where the request params are marshalled rather than the shared object.

stag_format = ResponseFormat(type="structural_tag", format=stag_format)
return GuidedDecodingParams(structural_tag=stag_format.model_dump_json(
by_alias=True, exclude_none=True))
return adapt_guided_decoding_params_for_reasoning_parser(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor behavior change from the refactor: the old code round-tripped the built structural tag through ResponseFormat.format, which is typed xgrammar.structural_tag.Format, so the tag (including the embedded user schema/regex content) was pydantic-validated at request time and a bad one returned a 4xx. adapt_guided_decoding_params_for_reasoning_parser now json.dumps a raw dict, so malformed structural tags are only caught later in the executor. Probably acceptable since the dict layout is constant and covered by the new unit tests, but if request-time validation was intentional, consider validating the dict against xgrammar.structural_tag.Format inside the shared helper.

Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
@dongfengy
dongfengy requested review from a team as code owners August 12, 2026 01:02
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unittest/llmapi/test_sampling_params.py (1)

216-216: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Annotate the added test functions.

Add -> None to each test function. Add precise parameter annotations to the parametrized test functions.

  • tests/unittest/llmapi/test_sampling_params.py#L216-L216: add a return annotation.
  • tests/unittest/llmapi/test_sampling_params.py#L242-L242: add a return annotation.
  • tests/unittest/llmapi/test_sampling_params.py#L261-L261: add a return annotation.
  • tests/unittest/llmapi/test_sampling_params.py#L283-L283: add parameter and return annotations.
  • tests/unittest/llmapi/test_sampling_params.py#L297-L297: add parameter and return annotations.
  • tests/unittest/llmapi/test_sampling_params.py#L314-L314: add parameter and return annotations.
  • tests/unittest/llmapi/test_sampling_params.py#L330-L330: add a return annotation.
  • tests/unittest/llmapi/test_sampling_params.py#L340-L340: add a return annotation.
  • tests/unittest/llmapi/test_sampling_params.py#L363-L363: add a return annotation.

As per coding guidelines, “Annotate every function.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/llmapi/test_sampling_params.py` at line 216, Annotate every
added test in tests/unittest/llmapi/test_sampling_params.py: add -> None to
test_harmony_guided_decoding_triggers_on_final_channel and the tests at lines
242, 261, 330, 340, and 363; add precise parameter annotations plus -> None to
the parametrized tests at lines 283, 297, and 314.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unittest/llmapi/test_sampling_params.py`:
- Around line 242-258: Add a test alongside
test_harmony_guided_decoding_accepts_json_schema_string that passes a Pydantic
model through adapt_guided_decoding_params_for_reasoning_parser with
HARMONY_REASONING_PARSER, then parse the resulting structural_tag and assert its
JSON-schema content matches the model’s model_json_schema() output.

---

Nitpick comments:
In `@tests/unittest/llmapi/test_sampling_params.py`:
- Line 216: Annotate every added test in
tests/unittest/llmapi/test_sampling_params.py: add -> None to
test_harmony_guided_decoding_triggers_on_final_channel and the tests at lines
242, 261, 330, 340, and 363; add precise parameter annotations plus -> None to
the parametrized tests at lines 283, 297, and 314.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 640e0289-9da6-4aae-b780-a7d78937233f

📥 Commits

Reviewing files that changed from the base of the PR and between 48df89d and 18e7748.

📒 Files selected for processing (9)
  • tensorrt_llm/evaluate/interface.py
  • tensorrt_llm/evaluate/json_mode_eval.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/llmapi/reasoning_parser.py
  • tensorrt_llm/serve/openai_protocol.py
  • tests/integration/test_lists/test-db/l0_cpu.yml
  • tests/integration/test_lists/waives.txt
  • tests/unittest/evaluate/test_generation_content.py
  • tests/unittest/llmapi/test_sampling_params.py
💤 Files with no reviewable changes (1)
  • tests/integration/test_lists/waives.txt
🚧 Files skipped from review as they are similar to previous changes (5)
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/evaluate/interface.py
  • tensorrt_llm/evaluate/json_mode_eval.py
  • tests/unittest/evaluate/test_generation_content.py
  • tensorrt_llm/serve/openai_protocol.py

Comment thread tests/unittest/llmapi/test_sampling_params.py
@dongfengy

Copy link
Copy Markdown
Collaborator Author

The fix looks right and the shared adapter is a real improvement over the duplicated serving logic (it also fixes the latent unbound-content NameError in the old _response_format_to_guided_decoding_params when no guide field matched). Two things should land with this PR so CI actually guards the fix:

  1. waives.txt still skips the regression test. accuracy/test_llm_api_pytorch.py::TestGPTOSS::test_eagle3_guided_decoding_4gpus[one_model] is SKIPped at tests/integration/test_lists/waives.txt:59 (under https://nvbugs/5596343). Since this PR is the fix for that failure (split into 6284101) and the description says the exact 4-GPU regression passed on head, remove the waiver here — otherwise the fixed test stays disabled and nothing in CI covers the bug.
  2. The new unit-test file never runs in CI — see the inline comment on tests/unittest/evaluate/test_generation_content.py.

One scope question worth a sentence in the description or a tracked follow-up: the raw-path adaptation is deliberately gated to xgrammar (resolve_raw_guided_decoding_reasoning_parser at tensorrt_llm/llmapi/reasoning_parser.py:241), so GPT-OSS + llguidance via raw LLM.generate() still applies the guide to the whole transcript. Since structural tags are xgrammar-only that's understandable, but it leaves the original symptom reachable on the other backend — is a follow-up planned, or should llguidance + gpt_oss at least warn?

I have fixed waives.txt and added new tests to CI.

Regarding scope, yes, this fixes all instances of Harmony parser + xgrammar and has been verified with solid tests. Harmony + llguidance requires significantly more work and may even require architectural changes. I would suggest treating this as a feature request so that we don’t bloat this bug-fix PR.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65431 [ run ] completed with state FAILURE. Commit: ff0987a
/LLM/main/L0_MergeRequest_PR pipeline #53181 completed with status: 'FAILURE'

CI Report

⚠️ 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

CI Agent Failure Analysis

Link to invocation

@ZhanruiSunCh ZhanruiSunCh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for infra part.

@crazydemo crazydemo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary - CONCERNS

Verdict: The code change is correct, well-factored (shares the adapter with the serving path and fixes the latent unbound-content NameError / schema-alias mangling), and unit-tested. It cannot merge as-is: the branch is in conflict (mergeable_state = dirty) and the fix only covers the xgrammar backend, leaving the original bug reachable on llguidance.

Issues

  • [MAJOR] repo state - PR is not mergeable (mergeable_state = dirty); rebase and resolve conflicts, then get CI green.
  • [MAJOR] tensorrt_llm/llmapi/reasoning_parser.py:241 - GPT-OSS + llguidance still constrains the whole transcript (partial fix).
  • [MINOR] tests/unittest/llmapi/test_sampling_params.py:216 - added tests lack type annotations.
  • [NIT] tests/unittest/evaluate/test_generation_content.py:1 - SPDX-only header, missing full NVIDIA license block.

QA view

  • Test coverage: partial - unit tests cover the adaptation and resolver functions and extract_final_content_from_generation well; the GPT-OSS+llguidance branch and the json_mode_eval scoring path have no unit test, and the raw e2e Harmony guided-decoding path relies solely on the re-enabled 4-GPU accuracy test.
  • SM coverage: architecture-independent - pure Python structural-tag construction, no arch guards; integration coverage runs on B200, new units on CPU.
  • Test code: missing annotations, SPDX-only header on the new file, Harmony conversion asserted only for the json guide (not json_object/regex/grammar), PEP 604 syntax needs py>=3.10.
  • Test time: small - one fast CPU unit file added; one 4-GPU accuracy test re-enabled by waiver removal (pre-existing test, adds GPU time).
  • Needs /qa-verify: yes - waiver removed to re-enable a 4-GPU regression test and test-list infra changed; QA should confirm that test passes post-rebase and the new CPU unit test is actually collected in CI, and note the llguidance path is unfixed/untested.

Does this actually fix nvbugs/6284101?

Partial. For gpt_oss + xgrammar, llm.py:1396-1413 rewrites the guide into a triggered_tags structural tag keyed on the Harmony final-channel marker, so the constraint no longer binds the reasoning transcript - the failing path is fixed and now guarded by the unwaived 4-GPU test. But resolve_raw_guided_decoding_reasoning_parser (reasoning_parser.py:239-243) gates on guided_decoding_backend == "xgrammar", so GPT-OSS with the llguidance backend returns None, no final-channel framing is applied, and the guide still constrains the full transcript. That path remains uncovered.

Possible new issues

  • Serving path now serializes via json.dumps rather than ResponseFormat.model_dump_json(by_alias=True, exclude_none=True). This is the intended fix (preserves a top-level schema property, tested), but any consumer relying on the old exclude_none/by_alias behavior would see a more literal JSON string. Content dicts contain no None values, so risk is low.
  • The Harmony branch of extract_final_content_from_generation swallows a broad exception tuple and falls back to raw text; a malformed adapter response would silently score against raw text. Eval-only, so limited blast radius.

What I could not verify

Runtime behavior of the unwaived 4-GPU test post-rebase; whether the new unittest/evaluate/test_generation_content.py list entry is actually collected by the CPU CI job (an earlier reviewer flagged it as not running); and the exact type of guided_decoding_params.json reaching the serving path in production (I only see the diff).

Findings not attached to a line

  • [MAJOR] ?:? - PR is not mergeable (mergeable_state = dirty)
    • The context reports mergeable=false / mergeable_state=dirty, i.e. the branch has merge conflicts against main. Regardless of code correctness this cannot be merged as-is; it must be rebased and the conflicts resolved, then CI (including the newly-unwaived 4-GPU TestGPTOSS::test_eagle3_guided_decoding_4gpus[one_model]) must be green before merge.

Automated review by NVCortex Lite, run by @crazydemo.

)


def test_harmony_guided_decoding_triggers_on_final_channel():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MINOR] Added test functions lack type annotations

Per the repo coding guideline ("annotate every function"), the new test functions and parametrized tests (this one and those at lines 242, 261, 283, 297, 314, 330, 340, 363) should carry -> None and precise parameter annotations. Purely a style/consistency nit; does not affect behavior.

@@ -0,0 +1,88 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NIT] Header is SPDX-only, missing full NVIDIA license block

Other test files in the repo carry the full NVIDIA copyright + Apache-2.0 header. This new file only has the two-line SPDX header. Add the standard block to match repo convention.

@crazydemo crazydemo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary - Approve (non-blocking)

Approving so this is not blocked on me. The points raised in my review comment above are non-blocking — please read them and address what you agree with before merging.

Worth doing before this is relied on: This is a bug fix that removes a waiver (waives.txt:59) to re-enable a 4-GPU accuracy regression test, and it changes test-list infra (l0_cpu.yml). QA should confirm the unwaived TestGPTOSS::test_eagle3_guided_decoding_4gpus[one_model] actually passes post-rebase and that the new CPU unit test is discovered/run in CI, before this is trusted. The llguidance path is unfixed and untested.

Automated review by NVCortex Lite, run by @crazydemo.

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.

7 participants