Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cleanup][A-6] clean some VarType for test #61550

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions test/legacy_test/test_gaussian_random_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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,
Expand All @@ -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__":
Expand Down
7 changes: 4 additions & 3 deletions test/legacy_test/test_lod_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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),
Expand All @@ -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)

Expand Down Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_math_op_patch_var_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions test/legacy_test/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down