未验证 提交 737fbdba 编写于 作者: 姜永久 提交者: GitHub

rm unittests eager guard tests part5 dataloader2dygraph_mnist (#48816)

上级 f53e5a04
...@@ -17,12 +17,11 @@ import unittest ...@@ -17,12 +17,11 @@ import unittest
import paddle import paddle
import paddle.vision.transforms as transforms import paddle.vision.transforms as transforms
from paddle.fluid.framework import _test_eager_guard
from paddle.io import Dataset from paddle.io import Dataset
class TestDatasetAbstract(unittest.TestCase): class TestDatasetAbstract(unittest.TestCase):
def func_test_main(self): def test_main(self):
dataset = Dataset() dataset = Dataset()
try: try:
d = dataset[0] d = dataset[0]
...@@ -36,11 +35,6 @@ class TestDatasetAbstract(unittest.TestCase): ...@@ -36,11 +35,6 @@ class TestDatasetAbstract(unittest.TestCase):
except NotImplementedError: except NotImplementedError:
pass pass
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class TestDatasetWithDiffOutputPlace(unittest.TestCase): class TestDatasetWithDiffOutputPlace(unittest.TestCase):
def get_dataloader(self, num_workers): def get_dataloader(self, num_workers):
...@@ -68,7 +62,7 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase): ...@@ -68,7 +62,7 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase):
self.assertTrue(label.place.is_cpu_place()) self.assertTrue(label.place.is_cpu_place())
break break
def func_test_single_process(self): def test_single_process(self):
self.run_check_on_cpu() self.run_check_on_cpu()
if paddle.is_compiled_with_cuda(): if paddle.is_compiled_with_cuda():
# Get (image, label) tuple from MNIST dataset # Get (image, label) tuple from MNIST dataset
...@@ -80,12 +74,7 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase): ...@@ -80,12 +74,7 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase):
self.assertTrue(label.place.is_cuda_pinned_place()) self.assertTrue(label.place.is_cuda_pinned_place())
break break
def test_single_process(self): def test_multi_process(self):
with _test_eager_guard():
self.func_test_single_process()
self.func_test_single_process()
def func_test_multi_process(self):
# DataLoader with multi-process mode is not supported on MacOs and Windows currently # DataLoader with multi-process mode is not supported on MacOs and Windows currently
if sys.platform != 'darwin' and sys.platform != 'win32': if sys.platform != 'darwin' and sys.platform != 'win32':
self.run_check_on_cpu() self.run_check_on_cpu()
...@@ -99,11 +88,6 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase): ...@@ -99,11 +88,6 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase):
self.assertTrue(label.place.is_cuda_pinned_place()) self.assertTrue(label.place.is_cuda_pinned_place())
break break
def test_multi_process(self):
with _test_eager_guard():
self.func_test_multi_process()
self.func_test_multi_process()
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.nn.initializer as I import paddle.nn.initializer as I
from paddle.fluid.framework import _test_eager_guard
class TestDeformConv2D(TestCase): class TestDeformConv2D(TestCase):
...@@ -233,10 +232,6 @@ class TestDeformConv2D(TestCase): ...@@ -233,10 +232,6 @@ class TestDeformConv2D(TestCase):
self.place = paddle.CUDAPlace(0) self.place = paddle.CUDAPlace(0)
self._test_identity() self._test_identity()
def test_identity_with_eager_guard(self):
with _test_eager_guard():
self.test_identity()
class TestDeformConv2DFunctional(TestCase): class TestDeformConv2DFunctional(TestCase):
batch_size = 4 batch_size = 4
...@@ -544,10 +539,6 @@ class TestDeformConv2DFunctional(TestCase): ...@@ -544,10 +539,6 @@ class TestDeformConv2DFunctional(TestCase):
self.place = paddle.CUDAPlace(0) self.place = paddle.CUDAPlace(0)
self._test_identity() self._test_identity()
def test_identity_with_eager_guard(self):
with _test_eager_guard():
self.test_identity()
# testcases for DeformConv2D # testcases for DeformConv2D
class TestDeformConv2DWithPadding(TestDeformConv2D): class TestDeformConv2DWithPadding(TestDeformConv2D):
......
...@@ -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
paddle.enable_static() paddle.enable_static()
...@@ -442,10 +441,6 @@ class TestModulatedDeformableConvInvalidInput(unittest.TestCase): ...@@ -442,10 +441,6 @@ class TestModulatedDeformableConvInvalidInput(unittest.TestCase):
self.assertRaises(ValueError, test_invalid_filter) self.assertRaises(ValueError, test_invalid_filter)
def test_error_with_eager_guard(self):
with _test_eager_guard():
self.test_error()
class TestDeformConv2DAPI(unittest.TestCase): class TestDeformConv2DAPI(unittest.TestCase):
def test_api(self): def test_api(self):
...@@ -484,10 +479,6 @@ class TestDeformConv2DAPI(unittest.TestCase): ...@@ -484,10 +479,6 @@ class TestDeformConv2DAPI(unittest.TestCase):
test_deform_conv2d_v2() test_deform_conv2d_v2()
def test_api_with_eager_guard(self):
with _test_eager_guard():
self.test_api()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -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
paddle.enable_static() paddle.enable_static()
...@@ -87,10 +86,6 @@ class TestDeterminantAPI(unittest.TestCase): ...@@ -87,10 +86,6 @@ class TestDeterminantAPI(unittest.TestCase):
np.testing.assert_allclose(out.numpy(), out_ref, rtol=0.001) np.testing.assert_allclose(out.numpy(), out_ref, rtol=0.001)
paddle.enable_static() paddle.enable_static()
def test_eager(self):
with _test_eager_guard():
self.test_api_dygraph()
class TestSlogDeterminantOp(OpTest): class TestSlogDeterminantOp(OpTest):
def setUp(self): def setUp(self):
......
...@@ -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, program_guard from paddle.fluid import Program, program_guard
from paddle.fluid.framework import _test_eager_guard
class TestDiagV2Op(OpTest): class TestDiagV2Op(OpTest):
...@@ -281,8 +280,6 @@ class TestDiagV2API(unittest.TestCase): ...@@ -281,8 +280,6 @@ class TestDiagV2API(unittest.TestCase):
def test_cpu(self): def test_cpu(self):
paddle.disable_static(place=paddle.fluid.CPUPlace()) paddle.disable_static(place=paddle.fluid.CPUPlace())
self.run_imperative() self.run_imperative()
with _test_eager_guard():
self.run_imperative()
paddle.enable_static() paddle.enable_static()
...@@ -295,8 +292,6 @@ class TestDiagV2API(unittest.TestCase): ...@@ -295,8 +292,6 @@ class TestDiagV2API(unittest.TestCase):
paddle.disable_static(place=paddle.fluid.CUDAPlace(0)) paddle.disable_static(place=paddle.fluid.CUDAPlace(0))
self.run_imperative() self.run_imperative()
with _test_eager_guard():
self.run_imperative()
paddle.enable_static() paddle.enable_static()
with fluid.program_guard(fluid.Program()): with fluid.program_guard(fluid.Program()):
......
...@@ -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
paddle.enable_static() paddle.enable_static()
...@@ -157,12 +156,11 @@ class TestDiagonalAPI(unittest.TestCase): ...@@ -157,12 +156,11 @@ class TestDiagonalAPI(unittest.TestCase):
def test_api_eager(self): def test_api_eager(self):
paddle.disable_static(self.place) paddle.disable_static(self.place)
with _test_eager_guard(): x_tensor = paddle.to_tensor(self.x)
x_tensor = paddle.to_tensor(self.x) out = paddle.diagonal(x_tensor)
out = paddle.diagonal(x_tensor) out2 = paddle.diagonal(x_tensor, offset=0, axis1=2, axis2=1)
out2 = paddle.diagonal(x_tensor, offset=0, axis1=2, axis2=1) out3 = paddle.diagonal(x_tensor, offset=1, axis1=0, axis2=1)
out3 = paddle.diagonal(x_tensor, offset=1, axis1=0, axis2=1) out4 = paddle.diagonal(x_tensor, offset=0, axis1=1, axis2=2)
out4 = paddle.diagonal(x_tensor, offset=0, axis1=1, axis2=2)
out_ref = np.diagonal(self.x) out_ref = np.diagonal(self.x)
np.testing.assert_allclose(out.numpy(), out_ref, rtol=1e-08) np.testing.assert_allclose(out.numpy(), out_ref, rtol=1e-08)
out2_ref = np.diagonal(self.x, offset=0, axis1=2, axis2=1) out2_ref = np.diagonal(self.x, offset=0, axis1=2, axis2=1)
...@@ -174,10 +172,6 @@ class TestDiagonalAPI(unittest.TestCase): ...@@ -174,10 +172,6 @@ class TestDiagonalAPI(unittest.TestCase):
paddle.enable_static() paddle.enable_static()
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_api_dygraph()
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.fluid.core as core import paddle.fluid.core as core
from paddle.fluid.framework import _test_eager_guard
class TestDiffOp(unittest.TestCase): class TestDiffOp(unittest.TestCase):
...@@ -75,9 +74,6 @@ class TestDiffOp(unittest.TestCase): ...@@ -75,9 +74,6 @@ class TestDiffOp(unittest.TestCase):
self.assertTrue((out.numpy() == self.output).all(), True) self.assertTrue((out.numpy() == self.output).all(), True)
def test_dygraph(self): def test_dygraph(self):
with _test_eager_guard():
self.setUp()
self.func_dygraph()
self.setUp() self.setUp()
self.func_dygraph() self.func_dygraph()
...@@ -145,9 +141,6 @@ class TestDiffOp(unittest.TestCase): ...@@ -145,9 +141,6 @@ class TestDiffOp(unittest.TestCase):
raise RuntimeError("Check Diff Gradient Failed") raise RuntimeError("Check Diff Gradient Failed")
def test_grad(self): def test_grad(self):
with _test_eager_guard():
self.setUp()
self.func_grad()
self.setUp() self.setUp()
self.func_grad() self.func_grad()
......
...@@ -21,7 +21,6 @@ from scipy.special import psi ...@@ -21,7 +21,6 @@ from scipy.special import psi
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import paddle.static as static import paddle.static as static
from paddle.fluid.framework import _test_eager_guard
class TestDigammaOp(OpTest): class TestDigammaOp(OpTest):
...@@ -95,10 +94,6 @@ class TestDigammaAPI(unittest.TestCase): ...@@ -95,10 +94,6 @@ class TestDigammaAPI(unittest.TestCase):
res = paddle.digamma(input_t).numpy() res = paddle.digamma(input_t).numpy()
np.testing.assert_allclose(res, sc_res, rtol=1e-05) np.testing.assert_allclose(res, sc_res, rtol=1e-05)
def test_in_eager_dynamic_mode(self):
with _test_eager_guard():
self.test_in_dynamic_mode()
def test_name_argument(self): def test_name_argument(self):
with static.program_guard(static.Program()): with static.program_guard(static.Program()):
x = static.data(name="x", shape=self._shape, dtype=self.dtypes[0]) x = static.data(name="x", shape=self._shape, dtype=self.dtypes[0])
...@@ -119,13 +114,6 @@ class TestDigammaAPI(unittest.TestCase): ...@@ -119,13 +114,6 @@ class TestDigammaAPI(unittest.TestCase):
input_t = paddle.to_tensor(input) input_t = paddle.to_tensor(input)
res = paddle.digamma(input_t) res = paddle.digamma(input_t)
with self.assertRaises(RuntimeError):
with fluid.dygraph.guard():
with _test_eager_guard():
input = np.random.random(self._shape).astype("int32")
input_t = paddle.to_tensor(input)
res = paddle.digamma(input_t)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -30,7 +30,6 @@ import paddle.fluid as fluid ...@@ -30,7 +30,6 @@ import paddle.fluid as fluid
import paddle.fluid.dygraph as dygraph import paddle.fluid.dygraph as dygraph
import paddle.fluid.incubate.fleet.base.role_maker as role_maker import paddle.fluid.incubate.fleet.base.role_maker as role_maker
from paddle.fluid import compiler from paddle.fluid import compiler
from paddle.fluid.framework import _test_eager_guard
from paddle.fluid.incubate.fleet.collective import DistributedStrategy, fleet from paddle.fluid.incubate.fleet.collective import DistributedStrategy, fleet
RUN_STEP = 5 RUN_STEP = 5
...@@ -1718,16 +1717,6 @@ class TestDistBase(unittest.TestCase): ...@@ -1718,16 +1717,6 @@ class TestDistBase(unittest.TestCase):
log_name="", log_name="",
): ):
if self._dygraph and (self._gloo_mode or self._nccl2_mode): if self._dygraph and (self._gloo_mode or self._nccl2_mode):
need_envs.update({"FLAGS_enable_eager_mode": "1"})
with _test_eager_guard():
self.check_with_place_func(
model_file=model_file,
delta=delta,
check_error_log=check_error_log,
need_envs=need_envs,
log_name=log_name,
)
need_envs.update({"FLAGS_enable_eager_mode": "0"})
self.check_with_place_func( self.check_with_place_func(
model_file=model_file, model_file=model_file,
delta=delta, delta=delta,
......
...@@ -18,7 +18,6 @@ import numpy as np ...@@ -18,7 +18,6 @@ import numpy as np
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid.framework import _test_eager_guard
from paddle.nn import Linear from paddle.nn import Linear
...@@ -136,8 +135,6 @@ class TestMnist(unittest.TestCase): ...@@ -136,8 +135,6 @@ class TestMnist(unittest.TestCase):
print(loss.numpy()) print(loss.numpy())
def test_mnist_fp16(self): def test_mnist_fp16(self):
with _test_eager_guard():
self.func_mnist_fp16()
self.func_mnist_fp16() self.func_mnist_fp16()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册