From 21fbc61aeef877c0457e0542235858ac205f3ca2 Mon Sep 17 00:00:00 2001 From: ZhouDuan <1184319564@qq.com> Date: Mon, 20 Oct 2025 02:58:34 +0000 Subject: [PATCH 1/4] fix some tests --- test/legacy_test/test_label_smooth_op.py | 2 +- test/legacy_test/test_max_op.py | 3 ++- test/legacy_test/test_min_op.py | 3 ++- test/legacy_test/test_sgd_op_bf16.py | 16 +++++++++++----- test/legacy_test/test_shape_op.py | 2 +- test/legacy_test/test_where_op.py | 6 +++--- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/test/legacy_test/test_label_smooth_op.py b/test/legacy_test/test_label_smooth_op.py index d28443863c1d4d..59621a12586c52 100644 --- a/test/legacy_test/test_label_smooth_op.py +++ b/test/legacy_test/test_label_smooth_op.py @@ -58,7 +58,7 @@ def test_check_grad(self): @unittest.skipIf( not (core.is_compiled_with_cuda() or is_custom_device()) - or not core.supports_bfloat16(), + or not core.is_bfloat16_supported(get_device_place()), "core is not compiled with CUDA or place do not support bfloat16", ) class TestLabelSmoothOpBF16(OpTest): diff --git a/test/legacy_test/test_max_op.py b/test/legacy_test/test_max_op.py index 00d37b17734112..a0eb80b2bae468 100644 --- a/test/legacy_test/test_max_op.py +++ b/test/legacy_test/test_max_op.py @@ -232,7 +232,8 @@ def test_check_grad(self): @unittest.skipIf( - not core.supports_bfloat16(), "place does not support BF16 evaluation" + not core.is_bfloat16_supported(get_device_place()), + "place does not support BF16 evaluation", ) class TestMaxBfloat16(unittest.TestCase): def init_data(self): diff --git a/test/legacy_test/test_min_op.py b/test/legacy_test/test_min_op.py index 49fbf88bae386a..8d51da32e99a10 100644 --- a/test/legacy_test/test_min_op.py +++ b/test/legacy_test/test_min_op.py @@ -220,7 +220,8 @@ def test_check_grad(self): @unittest.skipIf( - not core.supports_bfloat16(), "place does not support BF16 evaluation" + not core.is_bfloat16_supported(get_device_place()), + "place does not support BF16 evaluation", ) class TestMinBfloat16(unittest.TestCase): def init_data(self): diff --git a/test/legacy_test/test_sgd_op_bf16.py b/test/legacy_test/test_sgd_op_bf16.py index 1791fff375c99f..ccc5e605614426 100644 --- a/test/legacy_test/test_sgd_op_bf16.py +++ b/test/legacy_test/test_sgd_op_bf16.py @@ -22,6 +22,7 @@ OpTestTool, convert_float_to_uint16, convert_uint16_to_float, + get_device_place, ) from utils import compare_legacy_with_pt @@ -32,7 +33,8 @@ @unittest.skipIf( - not core.supports_bfloat16(), 'place does not support BF16 evaluation' + not core.is_bfloat16_supported(get_device_place()), + 'place does not support BF16 evaluation', ) class TestSGDOpBF16(OpTest): def setUp(self): @@ -62,7 +64,8 @@ def test_check_output(self): @unittest.skipIf( - not core.supports_bfloat16(), 'place does not support BF16 evaluation' + not core.is_bfloat16_supported(get_device_place()), + 'place does not support BF16 evaluation', ) class TestSGDOpBF16Case2(TestSGDOpBF16): def conf(self): @@ -129,7 +132,8 @@ def create_dense_lr_var(self, scope, place): @unittest.skipIf( - not core.supports_bfloat16(), 'place does not support BF16 evaluation' + not core.is_bfloat16_supported(get_device_place()), + 'place does not support BF16 evaluation', ) class TestSparseGradSGDOpBF16(TestSparseSGDOpBF16): def setUp(self): @@ -169,7 +173,8 @@ def test_sparse_grad_sgd(self): @unittest.skipIf( - not core.supports_bfloat16(), 'place does not support BF16 evaluation' + not core.is_bfloat16_supported(get_device_place()), + 'place does not support BF16 evaluation', ) class TestSparseGradSGDOpBF16Case2(TestSparseGradSGDOpBF16): def setup_params(self): @@ -186,7 +191,8 @@ def setup_params(self): @unittest.skipIf( - not core.supports_bfloat16(), 'place does not support BF16 evaluation' + not core.is_bfloat16_supported(get_device_place()), + 'place does not support BF16 evaluation', ) class TestSparseGradParamSGDOpBF16(TestSparseSGDOpBF16): def setUp(self): diff --git a/test/legacy_test/test_shape_op.py b/test/legacy_test/test_shape_op.py index 7f879eea8d1a1f..f468e1cbe9aa26 100644 --- a/test/legacy_test/test_shape_op.py +++ b/test/legacy_test/test_shape_op.py @@ -110,7 +110,7 @@ def test_check_output(self): @unittest.skipIf( not (core.is_compiled_with_cuda() or is_custom_device()) - or not core.supports_bfloat16(), + or not core.is_bfloat16_supported(get_device_place()), "core is not compiled with CUDA or place do not support bfloat16", ) class TestShapeOpBf16(OpTest): diff --git a/test/legacy_test/test_where_op.py b/test/legacy_test/test_where_op.py index b52ed925f8ac43..055660cd802839 100644 --- a/test/legacy_test/test_where_op.py +++ b/test/legacy_test/test_where_op.py @@ -549,7 +549,7 @@ def test_static_api_type_promotion_fp32_fp64(self): @unittest.skipIf( not ( (paddle.is_compiled_with_cuda() or is_custom_device()) - and paddle.base.core.supports_bfloat16() + and paddle.base.core.is_bfloat16_supported(get_device_place()) ), "bf16 is not supported in current device", ) @@ -562,7 +562,7 @@ def test_static_api_type_promotion_bf16_fp16(self): @unittest.skipIf( not ( (paddle.is_compiled_with_cuda() or is_custom_device()) - and paddle.base.core.supports_bfloat16() + and paddle.base.core.is_bfloat16_supported(get_device_place()) ), "bf16 is not supported in current device", ) @@ -575,7 +575,7 @@ def test_static_api_type_promotion_bf16_fp32(self): @unittest.skipIf( not ( (paddle.is_compiled_with_cuda() or is_custom_device()) - and paddle.base.core.supports_bfloat16() + and paddle.base.core.is_bfloat16_supported(get_device_place()) ), "bf16 is not supported in current device", ) From 5d84b4fe9a1334374ebb155e2e27f64ff6cbd65b Mon Sep 17 00:00:00 2001 From: ZhouDuan <1184319564@qq.com> Date: Thu, 23 Oct 2025 12:26:51 +0000 Subject: [PATCH 2/4] fix some tests --- test/legacy_test/test_elementwise_min_op.py | 11 +++-------- test/legacy_test/test_embedding_deterministic.py | 2 +- test/legacy_test/test_randint_op.py | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/test/legacy_test/test_elementwise_min_op.py b/test/legacy_test/test_elementwise_min_op.py index a23b15ebe0062e..ca7006c969f874 100644 --- a/test/legacy_test/test_elementwise_min_op.py +++ b/test/legacy_test/test_elementwise_min_op.py @@ -17,13 +17,12 @@ import numpy as np from op_test import ( OpTest, + check_cudnn_version_and_compute_capability, convert_float_to_uint16, - is_custom_device, skip_check_grad_ci, ) import paddle -from paddle.base import core paddle.enable_static() @@ -315,12 +314,8 @@ def setUp(self): @unittest.skipIf( - (core.is_compiled_with_cuda() or is_custom_device()) - and ( - core.cudnn_version() < 8100 - or paddle.device.cuda.get_device_capability()[0] < 8 - ), - "run test when gpu is available and the minimum cudnn version is 8.1.0 and gpu's compute capability is at least 8.0.", + not check_cudnn_version_and_compute_capability(8100, 8), + "only support compiled with CUDA or custom device, and for CUDA cudnn version need larger than 8.1.0 and device's compute capability is at least 8.0", ) class TestElementwiseBF16Op(OpTest): def init_data(self): diff --git a/test/legacy_test/test_embedding_deterministic.py b/test/legacy_test/test_embedding_deterministic.py index 359da818c206fc..86de9764388f47 100644 --- a/test/legacy_test/test_embedding_deterministic.py +++ b/test/legacy_test/test_embedding_deterministic.py @@ -121,7 +121,7 @@ def get_all_dtypes(): paddle.complex64, paddle.complex128, ] - if 'A100' in paddle.device.cuda.get_device_properties().name: + if 'A100' in paddle.device.get_device_properties().name: dtypes.append(paddle.bfloat16) return dtypes diff --git a/test/legacy_test/test_randint_op.py b/test/legacy_test/test_randint_op.py index f56b15a27946fa..809b1b26c1b1d4 100644 --- a/test/legacy_test/test_randint_op.py +++ b/test/legacy_test/test_randint_op.py @@ -171,7 +171,7 @@ def test_fixed_random_number(self): return # Different GPU generatte different random value. Only test V100 here. - if "V100" not in paddle.device.cuda.get_device_name(): + if "V100" not in paddle.device.get_device_name(): return print("Test Fixed Random number on GPU------>") From 2e9087cbb1aec08d0f10aaab45c4af352a0c2a3b Mon Sep 17 00:00:00 2001 From: ZhouDuan <1184319564@qq.com> Date: Mon, 27 Oct 2025 08:23:51 +0000 Subject: [PATCH 3/4] fix some tests --- test/legacy_test/test_as_strided.py | 4 ++-- test/legacy_test/test_full_like_op.py | 6 ++++-- test/legacy_test/test_index_select_strided.py | 4 ++-- test/legacy_test/test_slice_op.py | 2 +- test/legacy_test/test_tensor_unfold.py | 6 +++--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/test/legacy_test/test_as_strided.py b/test/legacy_test/test_as_strided.py index bd23952bb10a19..6a000b9d268f98 100644 --- a/test/legacy_test/test_as_strided.py +++ b/test/legacy_test/test_as_strided.py @@ -15,7 +15,7 @@ import unittest import numpy as np -from op_test import get_device, get_places, is_custom_device +from op_test import get_device, get_places import paddle from paddle import base @@ -26,7 +26,7 @@ def setUp(self): self.shape = [32, 32] self.typelist = ['float32', 'float64', 'int32', 'int64', 'float16'] self.places = get_places() - if base.core.is_compiled_with_cuda() or is_custom_device(): + if base.core.is_compiled_with_cuda(): self.places.append(base.CUDAPinnedPlace()) def test_as_strided_forward(self): diff --git a/test/legacy_test/test_full_like_op.py b/test/legacy_test/test_full_like_op.py index 682989b1180197..3c03cf2ad69381 100644 --- a/test/legacy_test/test_full_like_op.py +++ b/test/legacy_test/test_full_like_op.py @@ -29,6 +29,8 @@ from paddle.base.framework import convert_np_dtype_to_dtype_ from paddle.framework import in_pir_mode +paddle.enable_static() + def fill_any_like_wrapper(x, value, out_dtype=None, name=None): if isinstance(out_dtype, int): @@ -216,7 +218,7 @@ def if_enable_cinn(self): @unittest.skipIf( - not (core.is_compiled_with_cuda() or is_custom_device()), + not (core.is_compiled_with_cuda()), "core is not compiled with CUDA", ) class TestFullLikeOp4(unittest.TestCase): @@ -278,7 +280,7 @@ def test_full_kernel_cpu_zero_size(self): ) def test_full_kernel_gpu_zero_size(self): paddle.disable_static() - paddle.set_device("gpu:0") + paddle.set_device(get_device_place()) value = 5.5 dtype = "float32" shape = [0, 3] diff --git a/test/legacy_test/test_index_select_strided.py b/test/legacy_test/test_index_select_strided.py index 15f0364df9111f..913e5042572d66 100644 --- a/test/legacy_test/test_index_select_strided.py +++ b/test/legacy_test/test_index_select_strided.py @@ -15,7 +15,7 @@ import unittest import numpy as np -from op_test import get_device, get_places, is_custom_device +from op_test import get_device, get_places import paddle from paddle import base @@ -26,7 +26,7 @@ def setUp(self): self.shape = [3, 3] self.typelist = ['float32', 'float64', 'int32', 'int64', 'float16'] self.places = get_places() - if base.core.is_compiled_with_cuda() or is_custom_device(): + if base.core.is_compiled_with_cuda(): self.places.append(base.CUDAPinnedPlace()) def test_index_select_strided_forward(self): diff --git a/test/legacy_test/test_slice_op.py b/test/legacy_test/test_slice_op.py index e0e77923005f2f..fe203750ed3b02 100644 --- a/test/legacy_test/test_slice_op.py +++ b/test/legacy_test/test_slice_op.py @@ -1182,7 +1182,7 @@ def test_dismatch_shape(self): @unittest.skipIf( - not (core.is_compiled_with_cuda() or is_custom_device()), + not (core.is_compiled_with_cuda()), "core is not compiled with CUDA", ) class TestImperativeCUDAPinnedInput(unittest.TestCase): diff --git a/test/legacy_test/test_tensor_unfold.py b/test/legacy_test/test_tensor_unfold.py index 96b931516add80..abb8f3cc154731 100644 --- a/test/legacy_test/test_tensor_unfold.py +++ b/test/legacy_test/test_tensor_unfold.py @@ -15,7 +15,7 @@ import unittest import numpy as np -from op_test import get_device, get_places, is_custom_device +from op_test import get_device, get_places import paddle from paddle import base @@ -26,7 +26,7 @@ def setUp(self): self.shape = [5, 5] self.typelist = ['float32', 'float64', 'int32', 'int64', 'float16'] self.places = get_places() - if base.core.is_compiled_with_cuda() or is_custom_device(): + if base.core.is_compiled_with_cuda(): self.places.append(base.CUDAPinnedPlace()) def test_tensor_unfold_forward(self): @@ -64,7 +64,7 @@ def setUp(self): self.shape = [12] self.typelist = ['float32', 'float64', 'int32', 'int64', 'float16'] self.places = get_places() - if base.core.is_compiled_with_cuda() or is_custom_device(): + if base.core.is_compiled_with_cuda(): self.places.append(base.CUDAPinnedPlace()) def test_tensor_unfold_forward(self): From 703265e803281b1392c080e7cff028616238b793 Mon Sep 17 00:00:00 2001 From: ZhouDuan <1184319564@qq.com> Date: Wed, 29 Oct 2025 09:24:16 +0000 Subject: [PATCH 4/4] fix two tests --- test/legacy_test/test_rnn_decode_api.py | 11 +++++------ test/legacy_test/test_set_value_op.py | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/test/legacy_test/test_rnn_decode_api.py b/test/legacy_test/test_rnn_decode_api.py index 9a5450bc890842..a425847adba6bf 100644 --- a/test/legacy_test/test_rnn_decode_api.py +++ b/test/legacy_test/test_rnn_decode_api.py @@ -16,7 +16,7 @@ import unittest import numpy as np -from op_test import is_custom_device +from op_test import get_device_place, is_custom_device import paddle from paddle import Model, base, nn, set_device @@ -337,11 +337,10 @@ def check_output_with_place(self, place, mode="test"): ) def check_output(self): - devices = ( - ["CPU", "GPU"] - if (base.is_compiled_with_cuda() or is_custom_device()) - else ["CPU"] - ) + devices = ["CPU"] + if base.is_compiled_with_cuda() or is_custom_device(): + devices.append(get_device_place()) + for device in devices: place = set_device(device) self.check_output_with_place(place) diff --git a/test/legacy_test/test_set_value_op.py b/test/legacy_test/test_set_value_op.py index 5539edeb908cfa..dc6552aea6e93e 100644 --- a/test/legacy_test/test_set_value_op.py +++ b/test/legacy_test/test_set_value_op.py @@ -1801,15 +1801,15 @@ def test_value_input_is_scalar(self): ) class TestSetValueWithStrideError(unittest.TestCase): def test_same_place(self): - x = paddle.rand([5, 10], device=paddle.CUDAPlace(0)) - y = paddle.rand([10, 5], device=paddle.CUDAPlace(0)) + x = paddle.rand([5, 10], device=get_device_place()) + y = paddle.rand([10, 5], device=get_device_place()) y.transpose_([1, 0]) x.set_value(y) assert x.is_contiguous() def test_different_place1(self): # src place != dst place && src is not contiguous - x = paddle.rand([5, 10], device=paddle.CUDAPlace(0)) + x = paddle.rand([5, 10], device=get_device_place()) y = paddle.rand([10, 5], device=paddle.CPUPlace()) y.transpose_([1, 0]) x.set_value(y) @@ -1818,7 +1818,7 @@ def test_different_place1(self): def test_different_place2(self): # src place != dst place && dst is not contiguous with self.assertRaises(SystemError): - x = paddle.ones([5, 4], device=paddle.CUDAPlace(0)) + x = paddle.ones([5, 4], device=get_device_place()) x.transpose_([1, 0]) y = paddle.rand([4, 2], device=paddle.CPUPlace()) assert not x.is_contiguous()