-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[TRTLLM-8044][refactor] Rename data -> cache for cacheTransceiver #7659
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
Conversation
|
/bot run --disable-fail-fast |
|
PR_Github #18260 [ run ] triggered by Bot |
📝 WalkthroughWalkthroughRefactors batch-manager data transfer from DataResponder/DataRequester to CacheSender/CacheReceiver, removes DataTransceiverImpl, updates headers and includes, adds TransferSession and measurement utilities in cacheFormatter, adjusts AgentConnection buffer naming, switches UCX include to new transceiver header, and updates unit tests accordingly. CMake no longer builds dataTransceiverImpl.cpp. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant R as Receiver (CacheReceiver)
participant S as Sender (CacheSender)
participant M as ConnectionManager
participant F as Formatter
participant TS as TransferSession
rect rgba(230,240,255,0.6)
note over R,S: Request-info exchange (new)
R->>M: sendRequestInfo(llmRequest)
activate M
M-->>S: deliver RequestInfo
deactivate M
S->>S: recvRequestInfo()
S->>TS: create TransferSession(connections, DataContext,...)
end
rect rgba(235,255,235,0.6)
note over S,R: Data transfer phase
par Async send
S->>R: data chunks via connections
and Receive orchestration
R->>TS: receiveSync(TS)
S->>TS: sendSync(llmRequest)
end
end
rect rgba(255,245,230,0.6)
note over S: Completion/cleanup
S->>S: update CommState / release session
R->>R: finalize buffers/events
end
sequenceDiagram
autonumber
participant BM as CacheTransceiver
participant CS as CacheSender
participant CR as CacheReceiver
participant FQ as mSenderFutures
BM->>CS: sendAsync(req)
activate CS
CS-->>BM: std::future<void>
deactivate CS
BM->>FQ: store future (mSenderFutures)
BM->>CR: receiveAsync(req)
activate CR
CR-->>BM: std::future<void>
deactivate CR
loop poll
BM->>FQ: checkContextTransferStatus()
FQ-->>BM: completed/errored futures
BM->>FQ: erase completed
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Pre-merge checks (3 warnings)❌ Failed checks (3 warnings)
✨ Finishing Touches
🧪 Generate unit tests
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: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h (1)
187-193: Initialize mOffsetRatio to a safe default to avoid div-by-zero in send()send() divides by mOffsetRatio.second; a default-initialized pair risks 0. Initialize to {0, 1}.
struct SenderState { - MemoryDesc mCacheReceiverBufferDesc{nullptr, 0, 0}; - int validSegmentIdx{0}; - std::pair<size_t, size_t> mOffsetRatio; + MemoryDesc mCacheReceiverBufferDesc{nullptr, 0, 0}; + int validSegmentIdx{0}; + std::pair<size_t, size_t> mOffsetRatio{0, 1}; SenderState() = default; };cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (1)
107-113: Precondition checks before offset computation (avoid UB and OOB writes)Guard against zero denominator and ensure the computed region fits in dst buffer.
- auto dstBaseDesc = mSenderState.mCacheReceiverBufferDesc; - auto offset = size / mSenderState.mOffsetRatio.second * mSenderState.mOffsetRatio.first; + auto dstBaseDesc = mSenderState.mCacheReceiverBufferDesc; + TLLM_CHECK_WITH_INFO(mSenderState.mOffsetRatio.second != 0, "Invalid offset ratio: denominator is 0. Call setSenderState() first."); + auto offset = size / mSenderState.mOffsetRatio.second * mSenderState.mOffsetRatio.first; + TLLM_CHECK_WITH_INFO(offset <= dstBaseDesc.getLen(), "Computed offset exceeds destination buffer length."); + TLLM_CHECK_WITH_INFO(size <= (dstBaseDesc.getLen() - offset), "Transfer size overflows destination buffer.");cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (1)
170-176: Windows build break: dlerror() is POSIX-onlyThis TLLM_CHECK_WITH_INFO uses dlerror() even on _WIN32 path. Use GetLastError() on Windows, dlerror() elsewhere.
- TLLM_CHECK_WITH_INFO( - mWrapperLibHandle != nullptr, "UCX wrapper library is not open correctly. error : %s", dlerror()); + #if defined(_WIN32) + TLLM_CHECK_WITH_INFO( + mWrapperLibHandle != nullptr, "UCX wrapper library failed to open. error: %lu", GetLastError()); + #else + TLLM_CHECK_WITH_INFO( + mWrapperLibHandle != nullptr, "UCX wrapper library failed to open. error: %s", dlerror()); + #endif
🧹 Nitpick comments (13)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (1)
165-170: Parameter naming nit: avoid member-style prefix on parametersThe parameter mCacheReceiverBufferDesc uses the member-style 'm' prefix; prefer cacheReceiverBufferDesc for parameters. Consider also passing by const&.
cpp/tensorrt_llm/executor/cache_transmission/ucx_utils/connection.cpp (3)
117-121: Avoid magic 0xFFFFFFFF tag mask; introduce a named constantReplace repeated 0xFFFFFFFF with a file-scope constexpr per guidelines.
@@ -#include "tensorrt_llm/executor/cache_transmission/ucx_utils/connection.h" +#include "tensorrt_llm/executor/cache_transmission/ucx_utils/connection.h" + +namespace { +constexpr uint64_t kTAG_MASK = 0xFFFFFFFFull; +} // namespace @@ - uint64_t tag - = ((mSendTagPrefix & 0xFFFFFFFF) << 32) | static_cast<uint64_t>(batch_manager::TransceiverTag::kID_TAG); + uint64_t tag = ((mSendTagPrefix & kTAG_MASK) << 32) + | (static_cast<uint64_t>(batch_manager::TransceiverTag::kID_TAG) & kTAG_MASK); @@ - uint64_t sendTag = ((mSendTagPrefix & 0xFFFFFFFF) << 32) | (static_cast<uint64_t>(ctx.getTag()) & (0xFFFFFFFF)); + uint64_t sendTag = ((mSendTagPrefix & kTAG_MASK) << 32) | (static_cast<uint64_t>(ctx.getTag()) & kTAG_MASK); @@ - uint64_t recvTag = ((mRecvTagPrefix & 0xFFFFFFFF) << 32) | (static_cast<uint64_t}(ctx.getTag()) & (0xFFFFFFFF)); + uint64_t recvTag = ((mRecvTagPrefix & kTAG_MASK) << 32) | (static_cast<uint64_t>(ctx.getTag()) & kTAG_MASK);Also applies to: 149-151, 174-176
49-61: Avoid tight busy-wait loops on UCX requestsThe while (!req->isCompleted()) spin-loops can burn CPU. Add a small backoff or yield.
- while (!recvRequest->isCompleted()) - ; + while (!recvRequest->isCompleted()) + { + std::this_thread::yield(); + } @@ - while (!sendRequest->isCompleted()) - ; + while (!sendRequest->isCompleted()) + { + std::this_thread::yield(); + } @@ - while (!sendRequest->isCompleted()) - ; + while (!sendRequest->isCompleted()) + { + std::this_thread::yield(); + } @@ - while (!recvRequest->isCompleted()) - ; + while (!recvRequest->isCompleted()) + { + std::this_thread::yield(); + }Also applies to: 69-79
92-95: Portable logging format for 64-bit IDsIf mConnectionId types are 64-bit, %lu is non-portable (Windows long is 32-bit). Prefer PRIu64 or cast to unsigned long long and use %llu.
- "..., mConnectionId: %lu, mConnectionIdInPeer: %lu,fromRequester: %d", mConnectionId, mConnectionIdInPeer, mFromRequester); + "..., mConnectionId: %llu, mConnectionIdInPeer: %llu,fromRequester: %d", + static_cast<unsigned long long>(mConnectionId), + static_cast<unsigned long long>(mConnectionIdInPeer), + mFromRequester);Apply similarly to the other TLLM_LOG_DEBUG lines in this file.
Also applies to: 100-104, 109-113, 129-132, 142-144, 159-162, 168-171, 183-186
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h (1)
1-18: Header hygiene: use include guards per guidelines and update yearReplace #pragma once with a TRTLLM_CACHETRANSCEIVER_H guard and update the header year to 2025.
-#pragma once +#ifndef TRTLLM_CACHETRANSCEIVER_H +#define TRTLLM_CACHETRANSCEIVER_H @@ - * Copyright (c) 2023-2024, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2023-2025, NVIDIA CORPORATION. All rights reserved. @@ -#include <memory> +#include <memory> + +#endif // TRTLLM_CACHETRANSCEIVER_HNote: place the #endif at the end of the file.
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (1)
23-35: Prefer constexpr over macro for library nameReplace UCX_WRAPPER_LIB_NAME macro with a constexpr per guidelines.
-#define UCX_WRAPPER_LIB_NAME "tensorrt_llm_ucx_wrapper" +namespace { +constexpr char kUCX_WRAPPER_LIB_NAME[] = "tensorrt_llm_ucx_wrapper"; +} // namespace @@ - mWrapperLibHandle = dllOpen(UCX_WRAPPER_LIB_NAME); + mWrapperLibHandle = dllOpen(kUCX_WRAPPER_LIB_NAME);cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp (1)
160-160: Naming inconsistency: Prefer camel case for class names.The class name should follow the CamelCase convention as specified in the coding guidelines. Consider renaming to
MockCacheSender.-class MockCacheSender : public CacheSender +class MockCacheSender : public CacheSendercpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (1)
705-705: Minor: Inconsistent format specifier in log message.The log message uses
%ldfor request IDs which should be the appropriate format for the actual type.-TLLM_LOG_ERROR("Exception in CacheReceiver request(): request id:%ld , request context id:%ld : %s", +TLLM_LOG_ERROR("Exception in CacheReceiver request(): request id:%zu , request context id:%zu : %s",cpp/tensorrt_llm/batch_manager/cacheFormatter.h (1)
235-235: Consider adding error handling for rank retrieval.The MPI rank retrieval could potentially fail in non-MPI environments.
-auto rank = mpi::MpiComm::world().getRank(); +auto rank = 0; +if (mpi::MpiComm::world().isInitialized()) +{ + rank = mpi::MpiComm::world().getRank(); +}cpp/tensorrt_llm/batch_manager/dataTransceiver.h (4)
18-34: Replace #pragma once with required include guard and trim unused/heavy includesGuidelines require explicit include guards. Also, several headers appear unused in this interface header; prefer lighter includes to reduce compile-time coupling.
Apply:
-#pragma once +#ifndef TRTLLM_DATATRANSCEIVER_H +#define TRTLLM_DATATRANSCEIVER_H -#include <fstream> +#include <iosfwd> #include <future> -#include <map> #include <string> -#include "tensorrt_llm/batch_manager/cacheFormatter.h" #include "tensorrt_llm/batch_manager/llmRequest.h" -#include "tensorrt_llm/common/envUtils.h" -#include "tensorrt_llm/common/logger.h" #include "tensorrt_llm/executor/cacheCommunicator.h" #include "tensorrt_llm/executor/dataTransceiverState.h" -#include "tensorrt_llm/executor/serializeUtils.h" -#include "tensorrt_llm/runtime/cudaEvent.h" -#include "tensorrt_llm/runtime/utils/mpiUtils.h" +#include "tensorrt_llm/batch_manager/cacheFormatter.h"And add at EOF:
+ #endif // TRTLLM_DATATRANSCEIVER_H
119-128: Align Doxygen style with repo conventionGuidelines call for //! for single-line docs and //!< for members. Consider switching from /// @brief for consistency.
Example:
- /// @brief Asynchronously respond to the request and send data. + //! Asynchronously respond to the request and send data.Also applies to: 137-144, 149-154
172-177: Add brief Doxygen for sendRequestInfo/receiveSyncThese two public methods lack doc comments while others have them. Add short one-liners for consistency.
- TransferSession sendRequestInfo(LlmRequest const& llmRequest); + //! Send request metadata and acquire a transfer session for receive side. + TransferSession sendRequestInfo(LlmRequest const& llmRequest); - void receiveSync(TransferSession& session); + //! Blocking receive that unformats data into llmRequest via session. + void receiveSync(TransferSession& session);
38-41: Track TODO: consider moving transport aliases/types into a dedicated namespaceOpen an issue to plan the proposed tensorrt_llm::transmission namespace so we don’t leave a lingering TODO in public headers.
Want me to file a tracking issue with a lightweight migration plan?
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h(2 hunks)cpp/tensorrt_llm/batch_manager/CMakeLists.txt(0 hunks)cpp/tensorrt_llm/batch_manager/cacheFormatter.h(3 hunks)cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp(8 hunks)cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp(16 hunks)cpp/tensorrt_llm/batch_manager/dataTransceiver.h(3 hunks)cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp(0 hunks)cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.h(0 hunks)cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp(2 hunks)cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h(2 hunks)cpp/tensorrt_llm/executor/cache_transmission/ucx_utils/connection.cpp(1 hunks)cpp/tests/unit_tests/executor/ucxCommTest.cpp(0 hunks)cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp(11 hunks)
💤 Files with no reviewable changes (4)
- cpp/tests/unit_tests/executor/ucxCommTest.cpp
- cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp
- cpp/tensorrt_llm/batch_manager/CMakeLists.txt
- cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.h
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh}: Namespace closing braces must include a trailing comment with the namespace name (e.g., '} // namespace foo').
Prefer const or constexpr variables over #define for constants.
Declare variables that are not modified after initialization as const.
Avoid magic literals in code; except for 0, nullptr, true, false. Use named constants for comparisons and logic.
Use Allman brace style for formatting.
Place the semicolon of an empty for/while loop on a new line.
Bodies of switch/while/do-while/for must be compound statements (brace-delimited), and if/else must always be followed by brace-delimited statements.
Type names (e.g., classes) must be CamelCase starting with an uppercase letter (e.g., FooBar).
Local variables, methods, and namespaces use lowerCamelCase (e.g., localFooBar).
Non-magic-number global variables that are non-static and not in an anonymous namespace must be lowerCamelCase prefixed with 'g' (e.g., gDontUseGlobalFoos).
Non-magic-number globals that are static or in an anonymous namespace use lowerCamelCase prefixed with 's' (e.g., sMutableStaticGlobal).
Locally visible static variables use lowerCamelCase with 's' prefix (e.g., static std::once_flag sFlag).
Private/protected member variables use 'm' prefix with CamelCase (e.g., mNbFooValues). Public members may omit, but 'm' is encouraged for clarity.
Constants (enums, global constants, static constants, and function-scope magic/literal constants) use uppercase SNAKE_CASE with 'k' prefix (e.g., kDIGIT_NUM).
Function-scope constants that are not magic numbers or literals are named like non-constant variables (e.g., bool const pass = a && b).
If macros are necessary, name them in UPPER_SNAKE_CASE (e.g., FOO_VERSION) and prefer constants over #define.
Use LLVM clang-format; wrap lines at a maximum of 120 columns; use '// clang-format off/on' sparingly with justification.
Use smart pointers for heap allocations; prefer unique_ptr for sole ownership, shared_ptr for shared...
Files:
cpp/tensorrt_llm/executor/cache_transmission/ucx_utils/connection.cppcpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cppcpp/tensorrt_llm/batch_manager/cacheTransceiver.cppcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.hcpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cppcpp/tensorrt_llm/batch_manager/dataTransceiver.cppcpp/tensorrt_llm/batch_manager/cacheFormatter.h
**/*.{cpp,cxx,cc,cu,h,hpp,hh,hxx,cuh}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
C++ filenames should be lowerCamelCase (first letter lowercase) and must be case-insensitive unique within a compilation target.
Files:
cpp/tensorrt_llm/executor/cache_transmission/ucx_utils/connection.cppcpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cppcpp/tensorrt_llm/batch_manager/cacheTransceiver.cppcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.hcpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cppcpp/tensorrt_llm/batch_manager/dataTransceiver.cppcpp/tensorrt_llm/batch_manager/cacheFormatter.h
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use only spaces, no tabs; indent with 4 spaces.
Files:
cpp/tensorrt_llm/executor/cache_transmission/ucx_utils/connection.cppcpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cppcpp/tensorrt_llm/batch_manager/cacheTransceiver.cppcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.hcpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cppcpp/tensorrt_llm/batch_manager/dataTransceiver.cppcpp/tensorrt_llm/batch_manager/cacheFormatter.h
**/*.{h,hpp,hh,hxx,cpp,cxx,cc}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc}: Prefer anonymous namespaces over 'static' for internal linkage of functions.
All templates (class/function/member/static) must be instantiated at least once; non-POD classes should have private data members.
Files:
cpp/tensorrt_llm/executor/cache_transmission/ucx_utils/connection.cppcpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cppcpp/tensorrt_llm/batch_manager/cacheTransceiver.cppcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.hcpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cppcpp/tensorrt_llm/batch_manager/dataTransceiver.cppcpp/tensorrt_llm/batch_manager/cacheFormatter.h
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).
Files:
cpp/tensorrt_llm/executor/cache_transmission/ucx_utils/connection.cppcpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cppcpp/tensorrt_llm/batch_manager/cacheTransceiver.cppcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.hcpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cppcpp/tensorrt_llm/batch_manager/dataTransceiver.cppcpp/tensorrt_llm/batch_manager/cacheFormatter.h
**/*.{h,hpp,hh,hxx}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Document new class interfaces and function prototypes with Doxygen; use //! for single-line and //!< for members.
Files:
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.hcpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tensorrt_llm/batch_manager/cacheFormatter.h
**/*.{h,hpp,hh,hxx,cuh}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use include guards named 'TRTLLM_<FILE_NAME_IN_CAPS_WITH_UNDERSCORES>_H' (no leading or trailing underscore; directory names excluded).
Files:
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.hcpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tensorrt_llm/batch_manager/cacheFormatter.h
🧠 Learnings (3)
📚 Learning: 2025-08-06T08:18:28.669Z
Learnt from: zhengd-nv
PR: NVIDIA/TensorRT-LLM#6633
File: cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp:145-155
Timestamp: 2025-08-06T08:18:28.669Z
Learning: In cpp/tensorrt_llm/batch_manager/dataTransceiverImpl.cpp, the existing `mMtxForMap` mutex in DataSenderImpl is sufficient to synchronize measurement file operations in the `release` method, as all file operations occur within the same critical section that protects the `mRequestToSession` map access.
Applied to files:
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/batch_manager/cacheTransceiver.cppcpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cppcpp/tensorrt_llm/batch_manager/dataTransceiver.cppcpp/tensorrt_llm/batch_manager/cacheFormatter.h
📚 Learning: 2025-08-21T09:41:49.347Z
Learnt from: eopXD
PR: NVIDIA/TensorRT-LLM#6768
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:2010-2045
Timestamp: 2025-08-21T09:41:49.347Z
Learning: In cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp, updateSequenceCacheBlockOffsets is specifically for updating bookkeeping when blocks are added during the context phase, not for refreshing offsets after detach operations. During detach operations, GenerationRequest::removeFrontBlock handles the necessary cache block bookkeeping internally.
Applied to files:
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.hcpp/tensorrt_llm/batch_manager/cacheTransceiver.cppcpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp
📚 Learning: 2025-09-02T13:42:44.885Z
Learnt from: pcastonguay
PR: NVIDIA/TensorRT-LLM#7455
File: tensorrt_llm/_torch/pyexecutor/py_executor.py:1852-1860
Timestamp: 2025-09-02T13:42:44.885Z
Learning: In MPI communication within TensorRT-LLM pipeline parallelism, different communication types (tokens, logits, termination sync) must use disjoint tag namespaces to avoid message routing collisions when using the same source/destination patterns.
Applied to files:
cpp/tensorrt_llm/batch_manager/dataTransceiver.hcpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
🧬 Code graph analysis (7)
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h (2)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (4)
CacheSender(725-729)CacheSender(746-746)CacheReceiver(748-752)CacheReceiver(759-759)cpp/tensorrt_llm/batch_manager/dataTransceiver.h (2)
CacheSender(116-159)CacheReceiver(161-183)
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (2)
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp (6)
future(267-276)llmRequest(424-453)llmRequest(424-424)llmRequest(903-934)llmRequest(903-903)llmRequest(936-943)cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (13)
llmRequest(135-135)llmRequest(231-238)llmRequest(231-231)llmRequest(436-436)llmRequest(442-442)llmRequest(481-545)llmRequest(481-481)llmRequest(547-563)llmRequest(547-547)llmRequest(591-605)llmRequest(591-591)it(374-385)it(374-374)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h (1)
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (2)
setSenderState(164-170)setSenderState(164-165)
cpp/tensorrt_llm/batch_manager/dataTransceiver.h (3)
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h (2)
tensorrt_llm(32-131)nodiscard(67-90)cpp/tensorrt_llm/batch_manager/cacheFormatter.h (4)
tensorrt_llm(34-313)TransferSession(45-67)nodiscard(110-120)nodiscard(296-299)cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (40)
CacheSender(725-729)CacheSender(746-746)nodiscard(135-150)nodiscard(152-155)nodiscard(162-167)nodiscard(177-229)nodiscard(387-390)nodiscard(392-395)nodiscard(397-401)nodiscard(436-440)nodiscard(442-474)sendAsync(731-734)sendAsync(731-731)llmRequest(135-135)llmRequest(231-238)llmRequest(231-231)llmRequest(436-436)llmRequest(442-442)llmRequest(481-545)llmRequest(481-481)llmRequest(547-563)llmRequest(547-547)llmRequest(591-605)llmRequest(591-591)getCommState(736-739)getCommState(736-736)setCommState(741-744)setCommState(741-741)commState(157-160)commState(157-157)session(476-479)session(476-476)Impl(121-133)Impl(240-243)Impl(424-434)Impl(577-588)CacheReceiver(748-752)CacheReceiver(759-759)receiveAsync(754-757)receiveAsync(754-754)
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp (2)
cpp/tensorrt_llm/batch_manager/cacheFormatter.h (1)
TransferSession(45-67)cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (11)
llmRequest(135-135)llmRequest(231-238)llmRequest(231-231)llmRequest(436-436)llmRequest(442-442)llmRequest(481-545)llmRequest(481-481)llmRequest(547-563)llmRequest(547-547)llmRequest(591-605)llmRequest(591-591)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (3)
cpp/tensorrt_llm/batch_manager/cacheFormatter.h (3)
nodiscard(110-120)nodiscard(296-299)TransferSession(45-67)cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.cpp (7)
nodiscard(335-349)deserialize(85-92)deserialize(85-85)serialize(77-83)serialize(77-77)getCommState(416-420)getCommState(416-416)cpp/tensorrt_llm/batch_manager/dataTransceiver.h (3)
RequestInfo(62-113)CacheSender(116-159)CacheReceiver(161-183)
cpp/tensorrt_llm/batch_manager/cacheFormatter.h (3)
cpp/tensorrt_llm/batch_manager/dataTransceiver.h (2)
tensorrt_llm(35-185)- `` (82-85)
cpp/include/tensorrt_llm/executor/cacheCommunicator.h (1)
Connection(44-57)cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (24)
llmRequest(135-135)llmRequest(231-238)llmRequest(231-231)llmRequest(436-436)llmRequest(442-442)llmRequest(481-545)llmRequest(481-481)llmRequest(547-563)llmRequest(547-547)llmRequest(591-605)llmRequest(591-591)nodiscard(135-150)nodiscard(152-155)nodiscard(162-167)nodiscard(177-229)nodiscard(387-390)nodiscard(392-395)nodiscard(397-401)nodiscard(436-440)nodiscard(442-474)requestId(162-162)requestId(169-175)requestId(169-169)lock(549-549)
⏰ 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). (2)
- GitHub Check: Check PR Checklist Resolution
- GitHub Check: Pre-commit Check
🔇 Additional comments (34)
cpp/include/tensorrt_llm/batch_manager/cacheTransceiver.h (2)
37-39: Forward-decls updated to CacheSender/CacheReceiver look consistentMatches the refactor; no API exposure changes here.
113-116: Member rename aligns with new roles (sender/receiver)mCacheSender/mCacheReceiver and mSenderFutures naming improves clarity with the refactor.
cpp/tensorrt_llm/batch_manager/cacheTransceiver.cpp (4)
206-209: Construction of sender/receiver matches refactorInstantiation with shared formatter factory is good; avoids formatter duplication bugs.
224-225: Pointer to CommState lifetime: confirm stabilitymCommState stores the address of mCacheSender->getCommState(). Ensure getCommState() returns a reference to an object whose lifetime is tied to mCacheSender so mCommState never dangles.
If needed, store a copy instead:
- mCommState = std::addressof(mCacheSender->getCommState()); + static executor::kv_cache::CommState commStateCopy{}; + commStateCopy = mCacheSender->getCommState(); + mCommState = std::addressof(commStateCopy);(Or keep a const reference member bound to CacheSender’s internal object.)
260-262: Async flow wiring looks correctsendAsync/receiveAsync futures are captured and tracked; state transitions are consistent.
Also applies to: 276-278, 285-286, 303-305
383-389: Context futures bookkeeping is sound; minor insertion guard is clearPolling with wait_for(0) and erasing completed futures is fine; ordering preservation logic is straightforward.
Also applies to: 424-448
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp (7)
160-186: LGTM! Well-structured mock implementations.The mock classes are properly refactored to match the new CacheSender/CacheReceiver API surface. The setup and test expectations correctly reflect the renamed interfaces and updated method signatures.
399-407: LGTM! Clean refactoring from DataResponder to CacheSender.The test fixture setup correctly instantiates the new CacheSenderImpl and CacheReceiverImpl classes with appropriate parameters for the connection manager, cache state, and formatter.
437-437: Good test coverage for the renamed API.The test correctly validates the async send operation using the renamed
respondAndSendAsyncmethod on the CacheSender.
462-464: LGTM! Consistent member variable renaming.The member variables have been properly renamed to reflect the new CacheSender/CacheReceiver terminology while maintaining the same functionality.
791-797: LGTM! Proper initialization of cache transceivers with new API.The cache transceiver setup correctly uses the new CacheSenderImpl and CacheReceiverImpl constructors, maintaining consistency with the refactored API.
932-932: Consistent API usage throughout test methods.The test correctly uses the renamed
respondAndSendAsyncmethod, maintaining consistency with the new CacheSender API.
1164-1165: LGTM! Test fixture member variables properly updated.The member variables have been appropriately renamed from mResponder/mRequester to mSender/mRequester while maintaining type consistency with the new CacheSender/CacheReceiver classes.
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (12)
27-27: LGTM! Correct header update for new agent utilities.The include path has been properly updated to reflect the new cache transmission agent utilities location.
39-46: LGTM! Well-structured helper function for tag generation.The
tagFromRequestIdfunction provides a clean way to generate unique tags for request-based communication, avoiding potential collisions in the messaging system.
48-58: LGTM! Resource management structure properly encapsulated.The
ReceiveCacheResourcestruct appropriately encapsulates the buffer manager and CUDA event needed for receive operations, with proper move semantics for efficient resource transfer.
116-134: LGTM! Clean refactoring to CacheSender implementation.The implementation has been properly updated to use the new ConnectionManager-based approach with appropriate state management and formatter initialization.
177-229: Complex logic but correctly implemented.The
recvRequestInfomethod properly handles both agent and non-agent connection scenarios. The session management and connection tracking are well-structured with appropriate mutex protection.
231-238: LGTM! Clean synchronous send implementation.The
sendSyncmethod correctly retrieves the session, sets the LlmRequest, and delegates to the formatter for actual data formatting.
355-355: Consistent logging update.The error message has been properly updated to use "CacheSender" terminology.
421-435: LGTM! Clean CacheReceiver implementation.The implementation properly initializes the ConnectionManager, state, and formatter with appropriate validation checks.
476-479: Good separation of concerns.The
receiveSyncmethod cleanly delegates to the formatter for data unformatting, maintaining a clean separation between communication and data processing logic.
481-545: Complex but well-structured request info sending.The
sendRequestInfomethod properly handles selective cache transfer, agent connection management, and session creation. The logic is complex but necessary for the multi-connection architecture.
547-563: Good resource management with proper synchronization.The
getReceiveCacheResourcemethod correctly manages per-process resources with appropriate mutex protection and lazy initialization.
725-759: LGTM! Clean public API implementation.The public CacheSender and CacheReceiver classes provide clean wrappers around the implementation with proper forwarding and resource management.
cpp/tensorrt_llm/batch_manager/cacheFormatter.h (5)
25-25: LGTM! Correct header update.The include has been properly updated from dataTransceiver.h to cacheCommunicator.h, reflecting the architectural refactoring.
41-43: LGTM! Clear type aliases for namespace simplification.The type aliases improve code readability by avoiding repetitive namespace qualifications.
45-169: Well-designed TransferSession class with comprehensive functionality.The TransferSession class provides excellent encapsulation of multi-connection transfer operations with measurement capabilities. The design supports both synchronous operations and performance monitoring. The measurement recording is particularly useful for performance analysis.
116-120: Good documentation for deferred LlmRequest binding.The comment clearly explains why the LlmRequest might not be available initially in CacheSender, which helps maintainers understand the lifecycle.
211-269: Well-structured measurement helper with proper synchronization.The KvCacheMeasureHelper class provides comprehensive measurement capabilities with proper thread safety through mutex protection. The destructor correctly handles file output for collected metrics.
cpp/tensorrt_llm/batch_manager/dataTransceiver.h (4)
42-44: Type aliases are appropriate and improve API clarityThe public exposure of SizeType32, TransferSession, and BaseCacheFormatter in this namespace looks good.
Also applies to: 58-58
116-155: PImpl + [[nodiscard]] futures: interface looks solidConstructor, async entrypoint, comm-state accessors, and session-based ops are clean and non-virtual. Good separation from Impl.
161-179: Receiver interface rename/port looks consistentConstructor and async receive entrypoint match the sender symmetry; session-based methods align with formatter un/format flow.
45-56: Verify MPI tag namespaces are globally disjoint
No duplicatek*_TAGconstants were detected by the script. Still ensureTransceiverTag::kID_TAG(19),kINFO_SIZE_TAG(22),kINFO_TAG(32) and the enum values (REQUEST_SEND = 1,TERMINATION = 2) do not overlap with any other MPI tags used for tokens, logits, or termination sync across the codebase.
cpp/tensorrt_llm/executor/cache_transmission/agent_utils/connection.h
Outdated
Show resolved
Hide resolved
b2c79cd to
3e2df6a
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #18264 [ run ] triggered by Bot |
|
PR_Github #18260 [ run ] completed with state |
7ab68cd to
d916fee
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #18265 [ run ] triggered by Bot |
|
PR_Github #18264 [ run ] completed with state |
|
PR_Github #18265 [ run ] completed with state |
d916fee to
c495710
Compare
|
/bot run --disable-fail-fast |
c495710 to
7c86ee9
Compare
|
PR_Github #18300 [ run ] triggered by Bot |
|
@chuangz0 could you review as well? You wrote most of this code so want to make sure you agree with the changes. Thanks. |
7c86ee9 to
c9a286d
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #18395 [ run ] triggered by Bot |
|
PR_Github #18395 [ run ] completed with state |
c8dce4c to
9d8fb3f
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #18523 [ run ] triggered by Bot |
|
PR_Github #18523 [ run ] completed with state |
|
/bot run --disable-fail-fast |
99cfedd to
566d9a1
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #18550 [ run ] triggered by Bot |
|
PR_Github #18552 [ run ] triggered by Bot |
|
PR_Github #18550 [ run ] completed with state |
|
PR_Github #18552 [ run ] completed with state |
16d74eb to
d10ab6a
Compare
Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com> Refactor dataTransceiver classes Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
d10ab6a to
b2756e6
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #18657 [ run ] triggered by Bot |
|
PR_Github #18657 [ run ] completed with state |
Refactor dataTransceiver classes
Summary by CodeRabbit
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
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.
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.