-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[AutoParallel] Enhance processmesh #72052
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b589534
processmesh support convert group
xuxinyi389 eb90714
add_test
xuxinyi389 8f9a061
fix_test
xuxinyi389 507ee54
fix_en_docs
xuxinyi389 7b7aa91
move_test
xuxinyi389 38f9e95
Merge branch 'develop' of https://github.com/xuxinyi389/Paddle into e…
xuxinyi389 fbcb1a3
fix_bugs_of_get_mesh_with_dim
xuxinyi389 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
138 changes: 138 additions & 0 deletions
138
test/auto_parallel/hybrid_strategy/process_mesh_demo_unittest.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import paddle | ||
import paddle.distributed as dist | ||
|
||
|
||
class TestProcessMesh: | ||
def init_dist_env(self): | ||
dist.init_parallel_env() | ||
paddle.seed(2025) | ||
|
||
def test_get_submesh_with_dim(self): | ||
curr_rank = dist.get_rank() | ||
|
||
# Test 2D mesh | ||
mesh_2d = dist.ProcessMesh([[0, 1], [2, 3]], dim_names=["dp", "tp"]) | ||
|
||
# Test case 1: Get submesh for dp dimension | ||
dp_mesh = mesh_2d.get_submesh_with_dim("dp") | ||
dp_mesh_ = mesh_2d["dp"] | ||
assert dp_mesh == dp_mesh_ | ||
if curr_rank == 0: | ||
assert dp_mesh.process_ids == [0, 2] | ||
elif curr_rank == 1: | ||
assert dp_mesh.process_ids == [1, 3] | ||
|
||
# Test case 2: Get submesh for tp dimension | ||
tp_mesh = mesh_2d.get_submesh_with_dim("tp") | ||
tp_mesh_ = mesh_2d["tp"] | ||
assert tp_mesh == tp_mesh_ | ||
if curr_rank == 0: | ||
assert tp_mesh.process_ids == [0, 1] | ||
elif curr_rank == 1: | ||
assert tp_mesh.process_ids == [0, 1] | ||
|
||
# Test case 3: 3D mesh with 8 cards (2x2x2) | ||
mesh_3d = dist.ProcessMesh( | ||
[[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dim_names=["pp", "dp", "tp"] | ||
) | ||
|
||
# Test each dimension | ||
pp_mesh = mesh_3d.get_submesh_with_dim("pp") | ||
pp_mesh_ = mesh_3d["pp"] | ||
assert pp_mesh == pp_mesh_ | ||
dp_mesh = mesh_3d.get_submesh_with_dim("dp") | ||
dp_mesh_ = mesh_3d["dp"] | ||
assert dp_mesh == dp_mesh_ | ||
tp_mesh = mesh_3d.get_submesh_with_dim("tp") | ||
tp_mesh_ = mesh_3d["tp"] | ||
assert tp_mesh == tp_mesh_ | ||
|
||
# Verify pp dimension results | ||
if curr_rank == 0: | ||
assert pp_mesh.process_ids == [0, 4] | ||
elif curr_rank == 1: | ||
assert pp_mesh.process_ids == [1, 5] | ||
|
||
# Verify dp dimension results | ||
if curr_rank == 0: | ||
assert dp_mesh.process_ids == [0, 2] | ||
elif curr_rank == 1: | ||
assert dp_mesh.process_ids == [1, 3] | ||
|
||
# Verify tp dimension results | ||
if curr_rank == 0: | ||
assert tp_mesh.process_ids == [0, 1] | ||
elif curr_rank == 1: | ||
assert tp_mesh.process_ids == [0, 1] | ||
|
||
# Test case 4: When rank is not in the mesh | ||
mesh_small = dist.ProcessMesh([0, 1], dim_names=["x"]) | ||
if curr_rank not in [0, 1]: | ||
assert mesh_small.get_submesh_with_dim("x") is None | ||
|
||
def test_get_group(self): | ||
curr_rank = dist.get_rank() | ||
|
||
# Test case 1: Single dimension mesh without dim_name | ||
mesh_1d = dist.ProcessMesh([0, 1], dim_names=["x"]) | ||
if curr_rank in [0, 1]: | ||
group_1d = mesh_1d.get_group() | ||
assert isinstance(group_1d, dist.communication.group.Group) | ||
|
||
# Test case 2: Single dimension mesh with correct dim_name | ||
group_1d_with_name = mesh_1d.get_group(dim_name="x") | ||
assert isinstance( | ||
group_1d_with_name, dist.communication.group.Group | ||
) | ||
|
||
# Test case 3: Single dimension mesh with wrong dim_name | ||
try: | ||
mesh_1d.get_group(dim_name="wrong_name") | ||
raise AssertionError("Should raise ValueError") | ||
except ValueError: | ||
pass | ||
|
||
# Test case 4: Multi-dimension mesh | ||
mesh_2d = dist.ProcessMesh([[0, 1], [2, 3]], dim_names=["dp", "tp"]) | ||
if curr_rank in [0, 1, 2, 3]: | ||
# Test without dim_name | ||
try: | ||
mesh_2d.get_group() | ||
raise AssertionError("Should raise ValueError") | ||
except ValueError: | ||
pass | ||
|
||
# Test with correct dim_name | ||
group_2d = mesh_2d.get_group(dim_name="dp") | ||
assert isinstance(group_2d, dist.communication.group.Group) | ||
|
||
# Test with wrong dim_name | ||
try: | ||
mesh_2d.get_group(dim_name="wrong_name") | ||
raise AssertionError("Should raise ValueError") | ||
except ValueError: | ||
pass | ||
|
||
def test_process_mesh(self): | ||
self.init_dist_env() | ||
self.test_get_submesh_with_dim() | ||
self.test_get_group() | ||
|
||
|
||
if __name__ == '__main__': | ||
TestProcessMesh().test_process_mesh() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
import collective.test_communication_api_base as test_base | ||
|
||
|
||
class TestProcessMeshPass(test_base.CommunicationTestDistBase): | ||
def setUp(self): | ||
super().setUp( | ||
num_of_devices=2, | ||
timeout=50, | ||
) | ||
self._default_envs = { | ||
"FLAGS_cudnn_deterministic": "1", | ||
"FLAGS_enable_pir_api": "1", | ||
} | ||
self._changeable_envs = { | ||
"backend": ["gpu"], | ||
} | ||
|
||
def test_process_mesh(self): | ||
envs_list = test_base.gen_product_envs_list( | ||
self._default_envs, self._changeable_envs | ||
) | ||
for envs in envs_list: | ||
self.run_test_case( | ||
"process_mesh_demo_unittest.py", | ||
user_defined_envs=envs, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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
Oops, something went wrong.
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.
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.
这个方法和
get_mesh_with_dim
有什么区别?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.
get_mesh_with_dim 只是对 mesh 的一个简单重排,如mesh.get_mesh_with_dim(“dp”)只是把mesh的dp维放在最外维,并没有减少mesh内process_ids。mesh.get_submesh_with_dim("dp")则是获取包含当前rank的dp通信组的submesh。比如说:mesh_2d = dist.ProcessMesh([[0, 1, 2, 3], [4, 5, 6, 7]], dim_names=["dp", "tp"])
dp_mesh = mesh_2d.get_submesh_with_dim("dp")
on rank 0, 4 returns a 1D submesh of ProcessMesh:([0, 4]).
on rank 1, 5 returns a 1D submesh of ProcessMesh:([1, 5]).
on rank 2, 6 returns a 1D submesh of ProcessMesh:([2, 6]).
on rank 3, 7 returns a 1D submesh of ProcessMesh:([3, 7]).