Skip to content

Commit d808f16

Browse files
authored
rm eager guard tests part3_1 (#49059)
1 parent d0fefa2 commit d808f16

File tree

6 files changed

+16
-54
lines changed

6 files changed

+16
-54
lines changed

python/paddle/fluid/tests/unittests/test_cast_op.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import paddle.fluid.core as core
2525
import paddle.fluid.layers as layers
2626
from paddle.fluid import Program, program_guard
27-
from paddle.fluid.framework import _test_eager_guard
2827

2928

3029
class TestCastOpFp32ToFp64(OpTest):
@@ -122,16 +121,15 @@ def test_errors(self):
122121
class TestCastOpEager(unittest.TestCase):
123122
def test_eager(self):
124123
with paddle.fluid.dygraph.base.guard():
125-
with _test_eager_guard():
126-
x = paddle.ones([2, 2], dtype="float16")
127-
x.stop_gradient = False
128-
out = paddle.cast(x, "float32")
129-
np.testing.assert_array_equal(
130-
out, np.ones([2, 2]).astype('float32')
131-
)
132-
out.backward()
133-
np.testing.assert_array_equal(x.gradient(), x.numpy())
134-
self.assertTrue(x.gradient().dtype == np.float16)
124+
x = paddle.ones([2, 2], dtype="float16")
125+
x.stop_gradient = False
126+
out = paddle.cast(x, "float32")
127+
np.testing.assert_array_equal(
128+
out, np.ones([2, 2]).astype('float32')
129+
)
130+
out.backward()
131+
np.testing.assert_array_equal(x.gradient(), x.numpy())
132+
self.assertTrue(x.gradient().dtype == np.float16)
135133

136134

137135
class TestCastDoubleGradCheck(unittest.TestCase):

python/paddle/fluid/tests/unittests/test_clip_op.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import paddle
2121
import paddle.fluid as fluid
2222
from paddle.fluid import Program, program_guard
23-
from paddle.fluid.framework import _test_eager_guard
2423

2524

2625
class TestClipOp(OpTest):
@@ -231,7 +230,7 @@ def test_clip(self):
231230
)
232231
paddle.disable_static()
233232

234-
def func_clip_dygraph(self):
233+
def test_clip_dygraph(self):
235234
paddle.disable_static()
236235
place = (
237236
fluid.CUDAPlace(0)
@@ -279,20 +278,14 @@ def func_clip_dygraph(self):
279278
out_6.numpy(), data.clip(0.2, 0.8), rtol=1e-05
280279
)
281280

282-
def test_clip_dygraph(self):
283-
with _test_eager_guard():
284-
self.func_clip_dygraph()
285-
self.func_clip_dygraph()
286-
287281
def test_clip_dygraph_default_max(self):
288282
paddle.disable_static()
289-
with _test_eager_guard():
290-
x_int32 = paddle.to_tensor([1, 2, 3], dtype="int32")
291-
x_int64 = paddle.to_tensor([1, 2, 3], dtype="int64")
292-
x_f32 = paddle.to_tensor([1, 2, 3], dtype="float32")
293-
egr_out1 = paddle.clip(x_int32, min=1)
294-
egr_out2 = paddle.clip(x_int64, min=1)
295-
egr_out3 = paddle.clip(x_f32, min=1)
283+
x_int32 = paddle.to_tensor([1, 2, 3], dtype="int32")
284+
x_int64 = paddle.to_tensor([1, 2, 3], dtype="int64")
285+
x_f32 = paddle.to_tensor([1, 2, 3], dtype="float32")
286+
egr_out1 = paddle.clip(x_int32, min=1)
287+
egr_out2 = paddle.clip(x_int64, min=1)
288+
egr_out3 = paddle.clip(x_f32, min=1)
296289
x_int32 = paddle.to_tensor([1, 2, 3], dtype="int32")
297290
x_int64 = paddle.to_tensor([1, 2, 3], dtype="int64")
298291
x_f32 = paddle.to_tensor([1, 2, 3], dtype="float32")

python/paddle/fluid/tests/unittests/test_complex_abs.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import paddle
2121
import paddle.fluid.dygraph as dg
22-
from paddle.fluid.framework import _test_eager_guard
2322

2423

2524
class TestComplexAbsOp(OpTest):
@@ -109,10 +108,6 @@ def test_all_positive(self):
109108
y = paddle.abs(paddle.to_tensor(x))
110109
np.testing.assert_allclose(np.abs(x), y.numpy(), rtol=1e-05)
111110

112-
def test_eager(self):
113-
with _test_eager_guard():
114-
self.test_all_positive()
115-
116111

117112
class TestRealAbsOp(OpTest):
118113
def setUp(self):

python/paddle/fluid/tests/unittests/test_complex_cast.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import numpy as np
1818

1919
import paddle
20-
from paddle.fluid.framework import _test_eager_guard
2120

2221

2322
class TestComplexCastOp(unittest.TestCase):
@@ -80,12 +79,6 @@ def test_complex64_complex128(self):
8079
c_128.cast('complex128').numpy(), c_64.numpy(), rtol=1e-05
8180
)
8281

83-
def test_eager(self):
84-
with _test_eager_guard():
85-
self.test_complex64_complex128()
86-
self.test_real_to_complex()
87-
self.test_complex_to_real()
88-
8982

9083
if __name__ == '__main__':
9184
unittest.main()

python/paddle/fluid/tests/unittests/test_complex_elementwise_layers.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import paddle
2121
import paddle.fluid as fluid
2222
import paddle.fluid.dygraph as dg
23-
from paddle.fluid.framework import _test_eager_guard
2423

2524
paddle_apis = {
2625
"add": paddle.add,
@@ -112,12 +111,6 @@ def test_real_x_complex_y(self):
112111
self.compare_by_basic_api(x, y)
113112
self.compare_op_by_basic_api(x, y)
114113

115-
def test_eager(self):
116-
with _test_eager_guard():
117-
self.test_real_x_complex_y()
118-
self.test_complex_x_real_y()
119-
self.test_complex_xy()
120-
121114

122115
if __name__ == '__main__':
123116
unittest.main()

python/paddle/fluid/tests/unittests/test_complex_getitem.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import paddle.fluid as fluid
2020
import paddle.fluid.dygraph as dg
21-
from paddle.fluid.framework import _test_eager_guard
2221

2322

2423
class TestComplexGetitemLayer(unittest.TestCase):
@@ -95,15 +94,6 @@ def test_case6(self):
9594

9695
np.testing.assert_allclose(x_var_slice.numpy(), x_np_slice)
9796

98-
def test_eager(self):
99-
with _test_eager_guard():
100-
self.test_case1()
101-
self.test_case2()
102-
self.test_case3()
103-
self.test_case4()
104-
self.test_case5()
105-
self.test_case6()
106-
10797

10898
if __name__ == '__main__':
10999
unittest.main()

0 commit comments

Comments
 (0)