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

rm unittests eager guard test part14 initializer2layer_norm #48835

Merged
merged 2 commits into from
Dec 14, 2022
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
55 changes: 9 additions & 46 deletions python/paddle/fluid/tests/unittests/test_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,14 @@ def func_test_case_fp16(self):

def test_bilinear_initializer(self):
paddle.disable_static()
with framework._test_eager_guard():
eager_x = self.func_test_case()
eager_x = self.func_test_case()
legacy_x = self.func_test_case()
self.assertEqual(eager_x.numpy().all(), legacy_x.numpy().all())
paddle.enable_static()

def test_bilinear_initializer_fp16(self):
paddle.disable_static()
with framework._test_eager_guard():
eager_x = self.func_test_case_fp16()
eager_x = self.func_test_case_fp16()
legacy_x = self.func_test_case_fp16()
self.assertEqual(eager_x.numpy().all(), legacy_x.numpy().all())
paddle.enable_static()
Expand Down Expand Up @@ -712,7 +710,7 @@ def test_set_global_bias_initilizer(self):


class TestUniformInitializerDygraph(unittest.TestCase):
def func_uniform_initializer(self, dtype="float32"):
def test_uniform_initializer(self, dtype="float32"):
"""
In dygraph mode, we can use initializer directly to initialize a tensor.
"""
Expand All @@ -737,14 +735,9 @@ def func_uniform_initializer(self, dtype="float32"):

paddle.enable_static()

def test_uniform_initializer(self, dtype="float32"):
with framework._test_eager_guard():
self.func_uniform_initializer()
self.func_uniform_initializer()


class TestXavierInitializerDygraph(unittest.TestCase):
def func_xvarier_initializer(self, dtype="float32"):
def test_xvarier_initializer(self, dtype="float32"):
"""
In dygraph mode, we can use initializer directly to initialize a tensor.
"""
Expand All @@ -767,14 +760,9 @@ def func_xvarier_initializer(self, dtype="float32"):
np.testing.assert_allclose(hist, hist2, rtol=0, atol=0.01)
paddle.enable_static()

def test_xavier_initializer(self, dtype="float32"):
with framework._test_eager_guard():
self.func_xvarier_initializer()
self.func_xvarier_initializer()


class TestMSRAInitializerDygraph(unittest.TestCase):
def func_msra_initializer(self, dtype="float32"):
def test_msra_initializer(self, dtype="float32"):
"""
In dygraph mode, we can use initializer directly to initialize a tensor.
"""
Expand All @@ -797,14 +785,9 @@ def func_msra_initializer(self, dtype="float32"):
np.testing.assert_allclose(hist, hist2, rtol=0, atol=0.01)
paddle.enable_static()

def test_msra_initializer(self, dtype="float32"):
with framework._test_eager_guard():
self.func_msra_initializer()
self.func_msra_initializer()


class TesetconsistencyOfDynamicAndStaticGraph(unittest.TestCase):
def func_order(self):
def test_order(self):
paddle.set_device('cpu')
SEED = 123
weight_attr = paddle.framework.ParamAttr(
Expand Down Expand Up @@ -854,11 +837,6 @@ def run_static_graph():
np.testing.assert_array_equal(dynamic_res[0], static_res[0])
np.testing.assert_array_equal(dynamic_res[1], static_res[1])

def test_order(self):
with framework._test_eager_guard():
self.func_order()
self.func_order()


# 2-D Parameter with shape: [10, 15]
class TestOrthogonalInitializer1(unittest.TestCase):
Expand All @@ -881,7 +859,7 @@ def check_result(self, a, b):
np.matmul(a, a.T), 9 * np.eye(10), rtol=1e-5, atol=1e-8
)

def func_orthogonal(self):
def test_orthogonal(self):
self.config()
paddle.set_default_dtype(self.dtype)

Expand Down Expand Up @@ -918,11 +896,6 @@ def func_orthogonal(self):

self.check_result(res_dygraph, res_static)

def test_orthogonal(self):
with framework._test_eager_guard():
self.func_orthogonal()
self.func_orthogonal()


# 2-D Parameter with shape: [15, 10]
class TestOrthogonalInitializer2(TestOrthogonalInitializer1):
Expand Down Expand Up @@ -998,7 +971,7 @@ def check_result(self, a, b):
np.matmul(a, a.T), 9 * np.eye(6), rtol=1e-5, atol=1e-8
)

def func_orthogonal(self):
def test_orthogonal(self):
self.config()
paddle.set_default_dtype(self.dtype)

Expand Down Expand Up @@ -1030,11 +1003,6 @@ def func_orthogonal(self):
)[0]
self.check_result(res_dygraph, res_static)

def test_orthogonal(self):
with framework._test_eager_guard():
self.func_orthogonal()
self.func_orthogonal()


# 4-D Parameter with shape: [50, 4, 3, 3]
class TestOrthogonalInitializer5(TestOrthogonalInitializer4):
Expand Down Expand Up @@ -1105,7 +1073,7 @@ def check_result(self, w_dygraph, w_static, conv_in, conv_out):
np.testing.assert_array_equal(w_dygraph, w_static)
np.testing.assert_array_equal(conv_out, conv_in[:, 0:2, 1:9])

def func_dirac(self):
def test_dirac(self):
self.config()
paddle.set_default_dtype(self.dtype)

Expand Down Expand Up @@ -1151,11 +1119,6 @@ def func_dirac(self):
weight_dygraph, weight_static, conv_input, conv_output
)

def test_dirac(self):
with framework._test_eager_guard():
self.func_dirac()
self.func_dirac()


# initialize Conv2D weight
class TestDiracInitializer2(TestDiracInitializer1):
Expand Down
15 changes: 2 additions & 13 deletions python/paddle/fluid/tests/unittests/test_inner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import numpy as np

import paddle
from paddle.fluid.framework import _test_eager_guard
from paddle.static import Program, program_guard


Expand Down Expand Up @@ -54,7 +53,7 @@ def _run_dynamic_graph_case(self, x_data, y_data):
res = paddle.inner(x, y)
return res.numpy()

def func_test_multiply(self):
def test_multiply(self):
np.random.seed(7)

# test static computation graph: 3-d array
Expand Down Expand Up @@ -113,14 +112,9 @@ def func_test_multiply(self):
res = self._run_dynamic_graph_case(x_data, y_data)
np.testing.assert_allclose(res, np.inner(x_data, y_data), rtol=1e-05)

def test_multiply(self):
with _test_eager_guard():
self.func_test_multiply()
self.func_test_multiply()


class TestMultiplyError(unittest.TestCase):
def func_test_errors(self):
def test_errors(self):
# test static computation graph: dtype can not be int8
paddle.enable_static()
with program_guard(Program(), Program()):
Expand Down Expand Up @@ -174,11 +168,6 @@ def func_test_errors(self):
y_data = np.random.randn(200).astype(np.float32)
self.assertRaises(ValueError, paddle.inner, x_data, y_data)

def test_errors(self):
with _test_eager_guard():
self.func_test_errors()
self.func_test_errors()


if __name__ == '__main__':
paddle.enable_static()
Expand Down
Loading