Skip to content

Conversation

netanel-haber
Copy link
Collaborator

@netanel-haber netanel-haber commented Jul 17, 2025

Buggy flow prior to fix, for given request X:
State:

  1. scheduler is MAX_UTILIZATION = pausing is enabled
  2. overlap scheduler is enabled = previous batch is processed after current batch is scheduled

Flow:

  1. self._pause_requests(scheduled_batch.paused_requests) is called for request X: seq_slot is deleted by cpp when pause is called.
  2. After Pausing X, self._update_requests(self.previous_batch.sample_state) is called, which also holds X in self.previous_batch.sample_state.scheduled_requests.all_requests().
  3. update_requests reads the seq_slot off of X, but it has been erased in 2.

cpp deletes the seq_slot for its uses, as an implementation detail within the scheduler. py_seq_slot is not deleted when the request is paused, so we opt to use it. For consistency, we also transition to use this across the whole codebase where seq_slot was used before.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the handling of sequence slot identifiers in request processing, ensuring consistent use of the appropriate attribute across model execution and sampling components. This improves reliability in request mapping and token assignment during inference.

Buggy flow prior to fix, for given request X:
0. state:
        * scheduler is MAX_UTILIZATION = pausing is enabled
        * overlap scheduler is enabled = previous batch is processed *after* current batch is scheduled
1. [`self._pause_requests(scheduled_batch.paused_requests)`](https://github.com/NVIDIA/TensorRT-LLM/blob/a7184869001d28ca70a738e9862ea91cb147da8c/tensorrt_llm/_torch/pyexecutor/py_executor.py#L1110) is called for request X: `seq_slot` is deleted [**by cpp**](https://github.com/NVIDIA/TensorRT-LLM/blob/d71c6fe5267f4b61c51cc39d4594cdcb417f0703/cpp/include/tensorrt_llm/batch_manager/llmRequest.h#L830) when pause is called.
2. **After Pausing X**, [`self._update_requests(self.previous_batch.sample_state)`](https://github.com/NVIDIA/TensorRT-LLM/blob/d71c6fe5267f4b61c51cc39d4594cdcb417f0703/tensorrt_llm/_torch/pyexecutor/py_executor.py#L1138) is called, which also holds X in `self.previous_batch.sample_state.scheduled_requests.all_requests()`.
3. `update_requests` reads the seq_slot off of X, but it has been erased in 1.

cpp deletes the seq_slot for its uses, [as an implementation detail within the scheduler](https://github.com/NVIDIA/TensorRT-LLM/blob/d71c6fe5267f4b61c51cc39d4594cdcb417f0703/cpp/tensorrt_llm/batch_manager/assignReqSeqSlots.cpp#L33)
`py_seq_slot` is not deleted when the request is paused, so we opt to use it. For consistency, we also transition to use this across the whole codebase where `seq_slot` was used before.

Signed-off-by: Netanel Haber <[email protected]>
@netanel-haber netanel-haber requested review from a team as code owners July 17, 2025 15:45
@netanel-haber netanel-haber changed the title Always use py_seq_slot. Always use py_seq_slot Jul 17, 2025
Copy link
Contributor

coderabbitai bot commented Jul 17, 2025

Walkthrough

The changes systematically update internal references from seq_slot to py_seq_slot for request objects across three modules: model engine, sampler, and speculative sampler. These updates ensure that all indexing, assignment, and tensor operations use the correct attribute for sequence slot identification. No logic, control flow, or public interfaces are otherwise modified.

Changes

File(s) Change Summary
tensorrt_llm/_torch/pyexecutor/model_engine.py Replaced all request.seq_slot references with request.py_seq_slot for batch index assignment and list appends in input preparation methods.
tensorrt_llm/_torch/pyexecutor/sampler.py Replaced all request.seq_slot references with request.py_seq_slot across multiple internal methods, affecting indexing and tensor operations.
tensorrt_llm/_torch/speculative/mtp.py Replaced all request.seq_slot references with request.py_seq_slot in three methods for token and slot handling.

Poem

A hop, a skip, a slot anew,
The rabbit finds the right value—
py_seq_slot now leads the way,
In samplers, engines, all in play.
No more confusion, just code delight,
The sequence slots are now just right!
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 23b90e8 and 090d8bf.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/pyexecutor/sampler.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/_torch/pyexecutor/sampler.py
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netanel-haber netanel-haber changed the title Always use py_seq_slot [nvbug/5393888][nvbug/5393042] Always use py_seq_slot Jul 17, 2025
@netanel-haber
Copy link
Collaborator Author

/bot run

@netanel-haber netanel-haber requested a review from Funatiq July 17, 2025 15:47
@tensorrt-cicd
Copy link
Collaborator

PR_Github #12215 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12215 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9070 completed with status: 'FAILURE'

Copy link
Collaborator

@QiJune QiJune left a comment

Choose a reason for hiding this comment

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

LGTM

@netanel-haber
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12277 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12277 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9116 completed with status: 'FAILURE'

Copy link
Collaborator

@Funatiq Funatiq left a comment

Choose a reason for hiding this comment

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

This fix seems good enough. At some point we should also refactor the seq_slot handling in C++ or do things differently once we move away from the C++ slot manager.

@netanel-haber
Copy link
Collaborator Author

This fix seems good enough. At some point we should also refactor the seq_slot handling in C++ or do things differently once we move away from the C++ slot manager.

Yeah, I agree it isn't ideal but I'm okay with this because, as mentioned in the description - the C++ code resetting the seq_slot is an implementation detail of inner scheduling details, not a fundamental property of the seq_slot mechanism.

@netanel-haber
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12319 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12319 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9153 completed with status: 'SUCCESS'

@netanel-haber netanel-haber merged commit d9a3530 into NVIDIA:main Jul 18, 2025
3 checks passed
reasonsolo pushed a commit to reasonsolo/TensorRT-LLM that referenced this pull request Jul 21, 2025
timlee0212 pushed a commit to timlee0212/TensorRT-LLM that referenced this pull request Jul 21, 2025
NVShreyas pushed a commit to NVShreyas/TensorRT-LLM that referenced this pull request Jul 28, 2025
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