From 89bd4011ae5f468bba1abfad7bdfbde7ac9ac019 Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Mon, 5 Dec 2022 18:21:07 +0800 Subject: [PATCH] [CodeStyle][E401][F811] remove redefined imports and variables (#48538) --- .flake8 | 10 ++++++++-- python/paddle/autograd/__init__.py | 2 -- python/paddle/distributed/auto_parallel/utils.py | 1 - python/paddle/distributed/fleet/elastic/__init__.py | 3 ++- python/paddle/distributed/fleet/model.py | 1 - .../fluid/tests/custom_runtime/process_group_xccl.py | 1 - .../collective/fleet/dygraph_dist_save_load.py | 1 - .../collective/fleet/dygraph_group_sharded_api.py | 1 - .../fleet/dygraph_group_sharded_api_eager.py | 1 - .../collective/fleet/dygraph_group_sharded_stage2.py | 1 - .../dygraph_group_sharded_stage2_comm_overlap.py | 1 - .../collective/fleet/dygraph_group_sharded_stage3.py | 1 - .../fleet/dygraph_group_sharded_stage3_offload.py | 1 - .../fleet/dygraph_sharding_optimizer_stage2.py | 1 - .../collective/fleet/dygraph_sharding_stage2.py | 1 - .../collective/fleet/dygraph_sharding_stage3.py | 1 - .../fleet/dygraph_sharding_stage3_offload.py | 1 - .../fleet/parallel_dygraph_control_flow_same.py | 1 - .../collective/fleet/parallel_dygraph_no_sync.py | 1 - .../fleet/parallel_dygraph_no_sync_control_flow.py | 1 - .../collective/fleet/parallel_dygraph_se_resnext.py | 1 - .../multinode/mn_dygraph_group_sharded_stage3.py | 1 - .../multinode/mn_dygraph_sharding_stage2.py | 1 - .../tests/unittests/collective/process_group_gloo.py | 1 - .../tests/unittests/collective/process_group_mpi.py | 1 - python/paddle/fluid/tests/unittests/dist_word2vec.py | 2 -- .../unittests/dygraph_to_static/test_mobile_net.py | 2 +- .../unittests/dygraph_to_static/test_sentiment.py | 2 +- .../fluid/tests/unittests/ipu/test_pad_op_ipu.py | 4 ++-- .../unittests/parallel_dygraph_shared_unused_var.py | 1 - .../fluid/tests/unittests/test_batch_norm_op.py | 2 -- .../fluid/tests/unittests/test_batch_norm_op_v2.py | 2 -- .../tests/unittests/test_collective_api_base.py | 5 +---- .../fluid/tests/unittests/test_collective_base.py | 5 +---- python/paddle/fluid/tests/unittests/test_crop_op.py | 2 -- .../fluid/tests/unittests/test_crop_tensor_op.py | 2 -- .../fluid/tests/unittests/test_dist_fleet_base.py | 12 +++++------- .../unittests/test_fuse_relu_depthwise_conv_pass.py | 2 +- .../paddle/fluid/tests/unittests/test_gru_unit_op.py | 1 - .../unittests/test_imperative_ocr_attention_model.py | 2 +- .../fluid/tests/unittests/test_math_op_patch.py | 4 ++-- python/paddle/fluid/tests/unittests/test_norm_op.py | 2 -- .../tests/unittests/test_optimizer_for_varbase.py | 2 +- .../paddle/fluid/tests/unittests/test_reduce_op.py | 2 -- .../fluid/tests/unittests/test_searchsorted_op.py | 1 - .../unittests/test_split_and_merge_lod_tensor_op.py | 1 - python/paddle/fluid/tests/unittests/test_sum_op.py | 1 - python/paddle/fluid/tests/unittests/test_var_base.py | 5 ----- .../unittests/xpu/test_bilinear_interp_v2_op_xpu.py | 1 - .../tests/unittests/xpu/test_collective_base_xpu.py | 5 +---- .../fluid/tests/unittests/xpu/test_mean_op_xpu.py | 1 - .../fluid/tests/unittests/xpu/test_roll_op_xpu.py | 2 +- .../unittests/xpu/test_sequence_unpad_op_xpu.py | 3 --- python/paddle/jit/dy2static/call_transformer.py | 2 +- python/paddle/nn/functional/activation.py | 1 - python/paddle/nn/functional/common.py | 1 - python/paddle/nn/functional/loss.py | 2 +- python/paddle/nn/layer/__init__.py | 1 - python/paddle/tensor/math.py | 1 - python/paddle/tests/test_transforms.py | 2 +- python/paddle/utils/flops.py | 2 +- 61 files changed, 32 insertions(+), 93 deletions(-) diff --git a/.flake8 b/.flake8 index 84ebba9747..2d284df082 100644 --- a/.flake8 +++ b/.flake8 @@ -17,13 +17,13 @@ exclude = ignore = # E, see https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes E203, - E401,E402, + E402, E501, E721,E722,E731,E741, # F, see https://flake8.pycqa.org/en/latest/user/error-codes.html F405, - F811,F841, + F841, # W, see https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes W503 @@ -37,3 +37,9 @@ 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 diff --git a/python/paddle/autograd/__init__.py b/python/paddle/autograd/__init__.py index 19742cf6af..c05967ecd6 100644 --- a/python/paddle/autograd/__init__.py +++ b/python/paddle/autograd/__init__.py @@ -25,8 +25,6 @@ if _in_eager_mode_: else: from .py_layer import LegacyPyLayer as PyLayer # noqa: F401 from .py_layer import LegacyPyLayerContext as PyLayerContext # noqa: F401 -from ..framework import set_grad_enabled, is_grad_enabled # noqa: F401 -from ..fluid.dygraph.base import no_grad_ as no_grad # noqa: F401 from .saved_tensors_hooks import saved_tensors_hooks __all__ = [ # noqa diff --git a/python/paddle/distributed/auto_parallel/utils.py b/python/paddle/distributed/auto_parallel/utils.py index 0196ca9e7a..62004269e9 100644 --- a/python/paddle/distributed/auto_parallel/utils.py +++ b/python/paddle/distributed/auto_parallel/utils.py @@ -35,7 +35,6 @@ from paddle.fluid.framework import Variable from paddle.fluid.io import is_belong_to_optimizer, is_parameter OP_ROLE_KEY = core.op_proto_and_checker_maker.kOpRoleAttrName() -OpRole = core.op_proto_and_checker_maker.OpRole __no_shape_var_type__ = [ core.VarDesc.VarType.READER, diff --git a/python/paddle/distributed/fleet/elastic/__init__.py b/python/paddle/distributed/fleet/elastic/__init__.py index 447bedb21d..51fc0ca7d6 100644 --- a/python/paddle/distributed/fleet/elastic/__init__.py +++ b/python/paddle/distributed/fleet/elastic/__init__.py @@ -13,7 +13,8 @@ # limitations under the License. import signal -import os, sys +import os +import sys from .manager import ElasticManager from .manager import ElasticStatus diff --git a/python/paddle/distributed/fleet/model.py b/python/paddle/distributed/fleet/model.py index 8a480f0b9e..66c9804b5a 100755 --- a/python/paddle/distributed/fleet/model.py +++ b/python/paddle/distributed/fleet/model.py @@ -14,7 +14,6 @@ import paddle from paddle.distributed import fleet -from paddle.fluid.dygraph.varbase_patch_methods import _grad_scalar from .base.topology import ParallelMode from .meta_parallel import ( diff --git a/python/paddle/fluid/tests/custom_runtime/process_group_xccl.py b/python/paddle/fluid/tests/custom_runtime/process_group_xccl.py index 4abe2d7b63..d97b889ff0 100644 --- a/python/paddle/fluid/tests/custom_runtime/process_group_xccl.py +++ b/python/paddle/fluid/tests/custom_runtime/process_group_xccl.py @@ -18,7 +18,6 @@ import unittest import numpy as np import paddle -import paddle.fluid.core as core from paddle.fluid import core from paddle.fluid.dygraph.parallel import ParallelEnv from paddle.fluid.framework import _test_eager_guard diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_dist_save_load.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_dist_save_load.py index a9c525daae..553ce09704 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_dist_save_load.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_dist_save_load.py @@ -31,7 +31,6 @@ from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_optimizer_sta from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_stage2 import ( GroupShardedStage2, ) -from paddle.fluid.dygraph.nn import Linear from paddle.incubate.distributed.utils.io import load, save from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api.py index 6ecf1ca72d..ae6f7059bf 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api.py @@ -24,7 +24,6 @@ from paddle.distributed.sharding import ( group_sharded_parallel, save_group_sharded_model, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api_eager.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api_eager.py index 3849b80608..4d9f43db7f 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api_eager.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_api_eager.py @@ -22,7 +22,6 @@ from paddle.distributed.sharding import ( group_sharded_parallel, save_group_sharded_model, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage2.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage2.py index fc562ffae2..84be00cc1c 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage2.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage2.py @@ -28,7 +28,6 @@ from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_optimizer_sta from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_stage2 import ( GroupShardedStage2, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage2_comm_overlap.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage2_comm_overlap.py index 7e2b626ec4..e92577e78f 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage2_comm_overlap.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage2_comm_overlap.py @@ -28,7 +28,6 @@ from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_optimizer_sta from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_stage2 import ( GroupShardedStage2, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3.py index d462eb339b..95e0bdc6a0 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3.py @@ -34,7 +34,6 @@ from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_stage3 import from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_utils import ( GroupShardedScaler, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3_offload.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3_offload.py index 3bb6ed15a6..f12de252c2 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3_offload.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3_offload.py @@ -24,7 +24,6 @@ from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_stage3 import from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_utils import ( GroupShardedScaler, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_optimizer_stage2.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_optimizer_stage2.py index 2b42375073..e033603826 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_optimizer_stage2.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_optimizer_stage2.py @@ -23,7 +23,6 @@ from paddle.distributed.fleet.meta_optimizers.dygraph_optimizer.sharding_optimiz ShardingOptimizerStage2, ) from paddle.distributed.fleet.utils.internal_storage import GradStorage -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage2.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage2.py index 9a7d1081a6..94a735a01f 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage2.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage2.py @@ -29,7 +29,6 @@ from paddle.distributed.fleet.meta_optimizers.dygraph_optimizer.sharding_optimiz from paddle.distributed.fleet.meta_parallel.sharding.sharding_stage2 import ( ShardingStage2, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage3.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage3.py index 6822872a39..189c683db2 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage3.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage3.py @@ -35,7 +35,6 @@ from paddle.distributed.fleet.meta_parallel.sharding.sharding_stage3 import ( from paddle.distributed.fleet.meta_parallel.sharding.sharding_utils import ( ShardingScaler, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage3_offload.py b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage3_offload.py index 1ebcff04c8..07819a2f81 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage3_offload.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/dygraph_sharding_stage3_offload.py @@ -25,7 +25,6 @@ from paddle.distributed.fleet.meta_parallel.sharding.sharding_stage3 import ( from paddle.distributed.fleet.meta_parallel.sharding.sharding_utils import ( ShardingScaler, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_control_flow_same.py b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_control_flow_same.py index 9bf0f50676..2c83a3322f 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_control_flow_same.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_control_flow_same.py @@ -18,7 +18,6 @@ from test_dist_base import TestParallelDyGraphRunnerBase, runtime_main import paddle import paddle.fluid as fluid from paddle.fluid.dygraph.base import to_variable -from paddle.fluid.dygraph.nn import Linear from paddle.nn import Linear np.random.seed(2021) diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_no_sync.py b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_no_sync.py index 970b0cee70..59a0f9a250 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_no_sync.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_no_sync.py @@ -26,7 +26,6 @@ from test_dist_base import ( import paddle import paddle.distributed as dist import paddle.fluid as fluid -from paddle.fluid.dygraph.nn import Linear from paddle.nn import Linear seed = 90 diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_no_sync_control_flow.py b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_no_sync_control_flow.py index 8ac9d6b211..59a59a8042 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_no_sync_control_flow.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_no_sync_control_flow.py @@ -18,7 +18,6 @@ from test_dist_base import runtime_main import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.nn import Linear from paddle.nn import Linear seed = 90 diff --git a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_se_resnext.py b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_se_resnext.py index eef3f6bdd7..14bb4023b8 100644 --- a/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_se_resnext.py +++ b/python/paddle/fluid/tests/unittests/collective/fleet/parallel_dygraph_se_resnext.py @@ -20,7 +20,6 @@ from test_dist_base import TestParallelDyGraphRunnerBase, runtime_main import paddle import paddle.fluid as fluid from paddle.fluid.dygraph.base import to_variable -from paddle.fluid.dygraph.nn import Linear from paddle.nn import Linear batch_size = 64 diff --git a/python/paddle/fluid/tests/unittests/collective/multinode/mn_dygraph_group_sharded_stage3.py b/python/paddle/fluid/tests/unittests/collective/multinode/mn_dygraph_group_sharded_stage3.py index 5c328591bd..72f89eb25f 100644 --- a/python/paddle/fluid/tests/unittests/collective/multinode/mn_dygraph_group_sharded_stage3.py +++ b/python/paddle/fluid/tests/unittests/collective/multinode/mn_dygraph_group_sharded_stage3.py @@ -34,7 +34,6 @@ from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_stage3 import from paddle.distributed.fleet.meta_parallel.sharding.group_sharded_utils import ( GroupShardedScaler, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/multinode/mn_dygraph_sharding_stage2.py b/python/paddle/fluid/tests/unittests/collective/multinode/mn_dygraph_sharding_stage2.py index d68a6cb588..b088bf424b 100644 --- a/python/paddle/fluid/tests/unittests/collective/multinode/mn_dygraph_sharding_stage2.py +++ b/python/paddle/fluid/tests/unittests/collective/multinode/mn_dygraph_sharding_stage2.py @@ -29,7 +29,6 @@ from paddle.distributed.fleet.meta_optimizers.dygraph_optimizer.sharding_optimiz from paddle.distributed.fleet.meta_parallel.sharding.sharding_stage2 import ( ShardingStage2, ) -from paddle.fluid.dygraph.nn import Linear from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/collective/process_group_gloo.py b/python/paddle/fluid/tests/unittests/collective/process_group_gloo.py index 990a8d4867..ad2c91381a 100644 --- a/python/paddle/fluid/tests/unittests/collective/process_group_gloo.py +++ b/python/paddle/fluid/tests/unittests/collective/process_group_gloo.py @@ -18,7 +18,6 @@ import unittest import numpy as np import paddle -import paddle.fluid.core as core from paddle.fluid import core from paddle.fluid.dygraph.parallel import ParallelEnv from paddle.fluid.framework import _test_eager_guard diff --git a/python/paddle/fluid/tests/unittests/collective/process_group_mpi.py b/python/paddle/fluid/tests/unittests/collective/process_group_mpi.py index 1e82dedcc5..2fb9deb110 100644 --- a/python/paddle/fluid/tests/unittests/collective/process_group_mpi.py +++ b/python/paddle/fluid/tests/unittests/collective/process_group_mpi.py @@ -20,7 +20,6 @@ import numpy as np import paddle import paddle.distributed as dist -import paddle.fluid.core as core from paddle.distributed.collective import ( Group, _default_group_name, diff --git a/python/paddle/fluid/tests/unittests/dist_word2vec.py b/python/paddle/fluid/tests/unittests/dist_word2vec.py index 146521fa39..ed3a83a5b4 100644 --- a/python/paddle/fluid/tests/unittests/dist_word2vec.py +++ b/python/paddle/fluid/tests/unittests/dist_word2vec.py @@ -138,8 +138,6 @@ class TestDistWord2vec2x2(TestDistRunnerBase): if __name__ == "__main__": - import os - os.environ['CPU_NUM'] = '1' os.environ['USE_CUDA'] = "FALSE" runtime_main(TestDistWord2vec2x2) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py index 8358c12edc..ff36720594 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py @@ -23,7 +23,7 @@ from predictor_utils import PredictorTools import paddle import paddle.fluid as fluid from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX -from paddle.fluid.dygraph.nn import BatchNorm, Linear +from paddle.fluid.dygraph.nn import BatchNorm from paddle.fluid.initializer import MSRA from paddle.fluid.param_attr import ParamAttr from paddle.jit import ProgramTranslator diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py index c644cdfe0c..e259ce5cf2 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py @@ -20,7 +20,7 @@ from test_lac import DynamicGRU import paddle import paddle.fluid as fluid from paddle.fluid.dygraph import to_variable -from paddle.fluid.dygraph.nn import Embedding, Linear +from paddle.fluid.dygraph.nn import Embedding from paddle.jit import ProgramTranslator from paddle.jit.api import declarative from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/ipu/test_pad_op_ipu.py b/python/paddle/fluid/tests/unittests/ipu/test_pad_op_ipu.py index f716c58e4a..702f2b4ea1 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_pad_op_ipu.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_pad_op_ipu.py @@ -126,13 +126,13 @@ class TestCase7(TestBase): @unittest.skip("Only support NCL, NCHW, NCDHW") -class TestCase7(TestBase): +class TestCase8(TestBase): def set_op_attrs(self): self.attrs = {"pad": [1, 2, 3, 4], "data_format": "NHWC"} @unittest.skip("Only support NCL, NCHW, NCDHW") -class TestCase7(TestBase): +class TestCase9(TestBase): def set_op_attrs(self): self.attrs = {"pad": [1, 2, 3, 4, 1, 3], "data_format": "NDHWC"} diff --git a/python/paddle/fluid/tests/unittests/parallel_dygraph_shared_unused_var.py b/python/paddle/fluid/tests/unittests/parallel_dygraph_shared_unused_var.py index 1f063f849e..6257100779 100644 --- a/python/paddle/fluid/tests/unittests/parallel_dygraph_shared_unused_var.py +++ b/python/paddle/fluid/tests/unittests/parallel_dygraph_shared_unused_var.py @@ -18,7 +18,6 @@ from test_dist_base import TestParallelDyGraphRunnerBase, runtime_main import paddle import paddle.fluid as fluid from paddle.fluid.dygraph.base import to_variable -from paddle.fluid.dygraph.nn import Linear from paddle.nn import Linear np.random.seed(2021) diff --git a/python/paddle/fluid/tests/unittests/test_batch_norm_op.py b/python/paddle/fluid/tests/unittests/test_batch_norm_op.py index 9c3f04b136..34b3581302 100644 --- a/python/paddle/fluid/tests/unittests/test_batch_norm_op.py +++ b/python/paddle/fluid/tests/unittests/test_batch_norm_op.py @@ -847,7 +847,5 @@ class TestDygraphBatchNormOpenReserveSpace(unittest.TestCase): if __name__ == '__main__': - import paddle - paddle.enable_static() unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_batch_norm_op_v2.py b/python/paddle/fluid/tests/unittests/test_batch_norm_op_v2.py index 7056c34487..1818d39205 100644 --- a/python/paddle/fluid/tests/unittests/test_batch_norm_op_v2.py +++ b/python/paddle/fluid/tests/unittests/test_batch_norm_op_v2.py @@ -422,7 +422,5 @@ class TestBatchNormUseGlobalStatsCase3(TestBatchNormUseGlobalStats): if __name__ == '__main__': - import paddle - paddle.enable_static() unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_collective_api_base.py b/python/paddle/fluid/tests/unittests/test_collective_api_base.py index 096ac99f9c..9a53ab7762 100644 --- a/python/paddle/fluid/tests/unittests/test_collective_api_base.py +++ b/python/paddle/fluid/tests/unittests/test_collective_api_base.py @@ -14,6 +14,7 @@ import os import pickle +import socket import subprocess import sys import tempfile @@ -161,10 +162,6 @@ def runtime_main(test_class, col_type): model.run_trainer(args) -import socket -from contextlib import closing - - class TestDistBase(unittest.TestCase): def setUp(self): self._port_set = set() diff --git a/python/paddle/fluid/tests/unittests/test_collective_base.py b/python/paddle/fluid/tests/unittests/test_collective_base.py index 1483cd1d07..238a145f05 100644 --- a/python/paddle/fluid/tests/unittests/test_collective_base.py +++ b/python/paddle/fluid/tests/unittests/test_collective_base.py @@ -14,6 +14,7 @@ import os import pickle +import socket import subprocess import sys import tempfile @@ -140,10 +141,6 @@ def runtime_main(test_class, col_type, sub_type): model.run_trainer(args) -import socket -from contextlib import closing - - class TestDistBase(unittest.TestCase): def setUp(self): self._port_set = set() diff --git a/python/paddle/fluid/tests/unittests/test_crop_op.py b/python/paddle/fluid/tests/unittests/test_crop_op.py index 5e13eacb6e..1050fb0ad5 100644 --- a/python/paddle/fluid/tests/unittests/test_crop_op.py +++ b/python/paddle/fluid/tests/unittests/test_crop_op.py @@ -150,7 +150,5 @@ class TestCropNoneShape(unittest.TestCase): if __name__ == '__main__': - import paddle - paddle.enable_static() unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_crop_tensor_op.py b/python/paddle/fluid/tests/unittests/test_crop_tensor_op.py index 620c10a2bd..e8d78956fd 100644 --- a/python/paddle/fluid/tests/unittests/test_crop_tensor_op.py +++ b/python/paddle/fluid/tests/unittests/test_crop_tensor_op.py @@ -271,7 +271,5 @@ class TestCropTensorException(unittest.TestCase): if __name__ == '__main__': - import paddle - paddle.enable_static() unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_dist_fleet_base.py b/python/paddle/fluid/tests/unittests/test_dist_fleet_base.py index c84bd2b7ca..f1a790d8e8 100644 --- a/python/paddle/fluid/tests/unittests/test_dist_fleet_base.py +++ b/python/paddle/fluid/tests/unittests/test_dist_fleet_base.py @@ -12,14 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import paddle -import paddle.distributed.fleet as fleet -import paddle.distributed.fleet.base.role_maker as role_maker -import paddle.fluid as fluid -from paddle.distributed.fleet.utils.ps_util import DistributedInfer - """ - high level unit test for distribute fleet. +high level unit test for distribute fleet. """ import argparse @@ -34,6 +28,10 @@ import unittest from contextlib import closing import paddle +import paddle.distributed.fleet as fleet +import paddle.distributed.fleet.base.role_maker as role_maker +import paddle.fluid as fluid +from paddle.distributed.fleet.utils.ps_util import DistributedInfer paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/test_fuse_relu_depthwise_conv_pass.py b/python/paddle/fluid/tests/unittests/test_fuse_relu_depthwise_conv_pass.py index ed7cb760f0..a136a623d0 100644 --- a/python/paddle/fluid/tests/unittests/test_fuse_relu_depthwise_conv_pass.py +++ b/python/paddle/fluid/tests/unittests/test_fuse_relu_depthwise_conv_pass.py @@ -89,7 +89,7 @@ class TestMNIST(TestParallelExecutorBase): return optimizer if only_forward: - _optimizer = None + _optimizer = None # noqa: F811 ( fuse_op_first_loss, diff --git a/python/paddle/fluid/tests/unittests/test_gru_unit_op.py b/python/paddle/fluid/tests/unittests/test_gru_unit_op.py index 2f7c4a42e3..92fadf591a 100644 --- a/python/paddle/fluid/tests/unittests/test_gru_unit_op.py +++ b/python/paddle/fluid/tests/unittests/test_gru_unit_op.py @@ -19,7 +19,6 @@ import numpy as np from op_test import OpTest import paddle.fluid as fluid -from paddle import fluid from paddle.fluid.framework import Program, program_guard from paddle.fluid.layers import gru_unit diff --git a/python/paddle/fluid/tests/unittests/test_imperative_ocr_attention_model.py b/python/paddle/fluid/tests/unittests/test_imperative_ocr_attention_model.py index 8c46a64162..998e9de7ff 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_ocr_attention_model.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_ocr_attention_model.py @@ -21,7 +21,7 @@ import paddle import paddle.fluid as fluid from paddle.fluid import core from paddle.fluid.dygraph.base import to_variable -from paddle.fluid.dygraph.nn import BatchNorm, Embedding, GRUUnit, Linear +from paddle.fluid.dygraph.nn import BatchNorm, Embedding, GRUUnit from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear diff --git a/python/paddle/fluid/tests/unittests/test_math_op_patch.py b/python/paddle/fluid/tests/unittests/test_math_op_patch.py index a582b4951b..fb3b342131 100644 --- a/python/paddle/fluid/tests/unittests/test_math_op_patch.py +++ b/python/paddle/fluid/tests/unittests/test_math_op_patch.py @@ -53,7 +53,7 @@ class TestMathOpPatches(unittest.TestCase): place = fluid.CPUPlace() exe = fluid.Executor(place) a_np = np.random.random(size=[10, 1]).astype('float32') - b_np = exe.run( + (b_np,) = exe.run( fluid.default_main_program(), feed={"a": a_np}, fetch_list=[b] ) np.testing.assert_allclose(a_np + 10, b_np, rtol=1e-05) @@ -71,7 +71,7 @@ class TestMathOpPatches(unittest.TestCase): np.testing.assert_allclose(a_np - 10, b_np, rtol=1e-05) @prog_scope() - def test_radd_scalar(self): + def test_rsub_scalar(self): a = fluid.layers.data(name="a", shape=[1]) b = 10 - a place = fluid.CPUPlace() diff --git a/python/paddle/fluid/tests/unittests/test_norm_op.py b/python/paddle/fluid/tests/unittests/test_norm_op.py index 82e8796771..232d5ceda4 100644 --- a/python/paddle/fluid/tests/unittests/test_norm_op.py +++ b/python/paddle/fluid/tests/unittests/test_norm_op.py @@ -161,7 +161,5 @@ class API_NormTest(unittest.TestCase): if __name__ == '__main__': - import paddle - paddle.enable_static() unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_optimizer_for_varbase.py b/python/paddle/fluid/tests/unittests/test_optimizer_for_varbase.py index 183423ba98..e53ac6bbd9 100644 --- a/python/paddle/fluid/tests/unittests/test_optimizer_for_varbase.py +++ b/python/paddle/fluid/tests/unittests/test_optimizer_for_varbase.py @@ -184,7 +184,7 @@ class TestOptimizerForVarBase(unittest.TestCase): z.backward() opt.step() - def func_test_create_param_lr_with_no_1_value_for_coverage(self): + def test_create_param_lr_with_no_1_value_for_coverage(self): with _test_eager_guard(): self.func_test_create_param_lr_with_1_for_coverage() self.func_test_create_param_lr_with_1_for_coverage() diff --git a/python/paddle/fluid/tests/unittests/test_reduce_op.py b/python/paddle/fluid/tests/unittests/test_reduce_op.py index 53a1af18ea..b101c24e77 100644 --- a/python/paddle/fluid/tests/unittests/test_reduce_op.py +++ b/python/paddle/fluid/tests/unittests/test_reduce_op.py @@ -1114,7 +1114,5 @@ class TestAnyAPI(unittest.TestCase): if __name__ == '__main__': - import paddle - paddle.enable_static() unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_searchsorted_op.py b/python/paddle/fluid/tests/unittests/test_searchsorted_op.py index e5980cea17..c83e8d5344 100644 --- a/python/paddle/fluid/tests/unittests/test_searchsorted_op.py +++ b/python/paddle/fluid/tests/unittests/test_searchsorted_op.py @@ -21,7 +21,6 @@ import paddle import paddle.fluid.core as core paddle.enable_static() -from op_test import OpTest class TestSearchSorted(OpTest): diff --git a/python/paddle/fluid/tests/unittests/test_split_and_merge_lod_tensor_op.py b/python/paddle/fluid/tests/unittests/test_split_and_merge_lod_tensor_op.py index c5350445a9..943e197a96 100644 --- a/python/paddle/fluid/tests/unittests/test_split_and_merge_lod_tensor_op.py +++ b/python/paddle/fluid/tests/unittests/test_split_and_merge_lod_tensor_op.py @@ -22,7 +22,6 @@ import paddle.fluid.layers as layers from paddle.fluid import Program, program_guard from paddle.fluid.backward import append_backward from paddle.fluid.executor import Executor -from paddle.fluid.framework import Program, program_guard from paddle.fluid.layer_helper import LayerHelper from paddle.fluid.layers.control_flow import merge_lod_tensor, split_lod_tensor diff --git a/python/paddle/fluid/tests/unittests/test_sum_op.py b/python/paddle/fluid/tests/unittests/test_sum_op.py index 9626a872e2..55ce3b3101 100644 --- a/python/paddle/fluid/tests/unittests/test_sum_op.py +++ b/python/paddle/fluid/tests/unittests/test_sum_op.py @@ -19,7 +19,6 @@ import unittest import gradient_checker import numpy as np from decorator_helper import prog_scope -from op_test import OpTest import paddle import paddle.fluid as fluid diff --git a/python/paddle/fluid/tests/unittests/test_var_base.py b/python/paddle/fluid/tests/unittests/test_var_base.py index 62b66be093..6fe6583b52 100644 --- a/python/paddle/fluid/tests/unittests/test_var_base.py +++ b/python/paddle/fluid/tests/unittests/test_var_base.py @@ -1380,11 +1380,6 @@ class TestVarBase(unittest.TestCase): self.func_tensor_str_bf16() self.func_tensor_str_bf16() - def test_tensor_str_bf16(self): - with _test_eager_guard(): - self.func_tensor_str_bf16() - self.func_tensor_str_bf16() - def func_test_print_tensor_dtype(self): paddle.disable_static(paddle.CPUPlace()) a = paddle.rand([1]) diff --git a/python/paddle/fluid/tests/unittests/xpu/test_bilinear_interp_v2_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_bilinear_interp_v2_op_xpu.py index 974f5f67ba..81e08c000b 100755 --- a/python/paddle/fluid/tests/unittests/xpu/test_bilinear_interp_v2_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_bilinear_interp_v2_op_xpu.py @@ -18,7 +18,6 @@ import unittest import numpy as np sys.path.append("..") -import unittest from op_test_xpu import XPUOpTest from xpu.get_test_cover_info import ( diff --git a/python/paddle/fluid/tests/unittests/xpu/test_collective_base_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_collective_base_xpu.py index 31e061ed2a..22e0a63e48 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_collective_base_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_collective_base_xpu.py @@ -14,6 +14,7 @@ import os import pickle +import socket import subprocess import sys import tempfile @@ -165,10 +166,6 @@ def runtime_main(test_class, col_type, sub_type): model.run_trainer(args) -import socket -from contextlib import closing - - class TestDistBase(unittest.TestCase): def setUp(self): self._port_set = set() diff --git a/python/paddle/fluid/tests/unittests/xpu/test_mean_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_mean_op_xpu.py index 22f759b46f..3991862346 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_mean_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_mean_op_xpu.py @@ -26,7 +26,6 @@ from paddle.fluid import Program, program_guard np.random.seed(10) -from op_test_xpu import XPUOpTest from xpu.get_test_cover_info import ( XPUOpTestWrapper, create_test_class, diff --git a/python/paddle/fluid/tests/unittests/xpu/test_roll_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_roll_op_xpu.py index d747ade7b6..25b156a280 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_roll_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_roll_op_xpu.py @@ -79,7 +79,7 @@ class XPUTestRollOp(XPUOpTestWrapper): self.shifts = [8, -1] self.axis = [-1, -2] - class TestRollOpCase4(TestXPURollOp): + class TestRollOpCase5(TestXPURollOp): def init_shapes(self): self.x_shape = (100, 10, 5, 10) self.shifts = [20, -1] diff --git a/python/paddle/fluid/tests/unittests/xpu/test_sequence_unpad_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_sequence_unpad_op_xpu.py index 17edbf907b..c24b1c2cd9 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_sequence_unpad_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_sequence_unpad_op_xpu.py @@ -19,9 +19,6 @@ import numpy as np sys.path.append("..") -import unittest - -import numpy as np from op_test_xpu import XPUOpTest from xpu.get_test_cover_info import ( XPUOpTestWrapper, diff --git a/python/paddle/jit/dy2static/call_transformer.py b/python/paddle/jit/dy2static/call_transformer.py index c5ae35ee3d..012c73b99f 100644 --- a/python/paddle/jit/dy2static/call_transformer.py +++ b/python/paddle/jit/dy2static/call_transformer.py @@ -62,7 +62,7 @@ class CallTransformer(BaseTransformer): 'enumerate', 'print', } - is_builtin = eval("is_builtin({})".format(func_str)) + is_builtin = eval("is_builtin({})".format(func_str)) # noqa: F811 need_convert = func_str in need_convert_builtin_func_list return is_builtin and not need_convert except Exception: diff --git a/python/paddle/nn/functional/activation.py b/python/paddle/nn/functional/activation.py index 69e54a067d..6bf32317a4 100644 --- a/python/paddle/nn/functional/activation.py +++ b/python/paddle/nn/functional/activation.py @@ -14,7 +14,6 @@ import paddle from paddle import _C_ops, _legacy_C_ops, in_dynamic_mode -from paddle.fluid.framework import _in_legacy_dygraph, in_dygraph_mode from paddle.framework import core from ...fluid.data_feeder import check_dtype, check_variable_and_dtype diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index 2e27a4fc8c..4fbb792ce8 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -14,7 +14,6 @@ import paddle from paddle import _C_ops, _legacy_C_ops -from paddle.fluid.framework import _in_legacy_dygraph from paddle.fluid.layer_helper import LayerHelper from paddle.fluid.layers.tensor import fill_constant from paddle.framework import core, in_dynamic_mode diff --git a/python/paddle/nn/functional/loss.py b/python/paddle/nn/functional/loss.py index 481598ab95..dd5c2e1282 100755 --- a/python/paddle/nn/functional/loss.py +++ b/python/paddle/nn/functional/loss.py @@ -17,7 +17,7 @@ import paddle import paddle.fluid as fluid from paddle import _C_ops, _legacy_C_ops, in_dynamic_mode -from paddle.framework import _non_static_mode, core +from paddle.framework import core from paddle.utils import deprecated from ...fluid.data_feeder import check_variable_and_dtype diff --git a/python/paddle/nn/layer/__init__.py b/python/paddle/nn/layer/__init__.py index 1acea10d67..3daf3185b7 100644 --- a/python/paddle/nn/layer/__init__.py +++ b/python/paddle/nn/layer/__init__.py @@ -43,7 +43,6 @@ from .common import Dropout # noqa: F401 from .common import Dropout2D # noqa: F401 from .common import Dropout3D # noqa: F401 from .common import AlphaDropout # noqa: F401 -from .common import Upsample # noqa: F401 from .common import UpsamplingBilinear2D # noqa: F401 from .common import UpsamplingNearest2D # noqa: F401 from .common import Fold diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index 857f99c8f6..efa8d7c453 100644 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -30,7 +30,6 @@ from ..fluid.data_feeder import ( convert_dtype, ) from ..fluid.dygraph.inplace_utils import inplace_apis_in_dygraph_only -from ..fluid.framework import _in_legacy_dygraph from ..fluid.layers import elementwise_sub, utils from ..framework import ( LayerHelper, diff --git a/python/paddle/tests/test_transforms.py b/python/paddle/tests/test_transforms.py index 7045b63455..7d1280b894 100644 --- a/python/paddle/tests/test_transforms.py +++ b/python/paddle/tests/test_transforms.py @@ -652,7 +652,7 @@ class TestTransformsTensor(TestTransformsCV2): transform = transforms.RandomResizedCrop(64) transform(1) - test_color_jitter = None + test_color_jitter = None # noqa: F811 class TestFunctional(unittest.TestCase): diff --git a/python/paddle/utils/flops.py b/python/paddle/utils/flops.py index 9c13176769..a930e0ef54 100644 --- a/python/paddle/utils/flops.py +++ b/python/paddle/utils/flops.py @@ -117,7 +117,7 @@ def _elementwise_mul_flops(input_shapes, attrs): @register_flops("elementwise_div") -def _elementwise_mul_flops(input_shapes, attrs): +def _elementwise_div_flops(input_shapes, attrs): """FLOPs computation for elementwise_div op. For elementwise_div(input,other): input_shapes = [shape_of_input, shape_of_ohther] -- GitLab