-
Couldn't load subscription status.
- Fork 1.8k
[https://nvbugs/5448767][fix] sync termination of requests across PP ranks #7455
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
📝 WalkthroughWalkthroughCentralizes response finalization in DataResponder via a new helper and termination-aware waiting. Adds cross-pipeline termination synchronization in PyExecutor when KV cache reuse is enabled, deferring resource freeing until consensus. Integrates send-handle waiting and safety checks in executor loop. Test updates set log level via environment variable. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant R as DataResponder::Impl
participant CV as mResponderCv
participant Env as Env (parallel cache send)
participant Net as Sender
participant Req as llmRequest
rect rgba(230,240,255,0.5)
note over R: response() loop
R->>CV: wait until response ready or terminated
alt response ready
R->>R: sendResponse(blockHashes, it)
R->>Req: setRequestedBlockHashes(blockHashes)
alt Env.parallelCacheSend
R-->>Net: async send (detached thread)
else
R->>Net: inline sendAndRemoveResponse
end
R->>R: removeResponse(it), clear mCurrentRequest
else terminated
R-->R: break loop
end
end
sequenceDiagram
autonumber
participant PE as PyExecutor (rank i)
participant Ring as PP Ranks (ring)
participant KVC as KV Cache Manager
participant TX as KV Cache Transceiver
Note over PE: On request termination
alt PP>1 and KVC.reuse enabled and TX present
PE->>PE: record local_termination[req], pending_termination.add(req)
else
PE->>PE: _free_resources_for_request(req)
end
Note over PE: In PP microbatch loop
PE->>PE: wait/clear prior send handles
alt PP>1 and reuse enabled and TX present
PE->>Ring: _sync_termination(microbatch_id)
Ring-->>PE: merged termination states
alt consensus reached for req
PE->>PE: _free_resources_for_request(req)
end
end
note over PE: Sampling safety
PE->>PE: assert sampling_result is not None
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
✨ 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
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: 4
🧹 Nitpick comments (2)
tests/integration/defs/disaggregated/test_disaggregated.py (1)
170-173: Guard env=None and avoid clobbering user log level.Handle the optional env param and don't override an existing TLLM_LOG_LEVEL.
- run_env = env.copy() - run_env["UCX_TLS"] = "^ib" - run_env["TLLM_LOG_LEVEL"] = "info" + run_env = (env or {}).copy() + run_env["UCX_TLS"] = "^ib" + run_env.setdefault("TLLM_LOG_LEVEL", "info")tensorrt_llm/_torch/pyexecutor/py_executor.py (1)
1601-1615: Prefer pp_rank for readiness bookkeeping.Using PP ranks clarifies intent and avoids relying on global ranks equating to “one per PP stage.”
- if self.dist.rank not in state['ready_to_terminate']: - state['ready_to_terminate'].add(self.dist.rank) + if self.dist.pp_rank not in state['ready_to_terminate']: + state['ready_to_terminate'].add(self.dist.pp_rank)
📜 Review details
Configuration used: Path: .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.
📒 Files selected for processing (3)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp(2 hunks)tensorrt_llm/_torch/pyexecutor/py_executor.py(8 hunks)tests/integration/defs/disaggregated/test_disaggregated.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Filenames compiled into a target must be case-insensitively unique
Files:
tests/integration/defs/disaggregated/test_disaggregated.pytensorrt_llm/_torch/pyexecutor/py_executor.pycpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
**/*.{h,hpp,hh,hxx,cc,cpp,cxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use spaces, not tabs; indent 4 spaces
Files:
tests/integration/defs/disaggregated/test_disaggregated.pytensorrt_llm/_torch/pyexecutor/py_executor.pycpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: Code must target Python 3.8+
Indent with 4 spaces; do not use tabs (Python)
Maintain module namespace on import: prefer from package.subpackage import foo; use foo.Symbol()
Python filenames use snake_case
Python class names use PascalCase
Python functions and methods use snake_case
Python local variables use snake_case; if starting with a number concept, prefix with k (e.g., k_99th_percentile)
Python global variables use G_ prefix with UPPER_SNAKE_CASE
Python constants use UPPER_SNAKE_CASE
Avoid shadowing variables from outer scopes
Initialize all externally visible class members in init
For public interfaces, prefer docstrings over comments; comments should be for in-function or file-local interfaces
Use Google-style docstrings for classes and functions (Sphinx-parsable)
Document attributes and variables inline with docstrings immediately after assignment
Avoid reflection when a non-reflective approach suffices
Limit except clauses to specific exceptions where possible
When using try/except for duck-typing, keep try body minimal and move logic to else
Files:
tests/integration/defs/disaggregated/test_disaggregated.pytensorrt_llm/_torch/pyexecutor/py_executor.py
**/*.{cpp,cc,cxx,h,hpp,hh,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Prepend NVIDIA copyright header (current year) to all source files
Files:
tests/integration/defs/disaggregated/test_disaggregated.pytensorrt_llm/_torch/pyexecutor/py_executor.pycpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
**/*.{h,hpp,hh,hxx,cc,cpp,cxx,cu,cuh}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.{h,hpp,hh,hxx,cc,cpp,cxx,cu,cuh}: Closing braces of C++ namespaces must include a comment naming the namespace (e.g., } // namespace foo)
Avoid using literals (except 0, nullptr, true, false) directly in logic; use named constants for comparisons
Use Allman brace style in C++
Place semicolon of empty for/while loop on its own line
Use brace-delimited statements for bodies of switch/while/do/for and always brace if/else bodies
C++ type names use UpperCamelCase
Local variables, methods, and namespaces use lowerCamelCase
Non-static, externally visible globals use g prefix with lowerCamelCase (e.g., gDontUseGlobalFoos)
Static or anonymous-namespace globals use s prefix with lowerCamelCase (e.g., sMutableStaticGlobal)
Locally visible static variables use s prefix (e.g., static std::once_flag sFlag)
Member variables use m prefix with CamelCase (public may omit but encouraged)
Constants (enums, globals, static consts, function-scope magic numbers) use k prefix with UPPER_SNAKE (e.g., kDIGIT_NUM)
Function-scope non-literal, non-magic constants use normal non-const naming (e.g., const bool pass)
If macros are necessary, name them in UPPER_SNAKE_CASE
Avoid Hungarian notation except allowed app’s hungarian like nb for counts
Constructor parameters conflicting with member names get a trailing underscore (e.g., foo_)
Use uppercase literal suffixes (e.g., 1234L not 1234l)
Format C++ with clang-format (LLVM style), max line length 120; justify any exceptions with clang-format off/on blocks
Use C++-style comments; C comments not allowed except special inline cases; single-line comments use //
Use inline parameter comments in calls when arguments aren’t obvious (e.g., /* checkForErrors = / false)
Disable code with #if/#endif (optionally mnemonic conditions or no-op macros); do not comment out code; avoid dead code
Use the least forceful C++ cast; avoid removing const/volatile; avoid C-style and functional casts (except explicit constructors); cast void to T* with static_cas...
Files:
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
**/*.{cc,cpp,cxx,cu}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.{cc,cpp,cxx,cu}: Prefer const or constexpr variables over #define for constants in C++
Declare variables const if not modified after initialization
Use smart pointers for heap allocation; prefer unique_ptr for sole ownership, shared_ptr for shared; weak_ptr only exceptionally; avoid deprecated smart pointers
Avoid declaring large functions inline unless there’s a quantifiable benefit; remember in-class definitions are implicitly inline
Every defined function must be referenced at least once; avoid unused methods
Files:
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp
🧠 Learnings (2)
📚 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/tensorrt_llm/batch_manager/dataTransceiver.cpp
📚 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/tensorrt_llm/batch_manager/dataTransceiver.cpp
🧬 Code graph analysis (2)
tensorrt_llm/_torch/pyexecutor/py_executor.py (3)
tensorrt_llm/_torch/distributed/communicator.py (6)
pp_size(42-43)rank(22-23)isend_object(128-129)next_pp_rank(74-75)recv_object(131-132)prev_pp_rank(78-79)tensorrt_llm/mapping.py (4)
rank(324-325)rank(328-335)next_pp_rank(444-448)prev_pp_rank(438-442)tensorrt_llm/logger.py (1)
debug(143-144)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (1)
cpp/tensorrt_llm/common/envUtils.cpp (2)
getEnvParallelCacheSend(327-331)getEnvParallelCacheSend(327-327)
🔇 Additional comments (6)
cpp/tensorrt_llm/batch_manager/dataTransceiver.cpp (1)
261-277: LGTM on centralizing response finalization.Unified send path + termination-aware waiting improves correctness and readability.
tensorrt_llm/_torch/pyexecutor/py_executor.py (5)
205-205: Plumbing enable_kv_cache_reuse looks correct.
225-232: Init of termination-coordination state is sound.
878-880: Heads-up: termination ring uses same tags as token/logits comms.This call uses prev_microbatch_id tags that collide with inter-PP token/logits exchanges; see _sync_termination for fix below.
798-799: Sampling result assert is good safety.
839-842: Resetting send handle to None after wait is correct.
0afea26 to
712d0de
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #17267 [ run ] triggered by Bot |
|
PR_Github #17267 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #17429 [ run ] triggered by Bot |
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.
Can you rebase and resolve conflicts? Thanks.
|
PR_Github #17429 [ run ] completed with state |
850af4e to
d1463ef
Compare
Rebased and resolved! |
|
/bot run --disable-fail-fast |
|
PR_Github #17559 [ run ] triggered by Bot |
|
PR_Github #17559 [ run ] completed with state |
d1463ef to
128393f
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #17789 [ run ] triggered by Bot |
|
PR_Github #17789 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #17822 [ run ] triggered by Bot |
|
PR_Github #17822 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #17883 [ run ] triggered by Bot |
|
PR_Github #17883 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #17891 [ run ] triggered by Bot |
Signed-off-by: raayandhar <[email protected]>
Signed-off-by: Lizhi Zhou <[email protected]>
Signed-off-by: Lizhi Zhou <[email protected]>
Signed-off-by: raayandhar <[email protected]>
Signed-off-by: raayandhar <[email protected]>
Signed-off-by: raayandhar <[email protected]>
Signed-off-by: raayandhar <[email protected]>
Signed-off-by: raayandhar <[email protected]>
128393f to
d4c85c2
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #17894 [ run ] triggered by Bot |
|
PR_Github #17891 [ run ] completed with state |
|
PR_Github #17894 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #17911 [ run ] triggered by Bot |
|
PR_Github #17911 [ run ] completed with state |
…ranks (NVIDIA#7455) Signed-off-by: raayandhar <[email protected]> Signed-off-by: Lizhi Zhou <[email protected]> Co-authored-by: Lizhi Zhou <[email protected]>
Summary by CodeRabbit
Description
If
pp_size> 1 andenable_kv_cache_reuse, we need to sync termination across PP ranks otherwise, different ranks may have different KV cache blocks and a request may have differentPrepopulatedPromptLenwhich leads to a NCCL hang. Thus, we add a way to synchronize the termination of a request across PP ranks. This is expected to effect perf / add overhead. There will be a second PR to help address this.This PR also includes other fixes from other PRs targeting release/1.0:
Thanks to @reasonsolo as well for the help to make this PR.
Test Coverage
Tested
test_disaggregated_ctxpp2_gentp2[TinyLlama-1.1B-Chat-v1.0]locally. Previously hanging, no longer. Also tested agg https://nvbugs/5472947 but was unable to reproduce on my branch (with or without fix) and on main ToT. For this reason I have made this synchronization disagg-specific (check onkv_cache_transceiver)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.