-
Notifications
You must be signed in to change notification settings - Fork 2k
[TRTLLM-10197][chore] Refactor to setup for RNN cache transceiver #10957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[TRTLLM-10197][chore] Refactor to setup for RNN cache transceiver #10957
Conversation
📝 WalkthroughWalkthroughThis PR introduces a new abstract base class Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Sender as BaseCacheSenderImpl
participant Mgr as ConnectionManager
participant Fmt as BaseCacheFormatter
participant Queue as AsyncSendResource
App->>Sender: sendAsync(llmRequest)
activate Sender
Sender->>Queue: enqueue(request, promise)
activate Queue
Sender-->>App: return future
deactivate Sender
Queue->>Fmt: format(request)
activate Fmt
Fmt-->>Queue: formatted data
deactivate Fmt
Queue->>Mgr: send(formatted data)
activate Mgr
Mgr-->>Queue: success/error
deactivate Mgr
Queue->>Queue: signal promise
deactivate Queue
App->>App: await future
sequenceDiagram
participant App as Application
participant Receiver as BaseCacheReceiverImpl
participant Mgr as ConnectionManager
participant Fmt as BaseCacheFormatter
participant BufMgr as BufferManager
App->>Receiver: receiveAsync(llmRequest)
activate Receiver
Receiver->>Mgr: recv(request info)
activate Mgr
Mgr-->>Receiver: received data
deactivate Mgr
Receiver->>BufMgr: allocate buffer
activate BufMgr
BufMgr-->>Receiver: buffer
deactivate BufMgr
Receiver->>Fmt: deserialize(data, buffer)
activate Fmt
Fmt-->>Receiver: deserialized request
deactivate Fmt
Receiver-->>App: return future
deactivate Receiver
App->>App: await future
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
cpp/tensorrt_llm/batch_manager/cacheTransBuffer.h (1)
60-82: Use//!-style Doxygen comments in headers.Lines 60–82 use
///for documentation comments; headers must use//!and//!<per the project guidelines. Update all doc comments to the correct style.cpp/tensorrt_llm/batch_manager/cacheTransBuffer.cpp (2)
131-187: Replace#ifdefwith#if defined(...)for non-include-guard preprocessor conditionals.Line 133 uses
#ifdef __aarch64__; per coding guidelines, use#if defined(__aarch64__)instead. The#ifdefdirective should only be used for header include guards.
194-255: GuardcacheManagerbefore dereference incomputeTransferBufferSize.
computeTransferBufferSizedereferencescacheManagerat lines 199, 203, and 206 without any null check. Since the constructor calls this function in the initializer list before the body executes the check at line 260, a null pointer will cause undefined behavior. AddTLLM_CHECK(cacheManager);at the start ofcomputeTransferBufferSize.Suggested fix
size_t CacheTransBufferManager::computeTransferBufferSize( KVCacheManager::BaseKVCacheManager* cacheManager, std::optional<size_t> maxNumTokens, bool transferIndexerKCache) { + TLLM_CHECK(cacheManager); nvinfer1::DataType dataType; if (transferIndexerKCache) { dataType = cacheManager->getIndexerKCachePool()->getDataType();cpp/tensorrt_llm/batch_manager/dataTransceiver.h (2)
52-62: Duplicate type alias forBlockKey.
BlockKeyis defined twice: on line 53 and again on line 60. Both refer to the same type (kv_cache_manager::BlockKey). Remove one of these duplicate aliases.🔧 Proposed fix
using BaseCacheFormatter = kv_cache_manager::BaseCacheFormatter; using BlockKey = kv_cache_manager::BlockKey; // TODO: unify the following class into a namespace like tensorrt_llm::transmission using DataContext = tensorrt_llm::executor::kv_cache::DataContext; using Connection = tensorrt_llm::executor::kv_cache::Connection; using ConnectionManager = tensorrt_llm::executor::kv_cache::ConnectionManager; using SizeType32 = tensorrt_llm::runtime::SizeType32; -using BlockKey = tensorrt_llm::batch_manager::kv_cache_manager::BlockKey; using UniqueToken = tensorrt_llm::runtime::UniqueToken;
161-162: Remove redundant duplicate type aliases.Both
UniqueToken(line 61) andBlockKey(lines 53, 60) are already defined earlier in this file within the same namespace. These duplicate declarations are unnecessary and should be removed.🔧 Proposed fix
BlockKey mLastBlockKey{}; }; -using UniqueToken = tensorrt_llm::runtime::UniqueToken; -using BlockKey = tensorrt_llm::batch_manager::kv_cache_manager::BlockKey; - struct TransceiverTag
🤖 Fix all issues with AI agents
In `@cpp/tensorrt_llm/batch_manager/baseTransBuffer.cpp`:
- Around line 1-16: Update the SPDX header in baseTransBuffer.cpp to reflect the
2026 modification by changing the copyright year from "2025" to either "2026" or
the range "2025–2026" in the top comment block (the SPDX-FileCopyrightText line
and any other matching year occurrences in the same header).
In `@cpp/tensorrt_llm/batch_manager/baseTransBuffer.h`:
- Around line 1-16: Update the header copyright year in the top-of-file license
block in baseTransBuffer.h from "2025" to reflect the latest change (use either
"2025–2026" or "2026"); modify both the SPDX-FileCopyrightText line and any
other occurrences of the year in the same comment block so the SPDX header and
license text consistently show the updated year.
- Around line 41-102: Replace the triple-slash Doxygen comments in this header
with the project-preferred single-line `//!` style: update the class-level and
method comments for BaseTransBufferManager and each member
(assignBufferIndexForSend, freeBufferIndexForSend, assignBufferIndexForRecv,
freeBufferIndexForRecv, getOrAllocateSendBuffers, getOrAllocateRecvBuffers,
getSendBuffer, getRecvBuffer, getRecvBufferCount, getSendBufferCount,
getMaxNumTokens and the mMaxNumTokens member) so that `///` becomes `//!` and
any trailing member descriptions use `//!<` where appropriate to document class
members.
In `@cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp`:
- Around line 458-584: The code has multiple race conditions accessing
mReadyResponses and mAnyReady from response() and sendResponse(); fix by
consistently taking mSenderMutex for any lookup/iteration/empty check on
mReadyResponses (e.g., wrap the find at sendResponse, the empty checks at lines
like the if (!mReadyResponses.empty()) and the getCurrentResponse()/iteration
loops inside scoped_lock(mSenderMutex)), and ensure mAnyReady is either made
atomic or always read/updated under the same mutex used to set it (prefer
reading/updating mAnyReady under mCondMutex or under mSenderMutex consistently).
Change response() to acquire mSenderMutex to extract or move the current
response entry into a local variable before releasing the lock and calling
sendAndRemoveResponse/asyncSendAndRemoveResponse/removeResponse so iterators
won't be invalidated by concurrent sendAsync/cancelRequest; similarly protect
accesses to mCancelledRequests. For the TODO about cancelled requests
persisting, add cleanup logic (e.g., when isReady==false remove the request from
mCancelledRequests and mRemainSendCount under mSenderMutex or schedule a
timeout-based cleanup) so cancelled entries cannot remain indefinitely.
- Around line 1020-1107: Guard the empty block-range before dereferencing within
sendRequestInfo: check requestedBlockRange.getBlockIdsPerWindow().empty() (from
getBlockRangeForReceiving / requestedBlockRange) and TLLM_CHECK_WITH_INFO or
early-return/skip the block-specific logic if empty before calling
begin()->second.size() and computing indexFromEnd; ensure requestedBlockSize is
validated. Fix the TODO mapping for validConnectionIdx in the loop over
counterPartConnections: use auto it = std::find(pickUpIdx.begin(),
pickUpIdx.end(), i); if it == pickUpIdx.end() skip/continue that connection (or
handle as an error), otherwise compute size_t validConnectionIdx =
std::distance(pickUpIdx.begin(), it) before calling sendRequestAndBufferInfo on
the AgentConnection to avoid out-of-bounds indices.
In `@cpp/tensorrt_llm/batch_manager/dataTransceiver.h`:
- Around line 449-451: Typo: the mutex member is declared as
mProcessIoResouceMutex (missing 'r'); rename it to mProcessIoResourceMutex
everywhere to fix the spelling. Update the declaration in dataTransceiver.h and
all uses/references (e.g., lock_guard, std::unique_lock, or any member access)
to the corrected symbol so the class (and any other files) compile and
consistently refer to mProcessIoResourceMutex.
🧹 Nitpick comments (1)
cpp/tensorrt_llm/batch_manager/baseTransBuffer.h (1)
129-141: Prefer private data members with protected accessors.This class is non-POD; guidelines require private members. Consider making these private and exposing protected getters/setters for derived classes. As per coding guidelines, please adjust the member visibility.
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update copyright year to 2026.
This new header still lists 2025; please update to 2025–2026 or 2026. As per coding guidelines, the year should reflect the latest meaningful modification.
🤖 Prompt for AI Agents
In `@cpp/tensorrt_llm/batch_manager/baseTransBuffer.h` around lines 1 - 16, Update
the header copyright year in the top-of-file license block in baseTransBuffer.h
from "2025" to reflect the latest change (use either "2025–2026" or "2026");
modify both the SPDX-FileCopyrightText line and any other occurrences of the
year in the same comment block so the SPDX header and license text consistently
show the updated year.
Signed-off-by: Shreyas Misra <shreyasm@nvidia.com>
Signed-off-by: Shreyas Misra <shreyasm@nvidia.com>
Signed-off-by: Shreyas Misra <shreyasm@nvidia.com>
da98411 to
67c68c8
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #33395 [ run ] triggered by Bot. Commit: |
|
PR_Github #33395 [ run ] completed with state
|
Signed-off-by: Shreyas Misra <shreyasm@nvidia.com>
|
/bot run --disable-fail-fast |
|
PR_Github #33398 [ run ] triggered by Bot. Commit: |
|
PR_Github #33398 [ run ] completed with state
|
|
/bot run --disable-fail-fast --reuse-test |
|
PR_Github #33417 [ run ] triggered by Bot. Commit: |
|
PR_Github #33417 [ run ] completed with state
|
Summary by CodeRabbit
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.
Description
Test Coverage
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 thestage-listparameter 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.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip 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-pipelineReuse 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.