diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index 2b4e144f8..e408a02a9 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -3762,6 +3762,9 @@ "torch.cuda.CharTensor": { "Matcher": "ChangePrefixMatcher" }, + "torch.cuda.CudaError": { + "Matcher": "ChangePrefixMatcher" + }, "torch.cuda.DoubleTensor": { "Matcher": "ChangePrefixMatcher" }, @@ -3780,6 +3783,9 @@ "torch.cuda.LongTensor": { "Matcher": "ChangePrefixMatcher" }, + "torch.cuda.OutOfMemoryError": { + "Matcher": "ChangePrefixMatcher" + }, "torch.cuda.ShortTensor": { "Matcher": "ChangePrefixMatcher" }, diff --git a/tests/test_cuda_CudaError.py b/tests/test_cuda_CudaError.py new file mode 100644 index 000000000..623b76fe8 --- /dev/null +++ b/tests/test_cuda_CudaError.py @@ -0,0 +1,48 @@ +# 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.CudaError") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + try: + raise torch.cuda.CudaError("test") + except torch.cuda.CudaError as e: + result = str(e) + """ + ) + obj.run( + pytorch_code, + expect_paddle_code="import paddle\n\ntry:\n raise paddle.cuda.CudaError(\"test\")\nexcept paddle.cuda.CudaError as e:\n result = str(e)\n", + ) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = issubclass(torch.cuda.CudaError, RuntimeError) + """ + ) + obj.run( + pytorch_code, + expect_paddle_code="import paddle\n\nresult = issubclass(paddle.cuda.CudaError, RuntimeError)\n", + ) diff --git a/tests/test_cuda_OutOfMemoryError.py b/tests/test_cuda_OutOfMemoryError.py new file mode 100644 index 000000000..91de1f0cd --- /dev/null +++ b/tests/test_cuda_OutOfMemoryError.py @@ -0,0 +1,48 @@ +# 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.OutOfMemoryError") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + try: + raise torch.cuda.OutOfMemoryError("test") + except torch.cuda.OutOfMemoryError as e: + result = str(e) + """ + ) + obj.run( + pytorch_code, + expect_paddle_code="import paddle\n\ntry:\n raise paddle.cuda.OutOfMemoryError(\"test\")\nexcept paddle.cuda.OutOfMemoryError as e:\n result = str(e)\n", + ) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = issubclass(torch.cuda.OutOfMemoryError, RuntimeError) + """ + ) + obj.run( + pytorch_code, + expect_paddle_code="import paddle\n\nresult = issubclass(paddle.cuda.OutOfMemoryError, RuntimeError)\n", + )