From ab1babbb50945f398ebe028a44ebff93eb909561 Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Mon, 10 Oct 2022 17:03:15 +0800 Subject: [PATCH] [CodeStyle][F401] remove unused imports in unittests/distributed_passes,tokenizer,sequence (#46793) * [CodeStyle][F401] remove unused imports in unittests/distributed_passes,tokenizer,sequence * add noqa after required imports --- .../auto_parallel_pass_test_base.py | 4 ---- .../distributed_passes/dist_pass_test_base.py | 2 +- .../unittests/distributed_passes/pass_run_main.py | 1 - .../unittests/distributed_passes/ps_pass_test_base.py | 11 ++--------- .../distributed_passes/test_auto_parallel_amp_pass.py | 1 - ...t_auto_parallel_data_parallel_optimization_pass.py | 6 +----- .../test_auto_parallel_fp16_pass.py | 1 - .../test_auto_parallel_gradient_merge_pass.py | 3 --- .../test_auto_parallel_recompute_pass.py | 4 ---- .../test_auto_parallel_sharding_pass.py | 5 ----- .../distributed_passes/test_ps_server_pass.py | 6 +----- .../distributed_passes/test_ps_trainer_pass.py | 6 +----- .../unittests/sequence/test_sequence_first_step.py | 5 +---- .../unittests/sequence/test_sequence_last_step.py | 5 +---- .../tests/unittests/sequence/test_sequence_mask.py | 2 -- .../tests/unittests/sequence/test_sequence_reshape.py | 1 - .../tests/unittests/sequence/test_sequence_reverse.py | 1 - .../fluid/tests/unittests/tokenizer/bert_tokenizer.py | 4 ---- .../tests/unittests/tokenizer/tokenizer_utils.py | 2 +- 19 files changed, 9 insertions(+), 61 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/auto_parallel_pass_test_base.py b/python/paddle/fluid/tests/unittests/distributed_passes/auto_parallel_pass_test_base.py index e741cab8d7..4028bae08a 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/auto_parallel_pass_test_base.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/auto_parallel_pass_test_base.py @@ -14,12 +14,8 @@ import paddle import os -import random import sys import pickle -import shlex -import shutil -import inspect import numpy as np from collections import OrderedDict from dist_pass_test_base import DistPassTestBase diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/dist_pass_test_base.py b/python/paddle/fluid/tests/unittests/distributed_passes/dist_pass_test_base.py index 4f89b69a50..6b0d53d2d0 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/dist_pass_test_base.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/dist_pass_test_base.py @@ -23,7 +23,7 @@ import inspect import numpy as np from collections import OrderedDict from paddle.distributed.fleet.launch_utils import run_with_coverage -from paddle.distributed.passes.pass_base import new_pass, PassBase, PassManager +from paddle.distributed.passes.pass_base import PassBase, PassManager def prepare_python_path_and_return_module(path): diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/pass_run_main.py b/python/paddle/fluid/tests/unittests/distributed_passes/pass_run_main.py index 95c670ce90..cd98d39a09 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/pass_run_main.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/pass_run_main.py @@ -17,7 +17,6 @@ import paddle import pickle import importlib import os -import sys from paddle.distributed.fleet.launch_utils import run_with_coverage from dist_pass_test_base import prepare_python_path_and_return_module, DistPassTestBase diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/ps_pass_test_base.py b/python/paddle/fluid/tests/unittests/distributed_passes/ps_pass_test_base.py index beddb79fd9..bd2fa6b019 100755 --- a/python/paddle/fluid/tests/unittests/distributed_passes/ps_pass_test_base.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/ps_pass_test_base.py @@ -13,18 +13,11 @@ # limitations under the License. import os -import random import sys -import pickle import shlex -import shutil -import inspect import unittest -import numpy as np -from collections import OrderedDict -from paddle.distributed.ps.utils.public import logger -from paddle.fluid.tests.unittests.distributed_passes.dist_pass_test_base import prepare_python_path_and_return_module, remove_path_if_exists -import paddle.distributed.fleet as fleet +from paddle.fluid.tests.unittests.distributed_passes.dist_pass_test_base import ( # noqa: F401 + prepare_python_path_and_return_module, remove_path_if_exists) class PsPassTestBase(unittest.TestCase): diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_amp_pass.py b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_amp_pass.py index 4585fe997c..0d404d1732 100755 --- a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_amp_pass.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_amp_pass.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import random import numpy as np diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_data_parallel_optimization_pass.py b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_data_parallel_optimization_pass.py index 1f94d73814..7da95ddf8d 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_data_parallel_optimization_pass.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_data_parallel_optimization_pass.py @@ -18,16 +18,12 @@ import numpy as np import unittest import paddle -import paddle.nn as nn import paddle.distributed.fleet as fleet -from paddle.distributed.fleet import auto from paddle.distributed.auto_parallel.dist_context import get_default_distributed_context -from paddle.distributed.passes import new_pass, PassManager, PassContext +from paddle.distributed.passes import PassContext, new_pass from auto_parallel_pass_test_base import AutoPallelPassTestBase sys.path.append("..") -import auto_parallel_gpt_model as modeling -from auto_parallel_gpt_model import GPTModel, GPTForPretraining, GPTPretrainingCriterion class TestDataParallelPassWithScale1(AutoPallelPassTestBase): diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_fp16_pass.py b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_fp16_pass.py index 4c20153ccb..2dfe965fc0 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_fp16_pass.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_fp16_pass.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import random import numpy as np diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_gradient_merge_pass.py b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_gradient_merge_pass.py index de7ed4efb7..3b6eb35937 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_gradient_merge_pass.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_gradient_merge_pass.py @@ -12,12 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import time import unittest import random import numpy as np -import os -import shutil import logging import paddle diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_recompute_pass.py b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_recompute_pass.py index 84084ed709..fa5fd193ab 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_recompute_pass.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_recompute_pass.py @@ -12,16 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import random import numpy as np import unittest import paddle -import paddle.nn as nn import paddle.distributed.fleet as fleet -from paddle.distributed.fleet import auto -from paddle.distributed.passes import new_pass, PassManager from auto_parallel_pass_test_base import AutoPallelPassTestBase diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_sharding_pass.py b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_sharding_pass.py index 7bc4c811c3..21a9a81aa0 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_sharding_pass.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/test_auto_parallel_sharding_pass.py @@ -18,15 +18,10 @@ import numpy as np import unittest import paddle -import paddle.nn as nn import paddle.distributed.fleet as fleet -from paddle.distributed.fleet import auto -from paddle.distributed.passes import new_pass, PassManager from auto_parallel_pass_test_base import AutoPallelPassTestBase sys.path.append("..") -import auto_parallel_gpt_model as modeling -from auto_parallel_gpt_model import GPTModel, GPTForPretraining, GPTPretrainingCriterion class TestShardingPass(AutoPallelPassTestBase): diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/test_ps_server_pass.py b/python/paddle/fluid/tests/unittests/distributed_passes/test_ps_server_pass.py index 79f39c1cbd..e4844b664c 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/test_ps_server_pass.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/test_ps_server_pass.py @@ -12,12 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -import numpy as np -import paddle -from ps_pass_test_base import * -from paddle.fluid.tests.unittests.ps.ps_dnn_trainer import DnnTrainer +from ps_pass_test_base import PsPassTestBase class TestPsServerPass(PsPassTestBase): diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/test_ps_trainer_pass.py b/python/paddle/fluid/tests/unittests/distributed_passes/test_ps_trainer_pass.py index 8b9e010b1d..9b7f7820c8 100755 --- a/python/paddle/fluid/tests/unittests/distributed_passes/test_ps_trainer_pass.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/test_ps_trainer_pass.py @@ -12,14 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import unittest -import numpy as np -import paddle -from ps_pass_test_base import * +from ps_pass_test_base import remove_path_if_exists, PsPassTestBase from paddle.distributed.ps.utils.public import logger, ps_log_root_dir -from paddle.fluid.tests.unittests.ps.ps_dnn_trainer import DnnTrainer class TestPsTrainerPass(PsPassTestBase): diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_first_step.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_first_step.py index aee72167f5..25589f2ad9 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_first_step.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_first_step.py @@ -12,15 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. import paddle.fluid as fluid -from paddle.fluid.framework import convert_np_dtype_to_dtype_, Program, program_guard -import paddle.fluid.core as core +from paddle.fluid.framework import Program, program_guard import numpy as np -import copy import unittest import sys sys.path.append("../") -from op_test import OpTest class TestSequenceFirstStepOpError(unittest.TestCase): diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_last_step.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_last_step.py index 4def8bc3c7..0ddc348044 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_last_step.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_last_step.py @@ -12,15 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. import paddle.fluid as fluid -from paddle.fluid.framework import convert_np_dtype_to_dtype_, Program, program_guard -import paddle.fluid.core as core +from paddle.fluid.framework import Program, program_guard import numpy as np -import copy import unittest import sys sys.path.append("../") -from op_test import OpTest class TestSequenceLastStepOpError(unittest.TestCase): diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_mask.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_mask.py index af733edfb6..f240bc9900 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_mask.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_mask.py @@ -14,9 +14,7 @@ import paddle.fluid as fluid from paddle.fluid.framework import convert_np_dtype_to_dtype_, Program, program_guard -import paddle.fluid.core as core import numpy as np -import copy import unittest import sys diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_reshape.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_reshape.py index b408f5f95d..5577ad052c 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_reshape.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_reshape.py @@ -14,7 +14,6 @@ import unittest import numpy as np -import math import sys sys.path.append("../") diff --git a/python/paddle/fluid/tests/unittests/sequence/test_sequence_reverse.py b/python/paddle/fluid/tests/unittests/sequence/test_sequence_reverse.py index 8e1b447f92..e4612b064e 100644 --- a/python/paddle/fluid/tests/unittests/sequence/test_sequence_reverse.py +++ b/python/paddle/fluid/tests/unittests/sequence/test_sequence_reverse.py @@ -14,7 +14,6 @@ import unittest import paddle.fluid as fluid -import paddle.fluid.core as core import numpy as np import sys diff --git a/python/paddle/fluid/tests/unittests/tokenizer/bert_tokenizer.py b/python/paddle/fluid/tests/unittests/tokenizer/bert_tokenizer.py index a47ca33acd..24f2752854 100755 --- a/python/paddle/fluid/tests/unittests/tokenizer/bert_tokenizer.py +++ b/python/paddle/fluid/tests/unittests/tokenizer/bert_tokenizer.py @@ -13,11 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy -import io -import json import os -import six import unicodedata from tokenizer_utils import PretrainedTokenizer diff --git a/python/paddle/fluid/tests/unittests/tokenizer/tokenizer_utils.py b/python/paddle/fluid/tests/unittests/tokenizer/tokenizer_utils.py index 6f750e17bf..00fab5f3db 100644 --- a/python/paddle/fluid/tests/unittests/tokenizer/tokenizer_utils.py +++ b/python/paddle/fluid/tests/unittests/tokenizer/tokenizer_utils.py @@ -20,7 +20,7 @@ import json import os import unicodedata from shutil import copyfile -from typing import Iterable, Iterator, Optional, List, Any, Callable, Union +from typing import Optional from paddle.dataset.common import DATA_HOME from paddle.utils.download import get_path_from_url -- GitLab