diff --git a/test/legacy_test/test_gaussian_random_op.py b/test/legacy_test/test_gaussian_random_op.py index 2a0f30a84e03c..1600013af6aa2 100644 --- a/test/legacy_test/test_gaussian_random_op.py +++ b/test/legacy_test/test_gaussian_random_op.py @@ -75,7 +75,7 @@ def setUp(self): "mean": self.mean, "std": self.std, "seed": 10, - "dtype": paddle.base.core.VarDesc.VarType.FP16, + "dtype": paddle.float16, "use_mkldnn": self.use_mkldnn, } paddle.seed(10) @@ -128,7 +128,7 @@ def setUp(self): "mean": self.mean, "std": self.std, "seed": 10, - "dtype": paddle.base.core.VarDesc.VarType.BF16, + "dtype": paddle.bfloat16, "use_mkldnn": self.use_mkldnn, } paddle.seed(10) @@ -346,17 +346,17 @@ def test_default_dtype(self): def test_default_fp16(): paddle.framework.set_default_dtype('float16') out = paddle.tensor.random.gaussian([2, 3]) - self.assertEqual(out.dtype, base.core.VarDesc.VarType.FP16) + self.assertEqual(out.dtype, paddle.float16) def test_default_fp32(): paddle.framework.set_default_dtype('float32') out = paddle.tensor.random.gaussian([2, 3]) - self.assertEqual(out.dtype, base.core.VarDesc.VarType.FP32) + self.assertEqual(out.dtype, paddle.float32) def test_default_fp64(): paddle.framework.set_default_dtype('float64') out = paddle.tensor.random.gaussian([2, 3]) - self.assertEqual(out.dtype, base.core.VarDesc.VarType.FP64) + self.assertEqual(out.dtype, paddle.float64) if paddle.is_compiled_with_cuda(): paddle.set_device('gpu') @@ -370,17 +370,17 @@ def test_default_dtype(self): def test_default_fp16(): paddle.framework.set_default_dtype('float16') out = paddle.tensor.random.standard_normal([2, 3]) - self.assertEqual(out.dtype, base.core.VarDesc.VarType.FP16) + self.assertEqual(out.dtype, paddle.float16) def test_default_fp32(): paddle.framework.set_default_dtype('float32') out = paddle.tensor.random.standard_normal([2, 3]) - self.assertEqual(out.dtype, base.core.VarDesc.VarType.FP32) + self.assertEqual(out.dtype, paddle.float32) def test_default_fp64(): paddle.framework.set_default_dtype('float64') out = paddle.tensor.random.standard_normal([2, 3]) - self.assertEqual(out.dtype, base.core.VarDesc.VarType.FP64) + self.assertEqual(out.dtype, paddle.float64) if paddle.is_compiled_with_cuda(): paddle.set_device('gpu') @@ -428,9 +428,7 @@ def _check_random_value(dtype, expect, expect_mean, expect_std): -0.0000053026194133403266873214888799115129813799285329878330230713 ) expect_std = 0.99999191058126390974081232343451119959354400634765625 - _check_random_value( - core.VarDesc.VarType.FP64, expect, expect_mean, expect_std - ) + _check_random_value(paddle.float64, expect, expect_mean, expect_std) expect = [ -0.7988942, @@ -446,9 +444,7 @@ def _check_random_value(dtype, expect, expect_mean, expect_std): ] expect_mean = -0.00004762359094456769526004791259765625 expect_std = 0.999975681304931640625 - _check_random_value( - core.VarDesc.VarType.FP32, expect, expect_mean, expect_std - ) + _check_random_value(paddle.float32, expect, expect_mean, expect_std) if __name__ == "__main__": diff --git a/test/legacy_test/test_lod_tensor.py b/test/legacy_test/test_lod_tensor.py index 4bfe899787e8b..5703fa8bb26e7 100644 --- a/test/legacy_test/test_lod_tensor.py +++ b/test/legacy_test/test_lod_tensor.py @@ -16,6 +16,7 @@ import numpy as np +import paddle from paddle import base from paddle.base import core from paddle.base.lod_tensor import ( @@ -84,7 +85,7 @@ def test_create_lod_tensor(self): self.assertEqual( tensor.recursive_sequence_lengths(), correct_recursive_seq_lens ) - self.assertEqual(tensor._dtype(), core.VarDesc.VarType.INT64) + self.assertEqual(tensor._dtype(), paddle.int64) self.assertEqual(tensor.shape(), [5, 1]) np.testing.assert_array_equal( np.array(tensor), @@ -98,7 +99,7 @@ def test_create_lod_tensor(self): self.assertEqual( tensor.recursive_sequence_lengths(), recursive_seq_lens ) - self.assertEqual(tensor._dtype(), core.VarDesc.VarType.FP64) + self.assertEqual(tensor._dtype(), paddle.float64) self.assertEqual(tensor.shape(), [10, 1]) np.testing.assert_array_equal(np.array(tensor), data) @@ -182,7 +183,7 @@ def test_as_type(self): [[1, 3]], base.CPUPlace(), ) - fp32_tensor = tensor._as_type(core.VarDesc.VarType.FP32) + fp32_tensor = tensor._as_type(paddle.float32) print(fp32_tensor) diff --git a/test/legacy_test/test_math_op_patch.py b/test/legacy_test/test_math_op_patch.py index fc0446dac5433..fe0708098fb72 100644 --- a/test/legacy_test/test_math_op_patch.py +++ b/test/legacy_test/test_math_op_patch.py @@ -230,7 +230,7 @@ def test_equal(self): ) np.testing.assert_array_equal(c_np, a_np == b_np) - self.assertEqual(c.dtype, base.core.VarDesc.VarType.BOOL) + self.assertEqual(c.dtype, paddle.bool) @prog_scope() @test_with_pir_api diff --git a/test/legacy_test/test_math_op_patch_var_base.py b/test/legacy_test/test_math_op_patch_var_base.py index 1953d8d3dd242..93581476d1092 100644 --- a/test/legacy_test/test_math_op_patch_var_base.py +++ b/test/legacy_test/test_math_op_patch_var_base.py @@ -556,7 +556,7 @@ def test_astype(self): a = paddle.to_tensor(a_np) res1 = a.astype(np.float16) res2 = a.astype('float16') - res3 = a.astype(base.core.VarDesc.VarType.FP16) + res3 = a.astype(paddle.float16) self.assertEqual(res1.dtype, res2.dtype) self.assertEqual(res1.dtype, res3.dtype) @@ -571,7 +571,7 @@ def test_conpare_op_broadcast(self): a = paddle.to_tensor(a_np) b = paddle.to_tensor(b_np) - self.assertEqual((a != b).dtype, base.core.VarDesc.VarType.BOOL) + self.assertEqual((a != b).dtype, paddle.bool) np.testing.assert_array_equal((a != b).numpy(), a_np != b_np) def test_tensor_patch_method(self): diff --git a/test/legacy_test/test_parameter.py b/test/legacy_test/test_parameter.py index 415167e31fe61..2b17788c780e5 100644 --- a/test/legacy_test/test_parameter.py +++ b/test/legacy_test/test_parameter.py @@ -18,7 +18,6 @@ import numpy as np import paddle -from paddle.base import core from paddle.base.dygraph import guard from paddle.base.executor import Executor from paddle.base.framework import Variable, default_main_program @@ -41,7 +40,7 @@ def test_parameter(self): self.assertIsNotNone(param) self.assertEqual('fc.w', param.name) self.assertEqual((784, 100), param.shape) - self.assertEqual(core.VarDesc.VarType.FP32, param.dtype) + self.assertEqual(paddle.float32, param.dtype) self.assertEqual(0, param.block.idx) exe = Executor(paddle.CPUPlace()) p = exe.run(main_program, fetch_list=[param])[0]