diff --git a/accelerator/cpu_accelerator.py b/accelerator/cpu_accelerator.py index 33320bf22..11518d31e 100644 --- a/accelerator/cpu_accelerator.py +++ b/accelerator/cpu_accelerator.py @@ -5,7 +5,7 @@ import torch from deepspeed.accelerator.abstract_accelerator import DeepSpeedAccelerator -import oneccl_bindings_for_pytorch # noqa: F401 +import oneccl_bindings_for_pytorch # noqa: F401 # type: ignore import psutil import os @@ -229,7 +229,7 @@ class CPU_Accelerator(DeepSpeedAccelerator): try: # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed # if successful this also means we're doing a local install and not JIT compile path - from op_builder import __deepspeed__ # noqa: F401 + from op_builder import __deepspeed__ # noqa: F401 # type: ignore return "op_builder.cpu" except ImportError: return "deepspeed.ops.op_builder.cpu" @@ -253,7 +253,7 @@ class CPU_Accelerator(DeepSpeedAccelerator): try: # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed # if successful this also means we're doing a local install and not JIT compile path - from op_builder import __deepspeed__ # noqa: F401 + from op_builder import __deepspeed__ # noqa: F401 # type: ignore from op_builder.cpu import CCLCommBuilder, FusedAdamBuilder, CPUAdamBuilder, NotImplementedBuilder except ImportError: from deepspeed.ops.op_builder.cpu import CCLCommBuilder, FusedAdamBuilder, CPUAdamBuilder, NotImplementedBuilder diff --git a/accelerator/cuda_accelerator.py b/accelerator/cuda_accelerator.py index 8097f13a6..9c1e0d227 100644 --- a/accelerator/cuda_accelerator.py +++ b/accelerator/cuda_accelerator.py @@ -217,7 +217,7 @@ class CUDA_Accelerator(DeepSpeedAccelerator): try: # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed # if successful this also means we're doing a local install and not JIT compile path - from op_builder import __deepspeed__ # noqa: F401 + from op_builder import __deepspeed__ # noqa: F401 # type: ignore return "op_builder" except ImportError: return "deepspeed.ops.op_builder" diff --git a/accelerator/mps_accelerator.py b/accelerator/mps_accelerator.py index 6df5c876a..68e3b6df0 100644 --- a/accelerator/mps_accelerator.py +++ b/accelerator/mps_accelerator.py @@ -200,7 +200,7 @@ class MPS_Accelerator(DeepSpeedAccelerator): try: # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed # if successful this also means we're doing a local install and not JIT compile path - from op_builder import __deepspeed__ # noqa: F401 + from op_builder import __deepspeed__ # noqa: F401 # type: ignore return "op_builder" except ImportError: diff --git a/accelerator/npu_accelerator.py b/accelerator/npu_accelerator.py index f34e8bbd9..d62f22620 100644 --- a/accelerator/npu_accelerator.py +++ b/accelerator/npu_accelerator.py @@ -199,7 +199,7 @@ class NPU_Accelerator(DeepSpeedAccelerator): try: # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed # if successful this also means we're doing a local install and not JIT compile path - from op_builder import __deepspeed__ # noqa: F401 + from op_builder import __deepspeed__ # noqa: F401 # type: ignore return "op_builder.npu" except ImportError: return "deepspeed.ops.op_builder.npu" @@ -216,7 +216,7 @@ class NPU_Accelerator(DeepSpeedAccelerator): try: # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed # if successful this also means we're doing a local install and not JIT compile path - from op_builder import __deepspeed__ # noqa: F401 + from op_builder import __deepspeed__ # noqa: F401 # type: ignore from op_builder.npu import NotImplementedBuilder except ImportError: from deepspeed.ops.op_builder.npu import NotImplementedBuilder diff --git a/accelerator/real_accelerator.py b/accelerator/real_accelerator.py index 6e86edd20..cb9fb70cf 100644 --- a/accelerator/real_accelerator.py +++ b/accelerator/real_accelerator.py @@ -55,19 +55,19 @@ def get_accelerator(): accelerator_name = os.environ["DS_ACCELERATOR"] if accelerator_name == "xpu": try: - from intel_extension_for_deepspeed import XPU_Accelerator # noqa: F401 + from intel_extension_for_deepspeed import XPU_Accelerator # noqa: F401 # type: ignore except ImportError as e: raise ValueError( f"XPU_Accelerator requires intel_extension_for_deepspeed, which is not installed on this system.") elif accelerator_name == "cpu": try: - import intel_extension_for_pytorch # noqa: F401 + import intel_extension_for_pytorch # noqa: F401 # type: ignore except ImportError as e: raise ValueError( f"CPU_Accelerator requires intel_extension_for_pytorch, which is not installed on this system.") elif accelerator_name == "npu": try: - import torch_npu # noqa: F401 + import torch_npu # noqa: F401 # type: ignore except ImportError as e: raise ValueError(f"NPU_Accelerator requires torch_npu, which is not installed on this system.") pass @@ -100,21 +100,21 @@ def get_accelerator(): # between installation time and runtime. try: - from intel_extension_for_deepspeed import XPU_Accelerator # noqa: F401,F811 + from intel_extension_for_deepspeed import XPU_Accelerator # noqa: F401,F811 # type: ignore accelerator_name = "xpu" except ImportError as e: pass if accelerator_name == None: try: - import intel_extension_for_pytorch # noqa: F401,F811 + import intel_extension_for_pytorch # noqa: F401,F811 # type: ignore accelerator_name = "cpu" except ImportError as e: pass if accelerator_name == None: try: - import torch_npu # noqa: F401,F811 + import torch_npu # noqa: F401,F811 # type: ignore accelerator_name = "npu" except ImportError as e: diff --git a/deepspeed/__init__.py b/deepspeed/__init__.py index 98fc72b35..87b959f56 100755 --- a/deepspeed/__init__.py +++ b/deepspeed/__init__.py @@ -13,7 +13,7 @@ from torch.optim.lr_scheduler import _LRScheduler from packaging import version as pkg_version try: - import triton # noqa: F401 + import triton # noqa: F401 # type: ignore HAS_TRITON = True except ImportError: HAS_TRITON = False diff --git a/deepspeed/env_report.py b/deepspeed/env_report.py index 36fd00dcf..2c3a9e701 100644 --- a/deepspeed/env_report.py +++ b/deepspeed/env_report.py @@ -59,7 +59,7 @@ def op_report(verbose=True): def ninja_installed(): try: - import ninja # noqa: F401 + import ninja # noqa: F401 # type: ignore except ImportError: return False return True diff --git a/deepspeed/git_version_info.py b/deepspeed/git_version_info.py index 6ca0996bb..635842c76 100644 --- a/deepspeed/git_version_info.py +++ b/deepspeed/git_version_info.py @@ -5,7 +5,7 @@ try: # This is populated by setup.py - from .git_version_info_installed import * # noqa: F401 + from .git_version_info_installed import * # noqa: F401 # type: ignore except ModuleNotFoundError: import os if os.path.isfile('version.txt'): diff --git a/deepspeed/monitor/utils.py b/deepspeed/monitor/utils.py index a9bd915f4..265fc9811 100644 --- a/deepspeed/monitor/utils.py +++ b/deepspeed/monitor/utils.py @@ -8,7 +8,7 @@ def check_tb_availability(): try: # torch.utils.tensorboard will fail if `tensorboard` is not available, # see their docs for more details: https://pytorch.org/docs/1.8.0/tensorboard.html - import tensorboard # noqa: F401 + import tensorboard # noqa: F401 # type: ignore except ImportError: print('If you want to use tensorboard logging, please `pip install tensorboard`') raise @@ -16,7 +16,7 @@ def check_tb_availability(): def check_wandb_availability(): try: - import wandb # noqa: F401 + import wandb # noqa: F401 # type: ignore except ImportError: print( 'If you want to use wandb logging, please `pip install wandb` and follow the instructions at https://docs.wandb.ai/quickstart' diff --git a/op_builder/__init__.py b/op_builder/__init__.py index 2c55662df..afe481599 100644 --- a/op_builder/__init__.py +++ b/op_builder/__init__.py @@ -15,7 +15,7 @@ __deepspeed__ = True # List of all available op builders from deepspeed op_builder try: - import deepspeed.ops.op_builder # noqa: F401 + import deepspeed.ops.op_builder # noqa: F401 # type: ignore op_builder_dir = "deepspeed.ops.op_builder" except ImportError: op_builder_dir = "op_builder" diff --git a/op_builder/builder.py b/op_builder/builder.py index 3515e21a3..a3cbb6401 100644 --- a/op_builder/builder.py +++ b/op_builder/builder.py @@ -459,7 +459,7 @@ class OpBuilder(ABC): f"Unable to JIT load the {self.name} op due to it not being compatible due to hardware/software issue. {self.error_log}" ) try: - import ninja # noqa: F401 + import ninja # noqa: F401 # type: ignore except ImportError: raise RuntimeError(f"Unable to JIT load the {self.name} op due to ninja not being installed.") diff --git a/op_builder/cpu/builder.py b/op_builder/cpu/builder.py index b3198fb11..f6a71c7d1 100644 --- a/op_builder/cpu/builder.py +++ b/op_builder/cpu/builder.py @@ -6,7 +6,7 @@ try: # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed # if successful this also means we're doing a local install and not JIT compile path - from op_builder import __deepspeed__ # noqa: F401 + from op_builder import __deepspeed__ # noqa: F401 # type: ignore from op_builder.builder import OpBuilder except ImportError: from deepspeed.ops.op_builder.builder import OpBuilder diff --git a/op_builder/npu/builder.py b/op_builder/npu/builder.py index 3ac59ac4d..777338873 100644 --- a/op_builder/npu/builder.py +++ b/op_builder/npu/builder.py @@ -6,7 +6,7 @@ try: # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed # if successful this also means we're doing a local install and not JIT compile path - from op_builder import __deepspeed__ # noqa: F401 + from op_builder import __deepspeed__ # noqa: F401 # type: ignore from op_builder.builder import OpBuilder except ImportError: from deepspeed.ops.op_builder.builder import OpBuilder diff --git a/tests/benchmarks/flatten_bench.py b/tests/benchmarks/flatten_bench.py index d404acd5c..a09600db5 100755 --- a/tests/benchmarks/flatten_bench.py +++ b/tests/benchmarks/flatten_bench.py @@ -110,15 +110,15 @@ def timeme(): def line_profileme(): print("--------------- line_profiler -----------------") print("py") - profile(py)() # noqa: F821 + profile(py)() # noqa: F821 # type: ignore gc.collect() get_accelerator().empty_cache() print("cpp") - profile(cpp)() # noqa: F821 + profile(cpp)() # noqa: F821 # type: ignore gc.collect() get_accelerator().empty_cache() print("apex") - profile(apex)() # noqa: F821 + profile(apex)() # noqa: F821 # type: ignore gc.collect() get_accelerator().empty_cache() diff --git a/tests/benchmarks/unflatten_bench.py b/tests/benchmarks/unflatten_bench.py index dade45744..9f2f0e1e8 100755 --- a/tests/benchmarks/unflatten_bench.py +++ b/tests/benchmarks/unflatten_bench.py @@ -119,15 +119,15 @@ def timeme(): def line_profileme(): print("--------------- line_profier -----------------") print("py") - profile(py)() # noqa: F821 + profile(py)() # noqa: F821 # type: ignore gc.collect() get_accelerator().empty_cache() print("cpp") - profile(cpp)() # noqa: F821 + profile(cpp)() # noqa: F821 # type: ignore gc.collect() get_accelerator().empty_cache() print("apex") - profile(apex)() # noqa: F821 + profile(apex)() # noqa: F821 # type: ignore gc.collect() get_accelerator().empty_cache() diff --git a/tests/unit/modeling.py b/tests/unit/modeling.py index 7930fdafe..72adc8d38 100644 --- a/tests/unit/modeling.py +++ b/tests/unit/modeling.py @@ -819,21 +819,21 @@ class BertPreTrainedModel(nn.Module): archive_file = PRETRAINED_MODEL_ARCHIVE_MAP[pretrained_model_name_or_path] else: archive_file = pretrained_model_name_or_path - if resolved_archive_file == archive_file: # noqa: F821 + if resolved_archive_file == archive_file: # noqa: F821 # type: ignore logger.info("loading archive file {}".format(archive_file)) else: - logger.info("loading archive file {} from cache at {}".format(archive_file, - resolved_archive_file)) # noqa: F821 + logger.info("loading archive file {} from cache at {}".format( + archive_file, resolved_archive_file)) # noqa: F821 # type: ignore tempdir = None - if os.path.isdir(resolved_archive_file) or from_tf: # noqa: F821 - serialization_dir = resolved_archive_file # noqa: F821 + if os.path.isdir(resolved_archive_file) or from_tf: # noqa: F821 # type: ignore + serialization_dir = resolved_archive_file # noqa: F821 # type: ignore else: # Extract archive to temp dir tempdir = tempfile.mkdtemp() logger.info("extracting archive file {} to temp dir {}".format( - resolved_archive_file, # noqa: F821 + resolved_archive_file, # noqa: F821 # type: ignore tempdir)) - with tarfile.open(resolved_archive_file, 'r:gz') as archive: # noqa: F821 + with tarfile.open(resolved_archive_file, 'r:gz') as archive: # noqa: F821 # type: ignore archive.extractall(tempdir) serialization_dir = tempdir # Load config diff --git a/tests/unit/modelingpreln.py b/tests/unit/modelingpreln.py index 7058c1a74..c786e7a6a 100644 --- a/tests/unit/modelingpreln.py +++ b/tests/unit/modelingpreln.py @@ -914,21 +914,21 @@ class BertPreTrainedModel(nn.Module): archive_file = PRETRAINED_MODEL_ARCHIVE_MAP[pretrained_model_name_or_path] else: archive_file = pretrained_model_name_or_path - if resolved_archive_file == archive_file: # noqa: F821 + if resolved_archive_file == archive_file: # noqa: F821 # type: ignore logger.info("loading archive file {}".format(archive_file)) else: - logger.info("loading archive file {} from cache at {}".format(archive_file, - resolved_archive_file)) # noqa: F821 + logger.info("loading archive file {} from cache at {}".format( + archive_file, resolved_archive_file)) # noqa: F821 # type: ignore tempdir = None - if os.path.isdir(resolved_archive_file) or from_tf: # noqa: F821 - serialization_dir = resolved_archive_file # noqa: F821 + if os.path.isdir(resolved_archive_file) or from_tf: # noqa: F821 # type: ignore + serialization_dir = resolved_archive_file # noqa: F821 # type: ignore else: # Extract archive to temp dir tempdir = tempfile.mkdtemp() logger.info("extracting archive file {} to temp dir {}".format( - resolved_archive_file, # noqa: F821 + resolved_archive_file, # noqa: F821 # type: ignore tempdir)) - with tarfile.open(resolved_archive_file, 'r:gz') as archive: # noqa: F821 + with tarfile.open(resolved_archive_file, 'r:gz') as archive: # noqa: F821 # type: ignore archive.extractall(tempdir) serialization_dir = tempdir # Load config diff --git a/tests/unit/ops/transformer/inference/test_layer_norm.py b/tests/unit/ops/transformer/inference/test_layer_norm.py index 952904a78..1c5400b12 100644 --- a/tests/unit/ops/transformer/inference/test_layer_norm.py +++ b/tests/unit/ops/transformer/inference/test_layer_norm.py @@ -10,7 +10,7 @@ from deepspeed.accelerator import get_accelerator from deepspeed.ops.op_builder import InferenceBuilder from .inference_test_utils import allclose, get_dtypes try: - import triton # noqa: F401 + import triton # noqa: F401 # type: ignore from deepspeed.ops.transformer.inference.triton import ( layer_norm, layer_norm_residual, diff --git a/tests/unit/runtime/half_precision/test_fp16.py b/tests/unit/runtime/half_precision/test_fp16.py index 1b400ea67..3d5e18b46 100644 --- a/tests/unit/runtime/half_precision/test_fp16.py +++ b/tests/unit/runtime/half_precision/test_fp16.py @@ -15,7 +15,7 @@ from deepspeed.accelerator import get_accelerator from deepspeed.ops.op_builder import CPUAdamBuilder try: - from apex import amp # noqa: F401 + from apex import amp # noqa: F401 # type: ignore _amp_available = True except ImportError: _amp_available = False