Skip to content

Conversation

@milesial
Copy link
Collaborator

@milesial milesial commented Aug 21, 2025

Avoids a GIL grab from the scheduling C++ thread when unnecessary (blocking kernel scheduling of the sampler). Up to 20% throughput increase at high concurrencies when a batched processor is registered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 21, 2025

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

193 files out of 300 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Updated LogitsPostProcessor::operator() to accept the optional LogitsPostProcessorBatched parameter by const reference instead of by value in both declaration and definition. No logic or control flow changes.

Changes

Cohort / File(s) Summary of Changes
LogitsPostProcessor signature update
cpp/include/tensorrt_llm/batch_manager/logitsPostProcessor.h, cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp
Changed operator() parameter from std::optional<LogitsPostProcessorBatched> to std::optional<LogitsPostProcessorBatched> const&, retaining default std::nullopt; no internal logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

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

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@IzzyPutterman
Copy link
Collaborator

/bot run

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: 0

Caution

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

⚠️ Outside diff range comments (1)
cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp (1)

73-81: Guard against nullopt before dereferencing logitsPostProcessorBatched

If any request sets mApplyLogitsPostProcessorBatched but the caller provides no batched functor (defaulted/nullopt), this will dereference an empty optional. Add a guard.

Minimal fix:

if (!reqIdsVec.empty())
{
    logitsPostProcessorIsApplied = true;
    if (replicateLogitsPostProcessor || worldConfig.isFirstTensorParallelRank())
    {
        if (!logitsPostProcessorBatched)
        {
            // Choose one: log-and-return, assert, or throw (consistent with project policy).
            TLLM_LOG_ERROR("Batched logits post processor is required but not provided.");
            return false;
        }
        (*logitsPostProcessorBatched)(reqIdsVec, logitsVec, beamTokensVec, stream, clientIdsVec);
    }
}
🧹 Nitpick comments (4)
cpp/include/tensorrt_llm/batch_manager/logitsPostProcessor.h (3)

48-51: ABI heads-up: signature change alters the mangled symbol

Changing from by-value to by-const-ref is an ABI-breaking change for external consumers compiled against older headers. Please confirm this is internal-only or plan a coordinated rebuild/release note.


18-18: Add include guard per project guidelines

Guidelines require TRTLLM__H include guards. Replace or complement #pragma once with a guard.

Example:

// At top (replace #pragma once)
#ifndef TRTLLM_LOGITSPOSTPROCESSOR_H
#define TRTLLM_LOGITSPOSTPROCESSOR_H

// ... file contents ...

#endif // TRTLLM_LOGITSPOSTPROCESSOR_H

2-2: Update copyright year to include 2025

The .cpp already uses 2025. Please align the header.

- * SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp (1)

42-47: Micro-opt: pre-reserve vectors when collecting batched arguments

To avoid repeated reallocations when decoderRequests.size() is known, reserve capacity before the loop.

reqIdsVec.reserve(inputBuffers.decoderRequests.size());
logitsVec.reserve(inputBuffers.decoderRequests.size());
beamTokensVec.reserve(inputBuffers.decoderRequests.size());
clientIdsVec.reserve(inputBuffers.decoderRequests.size());
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ba0a86e and 827213e.

📒 Files selected for processing (2)
  • cpp/include/tensorrt_llm/batch_manager/logitsPostProcessor.h (1 hunks)
  • cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh}: In C++, close namespaces with a comment naming the namespace (e.g., } // namespace foo)
Prefer const/constexpr variables over #define for constants
Declare variables const if not modified after initialization
Use Allman brace style in C++
C++ filenames use lowerCamelCase and must be case-insensitively unique within a build target
C++ type names use UpperCamelCase
Local variables, methods, and namespaces use lowerCamelCase
Global non-static variables not in anonymous namespace use gPrefix lowerCamelCase (e.g., gExample)
Static globals or globals in anonymous namespaces use sPrefix lowerCamelCase
Locally visible static variables start with 's' (e.g., static std::once_flag sFlag;)
Member variables use mPrefix lowerCamelCase; public members may omit but are encouraged to use 'm'
Constants (enums, global/static/function-scope magic numbers) use kPREFIXED_UPPER_SNAKE (e.g., kDIGIT_NUM)
If macros are unavoidable, use UPPER_SNAKE_CASE (prefer constants over #define)
Constructor parameter that conflicts with a public member name gets trailing underscore (foo_)
Literal suffixes should be uppercase (e.g., 1234L not 1234l)
C++: use spaces only; indent 4 spaces
Run clang-format (LLVM style) before submitting; wrap lines at 120 characters
If formatting must be bypassed, use // clang-format off/on around the section
Prefer smart pointers; use unique_ptr for sole ownership, shared_ptr for shared; weak_ptr only in exceptional cases
Do not use deprecated pre-C++11 smart pointers
Use C++ style comments; avoid C comments except special inline cases; prefer // single-line
Capitalize and punctuate full-sentence comments
Follow Doxygen rules: use //! for comments and //!< for members in C++
Disable code with #if/#endif and mnemonic conditions; avoid commented-out code; avoid dead code
Do not throw exceptions across library boundaries
Use least-forceful casts; avoid removing const/volatile; avoid C-style and functional casts (except constructors); p...

Files:

  • cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp
  • cpp/include/tensorrt_llm/batch_manager/logitsPostProcessor.h
**/*.{cpp,cxx,cc,cu}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.{cpp,cxx,cc,cu}: Avoid literal values except for 0, nullptr, true, false; use named constexpr for other literals
Place semicolon of empty for/while loop on a new line
Always use brace-delimited bodies for switch/while/do-for/if/else
Use inline C comments in argument lists when parameter meaning is unclear (e.g., /* checkForErrors = */ false)
Do not use assignment in subexpressions (e.g., if (x = y) ... is forbidden)
Switch on enums should enumerate all values and omit default to catch new values at compile time
Structure switch statements; prohibit fallthrough except between empty cases; each case ends with break or throw; return at end of case not allowed; put break inside braces for compound case
Prefer anonymous namespaces over static for internal linkage of functions
Every defined function must be called at least once (no unused methods)

Files:

  • cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp
**/*.{h,hpp,hxx,hh,cuh,cpp,cxx,cc,cu}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Parameter names must be consistent between declarations and definitions

Files:

  • cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp
  • cpp/include/tensorrt_llm/batch_manager/logitsPostProcessor.h
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend NVIDIA copyright header (current year) to all source files

Files:

  • cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp
  • cpp/include/tensorrt_llm/batch_manager/logitsPostProcessor.h
**/*.{h,hpp,hxx,hh,cuh}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Header files must use include guards named TRTLLM__H without underscores prefix/suffix (e.g., TRTLLM_FOO_BAR_HELLO_H)

Files:

  • cpp/include/tensorrt_llm/batch_manager/logitsPostProcessor.h
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (2)
cpp/include/tensorrt_llm/batch_manager/logitsPostProcessor.h (1)

48-51: Good change: avoid copying std::function by passing std::optional<...> as const&

This eliminates potentially expensive copies of std::function without changing semantics. Declaration matches the definition.

cpp/tensorrt_llm/batch_manager/logitsPostProcessor.cpp (1)

35-38: Definition updated to take std::optional<...> by const& — consistent with header

No logic change; eliminates unnecessary copies of the callable.

@milesial milesial changed the base branch from main to release/1.0 August 21, 2025 06:23
@milesial milesial requested a review from a team as a code owner August 21, 2025 06:23
@tensorrt-cicd
Copy link
Collaborator

PR_Github #16010 [ ] completed with state FAILURE

@milesial milesial changed the base branch from release/1.0 to main August 21, 2025 06:23
To avoid triggering the GIL on pass-by-value copy (?)

Signed-off-by: Alexandre Milesi <[email protected]>
@milesial milesial force-pushed the logits-processor-fix branch from 827213e to d422b58 Compare August 21, 2025 06:30
@milesial milesial requested review from a team as code owners August 21, 2025 06:30
@milesial
Copy link
Collaborator Author

Need to test if the case where logitsPostProcessorBatched is null still works. EDIT: tested, works well

Can this null test be added to the CI?

Actually this would already be covered by the existing C++ executor tests, since the default is not having any processor registered / null.

Copy link
Collaborator

@brb-nv brb-nv left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Collaborator

@Superjomn Superjomn left a comment

Choose a reason for hiding this comment

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

LGTM

@brb-nv
Copy link
Collaborator

brb-nv commented Aug 22, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16128 [ run ] triggered by Bot

@juney-nvidia juney-nvidia enabled auto-merge (squash) August 22, 2025 07:45
@tensorrt-cicd
Copy link
Collaborator

PR_Github #16128 [ run ] completed with state SUCCESS
/LLM/release-1.0/L0_MergeRequest_PR pipeline #257 completed with status: 'SUCCESS'

@juney-nvidia juney-nvidia merged commit c1eefa8 into NVIDIA:release/1.0 Aug 22, 2025
4 checks passed
yuanjingx87 pushed a commit that referenced this pull request Aug 28, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 5, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 5, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 6, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 6, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 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.

9 participants