Skip to content

[None][chore] split up TorchSampler.Store#11566

Merged
ixlmar merged 3 commits intoNVIDIA:mainfrom
ixlmar:chore/fewer-optionals
Feb 20, 2026
Merged

[None][chore] split up TorchSampler.Store#11566
ixlmar merged 3 commits intoNVIDIA:mainfrom
ixlmar:chore/fewer-optionals

Conversation

@ixlmar
Copy link
Collaborator

@ixlmar ixlmar commented Feb 18, 2026

Description

Detailed changes:

  • Restore type correctness of sampler code
  • Prune obsolete BeamSearchMetadata.end_ids
  • Make type annotations stricter, by grouping fields with correlated values of is not None, reducing the amount of assert ... is not None required for type correctness.
  • Encapsulate request grouping and related cache data structures
  • Change an implementation detail in TorchSampler.setup_sampler_step to make tests more robust (cf. discussions in [TRTLLM-10791][feat] TorchSampler general host time optimization #11141)
  • Further decouple MTPSampler from TorchSampler

Test Coverage

n/a

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

Release Notes

  • Refactor

    • Reorganized internal sampler state management and data structure handling to improve code maintainability.
  • Breaking Changes

    • Removed end_ids field from BeamSearchMetadata. Update code referencing this field accordingly.

@ixlmar ixlmar requested review from Funatiq, hyukn and stnie February 18, 2026 11:21
@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 18, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36143 [ run ] triggered by Bot. Commit: 0beed4d

@ixlmar ixlmar force-pushed the chore/fewer-optionals branch from 0beed4d to b535285 Compare February 18, 2026 12:21
@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 18, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36146 [ run ] triggered by Bot. Commit: b535285

@ixlmar ixlmar marked this pull request as ready for review February 18, 2026 16:08
@ixlmar ixlmar requested review from a team as code owners February 18, 2026 16:08
@ixlmar ixlmar requested a review from sunnyqgg February 18, 2026 16:08
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

📝 Walkthrough

Walkthrough

This PR refactors the TorchSampler to introduce a new caching and grouping abstraction. A new _CachingRequestGrouper class manages per-slot grouping state and rebuilds grouping only when necessary. New storage abstractions BeamSearchStore and LogProbsStore encapsulate beam-search and log-probability buffers, replacing direct store access patterns. The end_ids field is removed from BeamSearchMetadata, and MTPSampler.Store is updated to no longer inherit from TorchSampler.Store. Tests are updated to use the new storage abstractions.

Changes

Cohort / File(s) Summary
Sampler Core Refactoring
tensorrt_llm/_torch/pyexecutor/sampler.py
Introduced _CachingRequestGrouper class with nested _Store to manage per-slot grouping state and cache recomputation needs. Added BeamSearchStore and LogProbsStore dataclasses to encapsulate beam-search and log-probability buffers. Refactored method signatures to thread through new storage abstractions and restructured grouping logic to use caching mechanisms.
Sampling Utilities
tensorrt_llm/_torch/pyexecutor/sampling_utils.py
Removed end_ids field from BeamSearchMetadata dataclass to simplify the public data structure.
Speculative Sampler
tensorrt_llm/_torch/speculative/mtp.py
Modified MTPSampler.Store to no longer inherit from TorchSampler.Store and removed inherited fields (finish_reasons, end_ids, max_lengths_tensor) and associated post_init method.
Test Suite Updates
tests/unittest/_torch/sampler/test_beam_search.py, tests/unittest/_torch/sampler/test_torch_sampler.py
Updated tests to reference beam_search_store and log_probs_store abstractions instead of direct sampler.store access. Removed end_ids initialization and adapted test infrastructure to use _filter_new_requests mocking with monkeypatch.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • Funatiq
  • stnie
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.30% 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 clearly summarizes the main structural change: splitting up TorchSampler.Store into separate data structures.
Description check ✅ Passed The PR description clearly outlines key changes and objectives (type correctness, field pruning, type annotation improvements, encapsulation, test robustness, and decoupling). It follows the template structure with description, test coverage, and checklist.

✏️ 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)
tensorrt_llm/_torch/pyexecutor/sampler.py (1)

1713-1727: ⚠️ Potential issue | 🟡 Minor

Add Google-style docstrings to the new request helpers.

_is_new_request and _filter_new_requests are new and lack Google-style docstrings required by the guidelines.

📝 Suggested docstrings
     `@staticmethod`
     def _is_new_request(request: LlmRequest) -> bool:
+        """Return True when a request needs per-slot initialization.
+
+        Args:
+            request: Request to evaluate.
+
+        Returns:
+            True if the request should be treated as new in setup.
+        """
         return (
             not request.is_finished
             and not request.py_is_draft
             and (
                 (request.is_context_init_state and request.is_last_context_chunk)
                 or request.is_disagg_generation_transmission_complete
             )
         )

     `@classmethod`
     def _filter_new_requests(cls, requests: ScheduledRequests) -> list[LlmRequest]:
+        """Return requests that require new-slot initialization.
+
+        Args:
+            requests: Scheduled request bundle.
+
+        Returns:
+            Filtered list of new requests.
+        """
         return [request for request in requests.context_requests if cls._is_new_request(request)]

As per coding guidelines, "Use Google style docstrings for classes and functions, which can be parsed by Sphinx."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/_torch/pyexecutor/sampler.py` around lines 1713 - 1727, Add
Google-style docstrings to the two new helper methods: for
_is_new_request(request: LlmRequest) add a short one-line summary, an Args
section describing the request parameter and its type, and a Returns section
describing the boolean meaning (True when request is active, not draft, and
either an initial context last chunk or disaggregated generation transmission is
complete); for _filter_new_requests(cls, requests: ScheduledRequests) add a
one-line summary, an Args section describing the requests parameter and its
type, and a Returns section describing that it returns a list[LlmRequest]
filtered from requests.context_requests using cls._is_new_request. Ensure the
docstrings follow Google style and are placed immediately above each method
definition.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tensorrt_llm/_torch/pyexecutor/sampler.py`:
- Around line 404-424: Update the inline attribute docstrings in the _Store
dataclass to use the required """<type>: Description""" format for each field
(e.g., change the current free-form string for slots_needing_recompute to
"""set: Slots where strategy needs (re)computation. Populated in
setup_sampler_step.""" and similarly update need_processed, need_raw,
strategies, uses_beam_search, non_greedy_slots, speculation_needs_probs,
needs_probs to include their types like list, set, etc., followed by the
existing descriptions); ensure every remaining attribute in class _Store follows
this exact "<type>: Description" pattern so they comply with the repo coding
guideline.

In `@tests/unittest/_torch/sampler/test_torch_sampler.py`:
- Around line 1206-1209: Rename the unused receiver parameter in the test helper
function to satisfy Ruff ARG001: update the local function _mock_filter used to
patch TorchSampler._filter_new_requests so its first parameter is renamed from
self to _self (or _) while keeping the rest of the signature (requests:
ScheduledRequests) -> list[LlmRequest] unchanged; leave the
patcher.setattr(TorchSampler, "_filter_new_requests", _mock_filter) call intact.

---

Outside diff comments:
In `@tensorrt_llm/_torch/pyexecutor/sampler.py`:
- Around line 1713-1727: Add Google-style docstrings to the two new helper
methods: for _is_new_request(request: LlmRequest) add a short one-line summary,
an Args section describing the request parameter and its type, and a Returns
section describing the boolean meaning (True when request is active, not draft,
and either an initial context last chunk or disaggregated generation
transmission is complete); for _filter_new_requests(cls, requests:
ScheduledRequests) add a one-line summary, an Args section describing the
requests parameter and its type, and a Returns section describing that it
returns a list[LlmRequest] filtered from requests.context_requests using
cls._is_new_request. Ensure the docstrings follow Google style and are placed
immediately above each method definition.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36146 [ run ] completed with state FAILURE. Commit: b535285
/LLM/main/L0_MergeRequest_PR pipeline #27934 completed with status: 'FAILURE'

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

@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 19, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36219 [ run ] triggered by Bot. Commit: b535285 Link to invocation

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36219 [ run ] completed with state SUCCESS. Commit: b535285
/LLM/main/L0_MergeRequest_PR pipeline #27999 completed with status: 'FAILURE'

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

@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 19, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36231 [ run ] triggered by Bot. Commit: b535285 Link to invocation

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36231 [ run ] completed with state SUCCESS. Commit: b535285
/LLM/main/L0_MergeRequest_PR pipeline #28010 completed with status: 'FAILURE'

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

@ixlmar ixlmar requested a review from stnie February 19, 2026 13:18
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 chore/fewer-optionals branch from 18d4e3c to e8c852b Compare February 19, 2026 13:20
@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 19, 2026

/bot run --disable-fail-fast

@ixlmar ixlmar requested review from mikeiovine and removed request for sunnyqgg February 19, 2026 13:23
@tensorrt-cicd
Copy link
Collaborator

PR_Github #36238 [ run ] triggered by Bot. Commit: e8c852b Link to invocation

Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 19, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36246 [ run ] triggered by Bot. Commit: 1f2c845 Link to invocation

@ixlmar ixlmar requested a review from Funatiq February 19, 2026 15:17
@tensorrt-cicd
Copy link
Collaborator

PR_Github #36246 [ run ] completed with state SUCCESS. Commit: 1f2c845
/LLM/main/L0_MergeRequest_PR pipeline #28023 completed with status: 'FAILURE'

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

@ixlmar
Copy link
Collaborator Author

ixlmar commented Feb 20, 2026

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36323 [ run ] triggered by Bot. Commit: 1f2c845 Link to invocation

@tensorrt-cicd
Copy link
Collaborator

PR_Github #36323 [ run ] completed with state SUCCESS. Commit: 1f2c845
/LLM/main/L0_MergeRequest_PR pipeline #28095 completed with status: 'SUCCESS'

Link to invocation

@ixlmar ixlmar merged commit 4759f74 into NVIDIA:main Feb 20, 2026
5 checks passed
@ixlmar ixlmar deleted the chore/fewer-optionals branch February 20, 2026 07:51
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.

5 participants