Skip to content

Conversation

@Funatiq
Copy link
Collaborator

@Funatiq Funatiq commented Jul 31, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Removed the "finished_steps" property from the Python API, which is no longer available in the DecoderState class.
    • Improved internal handling of finished states, resulting in more efficient memory usage and simplified processing during decoding.
  • Refactor
    • Streamlined tensor management for finished states, reducing unnecessary intermediate variables and operations.

Description

  • Previously we stored multiple FinishReason per request for the different steps of draft-target speculative decoding.
  • This doesn't seem to be necessary as we can reuse the same tensor for all steps.

Test Coverage

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.

Funatiq added 3 commits July 31, 2025 14:42
… in gptDecoderBatched

- Updated input and output finish reasons to use same tensor slice instead of multiple slices for different steps.

Signed-off-by: Robin Kobus <[email protected]>
- Removed steps dimension from the shape of finished steps in DecoderState.
- Updated the reshape logic in DecoderState to streamline buffer management and removed redundant reshaping of finished steps.
- Updated gptDecoderBatched to use the new shape of finished steps.

Signed-off-by: Robin Kobus <[email protected]>
- Removed the finished steps tensor from DecoderState and its associated methods.
- Updated references in createNewDecoderRequests and gptDecoderBatched to use finish reasons instead of finished steps.
- Adjusted bindings in both nanobind and pybind to reflect the removal of finished steps.

Signed-off-by: Robin Kobus <[email protected]>
@Funatiq
Copy link
Collaborator Author

Funatiq commented Jul 31, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13704 [ run ] triggered by Bot

@Funatiq Funatiq changed the title Dev/refactor ext draft refactor: Simplify finish reasons handling in DecoderState Jul 31, 2025
@Funatiq
Copy link
Collaborator Author

Funatiq commented Jul 31, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 31, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 31, 2025

📝 Walkthrough

Walkthrough

The changes remove the finished_steps tensor and its related logic from the DecoderState class and its usage throughout the codebase. This includes eliminating the tensor's allocation, initialization, reshaping, getter methods, and Python bindings. Associated tensor manipulation logic is also simplified or removed in decoding and batch management components.

Changes

Cohort / File(s) Change Summary
DecoderState Class Interface & Documentation
cpp/include/tensorrt_llm/runtime/decoderState.h
Removed mFinishedSteps member, getFinishedSteps() method, and related comments/documentation. Updated comment for getFinishReasons().
DecoderState Implementation
cpp/tensorrt_llm/runtime/decoderState.cpp
Removed all allocation, initialization, reshaping, and getter logic for mFinishedSteps. Updated buffer setup to share finishReasons tensor between input and output.
Python Bindings (nanobind)
cpp/tensorrt_llm/nanobind/runtime/bindings.cpp
Removed property binding exposing finished_steps in Python via nanobind.
Python Bindings (pybind11)
cpp/tensorrt_llm/pybind/runtime/bindings.cpp
Removed property binding exposing finished_steps in Python via pybind11.
Batch Manager Logic
cpp/tensorrt_llm/batch_manager/createNewDecoderRequests.cpp
Simplified logic for zeroing finished steps tensor by removing per-token iteration and conditional logic.
Decoder Forward Pass
cpp/tensorrt_llm/runtime/gptDecoderBatched.cpp
Removed manipulation of finished steps and related intermediate tensors. Simplified tensor assignments and removed unnecessary slicing.

Sequence Diagram(s)

sequenceDiagram
    participant Python API
    participant DecoderState
    participant Decoder Engine

    Python API->>DecoderState: Create/Access DecoderState
    Note right of DecoderState: (No longer exposes finished_steps)
    Python API->>DecoderState: Access finishReasons
    DecoderState->>Decoder Engine: Provide finishReasons tensor
    Decoder Engine->>DecoderState: Update finishReasons as needed
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 baece56 and 396c944.

📒 Files selected for processing (6)
  • cpp/include/tensorrt_llm/runtime/decoderState.h (1 hunks)
  • cpp/tensorrt_llm/batch_manager/createNewDecoderRequests.cpp (1 hunks)
  • cpp/tensorrt_llm/nanobind/runtime/bindings.cpp (0 hunks)
  • cpp/tensorrt_llm/pybind/runtime/bindings.cpp (0 hunks)
  • cpp/tensorrt_llm/runtime/decoderState.cpp (2 hunks)
  • cpp/tensorrt_llm/runtime/gptDecoderBatched.cpp (1 hunks)
💤 Files with no reviewable changes (2)
  • cpp/tensorrt_llm/nanobind/runtime/bindings.cpp
  • cpp/tensorrt_llm/pybind/runtime/bindings.cpp
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: yechank-nvidia
PR: NVIDIA/TensorRT-LLM#6254
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:1201-1204
Timestamp: 2025-07-22T09:22:14.726Z
Learning: In TensorRT-LLM's multimodal processing pipeline, shared tensor recovery using `from_shared_tensor()` is only needed during the context phase. Generation requests reuse the already-recovered tensor data and only need to call `strip_for_generation()` to remove unnecessary multimodal data while preserving the recovered tensors. This avoids redundant tensor recovery operations during generation.
📚 Learning: in tensorrt-llm's multimodal processing pipeline, shared tensor recovery using `from_shared_tensor()...
Learnt from: yechank-nvidia
PR: NVIDIA/TensorRT-LLM#6254
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:1201-1204
Timestamp: 2025-07-22T09:22:14.726Z
Learning: In TensorRT-LLM's multimodal processing pipeline, shared tensor recovery using `from_shared_tensor()` is only needed during the context phase. Generation requests reuse the already-recovered tensor data and only need to call `strip_for_generation()` to remove unnecessary multimodal data while preserving the recovered tensors. This avoids redundant tensor recovery operations during generation.

Applied to files:

  • cpp/tensorrt_llm/batch_manager/createNewDecoderRequests.cpp
  • cpp/tensorrt_llm/runtime/decoderState.cpp
  • cpp/tensorrt_llm/runtime/gptDecoderBatched.cpp
  • cpp/include/tensorrt_llm/runtime/decoderState.h
🔇 Additional comments (6)
cpp/tensorrt_llm/batch_manager/createNewDecoderRequests.cpp (1)

275-276: LGTM! Simplification improves efficiency.

The refactoring replaces the previous per-token iteration approach with a direct slice operation on decoderState.getFinishReasons(). This is more efficient and aligns well with the removal of the mFinishedSteps tensor.

cpp/tensorrt_llm/runtime/decoderState.cpp (2)

97-100: LGTM! Shared tensor approach simplifies architecture.

The refactoring removes the separate mFinishedSteps tensor and establishes a shared finishReasons tensor between input and output structures. This eliminates redundant tensor allocations and simplifies the state management by having a single source of truth for finish reasons.


258-258: LGTM! Tensor reshaping is consistent.

The newTokensSteps tensor reshaping using mMaxDecodingEngineTokens maintains proper tensor dimensions and is consistent with the overall refactoring approach.

cpp/include/tensorrt_llm/runtime/decoderState.h (1)

74-75: LGTM! Documentation improvement enhances clarity.

The updated comment clarifies that getFinishReasons() returns "finished states of type FinishedState", providing more specific and helpful documentation for API users.

cpp/tensorrt_llm/runtime/gptDecoderBatched.cpp (2)

129-130: LGTM! Direct tensor access improves code clarity.

The change removes intermediate tensor variables and directly accesses decoderState.getFinishReasons(), making the code more straightforward and consistent with the overall refactoring approach.


135-135: LGTM! Simplified tensor assignment reduces complexity.

The direct slicing assignment for dOutput.newTokens eliminates intermediate variables and makes the code more concise while maintaining the same functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 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 generate unit tests to generate unit tests for 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 or @coderabbitai title 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.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13704 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #10294 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@Funatiq
Copy link
Collaborator Author

Funatiq commented Aug 1, 2025

/bot run --extra-stage "A30-TensorRT-Post-Merge-2, A30-TensorRT-Post-Merge-4, A30-TensorRT-Post-Merge-5, A30-TensorRT-Post-Merge-6"

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13803 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

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

@Funatiq Funatiq requested review from DomBrown and dcampora August 1, 2025 13:30
@Funatiq Funatiq marked this pull request as ready for review August 1, 2025 13:30
@Funatiq Funatiq changed the title refactor: Simplify finish reasons handling in DecoderState [None][refactor] Simplify finish reasons handling in DecoderState Aug 1, 2025
Copy link
Collaborator

@DomBrown DomBrown left a comment

Choose a reason for hiding this comment

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

LGTM

@Funatiq Funatiq merged commit 918fedf into NVIDIA:main Aug 2, 2025
4 of 5 checks passed
@Funatiq Funatiq deleted the dev/refactor_ext_draft branch August 2, 2025 05:17
lancelly pushed a commit to lancelly/TensorRT-LLM that referenced this pull request Aug 6, 2025
jain-ria pushed a commit to jain-ria/TensorRT-LLM that referenced this pull request Aug 7, 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.

3 participants