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

rm unittests eager guard test part16 meshgrid2normalize (#48839)

* rm unittests eager guard test part16 meshgrid2normalize

* modify
上级 9bd20aa0
...@@ -19,7 +19,6 @@ from op_test import OpTest ...@@ -19,7 +19,6 @@ from op_test import OpTest
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid.framework import _test_eager_guard
class TestMeshgridOp(OpTest): class TestMeshgridOp(OpTest):
...@@ -200,10 +199,6 @@ class TestMeshgridOp6(unittest.TestCase): ...@@ -200,10 +199,6 @@ class TestMeshgridOp6(unittest.TestCase):
assert np.array_equal(res_3.shape, [100, 200]) assert np.array_equal(res_3.shape, [100, 200])
assert np.array_equal(res_4.shape, [100, 200]) assert np.array_equal(res_4.shape, [100, 200])
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_api_with_dygraph()
class TestMeshgridOp7(unittest.TestCase): class TestMeshgridOp7(unittest.TestCase):
def test_api_with_dygraph_list_input(self): def test_api_with_dygraph_list_input(self):
...@@ -230,10 +225,6 @@ class TestMeshgridOp7(unittest.TestCase): ...@@ -230,10 +225,6 @@ class TestMeshgridOp7(unittest.TestCase):
assert np.array_equal(res_3.shape, [100, 200]) assert np.array_equal(res_3.shape, [100, 200])
assert np.array_equal(res_4.shape, [100, 200]) assert np.array_equal(res_4.shape, [100, 200])
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_api_with_dygraph_list_input()
class TestMeshgridOp8(unittest.TestCase): class TestMeshgridOp8(unittest.TestCase):
def test_api_with_dygraph_tuple_input(self): def test_api_with_dygraph_tuple_input(self):
...@@ -260,10 +251,6 @@ class TestMeshgridOp8(unittest.TestCase): ...@@ -260,10 +251,6 @@ class TestMeshgridOp8(unittest.TestCase):
assert np.array_equal(res_3.shape, [100, 200]) assert np.array_equal(res_3.shape, [100, 200])
assert np.array_equal(res_4.shape, [100, 200]) assert np.array_equal(res_4.shape, [100, 200])
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_api_with_dygraph_tuple_input()
class TestMeshgridEager(unittest.TestCase): class TestMeshgridEager(unittest.TestCase):
def test_dygraph_api(self): def test_dygraph_api(self):
...@@ -290,7 +277,6 @@ class TestMeshgridEager(unittest.TestCase): ...@@ -290,7 +277,6 @@ class TestMeshgridEager(unittest.TestCase):
res_1, res_2 = paddle.tensor.meshgrid((tensor_1, tensor_2)) res_1, res_2 = paddle.tensor.meshgrid((tensor_1, tensor_2))
sum = paddle.add_n([res_1, res_2]) sum = paddle.add_n([res_1, res_2])
sum.backward() sum.backward()
with _test_eager_guard():
tensor_eager_1 = fluid.dygraph.to_variable(input_1) tensor_eager_1 = fluid.dygraph.to_variable(input_1)
tensor_eager_2 = fluid.dygraph.to_variable(input_2) tensor_eager_2 = fluid.dygraph.to_variable(input_2)
tensor_eager_1.stop_gradient = False tensor_eager_1.stop_gradient = False
...@@ -301,15 +287,11 @@ class TestMeshgridEager(unittest.TestCase): ...@@ -301,15 +287,11 @@ class TestMeshgridEager(unittest.TestCase):
sum_eager = paddle.add_n([res_eager_1, res_eager_2]) sum_eager = paddle.add_n([res_eager_1, res_eager_2])
sum_eager.backward() sum_eager.backward()
self.assertEqual( self.assertEqual(
( (tensor_1.grad.numpy() == tensor_eager_1.grad.numpy()).all(),
tensor_1.grad.numpy() == tensor_eager_1.grad.numpy()
).all(),
True, True,
) )
self.assertEqual( self.assertEqual(
( (tensor_2.grad.numpy() == tensor_eager_2.grad.numpy()).all(),
tensor_2.grad.numpy() == tensor_eager_2.grad.numpy()
).all(),
True, True,
) )
......
...@@ -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 ApiMinTest(unittest.TestCase): class ApiMinTest(unittest.TestCase):
...@@ -83,10 +82,6 @@ class ApiMinTest(unittest.TestCase): ...@@ -83,10 +82,6 @@ class ApiMinTest(unittest.TestCase):
z_expected = np.array(np.min(np_x, axis=0)) z_expected = np.array(np.min(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()
class TestOutDtype(unittest.TestCase): class TestOutDtype(unittest.TestCase):
def test_min(self): def test_min(self):
......
...@@ -21,7 +21,6 @@ from op_test import OpTest ...@@ -21,7 +21,6 @@ from op_test import OpTest
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.op import Operator from paddle.fluid.op import Operator
...@@ -558,11 +557,6 @@ class TestMomentumV2(unittest.TestCase): ...@@ -558,11 +557,6 @@ class TestMomentumV2(unittest.TestCase):
) )
self.assertRaises(ValueError, paddle.optimizer.Momentum, momentum=None) self.assertRaises(ValueError, paddle.optimizer.Momentum, momentum=None)
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_momentum_dygraph()
self.test_raise_error()
class TestMomentumOpWithDecay(OpTest): class TestMomentumOpWithDecay(OpTest):
def setUp(self): def setUp(self):
...@@ -996,10 +990,6 @@ class TestMultiTensorMomentumDygraph(unittest.TestCase): ...@@ -996,10 +990,6 @@ class TestMultiTensorMomentumDygraph(unittest.TestCase):
self._check_with_param_arrt(place, use_amp) self._check_with_param_arrt(place, use_amp)
self._check_with_param_group(place, use_amp) self._check_with_param_group(place, use_amp)
def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_main()
class TestMultiTensorMomentumStatic(unittest.TestCase): class TestMultiTensorMomentumStatic(unittest.TestCase):
def _momentum_optimize_static( def _momentum_optimize_static(
......
...@@ -19,7 +19,6 @@ from numpy.linalg import multi_dot ...@@ -19,7 +19,6 @@ from numpy.linalg import multi_dot
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()
...@@ -287,10 +286,6 @@ class APITestMultiDot(unittest.TestCase): ...@@ -287,10 +286,6 @@ class APITestMultiDot(unittest.TestCase):
expected_result = np.linalg.multi_dot([input_array1, input_array2]) expected_result = np.linalg.multi_dot([input_array1, input_array2])
np.testing.assert_allclose(expected_result, out.numpy(), rtol=1e-05) np.testing.assert_allclose(expected_result, out.numpy(), rtol=1e-05)
def test_dygraph_api(self):
with _test_eager_guard():
self.test_dygraph_without_out()
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -19,7 +19,6 @@ from op_test import OpTest ...@@ -19,7 +19,6 @@ from op_test import OpTest
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid.framework import _test_eager_guard
class TestMultiplexOp(OpTest): class TestMultiplexOp(OpTest):
...@@ -114,7 +113,6 @@ class TestMultiplexODygrap(unittest.TestCase): ...@@ -114,7 +113,6 @@ class TestMultiplexODygrap(unittest.TestCase):
inputs[1].stop_gradient = False inputs[1].stop_gradient = False
res = paddle.multiplex(inputs, index) res = paddle.multiplex(inputs, index)
res.backward() res.backward()
with _test_eager_guard():
inputs_eager = [paddle.to_tensor(img1), paddle.to_tensor(img2)] inputs_eager = [paddle.to_tensor(img1), paddle.to_tensor(img2)]
index_eager = paddle.to_tensor( index_eager = paddle.to_tensor(
np.array([[1], [0]]).astype(np.int32) np.array([[1], [0]]).astype(np.int32)
...@@ -125,15 +123,11 @@ class TestMultiplexODygrap(unittest.TestCase): ...@@ -125,15 +123,11 @@ class TestMultiplexODygrap(unittest.TestCase):
res_eager.backward() res_eager.backward()
self.assertEqual((res.numpy() == res_eager.numpy()).all(), True) self.assertEqual((res.numpy() == res_eager.numpy()).all(), True)
self.assertEqual( self.assertEqual(
( (inputs[0].grad.numpy() == inputs_eager[0].grad.numpy()).all(),
inputs[0].grad.numpy() == inputs_eager[0].grad.numpy()
).all(),
True, True,
) )
self.assertEqual( self.assertEqual(
( (inputs[1].grad.numpy() == inputs_eager[1].grad.numpy()).all(),
inputs[1].grad.numpy() == inputs_eager[1].grad.numpy()
).all(),
True, True,
) )
......
...@@ -18,7 +18,6 @@ import numpy as np ...@@ -18,7 +18,6 @@ import numpy as np
import paddle import paddle
import paddle.tensor as tensor import paddle.tensor as tensor
from paddle.fluid.framework import _test_eager_guard
from paddle.static import Program, program_guard from paddle.static import Program, program_guard
...@@ -55,7 +54,7 @@ class TestMultiplyApi(unittest.TestCase): ...@@ -55,7 +54,7 @@ class TestMultiplyApi(unittest.TestCase):
res = paddle.multiply(x, y) res = paddle.multiply(x, y)
return res.numpy() return res.numpy()
def func_test_multiply(self): def test_multiply(self):
np.random.seed(7) np.random.seed(7)
# test static computation graph: 1-d array # test static computation graph: 1-d array
...@@ -106,14 +105,9 @@ class TestMultiplyApi(unittest.TestCase): ...@@ -106,14 +105,9 @@ class TestMultiplyApi(unittest.TestCase):
res = self._run_dynamic_graph_case(x_data, y_data) res = self._run_dynamic_graph_case(x_data, y_data)
np.testing.assert_allclose(res, np.multiply(x_data, y_data), rtol=1e-05) np.testing.assert_allclose(res, np.multiply(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): class TestMultiplyError(unittest.TestCase):
def func_test_errors(self): def test_errors(self):
# test static computation graph: dtype can not be int8 # test static computation graph: dtype can not be int8
paddle.enable_static() paddle.enable_static()
with program_guard(Program(), Program()): with program_guard(Program(), Program()):
...@@ -186,11 +180,6 @@ class TestMultiplyError(unittest.TestCase): ...@@ -186,11 +180,6 @@ class TestMultiplyError(unittest.TestCase):
y_data = np.random.randn(200).astype(np.float32) y_data = np.random.randn(200).astype(np.float32)
self.assertRaises(ValueError, paddle.multiply, x_data, y_data) self.assertRaises(ValueError, paddle.multiply, x_data, y_data)
def test_errors(self):
with _test_eager_guard():
self.func_test_errors()
self.func_test_errors()
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
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid.framework import _test_eager_guard
from paddle.io import ( from paddle.io import (
ChainDataset, ChainDataset,
ComposeDataset, ComposeDataset,
...@@ -92,21 +91,16 @@ class TestTensorDataset(unittest.TestCase): ...@@ -92,21 +91,16 @@ class TestTensorDataset(unittest.TestCase):
assert np.allclose(input.numpy(), input_np[i]) assert np.allclose(input.numpy(), input_np[i])
assert np.allclose(label.numpy(), label_np[i]) assert np.allclose(label.numpy(), label_np[i])
def func_test_main(self): def test_main(self):
places = [paddle.CPUPlace()] places = [paddle.CPUPlace()]
if paddle.is_compiled_with_cuda(): if paddle.is_compiled_with_cuda():
places.append(paddle.CUDAPlace(0)) places.append(paddle.CUDAPlace(0))
for p in places: for p in places:
self.run_main(num_workers=0, places=p) self.run_main(num_workers=0, places=p)
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class TestComposeDataset(unittest.TestCase): class TestComposeDataset(unittest.TestCase):
def func_test_main(self): def test_main(self):
paddle.static.default_startup_program().random_seed = 1 paddle.static.default_startup_program().random_seed = 1
paddle.static.default_main_program().random_seed = 1 paddle.static.default_main_program().random_seed = 1
...@@ -124,14 +118,9 @@ class TestComposeDataset(unittest.TestCase): ...@@ -124,14 +118,9 @@ class TestComposeDataset(unittest.TestCase):
assert np.allclose(input2, input2_t) assert np.allclose(input2, input2_t)
assert np.allclose(label2, label2_t) assert np.allclose(label2, label2_t)
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class TestRandomSplitApi(unittest.TestCase): class TestRandomSplitApi(unittest.TestCase):
def func_test_main(self): def test_main(self):
paddle.static.default_startup_program().random_seed = 1 paddle.static.default_startup_program().random_seed = 1
paddle.static.default_main_program().random_seed = 1 paddle.static.default_main_program().random_seed = 1
...@@ -150,14 +139,9 @@ class TestRandomSplitApi(unittest.TestCase): ...@@ -150,14 +139,9 @@ class TestRandomSplitApi(unittest.TestCase):
self.assertTrue(len(elements_list) == 0) self.assertTrue(len(elements_list) == 0)
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class TestRandomSplitError(unittest.TestCase): class TestRandomSplitError(unittest.TestCase):
def func_test_errors(self): def test_errors(self):
paddle.static.default_startup_program().random_seed = 1 paddle.static.default_startup_program().random_seed = 1
paddle.static.default_main_program().random_seed = 1 paddle.static.default_main_program().random_seed = 1
...@@ -165,11 +149,6 @@ class TestRandomSplitError(unittest.TestCase): ...@@ -165,11 +149,6 @@ class TestRandomSplitError(unittest.TestCase):
self.assertRaises(ValueError, paddle.io.random_split, range(5), [8]) self.assertRaises(ValueError, paddle.io.random_split, range(5), [8])
self.assertRaises(ValueError, paddle.io.random_split, range(5), []) self.assertRaises(ValueError, paddle.io.random_split, range(5), [])
def test_errors(self):
with _test_eager_guard():
self.func_test_errors()
self.func_test_errors()
class TestSubsetDataset(unittest.TestCase): class TestSubsetDataset(unittest.TestCase):
def run_main(self, num_workers, places): def run_main(self, num_workers, places):
...@@ -228,7 +207,7 @@ class TestSubsetDataset(unittest.TestCase): ...@@ -228,7 +207,7 @@ class TestSubsetDataset(unittest.TestCase):
self.assertEqual(odd_list, elements_list) self.assertEqual(odd_list, elements_list)
def func_test_main(self): def test_main(self):
paddle.static.default_startup_program().random_seed = 1 paddle.static.default_startup_program().random_seed = 1
paddle.static.default_main_program().random_seed = 1 paddle.static.default_main_program().random_seed = 1
...@@ -238,11 +217,6 @@ class TestSubsetDataset(unittest.TestCase): ...@@ -238,11 +217,6 @@ class TestSubsetDataset(unittest.TestCase):
for p in places: for p in places:
self.run_main(num_workers=0, places=p) self.run_main(num_workers=0, places=p)
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class TestChainDataset(unittest.TestCase): class TestChainDataset(unittest.TestCase):
def run_main(self, num_workers, places): def run_main(self, num_workers, places):
...@@ -268,18 +242,13 @@ class TestChainDataset(unittest.TestCase): ...@@ -268,18 +242,13 @@ class TestChainDataset(unittest.TestCase):
assert np.allclose(label, samples[idx][1]) assert np.allclose(label, samples[idx][1])
idx += 1 idx += 1
def func_test_main(self): def test_main(self):
places = [paddle.CPUPlace()] places = [paddle.CPUPlace()]
if paddle.is_compiled_with_cuda(): if paddle.is_compiled_with_cuda():
places.append(paddle.CUDAPlace(0)) places.append(paddle.CUDAPlace(0))
for p in places: for p in places:
self.run_main(num_workers=0, places=p) self.run_main(num_workers=0, places=p)
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class NumpyMixTensorDataset(Dataset): class NumpyMixTensorDataset(Dataset):
def __init__(self, sample_num): def __init__(self, sample_num):
...@@ -380,15 +349,10 @@ class TestComplextDataset(unittest.TestCase): ...@@ -380,15 +349,10 @@ class TestComplextDataset(unittest.TestCase):
assert data[4]['a'].shape == [2] assert data[4]['a'].shape == [2]
assert data[4]['b'].shape == [2, 2] assert data[4]['b'].shape == [2, 2]
def func_test_main(self): def test_main(self):
for num_workers in [0, 2]: for num_workers in [0, 2]:
self.run_main(num_workers) self.run_main(num_workers)
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class SingleFieldDataset(Dataset): class SingleFieldDataset(Dataset):
def __init__(self, sample_num): def __init__(self, sample_num):
...@@ -426,15 +390,10 @@ class TestSingleFieldDataset(unittest.TestCase): ...@@ -426,15 +390,10 @@ class TestSingleFieldDataset(unittest.TestCase):
) )
assert data.shape == [2, 2, 3] assert data.shape == [2, 2, 3]
def func_test_main(self): def test_main(self):
for num_workers in [0, 2]: for num_workers in [0, 2]:
self.run_main(num_workers) self.run_main(num_workers)
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class SingleFieldIterableDataset(IterableDataset): class SingleFieldIterableDataset(IterableDataset):
def __init__(self, sample_num): def __init__(self, sample_num):
...@@ -460,18 +419,13 @@ class TestDataLoaderGenerateStates(unittest.TestCase): ...@@ -460,18 +419,13 @@ class TestDataLoaderGenerateStates(unittest.TestCase):
[457190280, 2660306227, 859341110, 354512857], [457190280, 2660306227, 859341110, 354512857],
] ]
def func_test_main(self): def test_main(self):
from paddle.fluid.dataloader.worker import _generate_states from paddle.fluid.dataloader.worker import _generate_states
for inp, outp in zip(self.inputs, self.outputs): for inp, outp in zip(self.inputs, self.outputs):
out = _generate_states(*inp) out = _generate_states(*inp)
assert out == outp assert out == outp
def test_main(self):
with _test_eager_guard():
self.func_test_main()
self.func_test_main()
class TestDatasetWithDropLast(unittest.TestCase): class TestDatasetWithDropLast(unittest.TestCase):
def run_main(self, dataset, num_samples, batch_size): def run_main(self, dataset, num_samples, batch_size):
...@@ -491,24 +445,14 @@ class TestDatasetWithDropLast(unittest.TestCase): ...@@ -491,24 +445,14 @@ class TestDatasetWithDropLast(unittest.TestCase):
datas.append(data) datas.append(data)
assert len(datas) == steps assert len(datas) == steps
def func_test_map_dataset(self): def test_map_dataset(self):
dataset = RandomDataset(10) dataset = RandomDataset(10)
self.run_main(dataset, 10, 3) self.run_main(dataset, 10, 3)
def test_map_dataset(self): def test_iterable_dataset(self):
with _test_eager_guard():
self.func_test_map_dataset()
self.func_test_map_dataset()
def func_test_iterable_dataset(self):
dataset = RandomIterableDataset(10) dataset = RandomIterableDataset(10)
self.run_main(dataset, 10, 3) self.run_main(dataset, 10, 3)
def test_iterable_dataset(self):
with _test_eager_guard():
self.func_test_iterable_dataset()
self.func_test_iterable_dataset()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -19,7 +19,6 @@ from op_test import OpTest ...@@ -19,7 +19,6 @@ from op_test import OpTest
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid.framework import _test_eager_guard
def nll_loss_1d( def nll_loss_1d(
...@@ -112,7 +111,6 @@ class TestNLLLoss(unittest.TestCase): ...@@ -112,7 +111,6 @@ class TestNLLLoss(unittest.TestCase):
dy_result = dy_res.numpy() dy_result = dy_res.numpy()
with fluid.dygraph.guard(): with fluid.dygraph.guard():
with _test_eager_guard():
nll_loss = paddle.nn.loss.NLLLoss() nll_loss = paddle.nn.loss.NLLLoss()
eager_res = nll_loss( eager_res = nll_loss(
paddle.to_tensor(input_np), paddle.to_tensor(label_np) paddle.to_tensor(input_np), paddle.to_tensor(label_np)
...@@ -158,7 +156,6 @@ class TestNLLLoss(unittest.TestCase): ...@@ -158,7 +156,6 @@ class TestNLLLoss(unittest.TestCase):
) )
dy_result = dy_res.numpy() dy_result = dy_res.numpy()
with _test_eager_guard():
nll_loss = paddle.nn.loss.NLLLoss(reduction='sum') nll_loss = paddle.nn.loss.NLLLoss(reduction='sum')
in_t = paddle.to_tensor(input_np) in_t = paddle.to_tensor(input_np)
label = paddle.to_tensor(label_np) label = paddle.to_tensor(label_np)
...@@ -215,7 +212,6 @@ class TestNLLLoss(unittest.TestCase): ...@@ -215,7 +212,6 @@ class TestNLLLoss(unittest.TestCase):
) )
dy_result = dy_res.numpy() dy_result = dy_res.numpy()
with _test_eager_guard():
nll_loss = paddle.nn.loss.NLLLoss( nll_loss = paddle.nn.loss.NLLLoss(
weight=paddle.to_tensor(weight_np) weight=paddle.to_tensor(weight_np)
) )
......
...@@ -17,13 +17,12 @@ import unittest ...@@ -17,13 +17,12 @@ import unittest
import numpy as np import numpy as np
import paddle import paddle
from paddle.fluid.framework import _test_eager_guard
paddle.disable_static() paddle.disable_static()
class EmbeddingDygraph(unittest.TestCase): class EmbeddingDygraph(unittest.TestCase):
def func_1(self): def test_1(self):
x_data = np.arange(3, 6).reshape((3, 1)).astype(np.int64) x_data = np.arange(3, 6).reshape((3, 1)).astype(np.int64)
paddle.disable_static(paddle.CPUPlace()) paddle.disable_static(paddle.CPUPlace())
x = paddle.to_tensor(x_data, stop_gradient=False) x = paddle.to_tensor(x_data, stop_gradient=False)
...@@ -42,12 +41,7 @@ class EmbeddingDygraph(unittest.TestCase): ...@@ -42,12 +41,7 @@ class EmbeddingDygraph(unittest.TestCase):
out.backward() out.backward()
adam.step() adam.step()
def test_1(self): def test_2(self):
with _test_eager_guard():
self.func_1()
self.func_1()
def func_2(self):
x_data = np.arange(3, 6).reshape((3, 1)).astype(np.int64) x_data = np.arange(3, 6).reshape((3, 1)).astype(np.int64)
y_data = np.arange(6, 12).reshape((3, 2)).astype(np.float32) y_data = np.arange(6, 12).reshape((3, 2)).astype(np.float32)
paddle.disable_static(paddle.CPUPlace()) paddle.disable_static(paddle.CPUPlace())
...@@ -63,11 +57,6 @@ class EmbeddingDygraph(unittest.TestCase): ...@@ -63,11 +57,6 @@ class EmbeddingDygraph(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
embedding = paddle.nn.Embedding(10, -3, sparse=True) embedding = paddle.nn.Embedding(10, -3, sparse=True)
def test_2(self):
with _test_eager_guard():
self.func_2()
self.func_2()
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.functional as F import paddle.nn.functional as F
from paddle.fluid.framework import _test_eager_guard
def p_normalize(x, axis=1, p=2, epsilon=1e-12, keepdims=True): def p_normalize(x, axis=1, p=2, epsilon=1e-12, keepdims=True):
...@@ -87,12 +86,6 @@ class TestNNFunctionalNormalize(unittest.TestCase): ...@@ -87,12 +86,6 @@ class TestNNFunctionalNormalize(unittest.TestCase):
with fluid.program_guard(fluid.Program()): with fluid.program_guard(fluid.Program()):
self.run_static() self.run_static()
def test_cpu_eager(self):
with _test_eager_guard():
paddle.disable_static(place=paddle.fluid.CPUPlace())
self.run_imperative()
paddle.enable_static()
def test_gpu(self): def test_gpu(self):
if not fluid.core.is_compiled_with_cuda(): if not fluid.core.is_compiled_with_cuda():
return return
...@@ -104,15 +97,6 @@ class TestNNFunctionalNormalize(unittest.TestCase): ...@@ -104,15 +97,6 @@ class TestNNFunctionalNormalize(unittest.TestCase):
with fluid.program_guard(fluid.Program()): with fluid.program_guard(fluid.Program()):
self.run_static(use_gpu=True) self.run_static(use_gpu=True)
def test_gpu_eager(self):
with _test_eager_guard():
if not fluid.core.is_compiled_with_cuda():
return
paddle.disable_static(place=paddle.fluid.CUDAPlace(0))
self.run_imperative()
paddle.enable_static()
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.
先完成此消息的编辑!
想要评论请 注册