未验证 提交 3900d562 编写于 作者: 姜永久 提交者: GitHub

rm unittests eager guard test part15 layers2maxout (#48837)

上级 53ce406a
...@@ -19,7 +19,6 @@ import numpy as np ...@@ -19,7 +19,6 @@ import numpy as np
import paddle import paddle
from paddle.distributed.models.moe import utils from paddle.distributed.models.moe import utils
from paddle.fluid import core from paddle.fluid import core
from paddle.fluid.framework import _test_eager_guard
def limit_by_capacity(expert_count, _capacity, n_worker): def limit_by_capacity(expert_count, _capacity, n_worker):
...@@ -88,7 +87,7 @@ class TestLimitByCapacityInt64API(unittest.TestCase): ...@@ -88,7 +87,7 @@ class TestLimitByCapacityInt64API(unittest.TestCase):
assert all_close(self.out, res[0], self.n_worker) assert all_close(self.out, res[0], self.n_worker)
def func_dygraph_api(self): def test_dygraph_api(self):
paddle.disable_static(self.place) paddle.disable_static(self.place)
capacity = paddle.to_tensor(self.capacity) capacity = paddle.to_tensor(self.capacity)
expert_count_tensor = paddle.to_tensor(self.expert_count) expert_count_tensor = paddle.to_tensor(self.expert_count)
...@@ -97,11 +96,6 @@ class TestLimitByCapacityInt64API(unittest.TestCase): ...@@ -97,11 +96,6 @@ class TestLimitByCapacityInt64API(unittest.TestCase):
) )
assert all_close(self.out, out.numpy(), self.n_worker) assert all_close(self.out, out.numpy(), self.n_worker)
def test_dygraph_api(self):
with _test_eager_guard():
self.func_dygraph_api()
self.func_dygraph_api()
@unittest.skipIf( @unittest.skipIf(
not core.is_compiled_with_cuda(), "core is not compiled with CUDA" not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
......
...@@ -18,7 +18,6 @@ import numpy as np ...@@ -18,7 +18,6 @@ import numpy as np
import paddle import paddle
import paddle.static as static import paddle.static as static
from paddle.fluid.framework import _test_eager_guard
p_list_n_n = ("fro", "nuc", 1, -1, np.inf, -np.inf) p_list_n_n = ("fro", "nuc", 1, -1, np.inf, -np.inf)
p_list_m_n = (None, 2, -2) p_list_m_n = (None, 2, -2)
...@@ -92,21 +91,16 @@ class API_TestStaticCond(unittest.TestCase): ...@@ -92,21 +91,16 @@ class API_TestStaticCond(unittest.TestCase):
class API_TestDygraphCond(unittest.TestCase): class API_TestDygraphCond(unittest.TestCase):
def func_out(self): def test_out(self):
paddle.disable_static() paddle.disable_static()
# test calling results of 'cond' in dynamic mode # test calling results of 'cond' in dynamic mode
x_list_n_n, x_list_m_n = gen_input() x_list_n_n, x_list_m_n = gen_input()
test_dygraph_assert_true(self, x_list_n_n, p_list_n_n + p_list_m_n) test_dygraph_assert_true(self, x_list_n_n, p_list_n_n + p_list_m_n)
test_dygraph_assert_true(self, x_list_m_n, p_list_m_n) test_dygraph_assert_true(self, x_list_m_n, p_list_m_n)
def test_out(self):
with _test_eager_guard():
self.func_out()
self.func_out()
class TestCondAPIError(unittest.TestCase): class TestCondAPIError(unittest.TestCase):
def func_dygraph_api_error(self): def test_dygraph_api_error(self):
paddle.disable_static() paddle.disable_static()
# test raising errors when 'cond' is called in dygraph mode # test raising errors when 'cond' is called in dygraph mode
p_list_error = ('fro_', '_nuc', -0.7, 0, 1.5, 3) p_list_error = ('fro_', '_nuc', -0.7, 0, 1.5, 3)
...@@ -121,11 +115,6 @@ class TestCondAPIError(unittest.TestCase): ...@@ -121,11 +115,6 @@ class TestCondAPIError(unittest.TestCase):
x_tensor = paddle.to_tensor(x) x_tensor = paddle.to_tensor(x)
self.assertRaises(ValueError, paddle.linalg.cond, x_tensor, p) self.assertRaises(ValueError, paddle.linalg.cond, x_tensor, p)
def test_dygraph_api_error(self):
with _test_eager_guard():
self.func_dygraph_api_error()
self.func_dygraph_api_error()
def test_static_api_error(self): def test_static_api_error(self):
paddle.enable_static() paddle.enable_static()
# test raising errors when 'cond' is called in static mode # test raising errors when 'cond' is called in static mode
...@@ -162,18 +151,13 @@ class TestCondAPIError(unittest.TestCase): ...@@ -162,18 +151,13 @@ class TestCondAPIError(unittest.TestCase):
class TestCondEmptyTensorInput(unittest.TestCase): class TestCondEmptyTensorInput(unittest.TestCase):
def func_dygraph_empty_tensor_input(self): def test_dygraph_empty_tensor_input(self):
paddle.disable_static() paddle.disable_static()
# test calling results of 'cond' when input is an empty tensor in dynamic mode # test calling results of 'cond' when input is an empty tensor in dynamic mode
x_list_n_n, x_list_m_n = gen_empty_input() x_list_n_n, x_list_m_n = gen_empty_input()
test_dygraph_assert_true(self, x_list_n_n, p_list_n_n + p_list_m_n) test_dygraph_assert_true(self, x_list_n_n, p_list_n_n + p_list_m_n)
test_dygraph_assert_true(self, x_list_m_n, p_list_m_n) test_dygraph_assert_true(self, x_list_m_n, p_list_m_n)
def test_dygraph_empty_tensor_input(self):
with _test_eager_guard():
self.func_dygraph_empty_tensor_input()
self.func_dygraph_empty_tensor_input()
if __name__ == "__main__": if __name__ == "__main__":
paddle.enable_static() paddle.enable_static()
......
...@@ -20,7 +20,6 @@ from op_test import OpTest ...@@ -20,7 +20,6 @@ from op_test import OpTest
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid import Program, core, program_guard from paddle.fluid import Program, core, program_guard
from paddle.fluid.framework import _test_eager_guard
class TestLinspaceOpCommonCase(OpTest): class TestLinspaceOpCommonCase(OpTest):
...@@ -128,11 +127,6 @@ class TestLinspaceAPI(unittest.TestCase): ...@@ -128,11 +127,6 @@ class TestLinspaceAPI(unittest.TestCase):
self.assertEqual((out2.numpy() == np_out2).all(), True) self.assertEqual((out2.numpy() == np_out2).all(), True)
self.assertEqual((out3.numpy() == np_out3).all(), True) self.assertEqual((out3.numpy() == np_out3).all(), True)
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_variable_input2()
self.test_imperative()
class TestLinspaceOpError(unittest.TestCase): class TestLinspaceOpError(unittest.TestCase):
def test_errors(self): def test_errors(self):
......
...@@ -17,7 +17,6 @@ import unittest ...@@ -17,7 +17,6 @@ import unittest
import numpy as np import numpy as np
import paddle import paddle
from paddle.fluid.framework import _test_eager_guard
from paddle.framework import _non_static_mode from paddle.framework import _non_static_mode
from paddle.static import Executor, Program, program_guard from paddle.static import Executor, Program, program_guard
...@@ -106,15 +105,14 @@ def run_eager(x_np, y_np, op_str, use_gpu=False, binary_op=True): ...@@ -106,15 +105,14 @@ def run_eager(x_np, y_np, op_str, use_gpu=False, binary_op=True):
if use_gpu and paddle.is_compiled_with_cuda(): if use_gpu and paddle.is_compiled_with_cuda():
place = paddle.CUDAPlace(0) place = paddle.CUDAPlace(0)
paddle.disable_static(place) paddle.disable_static(place)
with _test_eager_guard(): op = getattr(paddle, op_str)
op = getattr(paddle, op_str) x = paddle.to_tensor(x_np, dtype=x_np.dtype)
x = paddle.to_tensor(x_np, dtype=x_np.dtype) if not binary_op:
if not binary_op: dygraph_result = op(x)
dygraph_result = op(x) else:
else: y = paddle.to_tensor(y_np, dtype=y_np.dtype)
y = paddle.to_tensor(y_np, dtype=y_np.dtype) dygraph_result = op(x, y)
dygraph_result = op(x, y) return dygraph_result
return dygraph_result
def np_data_generator(np_shape, dtype, *args, **kwargs): def np_data_generator(np_shape, dtype, *args, **kwargs):
......
...@@ -18,7 +18,6 @@ import numpy as np ...@@ -18,7 +18,6 @@ import numpy as np
from op_test import OpTest from op_test import OpTest
import paddle import paddle
from paddle.fluid.framework import _test_eager_guard
np.random.seed(10) np.random.seed(10)
...@@ -117,11 +116,6 @@ class TestLogitAPI(unittest.TestCase): ...@@ -117,11 +116,6 @@ class TestLogitAPI(unittest.TestCase):
x = paddle.fluid.data(name='X2', shape=[100], dtype='float32') x = paddle.fluid.data(name='X2', shape=[100], dtype='float32')
self.assertRaises(TypeError, paddle.logit, x, dtype='int32') self.assertRaises(TypeError, paddle.logit, x, dtype='int32')
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_check_api()
self.test_errors()
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -19,7 +19,6 @@ import numpy as np ...@@ -19,7 +19,6 @@ import numpy as np
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import paddle.nn as nn import paddle.nn as nn
from paddle.fluid.framework import _test_eager_guard
LOOKAHEAD_K = 5 LOOKAHEAD_K = 5
LOOKAHEAD_ALPHA = 0.2 LOOKAHEAD_ALPHA = 0.2
...@@ -71,7 +70,7 @@ class TestLookAhead(unittest.TestCase): ...@@ -71,7 +70,7 @@ class TestLookAhead(unittest.TestCase):
) )
fast_param = latest_b - SGD_LR * b_grad fast_param = latest_b - SGD_LR * b_grad
def func_test_look_ahead_dygraph(self): def test_look_ahead_dygraph(self):
BATCH_SIZE = 16 BATCH_SIZE = 16
BATCH_NUM = 4 BATCH_NUM = 4
EPOCH_NUM = 4 EPOCH_NUM = 4
...@@ -152,11 +151,6 @@ class TestLookAhead(unittest.TestCase): ...@@ -152,11 +151,6 @@ class TestLookAhead(unittest.TestCase):
train(layer, loader, loss_fn, lookahead) train(layer, loader, loss_fn, lookahead)
def test_look_ahead_dygraph(self):
with _test_eager_guard():
self.func_test_look_ahead_dygraph()
self.func_test_look_ahead_dygraph()
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -20,7 +20,6 @@ from op_test import OpTest, convert_float_to_uint16, get_numeric_gradient ...@@ -20,7 +20,6 @@ from op_test import OpTest, convert_float_to_uint16, get_numeric_gradient
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import paddle.fluid.core as core import paddle.fluid.core as core
from paddle.fluid.framework import _test_eager_guard
from paddle.fluid.tests.unittests.testsuite import create_op from paddle.fluid.tests.unittests.testsuite import create_op
...@@ -559,11 +558,6 @@ class TestMatMulV2API(unittest.TestCase): ...@@ -559,11 +558,6 @@ class TestMatMulV2API(unittest.TestCase):
{'FLAGS_gemm_use_half_precision_compute_type': False} {'FLAGS_gemm_use_half_precision_compute_type': False}
) )
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_dygraph()
self.test_dygraph_fp16()
class TestComplexMatMulOp(OpTest): class TestComplexMatMulOp(OpTest):
def setUp(self): def setUp(self):
...@@ -732,10 +726,6 @@ class TestMatmulop(unittest.TestCase): ...@@ -732,10 +726,6 @@ class TestMatmulop(unittest.TestCase):
paddle.enable_static() paddle.enable_static()
def func_dygraph_matmul(self): # noqa: F811
with _test_eager_guard():
self.func_dygraph_matmul()
if __name__ == "__main__": if __name__ == "__main__":
paddle.enable_static() paddle.enable_static()
......
...@@ -20,7 +20,6 @@ from test_sum_op import TestReduceOPTensorAxisBase ...@@ -20,7 +20,6 @@ from test_sum_op import TestReduceOPTensorAxisBase
import paddle import paddle
import paddle.fluid.core as core import paddle.fluid.core as core
from paddle.fluid.framework import _test_eager_guard
class ApiMaxTest(unittest.TestCase): class ApiMaxTest(unittest.TestCase):
...@@ -83,10 +82,6 @@ class ApiMaxTest(unittest.TestCase): ...@@ -83,10 +82,6 @@ class ApiMaxTest(unittest.TestCase):
z_expected = np.array(np.max(np_x, axis=0)) z_expected = np.array(np.max(np_x, axis=0))
self.assertEqual((np_z == z_expected).all(), True) self.assertEqual((np_z == z_expected).all(), True)
def test_eager_api(self):
with _test_eager_guard():
self.test_imperative_api()
def test_big_dimension(self): def test_big_dimension(self):
paddle.disable_static() paddle.disable_static()
x = paddle.rand(shape=[2, 2, 2, 2, 2, 2, 2]) x = paddle.rand(shape=[2, 2, 2, 2, 2, 2, 2])
......
...@@ -20,7 +20,6 @@ from op_test import OpTest ...@@ -20,7 +20,6 @@ from op_test import OpTest
import paddle import paddle
import paddle.fluid.core as core import paddle.fluid.core as core
import paddle.nn.functional as F import paddle.nn.functional as F
from paddle.fluid.framework import _test_eager_guard
paddle.enable_static() paddle.enable_static()
np.random.seed(1) np.random.seed(1)
...@@ -108,7 +107,7 @@ class TestMaxoutAPI(unittest.TestCase): ...@@ -108,7 +107,7 @@ class TestMaxoutAPI(unittest.TestCase):
for r in res: for r in res:
np.testing.assert_allclose(out_ref, r, rtol=1e-05) np.testing.assert_allclose(out_ref, r, rtol=1e-05)
def func_test_dygraph_api(self): def test_dygraph_api(self):
paddle.disable_static(self.place) paddle.disable_static(self.place)
x = paddle.to_tensor(self.x_np) x = paddle.to_tensor(self.x_np)
out1 = F.maxout(x, self.groups, self.axis) out1 = F.maxout(x, self.groups, self.axis)
...@@ -136,11 +135,6 @@ class TestMaxoutAPI(unittest.TestCase): ...@@ -136,11 +135,6 @@ class TestMaxoutAPI(unittest.TestCase):
x_float32 = paddle.fluid.data(name='x_float32', shape=[2, 4, 6, 8]) x_float32 = paddle.fluid.data(name='x_float32', shape=[2, 4, 6, 8])
self.assertRaises(ValueError, F.maxout, x_float32, 2, 2) self.assertRaises(ValueError, F.maxout, x_float32, 2, 2)
def test_dygraph_api(self):
with _test_eager_guard():
self.func_test_dygraph_api()
self.func_test_dygraph_api()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册