Repository navigation
[TRTLLM-16725][refactor] Centralize PyTorch distributed initialization - #20704
yijingl-nvidia merged 1 commit into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Shared initialization API and workers tensorrt_llm/_torch/distributed/initialization.py, tensorrt_llm/_torch/visual_gen/executor.py, tensorrt_llm/executor/ray/gpu_worker.py |
Added init_torch_distributed to forward process-group parameters to PyTorch. Visual generation and Ray workers now use the helper. |
CUTE DSL MPI initialization tensorrt_llm/_torch/distributed/initialization.py, tensorrt_llm/_torch/moe/fused_moe/mega_moe_cute_dsl.py, tests/integration/defs/accuracy/test_disaggregated_serving.py |
Added CUTE DSL MPI setup with rendezvous endpoint selection and process-group initialization. The MoE call site delegates to the helper. The integration test comment now refers to it. |
DeepGEMM MPI initialization tensorrt_llm/_torch/distributed/initialization.py, tensorrt_llm/_torch/moe/fused_moe/mega_moe_deepgemm.py |
Added DeepGEMM MPI setup with launcher environment validation, local-rank selection, endpoint broadcasting, and one retry after an initialization error. The MoE call site delegates to the helper. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Refactor
Sequence Diagram(s)
sequenceDiagram
participant MPI
participant ensure_deepgemm_torch_distributed
participant PyTorchDistributed
MPI->>ensure_deepgemm_torch_distributed: provide rank, world size, and local rank
ensure_deepgemm_torch_distributed->>MPI: validate or broadcast rendezvous endpoint
ensure_deepgemm_torch_distributed->>PyTorchDistributed: initialize NCCL process group
PyTorchDistributed-->>ensure_deepgemm_torch_distributed: RuntimeError
ensure_deepgemm_torch_distributed->>MPI: broadcast a new endpoint
ensure_deepgemm_torch_distributed->>PyTorchDistributed: retry NCCL initialization
Suggested reviewers: rosong11
Merge Risk: 
Minimal · up to 864e5
-
The distributed-initialization consolidation has no established behavior regression and is mergeable after normal checks.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 6 files.
Full details: Description check
-
Explanation
The pull request includes the required Description, Test Coverage, and PR Checklist sections. It clearly explains the refactor, intended lack of functional change, affected components, test status, and relevant context.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
|
/bot run --disable-fail-fast |
chienchunhung
left a comment
There was a problem hiding this comment.
LGTM. This PR consolidates PyTorch process-group initialization from MegaMoE, VisualGen, and Ray. The extraction preserves backend-specific rendezvous, device selection, and worker initialization behavior.
@chang-l , @xxi-nv can you help coordinate the reviews from VIsualGen and MoE perspectives? Thanks!
|
PR_Github #79392 [ run ] triggered by Bot. Commit: |
|
PR_Github #79392 [ run ] completed with state
|
72a73d8 to
a26b75e
Compare
|
PR_Github #79722 [ run ] completed with state
|
a26b75e to
bbede63
Compare
|
/bot run |
|
PR_Github #79966 [ run ] triggered by Bot. Commit: |
|
PR_Github #79966 [ run ] completed with state
|
taianz-nv
left a comment
There was a problem hiding this comment.
Nit: ensure_cutedsl_torch_distributed / ensure_deepgemm_torch_distributed still call dist.init_process_group directly; routing them through init_torch_distributed would make this module the single entry point it aims to be.
Nit: the reflowed comment in test_disaggregated_serving.py (~L2477) exceeds the surrounding line width; rewrap it.
|
Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements. |
bbede63 to
678e06b
Compare
|
/bot run |
|
PR_Github #81260 [ run ] triggered by Bot. Commit: |
|
PR_Github #81260 [ run ] completed with state
|
678e06b to
864e54d
Compare
|
/bot run |
Thanks for the NIT. I've addressed them |
|
PR_Github #81756 [ run ] triggered by Bot. Commit: |
|
PR_Github #81756 [ run ] completed with state |
This makes it easier to reuse torch.dist functions in future and easier for mock in test. Signed-off-by: Yijing Li <[email protected]>
864e54d to
05b4ca3
Compare
|
/bot run |
|
PR_Github #82054 [ run ] triggered by Bot. Commit: |
|
PR_Github #82054 [ run ] completed with state
|
|
/bot run |
|
PR_Github #82118 [ run ] triggered by Bot. Commit: |
|
PR_Github #82118 [ run ] completed with state |
Description
This PR moves the code that starts the PyTorch process group into one new module,
tensorrt_llm/_torch/distributed/initialization.py.No functional change.
Before this PR, the two MegaMoE backends, the VisualGen executor and the Ray GPU worker each had their own copy. Consolidating into one module improves code readability and maintenance.
This PR does not depend on the other PRs in the series.
The latest push rebases on main. On main, #21225 changed the MegaMoE CuTe DSL bootstrap: rank 0 now hosts a
TCPStore, and the bootstrap does not useMASTER_ADDRorMASTER_PORT.ensure_cutedsl_torch_distributed()now has this code, so the moved code is still the same as on main.init_torch_distributed()now givesstoreandinit_methodtoinit_process_group()only when the caller sets them, so each caller makes the same call as before.Test Coverage
0 tests added, 0 tests changed.
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)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.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
To see a list of available CI bot commands, please comment
/bot help.PRs in this series
These PRs refactor checkpoint loading and add Model Streamer loading. They merge in this order, top to bottom.
checkpoint_io_policyfrom plain strings to the string enumCheckpointIOPolicy.CheckpointFormatfor the built-in checkpoint formats, make the checkpoint I/O helpers take onlyLoadFormat, and make the checkpoint I/O policy resolution easier to read.distributed/initialization.py.ModelLoader.load()shorter: move its MX, GMS, memory and model-hook helpers to new files inmodels/checkpoints/.BaseCheckpointLoader.modeling_kimi_linear.pytomodeling_kimi_k3_loader.py.checkpoint_io_policy="model_streamer", which loads a checkpoint with Run:ai Model Streamer.🤖 Generated with Claude Code
Dev Engineer Review
tensorrt_llm/_torch/distributed/initialization.py.RuntimeError. Verify these paths across launcher configurations and initialization failures.L0_MergeRequest_PRpipelines for commits72a73d8,a26b75e,bbede63, and678e06b. They do not identify the failing tests.QA Engineer Review
tests/integration/defs/accuracy/test_disaggregated_serving.pychanged a comment only. No test functions, IDs, or selectors changed, and no tests were added or modified to cover the shared initialization helpers.needs follow-up. The new initialization paths have no reported test additions, and the supplied CI comments do not identify failure details.Per-File QA Perspective
tensorrt_llm/_torch/distributed/initialization.py: Verify process-group initialization, MPI rank and world-size validation, rendezvous selection and reuse, CUDA-device handling, and retry behavior.tensorrt_llm/_torch/moe/fused_moe/mega_moe/mega_moe_cute_dsl.py: Verify that the shared helper preserves the CuteDSL backend’s initialization conditions, including single-rank and already-initialized cases.tensorrt_llm/_torch/moe/fused_moe/mega_moe/mega_moe_deepgemm.py: Verify launcher-variable validation, MPI fallback rendezvous, local-rank handling, and retry behavior.tensorrt_llm/_torch/visual_gen/executor.py: Verify that the shared helper preserves the existing process-group backend and initialization settings.tensorrt_llm/executor/ray/gpu_worker.py: Verify master and non-master TCP-store setup and equivalent process-group initialization.tests/integration/defs/accuracy/test_disaggregated_serving.py: The comment now identifiesensure_cutedsl_torch_distributedas the rendezvous implementation. Existing test selectors remain in CI and manual-QA lists; executable QA coverage did not change.