未验证 提交 675b3486 编写于 作者: 姜永久 提交者: GitHub

rm unittests eager guard tests part22 tril2warpctc (#48893)

上级 fb8f2de6
......@@ -19,7 +19,6 @@ from op_test import OpTest
import paddle
import paddle.fluid as fluid
from paddle.fluid.framework import _test_eager_guard
class TestTrilIndicesOp(OpTest):
......@@ -89,10 +88,6 @@ class TestTrilIndicesAPICaseDygraph(unittest.TestCase):
expected_result1 = np.tril_indices(4, 2, 4)
self.assertEqual((out1.numpy() == expected_result1).all(), True)
def test_dygraph_eager(self):
with _test_eager_guard():
self.test_dygraph()
class TestTrilIndicesAPICaseError(unittest.TestCase):
def test_case_error(self):
......
......@@ -19,7 +19,6 @@ from op_test import OpTest
import paddle
import paddle.fluid as fluid
from paddle.fluid.framework import _test_eager_guard
class TestTriuIndicesOp(OpTest):
......@@ -84,10 +83,6 @@ class TestTriuIndicesAPICaseDygraph(unittest.TestCase):
expected_result = np.triu_indices(4, 2, 4)
np.testing.assert_array_equal(out, expected_result)
def test_dygraph_eager(self):
with _test_eager_guard():
self.test_dygraph()
class TestTriuIndicesAPICaseError(unittest.TestCase):
def test_case_error(self):
......
......@@ -18,7 +18,6 @@ import numpy as np
from op_test import OpTest
import paddle
from paddle.fluid.framework import _test_eager_guard
paddle.enable_static()
......@@ -85,20 +84,6 @@ class TestTruncAPI(unittest.TestCase):
np.testing.assert_allclose(out.numpy(), out_ref, rtol=1e-08)
paddle.enable_static()
def test_api_eager(self):
paddle.disable_static(self.place)
with _test_eager_guard():
x_tensor = paddle.to_tensor(self.x)
out = paddle.trunc(x_tensor)
out_ref = np.trunc(self.x)
np.testing.assert_allclose(out.numpy(), out_ref, rtol=1e-08)
paddle.enable_static()
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_api_dygraph()
def test_errors(self):
with paddle.static.program_guard(paddle.static.Program()):
x = paddle.fluid.data('X', [20, 20], 'bool')
......
......@@ -20,7 +20,6 @@ import paddle
import paddle.fluid as fluid
import paddle.fluid.core as core
from paddle.fluid.executor import Executor
from paddle.fluid.framework import _test_eager_guard
class TestTrunctedGaussianRandomOp(unittest.TestCase):
......@@ -70,17 +69,16 @@ class TestTrunctedGaussianRandomOp(unittest.TestCase):
# directly
def gaussian_random_test_eager(self, place):
with fluid.dygraph.guard(place):
with _test_eager_guard():
out = paddle._C_ops.truncated_gaussian_random(
self.attrs["shape"],
self.attrs["mean"],
self.attrs["std"],
self.attrs["seed"],
core.VarDesc.VarType.FP32,
place,
)
self.assertAlmostEqual(numpy.mean(out.numpy()), 0.0, delta=0.1)
self.assertAlmostEqual(numpy.var(out.numpy()), 0.773, delta=0.1)
out = paddle._C_ops.truncated_gaussian_random(
self.attrs["shape"],
self.attrs["mean"],
self.attrs["std"],
self.attrs["seed"],
core.VarDesc.VarType.FP32,
place,
)
self.assertAlmostEqual(numpy.mean(out.numpy()), 0.0, delta=0.1)
self.assertAlmostEqual(numpy.var(out.numpy()), 0.773, delta=0.1)
if __name__ == "__main__":
......
......@@ -21,7 +21,6 @@ import paddle
import paddle.fluid as fluid
import paddle.tensor as tensor
from paddle.fluid import Program, program_guard
from paddle.fluid.framework import _test_eager_guard
class TestUnbind(unittest.TestCase):
......@@ -57,10 +56,6 @@ class TestUnbind(unittest.TestCase):
out.backward()
np.testing.assert_array_equal(x.grad.numpy(), np_grad)
def test_unbind_dygraph_final_state(self):
with _test_eager_guard():
self.test_unbind_dygraph()
class TestLayersUnbind(unittest.TestCase):
def test_layers_unbind(self):
......
......@@ -23,7 +23,6 @@ import paddle
import paddle.fluid as fluid
import paddle.fluid.core as core
from paddle.fluid import Program, program_guard
from paddle.fluid.framework import _test_eager_guard
from paddle.fluid.op import Operator
from paddle.tensor import random
......@@ -171,7 +170,7 @@ class TestUniformRandomOp(OpTest):
hist, prob = self.output_hist(np.array(outs[0]))
np.testing.assert_allclose(hist, prob, rtol=0, atol=0.01)
def func_test_check_api(self):
def test_check_api(self):
places = self._get_places()
for place in places:
with fluid.dygraph.base.guard(place=place):
......@@ -183,11 +182,6 @@ class TestUniformRandomOp(OpTest):
self.attrs['seed'],
)
def test_check_api_eager(self):
with _test_eager_guard():
self.func_test_check_api()
self.func_test_check_api()
class TestUniformRandomOpError(unittest.TestCase):
def test_errors(self):
......
......@@ -20,7 +20,6 @@ from op_test import OpTest
import paddle
import paddle.fluid as fluid
import paddle.fluid.core as core
from paddle.fluid.framework import _test_eager_guard
class TestUniqueOp(OpTest):
......@@ -262,12 +261,6 @@ class TestUniqueAPI(unittest.TestCase):
self.assertTrue((counts.numpy() == np_counts).all(), True)
paddle.enable_static()
def test_dygraph_api(self):
with _test_eager_guard():
self.test_dygraph_api_out()
self.test_dygraph_api_attr()
self.test_dygraph_attr_dtype()
def test_static_graph(self):
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
......
......@@ -17,7 +17,6 @@ import unittest
import numpy as np
import paddle
from paddle.fluid.framework import _test_eager_guard
# NOTE(pangyoki): Tensor View Strategy.
......@@ -36,7 +35,7 @@ class TestDygraphViewReuseAllocation(unittest.TestCase):
def view_api_processing(self, var):
return paddle.squeeze(var)
def func_test_view_api(self):
def test_view_api(self):
var = paddle.rand(self.input_shape)
view_var = self.view_api_processing(var)
view_var[0] = 2.0
......@@ -47,12 +46,7 @@ class TestDygraphViewReuseAllocation(unittest.TestCase):
view_var_numpy = view_var.numpy()
np.testing.assert_array_equal(var_numpy, view_var_numpy)
def test_view_api(self):
with _test_eager_guard():
self.func_test_view_api()
self.func_test_view_api()
def func_test_forward_version(self):
def test_forward_version(self):
var = paddle.rand(self.input_shape)
self.assertEqual(var.inplace_version, 0)
view_var = self.view_api_processing(var)
......@@ -69,12 +63,7 @@ class TestDygraphViewReuseAllocation(unittest.TestCase):
self.assertEqual(view_var.inplace_version, 2)
self.assertEqual(view_var_2.inplace_version, 2)
def test_forward_version(self):
with _test_eager_guard():
self.func_test_forward_version()
self.func_test_forward_version()
def func_test_backward_error(self):
def test_backward_error(self):
# It raises an error because the inplace operator will result
# in incorrect gradient computation.
with paddle.fluid.dygraph.guard():
......@@ -97,11 +86,6 @@ class TestDygraphViewReuseAllocation(unittest.TestCase):
):
loss.backward()
def test_backward_error(self):
with _test_eager_guard():
self.func_test_backward_error()
self.func_test_backward_error()
class TestUnsqueezeDygraphViewReuseAllocation(TestDygraphViewReuseAllocation):
def init_shape(self):
......
......@@ -23,7 +23,6 @@ import paddle
import paddle.fluid.core as core
import paddle.nn.functional as F
from paddle.fluid import Program, program_guard
from paddle.fluid.framework import _test_eager_guard
paddle.enable_static()
......@@ -718,8 +717,6 @@ class TestCTCLossAPICase(unittest.TestCase):
loss_pd_sum, loss_np_sum, rtol=1e-05, atol=1
)
with _test_eager_guard():
test_functinal_api()
test_functinal_api()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册