Skip to content

Comments

[TRTLLM-10030][chore] refactor finish reasons tests#11445

Merged
ixlmar merged 2 commits intoNVIDIA:mainfrom
ixlmar:test/finish-reasons
Feb 12, 2026
Merged

[TRTLLM-10030][chore] refactor finish reasons tests#11445
ixlmar merged 2 commits intoNVIDIA:mainfrom
ixlmar:test/finish-reasons

Conversation

@ixlmar
Copy link
Collaborator

@ixlmar ixlmar commented Feb 11, 2026

Description

Code changes group finish reasons related test code in TestFinishReasons and add check that TorchSampler._write_finish_reasons does not stream sync.

Test Coverage

PR extends existing tests.

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

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

Summary by CodeRabbit

  • Tests
    • Restructured test infrastructure for torch sampler validation with improved test organization and scaffolding to enhance test maintainability and reliability.

@ixlmar ixlmar requested review from Funatiq and stnie February 11, 2026 09:03
@ixlmar ixlmar marked this pull request as ready for review February 11, 2026 09:06
@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 11, 2026

/bot run --disable-fail-fast

@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 11, 2026

@Funatiq @stnie Change set is much smaller when ignoring whitespace (indentation change).

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Restructured test scaffolding in test_torch_sampler.py by introducing a class-based, provider-driven testing pattern. Replaced standalone constants and simple test helpers with a new TestFinishReasons class containing structured RequestCase instances, batched test setup logic, and refactored test methods for finish-reason writing and stop-words validation.

Changes

Cohort / File(s) Summary
Test Scaffolding Restructuring
tests/unittest/_torch/sampler/test_torch_sampler.py
Replaced standalone constants (NOT_FINISHED, STOP_WORDS, END_ID, LENGTH) and simple helpers with new TestFinishReasons class. Added nested RequestCase class with initialization logic for building LlmRequest objects. Introduced build() classmethod that returns a UutProvider context manager with TorchSampler wiring, warmup mechanisms, and finish-reason validation. Refactored test methods test_write_finish_reasons and test_are_stop_words_isnt_called_when_no_stop_words to use the new provider-based pattern with context/monkeypatch instrumentation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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
Title check ✅ Passed The title accurately summarizes the main change: refactoring finish reasons tests into a structured test class. It references the JIRA ticket and uses the appropriate 'chore' type designation.
Description check ✅ Passed The PR description includes a concise explanation of the changes (grouping finish reasons tests and adding stream sync check) and test coverage statement. However, it largely copies the template's GitHub Bot Help section without meaningful customization, and lacks details about why the refactoring improves the codebase.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unittest/_torch/sampler/test_torch_sampler.py (1)

1-1: ⚠️ Potential issue | 🟡 Minor

Update copyright year to 2026.

The copyright header says 2025, but this file has meaningful modifications in 2026. As per coding guidelines, "All source files must contain an NVIDIA copyright header with the year of latest meaningful modification."

Proposed fix
-# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
+# Copyright (c) 2025-2026, NVIDIA CORPORATION. All rights reserved.
🤖 Fix all issues with AI agents
In `@tests/unittest/_torch/sampler/test_torch_sampler.py`:
- Around line 686-698: The build(...) classmethod declares check_no_cuda_sync
but never uses it, so the no-CUDA-sync assertion is never triggered; modify
build to propagate this flag into the returned provider or return a tuple so the
caller can call _run_test_with_warmup(uut_provider, max_sync_s=...) when
check_no_cuda_sync is True. Specifically, update build (and its inner
_uut_provider if needed) so that the caller at the test invocation site receives
the check_no_cuda_sync value (or a computed max_sync_s) and then pass that into
_run_test_with_warmup(uut_provider, max_sync_s=...) instead of omitting
max_sync_s; ensure function names referenced: build, _uut_provider, and
_run_test_with_warmup are updated consistently.
- Around line 859-890: Remove the `@classmethod` decorator from
test_are_stop_words_isnt_called_when_no_stop_words and change its signature to
an instance method that accepts the pytest monkeypatch fixture (def
test_are_stop_words_isnt_called_when_no_stop_words(self, monkeypatch:
pytest.MonkeyPatch):). Update any uses of cls inside the method (e.g.,
cls.RequestCase, cls.NOT_FINISHED) to reference the test class via
self.__class__ or type(self) so the code still locates RequestCase and
NOT_FINISHED, and keep the monkeypatch usage to patch
TorchSampler._are_stop_words.
🧹 Nitpick comments (2)
tests/unittest/_torch/sampler/test_torch_sampler.py (2)

644-681: Shared mutable class-level state in seq_slots may cause fragile tests.

seq_slots is a class-level list mutated by .pop() on every RequestCase instantiation. This creates implicit coupling between test cases: slots consumed in one test are unavailable to subsequent tests, test ordering matters, and torch.randperm without a seed makes slot assignments non-reproducible across runs.

Consider creating the slot pool per build() invocation (or per test) instead:

Proposed fix — move slot generation into `build()` or `__init__`
     class RequestCase:
         MAX_NEW_TOKENS = 10
         MAX_NUM_SEQUENCES = 128
-        seq_slots = torch.randperm(MAX_NUM_SEQUENCES).tolist()
         BEAM = 0

         def __init__(
             self,
             *,
             prompt: list[int],
             new_tokens: list[int],
             finish_reasons: list[FinishReason],
             max_new_tokens: int = MAX_NEW_TOKENS,
             end_id: Optional[int] = None,
             num_draft_tokens: int | None = None,
             stop_words_list: Optional[list[list[int]]] = None,
+            seq_slot: int,
         ):
-            seq_slot = self.seq_slots.pop()  # random seq slot in MAX_NUM_SEQUENCES
             self.prompt = prompt

Then in build(), generate and distribute slots:

seq_slot_pool = torch.randperm(cls.MAX_NUM_SEQUENCES, generator=torch.Generator().manual_seed(42)).tolist()
for i, req in enumerate(requests_args):
    req['seq_slot'] = seq_slot_pool[i]

696-698: Misleading variable name max_tokens.

max_tokens holds a set of new-token counts (used to assert uniformity), but reads as if it stores a maximum value. Consider a clearer name like token_count_set or new_token_lengths.

Proposed rename
-                max_tokens = set(len(req.new_tokens) for req in requests)
-                assert len(max_tokens) == 1
-                max_draft_len = max_tokens.pop() - 1
+                new_token_lengths = set(len(req.new_tokens) for req in requests)
+                assert len(new_token_lengths) == 1
+                max_draft_len = new_token_lengths.pop() - 1

@tensorrt-cicd
Copy link
Collaborator

PR_Github #35611 [ run ] triggered by Bot. Commit: da83f5f

@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 11, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #35618 [ run ] triggered by Bot. Commit: 0336248

Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
@ixlmar ixlmar force-pushed the test/finish-reasons branch from 0336248 to 7d15ee8 Compare February 11, 2026 11:30
@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 11, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #35628 [ run ] triggered by Bot. Commit: 7d15ee8

@tensorrt-cicd
Copy link
Collaborator

PR_Github #35628 [ run ] completed with state SUCCESS. Commit: 7d15ee8
/LLM/main/L0_MergeRequest_PR pipeline #27521 completed with status: 'SUCCESS'

@ixlmar ixlmar enabled auto-merge (squash) February 12, 2026 07:31
@ixlmar ixlmar removed the request for review from stnie February 12, 2026 07:32
@ixlmar ixlmar disabled auto-merge February 12, 2026 07:32
@ixlmar ixlmar merged commit d0f3c41 into NVIDIA:main Feb 12, 2026
5 checks passed
@ixlmar ixlmar deleted the test/finish-reasons branch February 12, 2026 07:32
ekou24 pushed a commit to ekou24/TensorRT-LLM that referenced this pull request Feb 16, 2026
Signed-off-by: ixlmar <206748156+ixlmar@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.

3 participants