Skip to content

Commit d0fefa2

Browse files
authored
rm unittests eager guard tests part11 imperative_layer2ocr (#48828)
* rm unittests eager guard tests part11 imperative_layer2ocr * review
1 parent 1f93de3 commit d0fefa2

10 files changed

+18
-79
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import paddle
2020
import paddle.fluid as fluid
2121
import paddle.nn as nn
22-
from paddle.fluid.framework import _test_eager_guard
2322

2423

2524
class LeNetDygraph(fluid.dygraph.Layer):
@@ -74,7 +73,7 @@ def init_weights(layer):
7473

7574

7675
class TestLayerApply(unittest.TestCase):
77-
def func_apply_init_weight(self):
76+
def test_apply_init_weight(self):
7877
with fluid.dygraph.guard():
7978
net = LeNetDygraph()
8079

@@ -88,11 +87,6 @@ def func_apply_init_weight(self):
8887
np.testing.assert_allclose(layer.weight.numpy(), 0.7)
8988
np.testing.assert_allclose(layer.bias.numpy(), -0.2)
9089

91-
def test_apply_init_weight(self):
92-
with _test_eager_guard():
93-
self.func_apply_init_weight()
94-
self.func_apply_init_weight()
95-
9690

9791
if __name__ == '__main__':
9892
unittest.main()

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import paddle
2020
import paddle.fluid as fluid
2121
import paddle.nn as nn
22-
from paddle.fluid.framework import _test_eager_guard
2322

2423

2524
class LeNetDygraph(fluid.dygraph.Layer):
@@ -56,9 +55,8 @@ def func_apply_init_weight(self):
5655
return y1, y2
5756

5857
def test_func_apply_init_weight(self):
59-
with _test_eager_guard():
60-
paddle.seed(102)
61-
self.new_y1, self.new_y2 = self.func_apply_init_weight()
58+
paddle.seed(102)
59+
self.new_y1, self.new_y2 = self.func_apply_init_weight()
6260
paddle.seed(102)
6361
self.ori_y1, self.ori_y2 = self.func_apply_init_weight()
6462

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
import paddle
2020
import paddle.fluid as fluid
2121
import paddle.fluid.dygraph as dygraph
22-
from paddle.fluid.framework import _test_eager_guard
2322

2423

2524
class TestImperativeLayerTrainable(unittest.TestCase):
26-
def func_set_trainable(self):
25+
def test_set_trainable(self):
2726
with fluid.dygraph.guard():
2827
label = np.random.uniform(-1, 1, [10, 10]).astype(np.float32)
2928

@@ -45,11 +44,6 @@ def func_set_trainable(self):
4544
with self.assertRaises(ValueError):
4645
linear.weight.trainable = "1"
4746

48-
def test_set_trainable(self):
49-
with _test_eager_guard():
50-
self.func_set_trainable()
51-
self.func_set_trainable()
52-
5347

5448
if __name__ == '__main__':
5549
unittest.main()

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
import unittest
1616

1717
import paddle.nn as nn
18-
from paddle.fluid.framework import _test_eager_guard
1918

2019

2120
class TestLayerPrint(unittest.TestCase):
22-
def func_test_layer_str(self):
21+
def test_layer_str(self):
2322
module = nn.ELU(0.2)
2423
self.assertEqual(str(module), 'ELU(alpha=0.2)')
2524

@@ -385,11 +384,6 @@ def func_test_layer_str(self):
385384
'(6): GELU(approximate=True)\n)',
386385
)
387386

388-
def test_layer_str(self):
389-
with _test_eager_guard():
390-
self.func_test_layer_str()
391-
self.func_test_layer_str()
392-
393387

394388
if __name__ == '__main__':
395389
unittest.main()

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import paddle.fluid as fluid
2323
import paddle.fluid.core as core
2424
from paddle.fluid.dygraph.base import to_variable
25-
from paddle.fluid.framework import _test_eager_guard
2625
from paddle.fluid.optimizer import SGDOptimizer
2726

2827

@@ -80,19 +79,14 @@ def forward(self, input, label):
8079

8180

8281
class TestDygraphSimpleNet(unittest.TestCase):
83-
def func_simple_net(self):
82+
def test_simple_net(self):
8483
for is_sparse in [True, False]:
8584
dtype_list = ["float32"]
8685
if not core.is_compiled_with_rocm():
8786
dtype_list.append("float64")
8887
for dtype in dtype_list:
8988
self.simple_net_float32(is_sparse, dtype)
9089

91-
def test_simple_net(self):
92-
with _test_eager_guard():
93-
self.func_simple_net()
94-
self.func_simple_net()
95-
9690
def simple_net_float32(self, is_sparse, dtype):
9791
places = [fluid.CPUPlace()]
9892
if core.is_compiled_with_cuda():

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import paddle
2222
import paddle.fluid as fluid
2323
from paddle.fluid import core
24-
from paddle.fluid.framework import _test_eager_guard
2524
from paddle.fluid.optimizer import SGDOptimizer
2625
from paddle.nn import Linear
2726

@@ -113,7 +112,7 @@ def _reader_imple():
113112

114113
return _reader_imple
115114

116-
def func_test_mnist_float32(self):
115+
def test_mnist_float32(self):
117116
seed = 90
118117
epoch_num = 1
119118
batch_size = 128
@@ -269,11 +268,6 @@ def func_test_mnist_float32(self):
269268
value, dy_param_value[key], rtol=1e-05, atol=1e-05
270269
)
271270

272-
def test_mnist_float32(self):
273-
with _test_eager_guard():
274-
self.func_test_mnist_float32()
275-
self.func_test_mnist_float32()
276-
277271

278272
if __name__ == '__main__':
279273
paddle.enable_static()

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
import paddle.fluid as fluid
2323
from paddle.fluid import core
2424
from paddle.fluid.dygraph.base import to_variable
25-
from paddle.fluid.framework import _test_eager_guard
2625
from paddle.fluid.optimizer import SGDOptimizer
2726

2827

2928
class TestImperativeMnistSortGradient(unittest.TestCase):
30-
def func_test_mnist_sort_gradient_float32(self):
29+
def test_mnist_sort_gradient_float32(self):
3130
seed = 90
3231
epoch_num = 1
3332

@@ -168,11 +167,6 @@ def func_test_mnist_sort_gradient_float32(self):
168167
value, dy_param_value2[key], rtol=1e-05, atol=1e-05
169168
)
170169

171-
def test_mnist_sort_gradient_float32(self):
172-
with _test_eager_guard():
173-
self.func_test_mnist_sort_gradient_float32()
174-
self.func_test_mnist_sort_gradient_float32()
175-
176170

177171
if __name__ == '__main__':
178172
unittest.main()

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

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

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

2322

2423
class MyLayer(fluid.Layer):
@@ -34,7 +33,7 @@ def forward(self, x):
3433

3534

3635
class TestImperativeNamedSubLayers(unittest.TestCase):
37-
def func_test_named_sublayers(self):
36+
def test_named_sublayers(self):
3837
with fluid.dygraph.guard():
3938
fc1 = paddle.nn.Linear(10, 3)
4039
fc2 = paddle.nn.Linear(3, 10, bias_attr=False)
@@ -62,14 +61,9 @@ def func_test_named_sublayers(self):
6261
[model] + expected_sublayers,
6362
)
6463

65-
def test_named_sublayers(self):
66-
with _test_eager_guard():
67-
self.func_test_named_sublayers()
68-
self.func_test_named_sublayers()
69-
7064

7165
class TestImperativeNamedParameters(unittest.TestCase):
72-
def func_test_named_parameters(self):
66+
def test_named_parameters(self):
7367
with fluid.dygraph.guard():
7468
fc1 = paddle.nn.Linear(10, 3)
7569
fc2 = paddle.nn.Linear(3, 10, bias_attr=False)
@@ -87,12 +81,7 @@ def func_test_named_parameters(self):
8781

8882
self.assertListEqual(expected_named_parameters, named_parameters)
8983

90-
def test_named_parameters(self):
91-
with _test_eager_guard():
92-
self.func_test_named_parameters()
93-
self.func_test_named_parameters()
94-
95-
def func_test_dir_layer(self):
84+
def test_dir_layer(self):
9685
with fluid.dygraph.guard():
9786

9887
class Mymodel(fluid.dygraph.Layer):
@@ -140,11 +129,6 @@ def __init__(self):
140129
"model should contain parameter: weight",
141130
)
142131

143-
def test_dir_layer(self):
144-
with _test_eager_guard():
145-
self.func_test_dir_layer()
146-
self.func_test_dir_layer()
147-
148132

149133
if __name__ == '__main__':
150134
unittest.main()

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
import numpy as np
1919

2020
import paddle.fluid as fluid
21-
from paddle.fluid.framework import _in_legacy_dygraph, _test_eager_guard
21+
from paddle.fluid.framework import _in_legacy_dygraph
2222

2323

2424
class TestImperativeNumpyBridge(unittest.TestCase):
25-
def func_tensor_from_numpy(self):
25+
def test_tensor_from_numpy(self):
2626
data_np = np.array([[2, 3, 1]]).astype('float32')
2727
with fluid.dygraph.guard(fluid.CPUPlace()):
2828
with warnings.catch_warnings(record=True) as w:
@@ -52,11 +52,6 @@ def func_tensor_from_numpy(self):
5252
self.assertNotEqual(var2[0][0].numpy()[0], -1)
5353
self.assertFalse(np.array_equal(var2.numpy(), data_np))
5454

55-
def test_func_tensor_from_numpy(self):
56-
with _test_eager_guard():
57-
self.func_tensor_from_numpy()
58-
self.func_tensor_from_numpy()
59-
6055

6156
if __name__ == '__main__':
6257
unittest.main()

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import paddle.fluid as fluid
2222
from paddle.fluid import core
2323
from paddle.fluid.dygraph.base import to_variable
24-
from paddle.fluid.framework import _test_eager_guard
2524
from paddle.nn import BatchNorm, Linear
2625

2726

@@ -513,12 +512,11 @@ def run_dygraph():
513512
dy_out, dy_param_init_value, dy_param_value = run_dygraph()
514513

515514
with fluid.dygraph.guard():
516-
with _test_eager_guard():
517-
(
518-
eager_out,
519-
eager_param_init_value,
520-
eager_param_value,
521-
) = run_dygraph()
515+
(
516+
eager_out,
517+
eager_param_init_value,
518+
eager_param_value,
519+
) = run_dygraph()
522520

523521
with new_program_scope():
524522
paddle.seed(seed)

0 commit comments

Comments
 (0)