Fix 2D tensor communication for asymmetric DP in Bridge Communicator#4021
Merged
yashaswikarnati merged 1 commit intoNVIDIA:mainfrom Mar 25, 2026
Merged
Conversation
Contributor
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
_prepare_tensor_for_comm() always inserted a singleton dim at position -1 (the end), regardless of dim_mapping. With SBH format, the bridge operates on dim_mapping['b']=1, but after unsqueeze(-1), dim 1 is the hidden dimension, not batch. This caused incorrect cat/split operations when DP sizes differ between modules (fan-in/fan-out). Fix: add tensor_ndim parameter to BridgeCommunicator. For 2D tensors [B*S, H], batch is folded into dim 0, so fan-in/fan-out uses cat/split at dim 0 directly — no unsqueeze/squeeze needed. Each bridge gets tensor_ndim from module_output_ndim config in the communicator. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
099b859 to
32422aa
Compare
Contributor
Author
|
/claude review |
yaoyu-33
approved these changes
Mar 24, 2026
lhb8125
approved these changes
Mar 25, 2026
kvareddy
approved these changes
Mar 25, 2026
Contributor
Author
|
/ok to test 32422aa |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/23552484202 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds native 2D tensor support to
BridgeCommunicatorfor modules that produce[B*S, H]outputs (e.g., vision encoders), fixing a crash when DP sizes differ across modules.The problem
The bridge communicator assumed all tensors are 3D
[S, B, H]and usedunsqueeze(-1)/squeeze(-1)to adapt 2D tensors. This breaks with asymmetric DP because the bridge splits/concatenates alongdim_mapping['b']=1— but afterunsqueeze(-1), dim 1 is the hidden dimension, not batch:Fan-in (DP=3 → DP=1):
cat(dim=1)on 3 tensors concatenates along hidden →[577, 12288]instead of[1731, 4096].Fan-out (DP=1 → DP=3):
split(dim=1, 3)splits hidden into thirds →[1731, 1365]instead of[577, 4096].Silent when DP ratio is 1:1 (cat/split of 1 tensor are no-ops).
The fix
Add
tensor_ndimparameter toBridgeCommunicator. For 2D tensors, batch is folded into dim 0, so fan-in/fan-out usescat/splitat dim 0 directly — no unsqueeze needed:MultiModulePipelineCommunicatoracceptsmodule_output_ndimdict to configure each bridge per source module.Files changed
bridge_communicator.py—tensor_ndimparam,_batch_dimpropertymultimodule_communicator.py—module_output_ndimparam, passes to bridgestest_mimo_1f1b_schedule.py— 4 new 8-GPU asymmetric DP test configstest_bridge_communicator.py— 2 new 2D fan-in/fan-out testsTest plan
🤖 Generated with Claude Code