Repository navigation
[release/2.15][DeviceMesh] Sort split ranks when applicable (#201949) - #3881
Merged
pragupta merged 1 commit intoOct 27, 2026
Conversation
Go through the following checklist: - [x] Passes lint (`lintrunner -a`) - [x] Added/updated tests ## Summary (human written only) Sort split ranks did not account for preserve_rank_order correctly and sorted subgroup ranks by default. This was happening in eager path ## Agent details (AI-generated) ### Root cause The `new_group` DeviceMesh path sorts subgroup ranks by default and preserves mesh order when `preserve_rank_order=True`. The eager path instead passed mesh order directly to `split_group`, which intentionally preserves the supplied order. Default subgroup order therefore depended on the initialization path for every backend that supports splitting. ### Fix Sort ranks before every `split_group` call when `preserve_rank_order=False`. Keep mesh order when `preserve_rank_order=True`, matching the documented DeviceMesh contract and the existing `new_group` path. ### Behavior change Eager legacy NCCL, Gloo, XCCL, NCCL-lazy, TorchComms, and custom split backends now sort permuted subgroup ranks by default. This aligns them with non-eager initialization. Callers that need mesh order should pass `preserve_rank_order=True`. ### Validation The rank-order tests verify: - Default subgroup ranks are sorted. - `preserve_rank_order=True` follows mesh order. - The local rank matches the corresponding mesh coordinate. It covers the configured eager backend, explicit eager legacy NCCL, bound eager Gloo, and the existing eight-rank non-eager case. All four tests pass with the fix. Removing the sorting line makes both the legacy NCCL and Gloo regressions fail with reversed local ranks. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 agent_space/device-mesh-nightly/bin/python test/distributed/test_device_mesh.py DeviceMeshTest.test_device_mesh_preserve_rank_order_eager DeviceMeshTest.test_device_mesh_preserve_rank_order_eager_nccl_legacy DeviceMeshTestGlooBackend.test_device_mesh_preserve_rank_order_eager DeviceMeshTestNDim.test_device_mesh_preserve_rank_order -v ``` ```bash .venv/bin/spin quicklint ``` Pull Request resolved: pytorch#201949 Approved by: https://github.com/d4l3k (cherry picked from commit 020ab1c)
pragupta
deleted the
albmalamd/cherry-pick/2.15/201949-fix-device-mesh-split-rank-order
branch
October 27, 2026 13:59
jithunnair-amd
pushed a commit
that referenced
this pull request
Nov 4, 2026
…201949) (#3881) Go through the following checklist: - [x] Passes lint (`lintrunner -a`) - [x] Added/updated tests ## Summary (human written only) Sort split ranks did not account for preserve_rank_order correctly and sorted subgroup ranks by default. This was happening in eager path ## Agent details (AI-generated) ### Root cause The `new_group` DeviceMesh path sorts subgroup ranks by default and preserves mesh order when `preserve_rank_order=True`. The eager path instead passed mesh order directly to `split_group`, which intentionally preserves the supplied order. Default subgroup order therefore depended on the initialization path for every backend that supports splitting. ### Fix Sort ranks before every `split_group` call when `preserve_rank_order=False`. Keep mesh order when `preserve_rank_order=True`, matching the documented DeviceMesh contract and the existing `new_group` path. ### Behavior change Eager legacy NCCL, Gloo, XCCL, NCCL-lazy, TorchComms, and custom split backends now sort permuted subgroup ranks by default. This aligns them with non-eager initialization. Callers that need mesh order should pass `preserve_rank_order=True`. ### Validation The rank-order tests verify: - Default subgroup ranks are sorted. - `preserve_rank_order=True` follows mesh order. - The local rank matches the corresponding mesh coordinate. It covers the configured eager backend, explicit eager legacy NCCL, bound eager Gloo, and the existing eight-rank non-eager case. All four tests pass with the fix. Removing the sorting line makes both the legacy NCCL and Gloo regressions fail with reversed local ranks. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 agent_space/device-mesh-nightly/bin/python test/distributed/test_device_mesh.py DeviceMeshTest.test_device_mesh_preserve_rank_order_eager DeviceMeshTest.test_device_mesh_preserve_rank_order_eager_nccl_legacy DeviceMeshTestGlooBackend.test_device_mesh_preserve_rank_order_eager DeviceMeshTestNDim.test_device_mesh_preserve_rank_order -v ``` ```bash .venv/bin/spin quicklint ``` Pull Request resolved: pytorch#201949 Approved by: https://github.com/d4l3k (cherry picked from commit 020ab1c) Co-authored-by: Kapil Sharma <kapilsharma.frm@gmail.com>
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.
Go through the following checklist:
lintrunner -a)Summary (human written only)
Sort split ranks did not account for preserve_rank_order correctly and sorted subgroup ranks by default. This was happening in eager path
Agent details (AI-generated)
Root cause
The
new_groupDeviceMesh path sorts subgroup ranks by default and preserves mesh order whenpreserve_rank_order=True. The eager path instead passed mesh order directly tosplit_group, which intentionally preserves the supplied order. Default subgroup order therefore depended on the initialization path for every backend that supports splitting.Fix
Sort ranks before every
split_groupcall whenpreserve_rank_order=False. Keep mesh order whenpreserve_rank_order=True, matching the documented DeviceMesh contract and the existingnew_grouppath.Behavior change
Eager legacy NCCL, Gloo, XCCL, NCCL-lazy, TorchComms, and custom split backends now sort permuted subgroup ranks by default. This aligns them with non-eager initialization. Callers that need mesh order should pass
preserve_rank_order=True.Validation
The rank-order tests verify:
preserve_rank_order=Truefollows mesh order.It covers the configured eager backend, explicit eager legacy NCCL, bound eager Gloo, and the existing eight-rank non-eager case. All four tests pass with the fix. Removing the sorting line makes both the legacy NCCL and Gloo regressions fail with reversed local ranks.
Pull Request resolved: pytorch#201949
Approved by: https://github.com/d4l3k
(cherry picked from commit 020ab1c)