diff --git a/python/paddle/fluid/tests/unittests/test_erf_op.py b/python/paddle/fluid/tests/unittests/test_erf_op.py index 06b7f55069fb94d08dbdb5a5d551d23cff7d06ea..db5c48151c5052e83be61912ad7368b734c79aba 100644 --- a/python/paddle/fluid/tests/unittests/test_erf_op.py +++ b/python/paddle/fluid/tests/unittests/test_erf_op.py @@ -15,7 +15,7 @@ import unittest import numpy as np -from op_test import OpTest +from eager_op_test import OpTest from scipy.special import erf import paddle @@ -26,6 +26,7 @@ import paddle.fluid.dygraph as dg class TestErfOp(OpTest): def setUp(self): self.op_type = "erf" + self.python_api = paddle.erf self.dtype = self._init_dtype() self.x_shape = [11, 17] x = np.random.uniform(-1, 1, size=self.x_shape).astype(self.dtype) diff --git a/python/paddle/fluid/tests/unittests/test_expand_v2_op.py b/python/paddle/fluid/tests/unittests/test_expand_v2_op.py index 0a5eda417e95cd82b28f720d33729d9eb3231b43..0565be630a9421ec5a9313a1e73ca5a61ce9652f 100644 --- a/python/paddle/fluid/tests/unittests/test_expand_v2_op.py +++ b/python/paddle/fluid/tests/unittests/test_expand_v2_op.py @@ -17,7 +17,7 @@ import unittest import gradient_checker import numpy as np from decorator_helper import prog_scope -from op_test import OpTest +from eager_op_test import OpTest import paddle import paddle.fluid as fluid @@ -42,10 +42,10 @@ class TestExpandV2OpRank1(OpTest): self.expand_times = [1] def test_check_output(self): - self.check_output(check_eager=True) + self.check_output() def test_check_grad(self): - self.check_grad(['X'], 'Out', check_eager=True) + self.check_grad(['X'], 'Out') class TestExpandV2OpRank2_DimExpanding(TestExpandV2OpRank1): @@ -80,6 +80,7 @@ class TestExpandV2OpRank4(TestExpandV2OpRank1): class TestExpandV2OpRank1_tensor_attr(OpTest): def setUp(self): self.op_type = "expand_v2" + self.python_api = paddle.expand self.init_data() expand_shapes_tensor = [] for index, ele in enumerate(self.expand_shape): @@ -120,6 +121,7 @@ class TestExpandV2OpRank2_Corner_tensor_attr(TestExpandV2OpRank1_tensor_attr): class TestExpandV2OpRank1_tensor(OpTest): def setUp(self): self.op_type = "expand_v2" + self.python_api = paddle.expand self.init_data() self.inputs = { @@ -146,6 +148,7 @@ class TestExpandV2OpRank1_tensor(OpTest): class TestExpandV2OpInteger(OpTest): def setUp(self): self.op_type = "expand_v2" + self.python_api = paddle.expand self.inputs = { 'X': np.random.randint(10, size=(2, 4, 5)).astype("int32") } @@ -161,6 +164,7 @@ class TestExpandV2OpInteger(OpTest): class TestExpandV2OpBoolean(OpTest): def setUp(self): self.op_type = "expand_v2" + self.python_api = paddle.expand self.inputs = {'X': np.random.randint(2, size=(2, 4, 5)).astype("bool")} self.attrs = {'shape': [2, 4, 5]} output = np.tile(self.inputs['X'], (1, 1, 1)) @@ -174,6 +178,7 @@ class TestExpandV2OpBoolean(OpTest): class TestExpandV2OpInt64_t(OpTest): def setUp(self): self.op_type = "expand_v2" + self.python_api = paddle.expand self.inputs = { 'X': np.random.randint(10, size=(2, 4, 5)).astype("int64") } diff --git a/python/paddle/fluid/tests/unittests/test_gumbel_softmax_op.py b/python/paddle/fluid/tests/unittests/test_gumbel_softmax_op.py index 60b4cd5783347c5f15659fe0c6f676e1757b7ded..30e4d7943ff24a24d7f7de6dcf55c76c7eaa9801 100644 --- a/python/paddle/fluid/tests/unittests/test_gumbel_softmax_op.py +++ b/python/paddle/fluid/tests/unittests/test_gumbel_softmax_op.py @@ -13,10 +13,11 @@ import unittest import numpy as np -from op_test import OpTest +from eager_op_test import OpTest import paddle import paddle.fluid as fluid +import paddle.nn.functional as F paddle.enable_static() @@ -36,6 +37,7 @@ class TestGumbelSoftmaxOp(OpTest): def setUp(self): self.op_type = "gumbel_softmax" + self.python_api = F.gumbel_softmax self.init_attrs() np.random.seed(0) x = np.random.uniform(0.1, 1, self.shape).astype(self.dtype) @@ -53,6 +55,7 @@ class TestGumbelSoftmaxOp(OpTest): class TestGumbelSoftmax_ZeroDim(OpTest): def setUp(self): self.op_type = "gumbel_softmax" + self.python_api = F.gumbel_softmax self.dtype = "float64" x = np.random.uniform(0.1, 1, []).astype(self.dtype) out = np.array(1.0).astype(self.dtype) @@ -123,6 +126,7 @@ class TestGumbelSoftmaxOpSampleDistribution(OpTest): def setUp(self): self.op_type = "gumbel_softmax" + self.python_api = F.gumbel_softmax self.init_attrs() single_x = np.array([0.2, 0.3, 0.5]) batch_x = np.ones(self.shape) * single_x diff --git a/python/paddle/fluid/tests/unittests/test_is_empty_op.py b/python/paddle/fluid/tests/unittests/test_is_empty_op.py index 6cf410eaede84700d983b46751f5d15015e5791b..f771c33cb67e61d20a55eff33e4c6f563efd86c1 100644 --- a/python/paddle/fluid/tests/unittests/test_is_empty_op.py +++ b/python/paddle/fluid/tests/unittests/test_is_empty_op.py @@ -15,7 +15,7 @@ import unittest import numpy as np -from op_test import OpTest +from eager_op_test import OpTest import paddle @@ -23,6 +23,7 @@ import paddle class TestEmpty(OpTest): def setUp(self): self.op_type = "is_empty" + self.python_api = paddle.is_empty self.inputs = {'X': np.array([1, 2, 3])} self.outputs = {'Out': np.array([False])} @@ -33,6 +34,7 @@ class TestEmpty(OpTest): class TestNotEmpty(TestEmpty): def setUp(self): self.op_type = "is_empty" + self.python_api = paddle.is_empty self.inputs = {'X': np.array([])} self.outputs = {'Out': np.array([True])} diff --git a/python/paddle/fluid/tests/unittests/test_multiplex_op.py b/python/paddle/fluid/tests/unittests/test_multiplex_op.py index 563a9fdb34b34311b507620cdde5a65834d22b27..a0f8932ba23ab2ba2079d78346100f078ac42650 100644 --- a/python/paddle/fluid/tests/unittests/test_multiplex_op.py +++ b/python/paddle/fluid/tests/unittests/test_multiplex_op.py @@ -15,7 +15,7 @@ import unittest import numpy as np -from op_test import OpTest +from eager_op_test import OpTest import paddle import paddle.fluid as fluid @@ -24,6 +24,7 @@ import paddle.fluid as fluid class TestMultiplexOp(OpTest): def setUp(self): self.op_type = "multiplex" + self.python_api = paddle.tensor.multiplex rows = 4 index = np.arange(0, rows).astype('int32') np.random.shuffle(index) diff --git a/python/paddle/fluid/tests/unittests/test_transfer_layout_op.py b/python/paddle/fluid/tests/unittests/test_transfer_layout_op.py index 6c26a70694ac23bc8bb3530128ce3652e5cb36e9..fd65ddfa485275f8f9e47341945d604792e15295 100644 --- a/python/paddle/fluid/tests/unittests/test_transfer_layout_op.py +++ b/python/paddle/fluid/tests/unittests/test_transfer_layout_op.py @@ -15,7 +15,7 @@ import unittest import numpy as np -from op_test import OpTest +from eager_op_test import OpTest import paddle import paddle.fluid as fluid @@ -24,6 +24,10 @@ from paddle.fluid.framework import Program, program_guard from paddle.fluid.layer_helper import LayerHelper +def transpose_layout(x, src_layout, dst_layout): + return x.transpose([0, 2, 3, 1]) + + # default kNCHW class TestTransferLayoutOpkNCHWTokNHWC(OpTest): def setUp(self): @@ -31,6 +35,7 @@ class TestTransferLayoutOpkNCHWTokNHWC(OpTest): self.inputs = {'X': ipt.astype('float32')} self.outputs = {'Out': ipt.transpose([0, 2, 3, 1])} self.attrs = {'src_layout': 0, 'dst_layout': 1} # kNHWC + self.python_api = transpose_layout self.op_type = 'transfer_layout' def test_check_output(self): diff --git a/python/paddle/fluid/tests/unittests/test_transpose_op.py b/python/paddle/fluid/tests/unittests/test_transpose_op.py index a2f922dcd8db427b6c70666ca1b724fb9aa858a5..a05b2a5c0a30f2fa7cdb008af238bfeaeaa46e94 100644 --- a/python/paddle/fluid/tests/unittests/test_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_transpose_op.py @@ -17,12 +17,12 @@ import unittest import gradient_checker import numpy as np from decorator_helper import prog_scope +from eager_op_test import OpTest, convert_float_to_uint16 import paddle import paddle.fluid as fluid import paddle.fluid.core as core from paddle.fluid import Program, program_guard -from paddle.fluid.tests.unittests.op_test import OpTest, convert_float_to_uint16 paddle.enable_static() @@ -47,10 +47,10 @@ class TestTransposeOp(OpTest): self.use_mkldnn = False def test_check_output(self): - self.check_output(no_check_set=['XShape'], check_eager=True) + self.check_output(no_check_set=['XShape']) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_eager=True) + self.check_grad(['X'], 'Out') def initTestCase(self): self.shape = (3, 40) @@ -150,11 +150,11 @@ class TestAutoTuneTransposeOp(OpTest): self.use_mkldnn = False def test_check_output(self): - self.check_output(no_check_set=['XShape'], check_eager=True) + self.check_output(no_check_set=['XShape']) fluid.core.disable_autotune() def test_check_grad(self): - self.check_grad(['X'], 'Out', check_eager=True) + self.check_grad(['X'], 'Out') class TestTransposeBF16Op(OpTest): @@ -162,6 +162,7 @@ class TestTransposeBF16Op(OpTest): self.init_op_type() self.initTestCase() self.dtype = np.uint16 + self.python_api = paddle.transpose x = np.random.random(self.shape).astype("float32") self.inputs = {'X': convert_float_to_uint16(x)} @@ -580,7 +581,8 @@ class TestTransposeAPI_ZeroDim(unittest.TestCase): x = paddle.rand([]) x.stop_gradient = False out = paddle.transpose(x, []) - out.retain_grads() + if hasattr(out, 'retain_grads'): + out.retain_grads() out.backward() self.assertEqual(out.shape, [])