Skip to content

Commit

Permalink
[CodeStyle][F811] fix some test cases shadowed by the same name (#48745)
Browse files Browse the repository at this point in the history
* [CodeStyle][F811] fix some unittests

* fix setup.py

* remove ignore from flake8 config

* remove repeat TestAbsDoubleGradCheck

* fix rrelu test

* fix fft ut

* add noqa in fluid.lstm ut

* add rtol and atol in test_matmul_v2_op

* update rtol

* empty commit

* empty commit

* revert changes in matmul ut and add noqa

* rename test case name
  • Loading branch information
SigureMo authored Dec 8, 2022
1 parent da8e15e commit cdf31dc
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 65 deletions.
6 changes: 0 additions & 6 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,3 @@ per-file-ignores =
.cmake-format.py: F821
python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py: F821
python/paddle/fluid/tests/unittests/dygraph_to_static/test_closure_analysis.py: F821
# These files will be fixed in the future
python/paddle/fluid/tests/unittests/fft/test_fft_with_static_graph.py: F811
python/paddle/fluid/tests/unittests/test_activation_nn_grad.py: F811
python/paddle/fluid/tests/unittests/test_lstm_cudnn_op.py: F811
python/paddle/fluid/tests/unittests/test_matmul_v2_op.py: F811
python/paddle/fluid/tests/unittests/test_rrelu_op.py: F811
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_dygraph_group_sharded(self):
self.run_mnist_2gpu('dygraph_group_sharded_api_eager.py')

# check stage3 for some functions.
def test_dygraph_group_sharded(self):
def test_dygraph_group_sharded_stage3(self):
self.run_mnist_2gpu('dygraph_group_sharded_stage3_eager.py')


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,6 @@ def test_static_fftn(self):
@parameterize(
(TEST_CASE_NAME, 'x', 'n', 'axis', 'norm', 'expect_exception'),
[
(
'test_x_complex',
rand_x(4, complex=True),
None,
None,
'backward',
TypeError,
),
(
'test_n_nagative',
rand_x(4),
Expand All @@ -295,11 +287,11 @@ def test_static_fftn(self):
('test_norm_not_in_enum', rand_x(2), None, -1, 'random', ValueError),
],
)
class TestRfftnException(unittest.TestCase):
def test_static_rfftn(self):
class TestFftnException(unittest.TestCase):
def test_static_fftn(self):
with self.assertRaises(self.expect_exception):
with stgraph(
paddle.fft.rfftn,
paddle.fft.fftn,
self.place,
self.x,
self.n,
Expand Down
30 changes: 0 additions & 30 deletions python/paddle/fluid/tests/unittests/test_activation_nn_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,36 +407,6 @@ def test_grad(self):
self.func(p)


class TestAbsDoubleGradCheck(unittest.TestCase):
@prog_scope()
def func(self, place):
# the shape of input variable should be clearly specified, not inlcude -1.
shape = [2, 3, 7, 9]
eps = 1e-6
dtype = np.float64

x = layers.data('x', shape, False, dtype)
x.persistable = True
y = paddle.abs(x)
x_arr = np.random.uniform(-1, 1, shape).astype(dtype)
# Because we set delta = 0.005 in calculating numeric gradient,
# if x is too small, the numeric gradient is inaccurate.
# we should avoid this
x_arr[np.abs(x_arr) < 0.005] = 0.02

gradient_checker.double_grad_check(
[x], y, x_init=x_arr, place=place, eps=eps
)

def test_grad(self):
paddle.enable_static()
places = [fluid.CPUPlace()]
if core.is_compiled_with_cuda():
places.append(fluid.CUDAPlace(0))
for p in places:
self.func(p)


class TestLogDoubleGradCheck(unittest.TestCase):
def log_wrapper(self, x):
return paddle.log(x[0])
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_lstm_cudnn_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def test_lstm(self):
@unittest.skipIf(
not core.is_compiled_with_cuda(), "core is not compiled with CUDA"
)
class TestCUDNNlstmAPI(unittest.TestCase):
class TestCUDNNlstmAPI(unittest.TestCase): # noqa: F811
def test_lstm(self):
seq_len = 20
batch_size = 5
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_matmul_v2_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def func_dygraph_matmul(self):

paddle.enable_static()

def func_dygraph_matmul(self):
def func_dygraph_matmul(self): # noqa: F811
with _test_eager_guard():
self.func_dygraph_matmul()

Expand Down
19 changes: 5 additions & 14 deletions python/paddle/fluid/tests/unittests/test_rrelu_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ def setUp(self):
self.lower = 0.1
self.upper = 0.3
self.is_test = True
self.init_prams()
self.init_params()

def init_prams(self):
def init_params(self):
self.dtype = "float64"
self.x_shape = [2, 3, 4, 5]

Expand All @@ -343,22 +343,13 @@ def test_check_grad(self):
self.check_grad(['X'], 'Out')


class RReluTrainingTest(OpTest):
class RReluTrainingTest(RReluTest):
def setUp(self):
self.op_type = "rrelu"
self.lower = 0.3
self.upper = 0.3000009
self.upper = 0.300000009
self.is_test = False
self.init_prams()


class RReluTrainingTest(OpTest):
def setUp(self):
self.op_type = "rrelu"
self.lower = 0.3
self.upper = 0.3000009
self.is_test = False
self.init_prams()
self.init_params()


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from setuptools.command.egg_info import egg_info
from setuptools.command.install import install as InstallCommandBase
from setuptools.command.install_lib import install_lib
from setuptools.dist import Distribution

if sys.version_info < (3, 7):
raise RuntimeError(
Expand Down

0 comments on commit cdf31dc

Please sign in to comment.