diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index 60e412db5..c50c53744 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -4894,6 +4894,16 @@ "device": "device" } }, + "torch.cuda.device": { + "Matcher": "GenericMatcher", + "paddle_api": "paddle.CUDAPlace", + "args_list": [ + "device" + ], + "kwargs_change": { + "device": "id" + } + }, "torch.cuda.device_count": { "Matcher": "GenericMatcher", "paddle_api": "paddle.device.cuda.device_count", @@ -12421,6 +12431,15 @@ ], "min_input_args": 1 }, + "torch.nn.parallel.comm.broadcast": { + "Matcher": "GenericMatcher", + "paddle_api": "paddle.distributed.broadcast", + "args_list": [ + "tensor", + "devices", + "out" + ] + }, "torch.nn.utils.clip_grad_norm_": { "Matcher": "GenericMatcher", "paddle_api": "paddle.nn.utils.clip_grad_norm_", diff --git a/tests/test_cuda_device.py b/tests/test_cuda_device.py new file mode 100644 index 000000000..93245d0b7 --- /dev/null +++ b/tests/test_cuda_device.py @@ -0,0 +1,34 @@ +# Copyright (c) 2023 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 textwrap + +from apibase import APIBase + +obj = APIBase("torch.cuda.device") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = None + if torch.cuda.is_available(): + result = torch.cuda.device(0) + """ + ) + obj.run( + pytorch_code, + ["result"], + ) diff --git a/tests/test_nn_parallel_comm_broadcast.py b/tests/test_nn_parallel_comm_broadcast.py new file mode 100644 index 000000000..5cd136895 --- /dev/null +++ b/tests/test_nn_parallel_comm_broadcast.py @@ -0,0 +1,31 @@ +# Copyright (c) 2023 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 textwrap + +from apibase import APIBase + +obj = APIBase("torch.nn.parallel.comm.broadcast") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1., 2.]) + device = ['cuda:0'] + result = torch.nn.parallel.comm.broadcast(input, device) + """ + ) + obj.run(pytorch_code, ["result"])