diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index 016695ef6..4a3da8e8d 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -3783,6 +3783,9 @@ "tag" ] }, + "torch.distributed.ProcessGroup": { + "Matcher": "ChangePrefixMatcher" + }, "torch.distributed.ReduceOp": { "Matcher": "ChangePrefixMatcher" }, @@ -3813,14 +3816,7 @@ } }, "torch.distributed.all_gather_object": { - "Matcher": "AllGatherObjectMatcher", - "paddle_api": "paddle.distributed.all_gather_object", - "args_list": [ - "object_list", - "obj", - "group" - ], - "min_input_args": 2 + "Matcher": "ChangePrefixMatcher" }, "torch.distributed.all_reduce": { "Matcher": "ReverseAsyncOpMatcher", @@ -3934,29 +3930,7 @@ "Matcher": "ChangePrefixMatcher" }, "torch.distributed.init_process_group": { - "Matcher": "GenericMatcher", - "paddle_api": "paddle.distributed.init_parallel_env", - "args_list": [ - "backend", - "init_method", - "timeout", - "world_size", - "rank", - "store", - "group_name", - "pg_options" - ], - "kwargs_change": { - "backend": "", - "init_method": "", - "timeout": "", - "world_size": "", - "rank": "", - "store": "", - "group_name": "", - "pg_options": "" - }, - "min_input_args": 0 + "Matcher": "ChangePrefixMatcher" }, "torch.distributed.irecv": { "Matcher": "GenericMatcher", diff --git a/paconvert/api_matcher.py b/paconvert/api_matcher.py index ad52765e8..d9baa116a 100644 --- a/paconvert/api_matcher.py +++ b/paconvert/api_matcher.py @@ -4710,27 +4710,6 @@ def generate_code(self, kwargs): return code -class AllGatherObjectMatcher(BaseMatcher): - def generate_code(self, kwargs): - if "group" not in kwargs: - kwargs["group"] = None - - API_TEMPLATE = textwrap.dedent( - """ - {}=[] - {}(object_list={}, obj={}, group={}) - """ - ) - return API_TEMPLATE.format( - kwargs["object_list"], - self.get_paddle_api(), - kwargs["object_list"], - kwargs["obj"], - kwargs["group"], - self.kwargs_to_str(kwargs), - ) - - class SetUpMatcher(BaseMatcher): def generate_code(self, kwargs): is_torch_cpp_extension = False diff --git a/paconvert/attribute_mapping.json b/paconvert/attribute_mapping.json index 5de97b70b..5fc3f259b 100644 --- a/paconvert/attribute_mapping.json +++ b/paconvert/attribute_mapping.json @@ -145,6 +145,9 @@ "torch.distributed.ReduceOp.SUM": { "Matcher": "ChangePrefixMatcher" }, + "torch.distributed.group.WORLD": { + "Matcher": "ChangePrefixMatcher" + }, "torch.distributions.Distribution.batch_shape": {}, "torch.distributions.Distribution.event_shape": {}, "torch.distributions.Distribution.mean": {}, diff --git a/tests/distributed/ProcessGroup.py b/tests/distributed/ProcessGroup.py new file mode 100644 index 000000000..5f367a47d --- /dev/null +++ b/tests/distributed/ProcessGroup.py @@ -0,0 +1,34 @@ +# Copyright (c) 2026 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 os + +import torch +import torch.distributed as dist + +dist.init_process_group(backend="nccl") +rank = dist.get_rank() +torch.cuda.set_device(rank) + +pg = dist.group.WORLD +if rank == 0: + data = torch.tensor([4, 5, 6]).cuda() +else: + data = torch.tensor([1, 2, 3]).cuda() +dist.all_reduce(data, group=pg) +result = data +# [5, 7, 9] (2 GPUs) +if rank == 0: + print(result) + torch.save(result.cpu(), os.environ["DUMP_FILE"]) diff --git a/tests/distributed/group_WORLD.py b/tests/distributed/group_WORLD.py new file mode 100644 index 000000000..d39760419 --- /dev/null +++ b/tests/distributed/group_WORLD.py @@ -0,0 +1,34 @@ +# Copyright (c) 2026 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 os + +import torch +import torch.distributed as dist + +dist.init_process_group(backend="nccl") +rank = dist.get_rank() +torch.cuda.set_device(rank) + +group = dist.group.WORLD +if rank == 0: + data = torch.tensor([4, 5, 6]).cuda() +else: + data = torch.tensor([1, 2, 3]).cuda() +dist.all_reduce(data, group=group) +result = data +# [5, 7, 9] (2 GPUs) +if rank == 0: + print(result) + torch.save(result.cpu(), os.environ["DUMP_FILE"]) diff --git a/tests/distributed/init_process_group.py b/tests/distributed/init_process_group.py index 5b5526aed..ff6295bd7 100644 --- a/tests/distributed/init_process_group.py +++ b/tests/distributed/init_process_group.py @@ -21,8 +21,6 @@ rank = dist.get_rank() torch.cuda.set_device(rank) -result = dist.is_initialized() - if rank == 0: - print(result) - torch.save(result, os.environ["DUMP_FILE"]) + print(rank) + torch.save(rank, os.environ["DUMP_FILE"])