diff --git a/.gitignore b/.gitignore index 4316ef00d3d..9751a56d366 100644 --- a/.gitignore +++ b/.gitignore @@ -108,6 +108,9 @@ ENV/ # snapshots *.tar +# pylint config is left at dev's discretion, CI uses ruff/isort/black instead +.pylintrc + # VSCode .vscode/ diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index d148a69df31..00000000000 --- a/.pylintrc +++ /dev/null @@ -1,52 +0,0 @@ -[MASTER] -disable = arguments-differ, - cell-var-from-loop, - fixme, - global-statement, - invalid-name, - logging-format-interpolation, - missing-docstring, - no-self-use, - not-callable, - too-few-public-methods, - too-many-arguments, - too-many-instance-attributes, - too-many-locals, - unbalanced-tuple-unpacking, - ungrouped-imports, - unpacking-non-sequence, - unused-argument, - wrong-import-order, - attribute-defined-outside-init, - import-outside-toplevel, - duplicate-code, - consider-using-f-string, - logging-fstring-interpolation, - cyclic-import, - useless-import-alias - -max-line-length = 120 -ignore-docstrings = yes -ignored-modules = numpy,torch,cv2,openvino,tensorflow,optimum,memory_profiler -extension-pkg-whitelist = torch,cv2 -init-hook='import sys; sys.setrecursionlimit(8 * sys.getrecursionlimit())' # to avoid https://stackoverflow.com/questions/36496192/pylint-infinite-recursion-in-astriod-package -load-plugins=pylintfileheader -file-header-path=.file-header -file-header-ignore-empty-files=yes - -[SIMILARITIES] -ignore-imports = yes - -[BASIC] -bad-functions = print -good-names = logger,fn - -[DESIGN] -max-statements=60 -max-branches=13 -max-parents=9 - -[TYPECHECK] -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E0201 or E1101 when accessed. -generated-members=onnx.* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9382d0ba0b3..1b3cd89bcc3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,9 +34,12 @@ If your testing code is more extensive than unit tests (in terms of test executi Changes to NNCF Python code should conform to [Python Style Guide](./docs/styleguide/PyGuide.md) -Pylint is used throughout the project to ensure code cleanliness and quality. -A Pylint run is also done as part of the pre-commit scope - the pre-commit `pytest` scope will not be run if your code fails the Pylint checks. -The Pylint rules and exceptions for this repository are described in the standard [.pylintrc](./.pylintrc) format - make sure your local linter uses these. +Basic code style and static checks are enforced using a `pre-commit` Github action. +The exact checks that are run are described in the corresponding [config file](./.pre-commit-config.yaml). +The checks can be run locally using `make pre-commit`. +Most of these checks do in-place fixes at the same time they are run using `make pre-commit`. +Static analysis is done via `ruff` which does not do in-place fixes by default - run `ruff --fix` locally to autofix errors for which it is possible to do so. +Developers may use other tools locally (such as `pylint`) as long as no tool-specific control code is introduced and the pre-commit checks pass. ## Binary files diff --git a/Makefile b/Makefile index 8b4c079780e..5b71bb3eac1 100644 --- a/Makefile +++ b/Makefile @@ -17,9 +17,6 @@ endif install-pre-commit: pip install pre-commit==3.2.2 -install-pylint: - pip install pylint==2.13.9 - pip install pylintfileheader==0.3.2 ############################################################################### # ONNX backend @@ -31,15 +28,12 @@ install-onnx-test: pip install -r tests/cross_fw/examples/requirements.txt pip install -r tests/onnx/benchmarking/requirements.txt -install-onnx-dev: install-onnx-test install-pre-commit install-pylint +install-onnx-dev: install-onnx-test install-pre-commit pip install -r examples/post_training_quantization/onnx/mobilenet_v2/requirements.txt test-onnx: pytest ${COVERAGE_ARGS} tests/onnx $(DATA_ARG) --junitxml ${JUNITXML_PATH} -pylint-onnx: - pylint --rcfile .pylintrc \ - $(shell python3 tools/collect_pylint_input_files_for_backend.py onnx) test-install-onnx: pytest tests/cross_fw/install -s \ @@ -60,7 +54,7 @@ install-openvino-test: pip install -r tests/cross_fw/install/requirements.txt pip install -r tests/cross_fw/examples/requirements.txt -install-openvino-dev: install-openvino-test install-pre-commit install-pylint +install-openvino-dev: install-openvino-test install-pre-commit pip install -r examples/experimental/openvino/bert/requirements.txt pip install -r examples/experimental/openvino/yolo_v5/requirements.txt pip install -r examples/post_training_quantization/openvino/mobilenet_v2/requirements.txt @@ -71,10 +65,6 @@ install-openvino-dev: install-openvino-test install-pre-commit install-pylint test-openvino: pytest ${COVERAGE_ARGS} tests/openvino $(DATA_ARG) --junitxml ${JUNITXML_PATH} -pylint-openvino: - pylint --rcfile .pylintrc \ - $(shell python3 tools/collect_pylint_input_files_for_backend.py openvino) - test-install-openvino: pytest tests/cross_fw/install -s \ --backend openvino \ @@ -95,7 +85,7 @@ install-tensorflow-test: pip install -r tests/cross_fw/examples/requirements.txt pip install -r examples/tensorflow/requirements.txt -install-tensorflow-dev: install-tensorflow-test install-pre-commit install-pylint +install-tensorflow-dev: install-tensorflow-test install-pre-commit pip install -r examples/post_training_quantization/tensorflow/mobilenet_v2/requirements.txt test-tensorflow: @@ -103,10 +93,6 @@ test-tensorflow: --junitxml ${JUNITXML_PATH} \ $(DATA_ARG) -pylint-tensorflow: - pylint --rcfile .pylintrc \ - $(shell python3 tools/collect_pylint_input_files_for_backend.py tensorflow) - test-install-tensorflow: pytest tests/cross_fw/install -s --backend tf --junitxml ${JUNITXML_PATH} @@ -123,7 +109,7 @@ install-torch-test: pip install -r tests/cross_fw/examples/requirements.txt pip install -r examples/torch/requirements.txt --index-url https://download.pytorch.org/whl/cu118 --extra-index-url=https://pypi.org/simple -install-torch-dev: install-torch-test install-pre-commit install-pylint +install-torch-dev: install-torch-test install-pre-commit pip install -r examples/post_training_quantization/torch/mobilenet_v2/requirements.txt pip install -r examples/post_training_quantization/torch/ssd300_vgg16/requirements.txt @@ -136,12 +122,6 @@ test-torch-nightly: test-torch-weekly: pytest ${COVERAGE_ARGS} tests/torch -m weekly --junitxml ${JUNITXML_PATH} $(DATA_ARG) ${WEEKLY_MODELS_ARG} -COMMON_PYFILES := $(shell python3 tools/collect_pylint_input_files_for_backend.py common) -pylint-torch: - pylint --rcfile .pylintrc \ - $(COMMON_PYFILES) \ - $(shell python3 tools/collect_pylint_input_files_for_backend.py torch) - test-install-torch-cpu: pytest tests/cross_fw/install -s \ --backend torch \ @@ -167,10 +147,6 @@ install-common-test: pip install -r tests/cross_fw/install/requirements.txt pip install -r tests/cross_fw/examples/requirements.txt -pylint-common: - pylint --rcfile .pylintrc \ - $(COMMON_PYFILES) - test-common: pytest ${COVERAGE_ARGS} tests/common $(DATA_ARG) --junitxml ${JUNITXML_PATH} diff --git a/docs/api/source/conf.py b/docs/api/source/conf.py index f7a565f1581..6172cc7c3e4 100644 --- a/docs/api/source/conf.py +++ b/docs/api/source/conf.py @@ -56,7 +56,6 @@ def __init__(self): self.canonical_name_vs_fqn: Dict[str, str] = {} -# pylint: disable=too-many-branches def collect_api_entities() -> APIInfo: """ Collects the fully qualified names of symbols in NNCF package that contain a special attribute (set via @@ -73,13 +72,13 @@ def collect_api_entities() -> APIInfo: for _, modname, _ in pkgutil.walk_packages(path=nncf.__path__, prefix=nncf.__name__ + ".", onerror=lambda x: None): try: modules[modname] = importlib.import_module(modname) - except Exception as e: # pylint: disable=broad-except + except Exception as e: skipped_modules[modname] = str(e) from nncf.common.utils.api_marker import api canonical_imports_seen = set() - # pylint: disable=too-many-nested-blocks + for modname, module in modules.items(): print(f"{modname}") for obj_name, obj in inspect.getmembers(module): @@ -87,7 +86,7 @@ def collect_api_entities() -> APIInfo: if objects_module == modname: if inspect.isclass(obj) or inspect.isfunction(obj): if hasattr(obj, api.API_MARKER_ATTR): - marked_object_name = obj._nncf_api_marker # pylint: disable=protected-access + marked_object_name = obj._nncf_api_marker # Check the actual name of the originally marked object # so that the classes derived from base API classes don't # all automatically end up in API diff --git a/docs/styleguide/PyGuide.md b/docs/styleguide/PyGuide.md index 0c7f9169766..40e70432fb7 100644 --- a/docs/styleguide/PyGuide.md +++ b/docs/styleguide/PyGuide.md @@ -6,14 +6,13 @@ - [1 Introduction](#s1-introduction) - [2 Automating Code Formatting](#s2-auto-code-formatting) - [3 Python Language Rules](#s3-python-language-rules) - - [3.1 PyLint](#s3.1-pylint) - - [3.2 3rd party packages](#s3.2-3rd-party-packages) - - [3.3 Global variables](#s3.3-global-variables) - - [3.4 Nested/Local/Inner Classes and Functions](#s3.4-nested) - - [3.5 Default Iterators and Operators](#s3.5-default-iterators-and-operators) - - [3.6 Type Annotated Code](#s3.6-type-annotated-code) - - [3.7 Files and Sockets](#s3.7-files-and-sockets) - - [3.8 Abstract Classes](#s3.8-abstract-classes) + - [3.1 3rd party packages](#s3.1-3rd-party-packages) + - [3.2 Global variables](#s3.2-global-variables) + - [3.3 Nested/Local/Inner Classes and Functions](#s3.3-nested) + - [3.4 Default Iterators and Operators](#s3.4-default-iterators-and-operators) + - [3.5 Type Annotated Code](#s3.5-type-annotated-code) + - [3.6 Files and Sockets](#s3.6-files-and-sockets) + - [3.7 Abstract Classes](#s3.7-abstract-classes) - [4 Python Style Rules](#s4-python-style-rules) - [4.1 Line length](#s4.1-line-length) - [4.2 Comments and Docstrings](#s4.2-comments-and-docstrings) @@ -102,39 +101,19 @@ arr2 = [ ## 3 Python Language Rules - - - - -### 3.1 PyLint - -Run [pylint](https://github.com/PyCQA/pylint) over your code using this [pylintrc](../../.pylintrc). - -- Every warning reported by [pylint](https://github.com/PyCQA/pylint) must be resolved in one of the following way: - - *Preferred solution*: Change the code to fix the warning. - - *Exception*: Suppress the warning if they are inappropriate so that other issues are not hidden. - To suppress warnings you can set a line-level comment - - ```python - dict = "something awful" # Bad Idea... pylint: disable=redefined-builtin - ``` - - or update [pylintrc](../../.pylintrc) if applicable for the whole project. If the reason for the suppression - is not clear from the symbolic name, add an explanation. - - - + + -### 3.2 3rd party packages +### 3.1 3rd party packages Do not add new third-party dependencies unless absolutely necessary. All things being equal, give preference to built-in packages. - - + + -### 3.3 Global variables +### 3.2 Global variables Avoid global variables. @@ -143,11 +122,11 @@ Avoid global variables. - If needed, globals should be declared at the module level and made internal to the module by prepending an `_` to the name. External access must be done through public module-level functions. - - + + -### 3.4 Nested/Local/Inner Classes and Functions +### 3.3 Nested/Local/Inner Classes and Functions No need to overuse nested local functions or classes and inner classes. @@ -191,11 +170,11 @@ No need to overuse nested local functions or classes and inner classes. return m/3 ``` - - + + -### 3.5 Default Iterators and Operators +### 3.4 Default Iterators and Operators Use default iterators and operators for types that support them, like lists, dictionaries, and files. The built-in types define iterator methods, too. Prefer @@ -219,11 +198,11 @@ for line in afile.readlines(): ... for k, v in dict.iteritems(): ... ``` - - + + -### 3.6 Type Annotated Code +### 3.5 Type Annotated Code Code should be annotated with type hints according to [PEP-484](https://www.python.org/dev/peps/pep-0484/), and type-check the code at @@ -233,11 +212,11 @@ build time with a type checking tool like [mypy](http://www.mypy-lang.org/). def func(a: int) -> List[int]: ``` - - + + -### 3.7 Files and Sockets +### 3.6 Files and Sockets Explicitly close files and sockets when done with them. @@ -247,11 +226,11 @@ with open("hello.txt") as hello_file: print(line) ``` - - + + -### 3.8 Abstract Classes +### 3.7 Abstract Classes When defining abstract classes, the following template should be used: @@ -312,7 +291,6 @@ Explicit exceptions to the 120 character limit: - URLs, pathnames, or long flags in comments. - Long string module level constants not containing whitespace that would be inconvenient to split across lines such as URLs or pathnames. - - Pylint disable comments. (e.g.: `# pylint: disable=invalid-name`) diff --git a/examples/common/sample_config.py b/examples/common/sample_config.py index dfd730614f3..bd23ffb3dc7 100644 --- a/examples/common/sample_config.py +++ b/examples/common/sample_config.py @@ -48,13 +48,11 @@ def __call__(self, parser, namespace, values, option_string=None): return self._action(parser, namespace, values, option_string) -# pylint:disable=protected-access class CustomArgumentGroup(argparse._ArgumentGroup): def _add_action(self, action): super()._add_action(ActionWrapper(action)) -# pylint:disable=protected-access class CustomActionContainer(argparse._ActionsContainer): def add_argument_group(self, *args, **kwargs): group = CustomArgumentGroup(self, *args, **kwargs) diff --git a/examples/experimental/openvino/bert/main.py b/examples/experimental/openvino/bert/main.py index ea7a3772430..34dd31094b5 100644 --- a/examples/experimental/openvino/bert/main.py +++ b/examples/experimental/openvino/bert/main.py @@ -13,13 +13,13 @@ from pathlib import Path from typing import Any, Iterable -import datasets import evaluate import numpy as np import openvino.runtime as ov import torch import transformers +import datasets import nncf from nncf.parameters import ModelType diff --git a/examples/experimental/torch/classification/bootstrap_nas.py b/examples/experimental/torch/classification/bootstrap_nas.py index 5ae16e5c25d..5e14a2339f0 100644 --- a/examples/experimental/torch/classification/bootstrap_nas.py +++ b/examples/experimental/torch/classification/bootstrap_nas.py @@ -104,7 +104,6 @@ def main(argv): start_worker(main_worker, config) -# pylint:disable=too-many-branches,too-many-statements def main_worker(current_gpu, config: SampleConfig): configure_device(current_gpu, config) config.mlflow = SafeMLFLow(config) diff --git a/examples/experimental/torch/classification/bootstrap_nas_search.py b/examples/experimental/torch/classification/bootstrap_nas_search.py index 228641ff0bf..eb4dc1151e7 100644 --- a/examples/experimental/torch/classification/bootstrap_nas_search.py +++ b/examples/experimental/torch/classification/bootstrap_nas_search.py @@ -91,7 +91,6 @@ def main(argv): start_worker(main_worker, config) -# pylint:disable=too-many-branches,too-many-statements def main_worker(current_gpu, config: SampleConfig): configure_device(current_gpu, config) config.mlflow = SafeMLFLow(config) diff --git a/examples/tensorflow/classification/datasets/builder.py b/examples/tensorflow/classification/datasets/builder.py index 7da8770f583..136fd374c5c 100644 --- a/examples/tensorflow/classification/datasets/builder.py +++ b/examples/tensorflow/classification/datasets/builder.py @@ -130,7 +130,7 @@ def _preprocess(self, image: tf.Tensor, label: tf.Tensor): label = self._label_preprocessing_fn(label) label = tf.cast(label, tf.int32) if self._one_hot: - label = tf.one_hot(label, self.num_classes) # pylint: disable=E1120 + label = tf.one_hot(label, self.num_classes) label = tf.reshape(label, [self.num_classes]) return image, label diff --git a/examples/tensorflow/common/callbacks.py b/examples/tensorflow/common/callbacks.py index 2c7c36e5604..071d97b7c64 100644 --- a/examples/tensorflow/common/callbacks.py +++ b/examples/tensorflow/common/callbacks.py @@ -68,7 +68,6 @@ def __init__(self, log_dir: str, track_lr: bool = False, initial_step: int = 0, self.step = initial_step self._track_lr = track_lr - # pylint: disable=W0237 def on_train_batch_begin(self, epoch: int, logs: MutableMapping[str, Any] = None) -> None: self.step += 1 logs = logs or {} @@ -111,6 +110,6 @@ def _get_base_optimizer(self) -> tf.keras.optimizers.Optimizer: # The optimizer might be wrapped by another class, so unwrap it while hasattr(optimizer, "_optimizer"): - optimizer = optimizer._optimizer # pylint:disable=protected-access + optimizer = optimizer._optimizer return optimizer diff --git a/examples/tensorflow/common/object_detection/architecture/darknet.py b/examples/tensorflow/common/object_detection/architecture/darknet.py index 72a4083657d..792d7fd0b63 100644 --- a/examples/tensorflow/common/object_detection/architecture/darknet.py +++ b/examples/tensorflow/common/object_detection/architecture/darknet.py @@ -10,7 +10,7 @@ # limitations under the License. import tensorflow as tf -import tensorflow.keras.backend as K # pylint: disable=no-name-in-module +import tensorflow.keras.backend as K from examples.tensorflow.common.object_detection.architecture import nn_ops diff --git a/examples/tensorflow/common/object_detection/architecture/heads.py b/examples/tensorflow/common/object_detection/architecture/heads.py index 608cacb229c..71fd9a89bbe 100644 --- a/examples/tensorflow/common/object_detection/architecture/heads.py +++ b/examples/tensorflow/common/object_detection/architecture/heads.py @@ -220,7 +220,7 @@ def __init__( min_level, max_level, anchors_per_location, - num_convs=2, # pylint: disable=W0613 + num_convs=2, num_filters=256, use_separable_conv=False, activation="relu", @@ -288,7 +288,7 @@ def __init__( for level in range(self._min_level, self._max_level + 1): self._norm_activations[level] = norm_activation(name="rpn-l%d-bn" % level) - def _shared_rpn_heads(self, features, anchors_per_location, level, is_training): # pylint: disable=W0613 + def _shared_rpn_heads(self, features, anchors_per_location, level, is_training): """Shared RPN heads.""" features = self._rpn_conv(features) if self._use_batch_norm: diff --git a/examples/tensorflow/common/object_detection/losses.py b/examples/tensorflow/common/object_detection/losses.py index 2debc916fa1..ede14814f25 100644 --- a/examples/tensorflow/common/object_detection/losses.py +++ b/examples/tensorflow/common/object_detection/losses.py @@ -700,7 +700,7 @@ def __call__( use_softmax_loss=False, use_giou_loss=False, use_diou_loss=True, - ): # pylint: disable=R0915 + ): """ YOLOv3 loss function. diff --git a/examples/tensorflow/common/object_detection/utils/input_utils.py b/examples/tensorflow/common/object_detection/utils/input_utils.py index 66d37498690..79077497367 100644 --- a/examples/tensorflow/common/object_detection/utils/input_utils.py +++ b/examples/tensorflow/common/object_detection/utils/input_utils.py @@ -334,7 +334,7 @@ def _flip_boxes_left_right(boxes): row is in the form of [ymin, xmin, ymax, xmax]. :return: Flipped boxes. """ - ymin, xmin, ymax, xmax = tf.split(boxes, 4, axis=1) # pylint: disable=E1120, E1124 + ymin, xmin, ymax, xmax = tf.split(boxes, 4, axis=1) flipped_xmin = tf.subtract(1.0, xmax) flipped_xmax = tf.subtract(1.0, xmin) flipped_boxes = tf.concat([ymin, flipped_xmin, ymax, flipped_xmax], 1) @@ -411,7 +411,7 @@ def _flip_boxes_up_down(boxes): Returns: Flipped boxes. """ - ymin, xmin, ymax, xmax = tf.split(boxes, 4, axis=1) # pylint: disable=E1120, E1124 + ymin, xmin, ymax, xmax = tf.split(boxes, 4, axis=1) flipped_ymin = tf.subtract(1.0, ymax) flipped_ymax = tf.subtract(1.0, ymin) flipped_boxes = tf.concat([flipped_ymin, xmin, flipped_ymax, xmax], 1) @@ -494,7 +494,7 @@ def _rot90_boxes(boxes): Each row is in the form of [ymin, xmin, ymax, xmax]. :return: Rotated boxes. """ - ymin, xmin, ymax, xmax = tf.split(boxes, 4, axis=1) # pylint: disable=E1120, E1124 + ymin, xmin, ymax, xmax = tf.split(boxes, 4, axis=1) rotated_ymin = tf.subtract(1.0, xmax) rotated_ymax = tf.subtract(1.0, xmin) rotated_xmin = ymin diff --git a/examples/tensorflow/common/object_detection/utils/mask_utils.py b/examples/tensorflow/common/object_detection/utils/mask_utils.py index e36bb0af4f4..569f2156074 100644 --- a/examples/tensorflow/common/object_detection/utils/mask_utils.py +++ b/examples/tensorflow/common/object_detection/utils/mask_utils.py @@ -76,7 +76,7 @@ def expand_boxes(boxes, scale): w = np.maximum(w, 1) h = np.maximum(h, 1) - mask = cv2.resize(padded_mask, (w, h)) # pylint: disable=E1101 + mask = cv2.resize(padded_mask, (w, h)) mask = np.array(mask > 0.5, dtype=np.uint8) x_0 = min(max(ref_box[0], 0), image_width) diff --git a/examples/tensorflow/common/object_detection/utils/yolo_v4_utils.py b/examples/tensorflow/common/object_detection/utils/yolo_v4_utils.py index b527130a850..52c62db617a 100644 --- a/examples/tensorflow/common/object_detection/utils/yolo_v4_utils.py +++ b/examples/tensorflow/common/object_detection/utils/yolo_v4_utils.py @@ -183,7 +183,7 @@ def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1): # box1(4,n), return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + 1e-16) > area_thr) & (ar < ar_thr) # candidates -def merge_mosaic_bboxes(bboxes, crop_x, crop_y, image_size): # pylint: disable=R0912 +def merge_mosaic_bboxes(bboxes, crop_x, crop_y, image_size): # adjust & merge mosaic samples bboxes as following area order: # ----------- # | | | diff --git a/examples/tensorflow/common/utils.py b/examples/tensorflow/common/utils.py index 7e93d579d49..d1a8cccf379 100644 --- a/examples/tensorflow/common/utils.py +++ b/examples/tensorflow/common/utils.py @@ -150,7 +150,7 @@ def __init__(self, log_dir, name): log_dir: the model folder path name: the summary subfolder name """ - self.writer = tf.summary.create_file_writer(os.path.join(log_dir, name)) # pylint: disable=E1101 + self.writer = tf.summary.create_file_writer(os.path.join(log_dir, name)) def __call__(self, metrics, step): """Write metrics to summary with the given writer @@ -160,7 +160,7 @@ def __call__(self, metrics, step): step: integer. The training step """ - with self.writer.as_default(): # pylint: disable=E1129 + with self.writer.as_default(): for metric_name, value in metrics.items(): tf.summary.scalar(metric_name, value, step=step) self.writer.flush() diff --git a/examples/tensorflow/object_detection/postprocessing/yolo_v4_postprocessing.py b/examples/tensorflow/object_detection/postprocessing/yolo_v4_postprocessing.py index ca9a482b28b..282a75ae498 100644 --- a/examples/tensorflow/object_detection/postprocessing/yolo_v4_postprocessing.py +++ b/examples/tensorflow/object_detection/postprocessing/yolo_v4_postprocessing.py @@ -12,7 +12,7 @@ import copy import numpy as np -from scipy.special import expit # pylint: disable=E0611 +from scipy.special import expit from scipy.special import softmax diff --git a/examples/tensorflow/object_detection/preprocessing/retinanet_preprocessing.py b/examples/tensorflow/object_detection/preprocessing/retinanet_preprocessing.py index 30ffb75be0d..61f7d4b7c30 100644 --- a/examples/tensorflow/object_detection/preprocessing/retinanet_preprocessing.py +++ b/examples/tensorflow/object_detection/preprocessing/retinanet_preprocessing.py @@ -152,7 +152,7 @@ def _parse_train_data(self, data): # Flips image randomly during training. if self._aug_rand_hflip: - image, boxes = input_utils.random_horizontal_flip(image, boxes) # pylint: disable=W0632 + image, boxes = input_utils.random_horizontal_flip(image, boxes) # Converts boxes from normalized coordinates to pixel coordinates. boxes = box_utils.denormalize_boxes(boxes, image_shape) diff --git a/examples/tensorflow/segmentation/preprocessing/maskrcnn_preprocessing.py b/examples/tensorflow/segmentation/preprocessing/maskrcnn_preprocessing.py index 0e2d944e0b3..9d70a92bcf4 100644 --- a/examples/tensorflow/segmentation/preprocessing/maskrcnn_preprocessing.py +++ b/examples/tensorflow/segmentation/preprocessing/maskrcnn_preprocessing.py @@ -164,9 +164,9 @@ def _parse_train_data(self, data): # Flips image randomly during training. if self._aug_rand_hflip: if self._include_mask: - image, boxes, masks = input_utils.random_horizontal_flip(image, boxes, masks) # pylint: disable=W0632 + image, boxes, masks = input_utils.random_horizontal_flip(image, boxes, masks) else: - image, boxes = input_utils.random_horizontal_flip(image, boxes) # pylint: disable=W0632 + image, boxes = input_utils.random_horizontal_flip(image, boxes) # Converts boxes from normalized coordinates to pixel coordinates. # Now the coordinates of boxes are w.r.t. the original image. diff --git a/examples/torch/classification/main.py b/examples/torch/classification/main.py index 0b2864b5b19..5c80db6b8f5 100644 --- a/examples/torch/classification/main.py +++ b/examples/torch/classification/main.py @@ -130,9 +130,7 @@ def main(argv): if not is_staged_quantization(config): start_worker(main_worker, config) else: - from examples.torch.classification.staged_quantization_worker import ( - staged_quantization_main_worker, # pylint: disable=cyclic-import - ) + from examples.torch.classification.staged_quantization_worker import staged_quantization_main_worker start_worker(staged_quantization_main_worker, config) @@ -145,7 +143,6 @@ def inception_criterion_fn(model_outputs: Any, target: Any, criterion: _Loss) -> return loss1 + 0.4 * loss2 -# pylint:disable=too-many-branches,too-many-statements def main_worker(current_gpu, config: SampleConfig): configure_device(current_gpu, config) config.mlflow = SafeMLFLow(config) @@ -277,7 +274,7 @@ def model_eval_fn(model): if "train" in config.mode: if is_accuracy_aware_training(config): # validation function that returns the target metric value - # pylint: disable=E1123 + def validate_fn(model, epoch): top1, _, _ = validate(val_loader, model, criterion, config, epoch=epoch) return top1 diff --git a/examples/torch/classification/staged_quantization_worker.py b/examples/torch/classification/staged_quantization_worker.py index 7498d804b67..2a73b630c24 100644 --- a/examples/torch/classification/staged_quantization_worker.py +++ b/examples/torch/classification/staged_quantization_worker.py @@ -122,8 +122,6 @@ def state_dict(self): return self.__dict__ -# pylint:disable=too-many-branches -# pylint:disable=too-many-statements def staged_quantization_main_worker(current_gpu, config): configure_device(current_gpu, config) config.mlflow = SafeMLFLow(config) @@ -313,7 +311,7 @@ def train_staged( acc1 = best_acc1 if epoch % config.test_every_n_epochs == 0: # evaluate on validation set - # pylint: disable=E1123 + acc1, _, _ = validate(val_loader, model, criterion, config, epoch=epoch) compression_stage = compression_ctrl.compression_stage() diff --git a/examples/torch/common/model_loader.py b/examples/torch/common/model_loader.py index e688489f113..be8a55d5ae6 100644 --- a/examples/torch/common/model_loader.py +++ b/examples/torch/common/model_loader.py @@ -92,7 +92,7 @@ def is_url(uri): try: parsed_url = urllib.parse.urlparse(uri) return parsed_url.scheme and parsed_url.netloc - except: # pylint: disable=bare-except # noqa: E722 + except: # noqa: E722 return False diff --git a/examples/torch/common/restricted_pickle_module.py b/examples/torch/common/restricted_pickle_module.py index 4de0d0334e6..4ee052a109a 100644 --- a/examples/torch/common/restricted_pickle_module.py +++ b/examples/torch/common/restricted_pickle_module.py @@ -32,7 +32,6 @@ class Unpickler(pickle.Unpickler): safe_builtins = {"range", "complex", "set", "frozenset", "slice", "dict"} safe_collections = {"OrderedDict", "defaultdict"} - # pylint:disable=protected-access allowed_classes = { "torch": {"Tensor", "FloatStorage", "LongStorage", "IntStorage"}, "torch._utils": {"_rebuild_tensor", "_rebuild_tensor_v2", "_rebuild_parameter"}, diff --git a/examples/torch/common/utils.py b/examples/torch/common/utils.py index ffd02d573d8..8a42acd2415 100644 --- a/examples/torch/common/utils.py +++ b/examples/torch/common/utils.py @@ -24,8 +24,6 @@ import mlflow import torch from PIL import Image - -# pylint: disable=import-error from returns.maybe import Maybe from returns.maybe import Nothing from torch.utils import data @@ -207,7 +205,6 @@ def make_additional_checkpoints(checkpoint_path: str, is_best: bool, epoch: int, copyfile(checkpoint_path, str(intermediate_checkpoint)) -# pylint:disable=no-member class ForkedPdb(pdb.Pdb): """A Pdb subclass that may be used from a forked multiprocessing child diff --git a/examples/torch/object_detection/layers/box_utils.py b/examples/torch/object_detection/layers/box_utils.py index 404e417c025..d39d1242362 100644 --- a/examples/torch/object_detection/layers/box_utils.py +++ b/examples/torch/object_detection/layers/box_utils.py @@ -174,7 +174,6 @@ def log_sum_exp(x): return torch.log(torch.sum(torch.exp(x - x_max), 1, keepdim=True)) + x_max -# pylint:disable=abstract-method class NMSFunction(torch.autograd.Function): @staticmethod def forward(ctx, boxes, scores, threshold, top_k=200): diff --git a/examples/torch/object_detection/layers/functions/detection.py b/examples/torch/object_detection/layers/functions/detection.py index 2230b38b488..a774ecf0e45 100644 --- a/examples/torch/object_detection/layers/functions/detection.py +++ b/examples/torch/object_detection/layers/functions/detection.py @@ -55,7 +55,6 @@ def backward(ctx, grad_out): return grad_out -# pylint:disable=abstract-method class DetectionOutputFunction(torch.autograd.Function): """At test time, Detect is the final layer of SSD. Decode location preds, apply non-maximum suppression to location predictions based on conf diff --git a/examples/torch/object_detection/layers/functions/prior_box.py b/examples/torch/object_detection/layers/functions/prior_box.py index 6b8b6c5c550..5963cb14ac1 100644 --- a/examples/torch/object_detection/layers/functions/prior_box.py +++ b/examples/torch/object_detection/layers/functions/prior_box.py @@ -57,7 +57,6 @@ def forward(self, input_fm, img_tensor): return PriorBoxFunction.apply(input_fm, img_tensor, self) -# pylint:disable=abstract-method class PriorBoxFunction(torch.autograd.Function): """Compute priorbox coordinates in point form for each source feature map. diff --git a/examples/torch/object_detection/layers/modules/l2norm.py b/examples/torch/object_detection/layers/modules/l2norm.py index 170f493461a..e1d4ae26104 100644 --- a/examples/torch/object_detection/layers/modules/l2norm.py +++ b/examples/torch/object_detection/layers/modules/l2norm.py @@ -45,7 +45,6 @@ def forward(self, x): return L2NormFunction.apply(x, self.weight, self) -# pylint:disable=abstract-method class L2NormFunction(torch.autograd.Function): @staticmethod def forward(ctx, x, weight, l2NormParams): diff --git a/examples/torch/object_detection/layers/modules/ssd_head.py b/examples/torch/object_detection/layers/modules/ssd_head.py index 74fe99b2453..0ff575eaf38 100644 --- a/examples/torch/object_detection/layers/modules/ssd_head.py +++ b/examples/torch/object_detection/layers/modules/ssd_head.py @@ -112,7 +112,6 @@ def __init__(self, outputs, modules): super().__init__(*modules) self.outputs = [str(o) for o in outputs] - # pylint:disable=W0237 def forward(self, x): outputs = [] for name, module in self._modules.items(): diff --git a/examples/torch/object_detection/main.py b/examples/torch/object_detection/main.py index c44d58ad98f..0aa9c6e04a2 100644 --- a/examples/torch/object_detection/main.py +++ b/examples/torch/object_detection/main.py @@ -105,7 +105,6 @@ def main(argv): start_worker(main_worker, config) -# pylint:disable=too-many-branches,too-many-statements def main_worker(current_gpu, config): ################################# # Setup experiment environment @@ -236,7 +235,7 @@ def model_eval_fn(model): if "train" in config.mode and is_accuracy_aware_training(config): # validation function that returns the target metric value - # pylint: disable=E1123 + def validate_fn(model, epoch): model.eval() mAP = test_net(model, config.device, test_data_loader, distributed=config.distributed) @@ -417,7 +416,6 @@ def train_step(batch_iterator, compression_ctrl, config, criterion, net, train_d return batch_iterator, batch_loss, batch_loss_c, batch_loss_l, loss_comp -# pylint: disable=too-many-statements def train(net, compression_ctrl, train_data_loader, test_data_loader, criterion, optimizer, config, lr_scheduler): net.train() loc_loss = 0 diff --git a/examples/torch/semantic_segmentation/main.py b/examples/torch/semantic_segmentation/main.py index 15f328d630c..f8d5749b225 100644 --- a/examples/torch/semantic_segmentation/main.py +++ b/examples/torch/semantic_segmentation/main.py @@ -291,8 +291,6 @@ def get_params_to_optimize(model_without_dp, aux_lr, config): return params_to_optimize -# pylint: disable=too-many-branches -# pylint: disable=too-many-statements def train( model, model_without_dp, diff --git a/examples/torch/semantic_segmentation/metric/confusionmatrix.py b/examples/torch/semantic_segmentation/metric/confusionmatrix.py index c06cb4848a9..f0c82ef74e8 100644 --- a/examples/torch/semantic_segmentation/metric/confusionmatrix.py +++ b/examples/torch/semantic_segmentation/metric/confusionmatrix.py @@ -88,7 +88,7 @@ def add(self, predicted, target): bincount_2d = np.bincount(x.astype(np.int32), minlength=self.num_classes**2) # See Pylint issue #2721 - # pylint: disable=no-member + assert bincount_2d.size == self.num_classes**2 conf = bincount_2d.reshape((self.num_classes, self.num_classes)) diff --git a/examples/torch/semantic_segmentation/utils/data.py b/examples/torch/semantic_segmentation/utils/data.py index 8f0f5d878fc..b6dc525c504 100644 --- a/examples/torch/semantic_segmentation/utils/data.py +++ b/examples/torch/semantic_segmentation/utils/data.py @@ -101,7 +101,7 @@ def remap(image, old_values, new_values): # equal to 0 if new != 0: # See Pylint issue #2721 - # pylint: disable=unsupported-assignment-operation + tmp[image == old] = new return Image.fromarray(tmp) @@ -303,7 +303,7 @@ def label_to_color(label, class_encoding): def color_to_label(color_labels: Image, class_encoding: OrderedDict): color_labels = np.array(color_labels.convert("RGB")) - # pylint: disable=unsubscriptable-object + labels = np.zeros((color_labels.shape[0], color_labels.shape[1]), dtype=np.int64) red = color_labels[..., 0] diff --git a/examples/torch/semantic_segmentation/utils/loss_funcs.py b/examples/torch/semantic_segmentation/utils/loss_funcs.py index 188499d3fef..f25d4647e1b 100644 --- a/examples/torch/semantic_segmentation/utils/loss_funcs.py +++ b/examples/torch/semantic_segmentation/utils/loss_funcs.py @@ -68,7 +68,6 @@ def cross_entropy_icnet(inputs, target: torch.Tensor, weight: list): def do_model_specific_postprocessing(model_name, labels, model_outputs): - # pylint:disable=no-member metric_outputs = model_outputs if model_name == "unet": # UNet predicts center image crops diff --git a/nncf/__init__.py b/nncf/__init__.py index d047a37e0b4..4ace2c75548 100644 --- a/nncf/__init__.py +++ b/nncf/__init__.py @@ -33,8 +33,8 @@ _SUPPORTED_FRAMEWORKS = ["torch", "tensorflow", "onnx", "openvino"] -from importlib.util import find_spec as _find_spec # noqa: E402 # pylint:disable=wrong-import-position -from pathlib import Path as _Path # noqa: E402 # pylint:disable=wrong-import-position +from importlib.util import find_spec as _find_spec # noqa: E402 +from pathlib import Path as _Path # noqa: E402 _AVAILABLE_FRAMEWORKS = {} diff --git a/nncf/common/composite_compression.py b/nncf/common/composite_compression.py index 4c07789bf3a..b6989b4e6f0 100644 --- a/nncf/common/composite_compression.py +++ b/nncf/common/composite_compression.py @@ -324,12 +324,12 @@ def export_model( self.prepare_for_export() backend = get_backend(self.model) if backend is BackendType.TENSORFLOW: - from nncf.tensorflow.exporter import TFExporter # pylint: disable=cyclic-import + from nncf.tensorflow.exporter import TFExporter exporter = TFExporter(self.model, input_names, output_names, model_args) else: assert backend is BackendType.TORCH - from nncf.torch.exporter import PTExporter # pylint: disable=cyclic-import + from nncf.torch.exporter import PTExporter exporter = PTExporter(self.model, input_names, output_names, model_args) if save_format is not None: diff --git a/nncf/common/compression.py b/nncf/common/compression.py index 9a11803ead8..4d2460f2c3d 100644 --- a/nncf/common/compression.py +++ b/nncf/common/compression.py @@ -105,12 +105,12 @@ def export_model( self.prepare_for_export() backend = get_backend(self.model) if backend is BackendType.TENSORFLOW: - from nncf.tensorflow.exporter import TFExporter # pylint: disable=cyclic-import + from nncf.tensorflow.exporter import TFExporter exporter = TFExporter(self.model, input_names, output_names, model_args) else: assert backend is BackendType.TORCH - from nncf.torch.exporter import PTExporter # pylint: disable=cyclic-import + from nncf.torch.exporter import PTExporter exporter = PTExporter(self.model, input_names, output_names, model_args) if save_format is not None: diff --git a/nncf/common/graph/graph.py b/nncf/common/graph/graph.py index 756f3d3718e..4eb61c72399 100644 --- a/nncf/common/graph/graph.py +++ b/nncf/common/graph/graph.py @@ -177,7 +177,6 @@ def __init__(self, input_edges: List[NNCFGraphEdge], output_edges: List[NNCFGrap self.output_edges = output_edges -# pylint:disable=too-many-public-methods class NNCFGraph: """ Wrapper over a regular directed acyclic graph that represents a control flow/execution graph of a DNN diff --git a/nncf/common/hardware/config.py b/nncf/common/hardware/config.py index 691c3db469e..371098d9390 100644 --- a/nncf/common/hardware/config.py +++ b/nncf/common/hardware/config.py @@ -85,7 +85,6 @@ def get_path_to_hw_config(hw_config_type: HWConfigType): @classmethod def from_dict(cls, dct: dict): - # pylint:disable=too-many-nested-blocks,too-many-branches hw_config = cls() hw_config.target_device = dct["target_device"] diff --git a/nncf/common/initialization/batchnorm_adaptation.py b/nncf/common/initialization/batchnorm_adaptation.py index de0b9008903..c8d6d996c46 100644 --- a/nncf/common/initialization/batchnorm_adaptation.py +++ b/nncf/common/initialization/batchnorm_adaptation.py @@ -84,16 +84,12 @@ def run(self, model: TModel) -> None: """ backend = get_backend(model) if backend is BackendType.TORCH: - from nncf.torch.batchnorm_adaptation import ( - PTBatchnormAdaptationAlgorithmImpl, # pylint: disable=cyclic-import - ) + from nncf.torch.batchnorm_adaptation import PTBatchnormAdaptationAlgorithmImpl impl_cls = PTBatchnormAdaptationAlgorithmImpl else: assert backend is BackendType.TENSORFLOW - from nncf.tensorflow.batchnorm_adaptation import ( - TFBatchnormAdaptationAlgorithmImpl, # pylint: disable=cyclic-import - ) + from nncf.tensorflow.batchnorm_adaptation import TFBatchnormAdaptationAlgorithmImpl impl_cls = TFBatchnormAdaptationAlgorithmImpl impl = impl_cls(self._data_loader, self._num_bn_adaptation_steps, self._device) diff --git a/nncf/common/insertion_point_graph.py b/nncf/common/insertion_point_graph.py index 7e71a38cdc7..c3fa6f52fe7 100644 --- a/nncf/common/insertion_point_graph.py +++ b/nncf/common/insertion_point_graph.py @@ -91,8 +91,7 @@ def __init__( If left unspecified, every node in `nncf_graph` will be allowed to have a single post-hook for its output (post-hooking separate tensors in an operation's output is not currently supported) """ - # pylint:disable=too-many-branches - # pylint:disable=too-many-statements + super().__init__() self._base_nx_graph = deepcopy(nncf_graph.get_nx_graph_copy()) if weight_modifiable_node_names is None: @@ -333,7 +332,7 @@ def get_ip_graph_with_merged_hw_optimized_operations( :param full_fusing_pattern: The GraphPatttern object representing a composition of fusing pattern variants. :return: The InsertionPointGraph with nodes fused according to pattern matching. """ - # pylint:disable=too-many-branches + merged_ip_graph = deepcopy(self) matches = find_subgraphs_matching_pattern(merged_ip_graph.get_base_nx_graph(), full_fusing_pattern) for match in matches: diff --git a/nncf/common/logging/track_progress.py b/nncf/common/logging/track_progress.py index b852c372c87..b82a95f32bf 100644 --- a/nncf/common/logging/track_progress.py +++ b/nncf/common/logging/track_progress.py @@ -50,13 +50,13 @@ def render(self, task: Task) -> Text: class TimeElapsedColumnWithStyle(TimeElapsedColumn): def render(self, task: "Task") -> Text: text = super().render(task) - return Text(text._text[0], style=INTEL_BLUE_COLOR) # pylint: disable=protected-access + return Text(text._text[0], style=INTEL_BLUE_COLOR) class TimeRemainingColumnWithStyle(TimeRemainingColumn): def render(self, task: "Task") -> Text: text = super().render(task) - return Text(text._text[0], style=INTEL_BLUE_COLOR) # pylint: disable=protected-access + return Text(text._text[0], style=INTEL_BLUE_COLOR) class track: diff --git a/nncf/common/pruning/node_selector.py b/nncf/common/pruning/node_selector.py index 08d386231e0..4fc8d286327 100644 --- a/nncf/common/pruning/node_selector.py +++ b/nncf/common/pruning/node_selector.py @@ -91,7 +91,7 @@ def create_pruning_groups(self, graph: NNCFGraph) -> Clusterization[NNCFNode]: :param graph: Graph to work with and their initialization parameters as values. :return: Clusterization of pruned nodes. """ - # pylint:disable=too-many-branches + all_nodes_to_prune = graph.get_nodes_by_types(self._prune_operations_types) # NNCFNodes here # 1. Clusters for special ops diff --git a/nncf/common/quantization/quantizer_propagation/graph.py b/nncf/common/quantization/quantizer_propagation/graph.py index 47963285937..a46968ea974 100644 --- a/nncf/common/quantization/quantizer_propagation/graph.py +++ b/nncf/common/quantization/quantizer_propagation/graph.py @@ -8,7 +8,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# pylint:disable=too-many-lines + from collections import deque from copy import copy from copy import deepcopy @@ -49,7 +49,7 @@ class QuantizerPropagationStateGraph(nx.DiGraph): - # pylint:disable=too-many-public-methods,too-many-return-statements + """ This class is based upon InsertionPointGraph and represents a"chessboard" for PropagatingQuantizer items. It tracks the current state of @@ -60,6 +60,7 @@ class QuantizerPropagationStateGraph(nx.DiGraph): the same graph node/edge. This class is mainly operated upon by the QuantizerPropagationSolver objects. """ + PROPAGATING_QUANTIZER_NODE_ATTR = "propagating_quantizer" AFFECTING_PROPAGATING_QUANTIZERS_ATTR = "affecting_propagating_quantizers" QUANTIZATION_TRAIT_NODE_ATTR = "quantization_trait" @@ -265,7 +266,6 @@ def is_insertion_point(qpsg_node_type: QuantizerPropagationStateGraphNodeType) - QuantizerPropagationStateGraphNodeType.POST_HOOK, ] - # pylint:disable=too-many-branches def merge_quantizer_into_path(self, prop_quantizer: PropagatingQuantizer, path: PropagationPath): curr_node = self.nodes[prop_quantizer.current_location_node_key] curr_node[QuantizerPropagationStateGraph.PROPAGATING_QUANTIZER_NODE_ATTR] = None @@ -348,7 +348,6 @@ def _get_major_unified_scale_type(type_list: List[Optional[UnifiedScaleType]]) - major_unified_scale_type = UnifiedScaleType.UNIFY_ONLY_PER_TENSOR return major_unified_scale_type - # pylint:disable=too-many-statements def merge_quantizers_for_branching_node( self, quantizers_to_merge: List[PropagatingQuantizer], diff --git a/nncf/common/quantization/quantizer_propagation/solver.py b/nncf/common/quantization/quantizer_propagation/solver.py index 2a9f8e31efa..cfd856e3d62 100644 --- a/nncf/common/quantization/quantizer_propagation/solver.py +++ b/nncf/common/quantization/quantizer_propagation/solver.py @@ -9,7 +9,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint:disable=too-many-lines + from collections import Counter from collections import OrderedDict from collections import deque @@ -397,9 +397,7 @@ def __init__( self._hw_config: HWConfig = hw_config self._visualizer = None if is_debug(): - from nncf.common.quantization.quantizer_propagation.visualizer import ( - QuantizerPropagationVisualizer, # pylint: disable=cyclic-import - ) + from nncf.common.quantization.quantizer_propagation.visualizer import QuantizerPropagationVisualizer self._visualizer = QuantizerPropagationVisualizer(DEBUG_LOG_DIR + "/quant_prop") self._propagation_strategy = ( @@ -465,7 +463,6 @@ def _filter_by_weight_ignored_target_scopes( nncf_logger.debug(f"Ignored adding weight quantizer for: {node_name}") return weight_quantizable_node_names_vs_qconfigs - # pylint:disable=too-many-branches def run_on_ip_graph(self, ip_graph: InsertionPointGraph) -> QuantizationProposal: """ The main function to be used on an InsertionPointGraph to produce @@ -607,7 +604,6 @@ def _handle_quantizer_merge( quant_prop_graph: QuantizerPropagationStateGraph, branching_node_key: str, ): - # pylint:disable=too-many-branches waiting_pqs_list = list(waiting_pqs) merged_pqs = [] unmerged_pqs = [] @@ -679,8 +675,6 @@ def propagation_step( :return: The new state of `quant_prop_graph` with `curr_prop_quantizer` propagated one step further. """ - # pylint:disable=too-many-branches - # pylint:disable=too-many-statements curr_node_key = curr_prop_quantizer.current_location_node_key curr_node = quant_prop_graph.nodes[curr_node_key] curr_node_type = curr_node[QuantizerPropagationStateGraph.NODE_TYPE_NODE_ATTR] @@ -1000,7 +994,7 @@ def coalesce_insertion_points( corresponding TargetPoints. :return: A list of TargetPoint groups; each group is a list of TargetPoint's. """ - # pylint:disable=too-many-branches + if linked_scopes_groups_list is None: return [ [ @@ -1090,7 +1084,6 @@ def _filter_qconfigs_according_to_scope( def _setup_initial_quantizers_for_operator_node( self, operator_node_key: str, quant_prop_graph: QuantizerPropagationStateGraph ): - # pylint:disable=too-many-branches node = quant_prop_graph.nodes[operator_node_key] # preds are in sorted order for reproducibility @@ -1200,7 +1193,6 @@ def _setup_initial_quantizers_for_operator_node( additional_pq.last_accepting_location_node_key = additional_pq_ip_key self._active_propagating_quantizers_queue.appendleft(additional_pq) - # pylint:disable=too-many-return-statements def check_branching_transition( self, quant_prop_graph: QuantizerPropagationStateGraph, @@ -1315,7 +1307,7 @@ def check_transition_via_path( cloned before transition, which impacts the logic of the function. :return: The status of the transition determining how it should proceed. """ - # pylint:disable=too-many-branches + for from_node_key, to_node_key in path: from_node = quant_prop_graph.nodes[from_node_key] @@ -1392,7 +1384,6 @@ def get_merged_qconfigs_for_downward_branching_case( of the merged quantizer, if any, and the second element corresponds to configurations of the quantizers that would have to remain on the branches (if any). """ - # pylint:disable=too-many-branches if self._propagation_strategy == PropagationStrategy.DO_NOT_MERGE_BRANCH_FQS: # Do not merge at all diff --git a/nncf/common/utils/debug.py b/nncf/common/utils/debug.py index 887e677805e..25670390414 100644 --- a/nncf/common/utils/debug.py +++ b/nncf/common/utils/debug.py @@ -28,7 +28,7 @@ def set_debug_log_dir(dir_: str): @contextmanager def nncf_debug(): - from nncf.common.logging.logger import set_log_level # pylint: disable=cyclic-import + from nncf.common.logging.logger import set_log_level set_log_level(logging.DEBUG) yield diff --git a/nncf/common/utils/logger/__init__.py b/nncf/common/utils/logger/__init__.py index d074af82b7d..026057532d4 100644 --- a/nncf/common/utils/logger/__init__.py +++ b/nncf/common/utils/logger/__init__.py @@ -10,8 +10,6 @@ # limitations under the License. from nncf.common.deprecation import warning_deprecated -# pylint:disable=wrong-import-position - warning_deprecated( "Importing from nncf.common.utils.logger is deprecated. " "Import `from nncf` directly instead, i.e.: \n" @@ -19,7 +17,7 @@ "`from nncf import nncf_logger` instead of `from nncf.common.utils.logger import logger as nncf_logger`" ) -# pylint:disable=unused-import + from nncf.common.logging.logger import disable_logging as disable_logging # noqa: E402 from nncf.common.logging.logger import nncf_logger as logger # noqa: E402, F401 from nncf.common.logging.logger import set_log_level as set_log_level # noqa: E402 diff --git a/nncf/common/utils/os.py b/nncf/common/utils/os.py index fb6f146304b..23821432d34 100644 --- a/nncf/common/utils/os.py +++ b/nncf/common/utils/os.py @@ -15,7 +15,6 @@ import psutil -# pylint: disable=W1514 @contextmanager def safe_open(file: Path, *args, **kwargs): """ @@ -52,7 +51,7 @@ def get_available_cpu_count(logical: bool = True) -> int: try: num_cpu = psutil.cpu_count(logical=logical) return num_cpu if num_cpu is not None else 1 - except Exception: # pylint: disable=broad-except + except Exception: return 1 @@ -62,5 +61,5 @@ def get_available_memory_amount() -> int: """ try: return psutil.virtual_memory()[1] - except Exception: # pylint: disable=broad-except + except Exception: return 0 diff --git a/nncf/common/utils/patcher.py b/nncf/common/utils/patcher.py index 097f466762a..726e0110ff7 100644 --- a/nncf/common/utils/patcher.py +++ b/nncf/common/utils/patcher.py @@ -116,7 +116,7 @@ def import_obj(self, obj_cls): # noqa: C901 else: if "_partialmethod" in obj_cls.__dict__: while "_partialmethod" in obj_cls.__dict__: - obj_cls = obj_cls._partialmethod.keywords["__fn"] # pylint: disable=protected-access + obj_cls = obj_cls._partialmethod.keywords["__fn"] while isinstance(obj_cls, (partial, partialmethod)): obj_cls = obj_cls.keywords["__fn"] diff --git a/nncf/config/config.py b/nncf/config/config.py index cf1cff31358..fc6ecc50e89 100644 --- a/nncf/config/config.py +++ b/nncf/config/config.py @@ -97,7 +97,7 @@ def get_redefinable_global_param_value_for_algo(self, param_name: str, algo_name the resolution of the redefinable parameter should occur. :return: The value of the parameter that should be applied for the algo specified by `algo_name`. """ - from nncf.config.extractors import extract_algo_specific_config # pylint: disable=cyclic-import + from nncf.config.extractors import extract_algo_specific_config algo_config = extract_algo_specific_config(self, algo_name) param = self.get(param_name) diff --git a/nncf/config/extractors.py b/nncf/config/extractors.py index 2bee6557083..75d6c146de4 100644 --- a/nncf/config/extractors.py +++ b/nncf/config/extractors.py @@ -48,7 +48,7 @@ def extract_algo_specific_config(config: NNCFConfig, algo_name_to_match: str) -> assert isinstance(compression_section, dict) algo_list = [compression_section] - from nncf.common.compression import NO_COMPRESSION_ALGORITHM_NAME # pylint: disable=cyclic-import + from nncf.common.compression import NO_COMPRESSION_ALGORITHM_NAME if algo_name_to_match == NO_COMPRESSION_ALGORITHM_NAME: if len(algo_list) > 0: @@ -194,7 +194,7 @@ class NNCFAlgorithmNames: SPARSITY = ["rb_sparsity", "magnitude_sparsity", "const_sparsity"] def validate_accuracy_aware_schema(config: NNCFConfig, params: Dict[str, object]): - from nncf.common.accuracy_aware_training import AccuracyAwareTrainingMode # pylint: disable=cyclic-import + from nncf.common.accuracy_aware_training import AccuracyAwareTrainingMode if params["mode"] == AccuracyAwareTrainingMode.EARLY_EXIT: return diff --git a/nncf/experimental/tensor/functions.py b/nncf/experimental/tensor/functions.py index a71ac209012..80825292f8a 100644 --- a/nncf/experimental/tensor/functions.py +++ b/nncf/experimental/tensor/functions.py @@ -73,7 +73,7 @@ def flatten(a: Tensor) -> Tensor: @functools.singledispatch @_tensor_guard -def max(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor: # pylint: disable=redefined-builtin +def max(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor: """ Return the maximum of an array or maximum along an axis. @@ -86,7 +86,7 @@ def max(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor @functools.singledispatch @_tensor_guard -def min(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor: # pylint: disable=redefined-builtin +def min(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor: """ Return the minimum of an array or minimum along an axis. @@ -99,7 +99,7 @@ def min(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor @functools.singledispatch @_tensor_guard -def abs(a: Tensor) -> Tensor: # pylint: disable=redefined-builtin +def abs(a: Tensor) -> Tensor: """ Calculate the absolute value element-wise. @@ -150,7 +150,7 @@ def reshape(a: Tensor, shape: Tuple[int, ...]) -> Tensor: @functools.singledispatch @_tensor_guard -def all(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor: # pylint: disable=redefined-builtin +def all(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor: """ Test whether all tensor elements along a given axis evaluate to True. @@ -191,7 +191,7 @@ def allclose( @functools.singledispatch @_tensor_guard -def any(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor: # pylint: disable=redefined-builtin +def any(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Tensor: """ Test whether any tensor elements along a given axis evaluate to True. @@ -384,7 +384,7 @@ def mean(a: Tensor, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims @functools.singledispatch @_tensor_guard -def round(a: Tensor, decimals=0) -> Tensor: # pylint: disable=redefined-builtin +def round(a: Tensor, decimals=0) -> Tensor: """ Evenly round to the given number of decimals. @@ -437,7 +437,6 @@ def _dispatch_list(fn: "functools._SingleDispatchCallable", tensor_list: List[Te def _initialize_backends(): - # pylint: disable=unused-import import nncf.experimental.tensor.numpy_functions try: diff --git a/nncf/experimental/tensor/numpy_functions.py b/nncf/experimental/tensor/numpy_functions.py index b4c515b1da1..84ba9128566 100644 --- a/nncf/experimental/tensor/numpy_functions.py +++ b/nncf/experimental/tensor/numpy_functions.py @@ -188,7 +188,7 @@ def _(a: Union[np.ndarray, np.generic], decimals: int = 0) -> np.ndarray: return np.round(a, decimals=decimals) -@_register_numpy_types(fns._binary_op_nowarn) # pylint: disable=protected-access +@_register_numpy_types(fns._binary_op_nowarn) def _( a: Union[np.ndarray, np.generic], b: Union[np.ndarray, np.generic, float], operator_fn: Callable ) -> Union[np.ndarray, np.generic]: @@ -197,7 +197,7 @@ def _( return operator_fn(a, b) -@_register_numpy_types(fns._binary_reverse_op_nowarn) # pylint: disable=protected-access +@_register_numpy_types(fns._binary_reverse_op_nowarn) def _( a: Union[np.ndarray, np.generic], b: Union[np.ndarray, np.generic, float], operator_fn: Callable ) -> Union[np.ndarray, np.generic]: diff --git a/nncf/experimental/tensor/torch_functions.py b/nncf/experimental/tensor/torch_functions.py index 273d5419781..e239dec83f8 100644 --- a/nncf/experimental/tensor/torch_functions.py +++ b/nncf/experimental/tensor/torch_functions.py @@ -188,11 +188,11 @@ def _(a: torch.Tensor, decimals=0) -> torch.Tensor: return torch.round(a, decimals=decimals) -@fns._binary_op_nowarn.register(torch.Tensor) # pylint: disable=protected-access +@fns._binary_op_nowarn.register(torch.Tensor) def _(a: torch.Tensor, b: Union[torch.Tensor, float], operator_fn: Callable) -> torch.Tensor: return operator_fn(a, b) -@fns._binary_reverse_op_nowarn.register(torch.Tensor) # pylint: disable=protected-access +@fns._binary_reverse_op_nowarn.register(torch.Tensor) def _(a: torch.Tensor, b: Union[torch.Tensor, float], operator_fn: Callable) -> torch.Tensor: return operator_fn(b, a) diff --git a/nncf/experimental/tensorflow/graph/converter.py b/nncf/experimental/tensorflow/graph/converter.py index d288a0b5f40..31319fbf0e6 100644 --- a/nncf/experimental/tensorflow/graph/converter.py +++ b/nncf/experimental/tensorflow/graph/converter.py @@ -81,7 +81,7 @@ def build(self, graph_optimizers: List[str]): ) # Step 3: Convert the GraphDef to a tf.Graph - with tf.Graph().as_default() as graph: # pylint:disable=not-context-manager + with tf.Graph().as_default() as graph: tf.graph_util.import_graph_def(graph_def, name="") return graph, input_tensors, output_tensors diff --git a/nncf/experimental/tensorflow/patch_tf.py b/nncf/experimental/tensorflow/patch_tf.py index 0ebfa305dbe..c6f77d69072 100644 --- a/nncf/experimental/tensorflow/patch_tf.py +++ b/nncf/experimental/tensorflow/patch_tf.py @@ -248,7 +248,7 @@ def wrapper(*args, **kwargs): (obj,) = args # self eager_context = context.context() old_name = eager_context.scope_name - name = obj._name # pylint: disable=protected-access + name = obj._name if not name: scope_name = "" @@ -263,7 +263,7 @@ def wrapper(*args, **kwargs): def _restore_name_scope(*_): eager_context.scope_name = old_name - obj._exit_fns.append(_restore_name_scope) # pylint: disable=protected-access + obj._exit_fns.append(_restore_name_scope) else: scope_name = func(*args, **kwargs) return scope_name diff --git a/nncf/experimental/torch/nas/bootstrapNAS/elasticity/elastic_width.py b/nncf/experimental/torch/nas/bootstrapNAS/elasticity/elastic_width.py index fd918a54cc7..a3523a51cf6 100644 --- a/nncf/experimental/torch/nas/bootstrapNAS/elasticity/elastic_width.py +++ b/nncf/experimental/torch/nas/bootstrapNAS/elasticity/elastic_width.py @@ -9,7 +9,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=too-many-lines,too-many-nested-blocks,too-many-branches import random from collections import OrderedDict diff --git a/nncf/experimental/torch/nas/bootstrapNAS/elasticity/multi_elasticity_handler.py b/nncf/experimental/torch/nas/bootstrapNAS/elasticity/multi_elasticity_handler.py index 4beca169579..76ae525d275 100644 --- a/nncf/experimental/torch/nas/bootstrapNAS/elasticity/multi_elasticity_handler.py +++ b/nncf/experimental/torch/nas/bootstrapNAS/elasticity/multi_elasticity_handler.py @@ -46,7 +46,6 @@ class MEHandlerStateNames: STATES_OF_HANDLERS = "states_of_handlers" -# pylint: disable=too-many-public-methods class MultiElasticityHandler(ElasticityHandler): """ An interface for handling multiple elasticity in the network. The elasticity defines variable values in properties diff --git a/nncf/experimental/torch/search_building_blocks/search_graph.py b/nncf/experimental/torch/search_building_blocks/search_graph.py index a2820130f87..99a146dd890 100644 --- a/nncf/experimental/torch/search_building_blocks/search_graph.py +++ b/nncf/experimental/torch/search_building_blocks/search_graph.py @@ -116,7 +116,6 @@ def __init__(self, nx_merged_graph: nx.DiGraph): self._nx_graph = nx_merged_graph old_merged_graph_nodes = deepcopy(self._nx_graph._node) for node_key in old_merged_graph_nodes: - # pylint: disable=protected-access next_nodes = self._nx_graph._succ[node_key] if len(list(next_nodes)) > 1: self._insert_dummy_node(node_key) @@ -183,7 +182,6 @@ def get_next_edges(self, node_key: str) -> Dict[str, Any]: return self._nx_graph.succ[node_key] def _insert_dummy_node(self, node_key: str): - # pylint: disable=protected-access next_nodes = deepcopy(self._nx_graph._succ[node_key]) dummy_node_attr = {SearchGraph.IS_DUMMY_NODE_ATTR: True} node_key_attr = deepcopy(self._nx_graph._node[node_key]) @@ -256,7 +254,7 @@ def get_merged_original_graph_with_pattern(orig_graph: nx.DiGraph, hw_fused_ops: merged_graph = orig_graph if not hw_fused_ops: return merged_graph - # pylint: disable=protected-access + pattern_fusing_graph = PatternsManager.get_full_hw_pattern_graph(backend=BackendType.TORCH, device=TargetDevice.ANY) matches = find_subgraphs_matching_pattern(orig_graph, pattern_fusing_graph) nx.set_node_attributes(merged_graph, False, SearchGraph.IS_DUMMY_NODE_ATTR) @@ -282,7 +280,7 @@ def get_merged_original_graph_with_pattern(orig_graph: nx.DiGraph, hw_fused_ops: for node_key in match: attrs = orig_graph.nodes[node_key] merged_node_key += str(attrs["id"]) + " " + attrs[SearchGraph.TYPE_NODE_ATTR] + " " - # pylint: disable=protected-access + merged_nodes.append(orig_graph.nodes[node_key]) merged_graph.remove_node(node_key) type_list.append(attrs[SearchGraph.TYPE_NODE_ATTR]) @@ -301,7 +299,6 @@ def get_merged_original_graph_with_pattern(orig_graph: nx.DiGraph, hw_fused_ops: return merged_graph -# pylint:disable=too-many-branches def check_graph_has_no_hanging_edges_after_block_removal( graph: SearchGraph, first_skipped_node: SearchGraphNode, end_node: SearchGraphNode ) -> bool: @@ -375,7 +372,6 @@ def check_graph_has_no_duplicate_edges_after_block_removal( # \ / D # D forbidden - # pylint: disable=protected-access if first_skipped_node.is_dummy: next_end_node = sgraph.get_next_nodes(end_node.node_key) if len(next_end_node) != 0: diff --git a/nncf/experimental/torch/sparsity/movement/layers.py b/nncf/experimental/torch/sparsity/movement/layers.py index e1d2e52813b..62e09d06c4b 100644 --- a/nncf/experimental/torch/sparsity/movement/layers.py +++ b/nncf/experimental/torch/sparsity/movement/layers.py @@ -331,7 +331,6 @@ class MaskCalculationHook: """ def __init__(self, module: nn.Module): - # pylint: disable=protected-access self.hook = module._register_state_dict_hook(self.hook_fn) def hook_fn(self, module, state_dict: Dict, prefix: str, local_metadata): diff --git a/nncf/onnx/statistics/collectors.py b/nncf/onnx/statistics/collectors.py index 2ce98915edc..8950694e04a 100644 --- a/nncf/onnx/statistics/collectors.py +++ b/nncf/onnx/statistics/collectors.py @@ -26,7 +26,6 @@ from nncf.onnx.tensor import ONNXNNCFTensor -# pylint: disable=too-many-public-methods class ONNXNNCFCollectorTensorProcessor(NNCFCollectorTensorProcessor): """ A realization of the processing methods for ONNXNNCFTensors. diff --git a/nncf/openvino/graph/model_transformer.py b/nncf/openvino/graph/model_transformer.py index 16cad27bb65..9813fbdc684 100644 --- a/nncf/openvino/graph/model_transformer.py +++ b/nncf/openvino/graph/model_transformer.py @@ -15,7 +15,7 @@ import numpy as np import openvino.runtime as ov -from openvino._pyopenvino import DescriptorTensor # pylint: disable=no-name-in-module +from openvino._pyopenvino import DescriptorTensor from openvino.runtime import opset9 as opset from nncf.common.graph.model_transformer import ModelTransformer diff --git a/nncf/openvino/graph/nncf_graph_builder.py b/nncf/openvino/graph/nncf_graph_builder.py index 1a5374c65e7..e4d0fac1da2 100644 --- a/nncf/openvino/graph/nncf_graph_builder.py +++ b/nncf/openvino/graph/nncf_graph_builder.py @@ -125,7 +125,6 @@ def _add_nncf_node(node: ov.Node, graph: NNCFGraph) -> None: metatype = get_node_metatype(node) graph.add_nncf_node(node_name=node.get_friendly_name(), node_type=node_type, node_metatype=metatype) - # pylint: disable=too-many-branches @staticmethod def create_nncf_graph(model: ov.Model) -> NNCFGraph: """ diff --git a/nncf/openvino/pot/engine.py b/nncf/openvino/pot/engine.py index 60aeae612ab..f9a8b7fc66d 100644 --- a/nncf/openvino/pot/engine.py +++ b/nncf/openvino/pot/engine.py @@ -64,7 +64,6 @@ def __iter__(self): for idx, x in enumerate(self._iterable): yield (idx, x) - # pylint: disable=protected-access def __len__(self) -> int: if self._length is None: data_source = None diff --git a/nncf/openvino/pot/quantization/accuracy_aware.py b/nncf/openvino/pot/quantization/accuracy_aware.py index 09ffceff0ee..0e2529740c6 100644 --- a/nncf/openvino/pot/quantization/accuracy_aware.py +++ b/nncf/openvino/pot/quantization/accuracy_aware.py @@ -14,9 +14,9 @@ import numpy as np from openvino.tools import pot - # TODO(andrey-churkin): Should be removed after OpenVINO release. -# pylint: disable=E1101 + + class NMSEBasedAccuracyAware(pot.AccuracyAwareCommon): """ NMSE based implementation of the Accuracy Aware algorithm from the POT. diff --git a/nncf/openvino/pot/quantization/quantize_model.py b/nncf/openvino/pot/quantization/quantize_model.py index 5bb985bff9e..3b37bf2d854 100644 --- a/nncf/openvino/pot/quantization/quantize_model.py +++ b/nncf/openvino/pot/quantization/quantize_model.py @@ -462,7 +462,7 @@ def quantize_with_accuracy_control_impl( ) # Check whether it is possible to calculate the metric for one data item. - # pylint: disable=W0703 + use_original_metric = True try: ie = ov.Core() diff --git a/nncf/openvino/statistics/collectors.py b/nncf/openvino/statistics/collectors.py index 4672541d86b..dd586fb4523 100644 --- a/nncf/openvino/statistics/collectors.py +++ b/nncf/openvino/statistics/collectors.py @@ -43,7 +43,6 @@ from nncf.quantization.advanced_parameters import StatisticsType -# pylint: disable=too-many-public-methods class OVNNCFCollectorTensorProcessor(NNCFCollectorTensorProcessor): """ A realization of the processing methods for OVNNCFTensors. diff --git a/nncf/quantization/algorithms/accuracy_control/evaluator.py b/nncf/quantization/algorithms/accuracy_control/evaluator.py index 71f59153b98..cb1e3173e6c 100644 --- a/nncf/quantization/algorithms/accuracy_control/evaluator.py +++ b/nncf/quantization/algorithms/accuracy_control/evaluator.py @@ -212,7 +212,7 @@ def determine_mode( metric_mode = None data_item = dataset.get_data([0]) - # pylint: disable=W0703 + try: metric_value, values_for_each_item = validation_fn(model_for_inference, data_item) except Exception: @@ -231,7 +231,6 @@ def determine_mode( convert_to_float_possible = True if values_for_each_item is not None: - # pylint: disable=W0703 try: _ = float(values_for_each_item[0]) except Exception: diff --git a/nncf/quantization/algorithms/bias_correction/backend.py b/nncf/quantization/algorithms/bias_correction/backend.py index 08eb9d433c8..b256857f64d 100644 --- a/nncf/quantization/algorithms/bias_correction/backend.py +++ b/nncf/quantization/algorithms/bias_correction/backend.py @@ -27,7 +27,6 @@ OutputType = TypeVar("OutputType") -# pylint:disable=too-many-public-methods class BiasCorrectionAlgoBackend(ABC): @property @abstractmethod diff --git a/nncf/quantization/algorithms/bias_correction/onnx_backend.py b/nncf/quantization/algorithms/bias_correction/onnx_backend.py index 498f33d0aba..a6be54a2355 100644 --- a/nncf/quantization/algorithms/bias_correction/onnx_backend.py +++ b/nncf/quantization/algorithms/bias_correction/onnx_backend.py @@ -35,7 +35,7 @@ from nncf.quantization.algorithms.bias_correction.backend import BiasCorrectionAlgoBackend -# pylint:disable=too-many-public-methods +@ALGO_BACKENDS.register(BackendType.ONNX) class ONNXBiasCorrectionAlgoBackend(BiasCorrectionAlgoBackend): @property def tensor_processor(self) -> ONNXNNCFCollectorTensorProcessor: diff --git a/nncf/quantization/algorithms/bias_correction/openvino_backend.py b/nncf/quantization/algorithms/bias_correction/openvino_backend.py index 1af3bb9d4cf..0f38da3cc2f 100644 --- a/nncf/quantization/algorithms/bias_correction/openvino_backend.py +++ b/nncf/quantization/algorithms/bias_correction/openvino_backend.py @@ -35,7 +35,7 @@ from nncf.quantization.algorithms.bias_correction.backend import BiasCorrectionAlgoBackend -# pylint:disable=too-many-public-methods +@ALGO_BACKENDS.register(BackendType.OPENVINO) class OVBiasCorrectionAlgoBackend(BiasCorrectionAlgoBackend): @property def tensor_processor(self) -> OVNNCFCollectorTensorProcessor: diff --git a/nncf/quantization/algorithms/min_max/backend.py b/nncf/quantization/algorithms/min_max/backend.py index 733fe3fe736..2c105309c8e 100644 --- a/nncf/quantization/algorithms/min_max/backend.py +++ b/nncf/quantization/algorithms/min_max/backend.py @@ -31,7 +31,6 @@ TModel = TypeVar("TModel") -# pylint:disable=too-many-public-methods class MinMaxAlgoBackend(ABC): @property @abstractmethod diff --git a/nncf/quantization/algorithms/min_max/onnx_backend.py b/nncf/quantization/algorithms/min_max/onnx_backend.py index a549418b05c..16c033c81c1 100644 --- a/nncf/quantization/algorithms/min_max/onnx_backend.py +++ b/nncf/quantization/algorithms/min_max/onnx_backend.py @@ -43,7 +43,7 @@ from nncf.quantization.range_estimator import RangeEstimatorParameters -# pylint:disable=too-many-public-methods +@ALGO_BACKENDS.register(BackendType.ONNX) class ONNXMinMaxAlgoBackend(MinMaxAlgoBackend): @property def mat_mul_metatypes(self) -> List[OperatorMetatype]: diff --git a/nncf/quantization/algorithms/min_max/openvino_backend.py b/nncf/quantization/algorithms/min_max/openvino_backend.py index c2010910f56..9c8b833c69c 100644 --- a/nncf/quantization/algorithms/min_max/openvino_backend.py +++ b/nncf/quantization/algorithms/min_max/openvino_backend.py @@ -43,7 +43,7 @@ from nncf.quantization.fake_quantize import FakeQuantizeParameters -# pylint:disable=too-many-public-methods +@ALGO_BACKENDS.register(BackendType.OPENVINO) class OVMinMaxAlgoBackend(MinMaxAlgoBackend): @property def mat_mul_metatypes(self) -> List[OperatorMetatype]: diff --git a/nncf/quantization/algorithms/min_max/torch_backend.py b/nncf/quantization/algorithms/min_max/torch_backend.py index cecbb79862b..f0fb7415124 100644 --- a/nncf/quantization/algorithms/min_max/torch_backend.py +++ b/nncf/quantization/algorithms/min_max/torch_backend.py @@ -47,7 +47,7 @@ from nncf.torch.tensor_statistics.statistics import PTMinMaxTensorStatistic -# pylint:disable=too-many-public-methods +@ALGO_BACKENDS.register(BackendType.TORCH) class PTMinMaxAlgoBackend(MinMaxAlgoBackend): TARGET_TYPE_TO_PT_INS_TYPE_MAP = { TargetType.PRE_LAYER_OPERATION: TargetType.OPERATOR_PRE_HOOK, diff --git a/nncf/telemetry/wrapper.py b/nncf/telemetry/wrapper.py index e6a4040a677..fe3421cad0a 100644 --- a/nncf/telemetry/wrapper.py +++ b/nncf/telemetry/wrapper.py @@ -81,7 +81,7 @@ def skip_if_raised(func: Callable[..., None]) -> Callable[..., None]: def wrapped(*args, **kwargs): try: func(*args, **kwargs) - # pylint:disable=broad-except + except Exception as e: nncf_logger.debug(f"Skipped calling {func} - internally triggered exception {e}") @@ -100,7 +100,7 @@ def __init__(self): backend="ga4", enable_opt_in_dialog=False, ) - # pylint:disable=broad-except + except Exception as e: nncf_logger.debug(f"Failed to instantiate telemetry object: exception {e}") diff --git a/nncf/tensorflow/__init__.py b/nncf/tensorflow/__init__.py index e98802e35a9..5c746a67aeb 100644 --- a/nncf/tensorflow/__init__.py +++ b/nncf/tensorflow/__init__.py @@ -11,7 +11,7 @@ """ Base subpackage for NNCF TensorFlow functionality. """ -# pylint:skip-file + import tensorflow from packaging import version diff --git a/nncf/tensorflow/accuracy_aware_training/keras_model_utils.py b/nncf/tensorflow/accuracy_aware_training/keras_model_utils.py index 25763c77e7a..2e485f0ef92 100644 --- a/nncf/tensorflow/accuracy_aware_training/keras_model_utils.py +++ b/nncf/tensorflow/accuracy_aware_training/keras_model_utils.py @@ -38,11 +38,9 @@ def accuracy_aware_fit( if result_dict_to_val_metric_fn is None: result_dict_to_val_metric_fn = lambda metric: metric - # pylint:disable=line-too-long with cls_instance.distribute_strategy.scope(), tf_internals.keras_engine.training_utils.RespectCompiledTrainableState( # noqa: E501 cls_instance ): - # pylint: disable=protected-access data_handler = tf_internals.keras_engine.data_adapter.DataHandler( x=train_dataset, y=None, diff --git a/nncf/tensorflow/accuracy_aware_training/runner.py b/nncf/tensorflow/accuracy_aware_training/runner.py index ac3444e058b..7e39165271e 100644 --- a/nncf/tensorflow/accuracy_aware_training/runner.py +++ b/nncf/tensorflow/accuracy_aware_training/runner.py @@ -13,7 +13,7 @@ import tensorflow as tf import tensorflow_addons as tfa -from tensorflow.keras.optimizers import schedules # pylint:disable=no-name-in-module +from tensorflow.keras.optimizers import schedules from nncf.common.accuracy_aware_training.runner import BaseAccuracyAwareTrainingRunner from nncf.common.accuracy_aware_training.runner import BaseAdaptiveCompressionLevelTrainingRunner diff --git a/nncf/tensorflow/callbacks/statistics_callback.py b/nncf/tensorflow/callbacks/statistics_callback.py index cfbbecb30a1..446e997f528 100644 --- a/nncf/tensorflow/callbacks/statistics_callback.py +++ b/nncf/tensorflow/callbacks/statistics_callback.py @@ -45,11 +45,11 @@ def __init__( if log_tensorboard: if log_dir is None: raise ValueError("log_dir must be specified if log_tensorboard is true.") - # pylint: disable=no-member + self._file_writer = tf.summary.create_file_writer(log_dir + "/compression") def _dump_to_tensorboard(self, logs: dict, step: int): - with self._file_writer.as_default(): # pylint: disable=E1129 + with self._file_writer.as_default(): for name, value in logs.items(): tf.summary.scalar(name, value, step=step) diff --git a/nncf/tensorflow/graph/converter.py b/nncf/tensorflow/graph/converter.py index 9b9a6a3607a..3708b1c83e7 100644 --- a/nncf/tensorflow/graph/converter.py +++ b/nncf/tensorflow/graph/converter.py @@ -598,7 +598,6 @@ def convert(self) -> NNCFGraph: ) node_name_vs_nncf_node_ids[node_name] = nncf_node.node_id - # pylint:disable=protected-access if layer in self._model._output_layers: output_idx = self._model._output_layers.index(layer) output_node_id_vs_model_output_idx[nncf_node.node_id] = output_idx diff --git a/nncf/tensorflow/graph/model_transformer.py b/nncf/tensorflow/graph/model_transformer.py index e0ef7647d2d..210835f4446 100644 --- a/nncf/tensorflow/graph/model_transformer.py +++ b/nncf/tensorflow/graph/model_transformer.py @@ -156,7 +156,6 @@ def _insert(self, target_point: Union[TargetPoint, TFMultiLayerPoint], insertion else: raise TypeError("Insertion transform does not support {} target point type".format(target_point.type)) - # pylint:disable=too-many-branches def _shared_insert_layers(self, target_points: List[TargetPoint], layers_to_insert: List[Callable]): functional_model = is_functional_model(self._model) if functional_model: diff --git a/nncf/tensorflow/helpers/model_creation.py b/nncf/tensorflow/helpers/model_creation.py index e8d842a1685..653142347df 100644 --- a/nncf/tensorflow/helpers/model_creation.py +++ b/nncf/tensorflow/helpers/model_creation.py @@ -86,7 +86,7 @@ def create_compressed_model( "`tensorflow_hub.KerasLayer` layer yet." ) - from nncf.experimental.tensorflow.nncf_network import NNCFNetwork # pylint: disable=cyclic-import + from nncf.experimental.tensorflow.nncf_network import NNCFNetwork input_signature = get_input_signature(config) model = NNCFNetwork(model, input_signature) diff --git a/nncf/tensorflow/pruning/tensor_processor.py b/nncf/tensorflow/pruning/tensor_processor.py index f472a5c2b11..7e00722cfdd 100644 --- a/nncf/tensorflow/pruning/tensor_processor.py +++ b/nncf/tensorflow/pruning/tensor_processor.py @@ -25,7 +25,6 @@ class TFNNCFPruningTensorProcessor(NNCFPruningBaseTensorProcessor): @classmethod def concatenate(cls, tensors: List[NNCFTensor], axis: int) -> NNCFTensor: - # pylint: disable=E1120,E1123 ret_tensor = tf.concat([t.tensor for t in tensors], axis=axis) return TFNNCFTensor(ret_tensor) @@ -51,7 +50,6 @@ def elementwise_mask_propagation(cls, input_masks: List[NNCFTensor]) -> NNCFTens @classmethod def split(cls, tensor: NNCFTensor, output_shapes: List[int]) -> List[NNCFTensor]: - # pylint: disable=E1120 chunks = len(output_shapes) ret_tensors = tf.split(tensor.tensor, chunks) return [TFNNCFTensor(ret_tensor) for ret_tensor in ret_tensors] diff --git a/nncf/tensorflow/quantization/quantize_model.py b/nncf/tensorflow/quantization/quantize_model.py index 4d726d88651..a9f605bce4f 100644 --- a/nncf/tensorflow/quantization/quantize_model.py +++ b/nncf/tensorflow/quantization/quantize_model.py @@ -53,7 +53,7 @@ def batch_size(self) -> int: if isinstance(batch_size, tf.Tensor): batch_size = batch_size.numpy() batch_size = int(batch_size) - except: # pylint: disable=W0702 # noqa: E722 + except: # noqa: E722 batch_size = 1 return batch_size diff --git a/nncf/tensorflow/tensor_statistics/collectors.py b/nncf/tensorflow/tensor_statistics/collectors.py index a8c3da70a8b..feb78047b4b 100644 --- a/nncf/tensorflow/tensor_statistics/collectors.py +++ b/nncf/tensorflow/tensor_statistics/collectors.py @@ -92,7 +92,7 @@ def stack(x: Union[List[tf.Tensor], Deque[tf.Tensor]], axis: int = 0) -> NNCFTen @staticmethod def unstack(x: NNCFTensor, axis: int = 0) -> List[NNCFTensor]: tensor = x.tensor - if list(tensor.shape) == []: # pylint: disable=C1803 + if list(tensor.shape) == []: tensor = tf.expand_dims(tensor, 0) tensor_list = tf.unstack(tensor, axis=axis) return [TFNNCFTensor(t) for t in tensor_list] diff --git a/nncf/tensorflow/tf_internals.py b/nncf/tensorflow/tf_internals.py index 94b6ca13534..b326556af6b 100644 --- a/nncf/tensorflow/tf_internals.py +++ b/nncf/tensorflow/tf_internals.py @@ -9,9 +9,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import -# pylint: disable=import-error -# pylint: disable=no-name-in-module from keras import backend as backend from keras import layers as layers diff --git a/nncf/tensorflow/utils/state.py b/nncf/tensorflow/utils/state.py index bd0413171ca..9c439ca69e6 100644 --- a/nncf/tensorflow/utils/state.py +++ b/nncf/tensorflow/utils/state.py @@ -16,9 +16,9 @@ from nncf.common.compression import BaseCompressionAlgorithmController - # TODO(achurkin): remove pylint ignore after 120296 ticked is fixed -# pylint: disable=abstract-method + + class TFCompressionState(tf.train.experimental.PythonState): """ A wrapper for `BaseCompressionAlgorithmController` that allows saving diff --git a/nncf/torch/__init__.py b/nncf/torch/__init__.py index f62e8e33fe8..8910cdc95a5 100644 --- a/nncf/torch/__init__.py +++ b/nncf/torch/__init__.py @@ -9,7 +9,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # isort: off -# pylint: skip-file + """ Base subpackage for NNCF PyTorch functionality. """ diff --git a/nncf/torch/algo_selector.py b/nncf/torch/algo_selector.py index 3f5dab59e64..dc513843bd6 100644 --- a/nncf/torch/algo_selector.py +++ b/nncf/torch/algo_selector.py @@ -56,7 +56,6 @@ def _handle_frozen_layers(self, target_model: NNCFNetwork): pass -# pylint:disable=abstract-method class NoCompressionAlgorithmController(PTCompressionAlgorithmController): def __init__(self, target_model): super().__init__(target_model) diff --git a/nncf/torch/automl/environment/quantization_env.py b/nncf/torch/automl/environment/quantization_env.py index 59de15e524a..017378d7a23 100644 --- a/nncf/torch/automl/environment/quantization_env.py +++ b/nncf/torch/automl/environment/quantization_env.py @@ -126,7 +126,6 @@ def __init__( class QuantizationEnv: - # pylint:disable=too-many-branches,too-many-statements def __init__( self, model: NNCFNetwork, diff --git a/nncf/torch/binarization/algo.py b/nncf/torch/binarization/algo.py index 998c4d6ecf1..6db1e61bdc3 100644 --- a/nncf/torch/binarization/algo.py +++ b/nncf/torch/binarization/algo.py @@ -119,7 +119,7 @@ def __init__(self, target_model: NNCFNetwork, config: NNCFConfig): scheduler_cls = QUANTIZATION_SCHEDULERS.get("staged") algo_config = extract_algo_specific_config(config, "binarization") self._scheduler = scheduler_cls(self, algo_config.get("params", {})) - from nncf.torch.utils import is_main_process # pylint: disable=cyclic-import + from nncf.torch.utils import is_main_process if is_main_process(): self._compute_and_display_flops_binarization_rate() diff --git a/nncf/torch/binarization/binarize_functions.py b/nncf/torch/binarization/binarize_functions.py index 2225ffee78e..664ed94bd27 100644 --- a/nncf/torch/binarization/binarize_functions.py +++ b/nncf/torch/binarization/binarize_functions.py @@ -12,7 +12,7 @@ from typing import Any import torch -from torch.onnx.symbolic_helper import _is_constant # pylint:disable=protected-access +from torch.onnx.symbolic_helper import _is_constant from nncf.common.logging import nncf_logger from nncf.torch.binarization.extensions import BinarizedFunctionsCUDA @@ -36,7 +36,6 @@ def _unsqueeze_helper(g, input_, axes_i): return g.op("Unsqueeze", input_, axes_i=axes_i[0]) -# pylint:disable=abstract-method class XNORBinarizeFn(torch.autograd.Function): """Binarizes x into `scale` * { +1; -1}, where +1 or -1 are chosen based on whether the x element value is >0 or <0. `scale` is determined as mean of absolute @@ -68,7 +67,6 @@ def backward(ctx: Any, *grad_outputs: Any) -> Any: return grad_outputs[0] -# pylint:disable=abstract-method class DOREFABinarizeFn(torch.autograd.Function): """Binarizes x into `scale` * { +1; -1}, where +1 or -1 are chosen based on whether the x element value is >0 or <0. `scale` is determined as mean of absolute @@ -101,7 +99,8 @@ def backward(ctx: Any, *grad_outputs: Any) -> Any: # Activation binarization function -# pylint:disable=abstract-method + + class ActivationBinarizationScaleThresholdFn(torch.autograd.Function): @staticmethod def symbolic(g, x, scale, threshold): diff --git a/nncf/torch/binarization/extensions.py b/nncf/torch/binarization/extensions.py index be71fd99ec3..6e518429968 100644 --- a/nncf/torch/binarization/extensions.py +++ b/nncf/torch/binarization/extensions.py @@ -63,7 +63,7 @@ def load(cls): ) except ExtensionLoaderTimeoutException as e: raise e - except Exception as e: # pylint:disable=broad-except + except Exception as e: nncf_logger.warning( f"Could not compile CPU binarization extensions. " f"Falling back on torch native operations - " diff --git a/nncf/torch/checkpoint_loading.py b/nncf/torch/checkpoint_loading.py index 7931b200094..62e95c1bbd4 100644 --- a/nncf/torch/checkpoint_loading.py +++ b/nncf/torch/checkpoint_loading.py @@ -45,7 +45,7 @@ def load_state( model_state_dict = model.state_dict() - from nncf.torch.utils import maybe_convert_legacy_names_in_model_state # pylint: disable=cyclic-import + from nncf.torch.utils import maybe_convert_legacy_names_in_model_state maybe_convert_legacy_names_in_model_state(state_dict_to_load) key_matcher = KeyMatcher(is_resume, state_dict_to_load, model_state_dict, keys_to_ignore) diff --git a/nncf/torch/dynamic_graph/context.py b/nncf/torch/dynamic_graph/context.py index 9d9e1a645c3..d57e042af1e 100644 --- a/nncf/torch/dynamic_graph/context.py +++ b/nncf/torch/dynamic_graph/context.py @@ -86,7 +86,6 @@ def __deepcopy__(self, memo): return CopySafeThreadingVars() -# pylint: disable=too-many-public-methods class TracingContext: def __init__(self): self.graph = DynamicGraph() @@ -473,7 +472,7 @@ def disable_tracing(method): :param method: A method to patch. """ - def no_nncf_trace_wrapper(self, fn, *args, **kwargs): # pylint: disable=unused-argument + def no_nncf_trace_wrapper(self, fn, *args, **kwargs): with no_nncf_trace(): return fn(*args, **kwargs) diff --git a/nncf/torch/dynamic_graph/graph.py b/nncf/torch/dynamic_graph/graph.py index bdfdf647820..5aef6f4b6c1 100644 --- a/nncf/torch/dynamic_graph/graph.py +++ b/nncf/torch/dynamic_graph/graph.py @@ -524,7 +524,7 @@ def __init__(self, node_id_to_key_dict, nx_graph): # TODO: optimize by matching exact module type @staticmethod def _within_iteration(scope: Scope): - from nncf.torch.layers import ITERATION_MODULES # pylint: disable=cyclic-import + from nncf.torch.layers import ITERATION_MODULES for scope_element in scope.scope_elements: if scope_element.calling_module_class_name in ITERATION_MODULES.registry_dict: @@ -645,8 +645,8 @@ def add_node( op_address, tensor_metas, input_comparators_per_scope, inputs, node_parameters ) - from nncf.common.graph.definitions import MODEL_INPUT_OP_NAME # pylint: disable=cyclic-import - from nncf.common.graph.definitions import MODEL_OUTPUT_OP_NAME # pylint: disable=cyclic-import + from nncf.common.graph.definitions import MODEL_INPUT_OP_NAME + from nncf.common.graph.definitions import MODEL_OUTPUT_OP_NAME if node.op_exec_context.operator_name == MODEL_INPUT_OP_NAME: self._input_nncf_nodes.append(node) diff --git a/nncf/torch/dynamic_graph/graph_tracer.py b/nncf/torch/dynamic_graph/graph_tracer.py index 3da1bf41f3d..aa93f34788a 100644 --- a/nncf/torch/dynamic_graph/graph_tracer.py +++ b/nncf/torch/dynamic_graph/graph_tracer.py @@ -102,7 +102,7 @@ def trace_graph( context_to_use = TracingContext() context_to_use.enable_trace_dynamic_graph() - from nncf.torch.utils import training_mode_switcher # pylint: disable=cyclic-import + from nncf.torch.utils import training_mode_switcher with context_to_use as _ctx: _ctx.base_module_thread_local_replica = model @@ -126,13 +126,9 @@ def create_dummy_forward_fn( with_output_tracing=False, ): def default_dummy_forward_fn(model): - from nncf.torch.dynamic_graph.io_handling import replicate_same_tensors # pylint: disable=cyclic-import - from nncf.torch.dynamic_graph.io_handling import ( - wrap_nncf_model_inputs_with_objwalk, # pylint: disable=cyclic-import - ) - from nncf.torch.dynamic_graph.io_handling import ( - wrap_nncf_model_outputs_with_objwalk, # pylint: disable=cyclic-import - ) + from nncf.torch.dynamic_graph.io_handling import replicate_same_tensors + from nncf.torch.dynamic_graph.io_handling import wrap_nncf_model_inputs_with_objwalk + from nncf.torch.dynamic_graph.io_handling import wrap_nncf_model_outputs_with_objwalk device = get_model_device(model) args_list = [create_mock_tensor(info, device) for info in input_infos if info.keyword is None] diff --git a/nncf/torch/dynamic_graph/op_input_processing.py b/nncf/torch/dynamic_graph/op_input_processing.py index 135002368e1..f4b7a96a067 100644 --- a/nncf/torch/dynamic_graph/op_input_processing.py +++ b/nncf/torch/dynamic_graph/op_input_processing.py @@ -30,7 +30,6 @@ def __init__(self, op_args, op_kwargs): op_args_index_entries = NestedObjectIndex(self.op_args, previous_level_setter=partial(setattr, self, "op_args")) op_kwargs_index_entries = NestedObjectIndex(self.op_kwargs) - # pylint:disable=unnecessary-comprehension self._index = { idx: entry for idx, entry in enumerate( diff --git a/nncf/torch/dynamic_graph/patch_pytorch.py b/nncf/torch/dynamic_graph/patch_pytorch.py index f17901a6989..cf4e24ff9a0 100644 --- a/nncf/torch/dynamic_graph/patch_pytorch.py +++ b/nncf/torch/dynamic_graph/patch_pytorch.py @@ -42,7 +42,6 @@ def get_namespace_to_patch(namespace_target: NamespaceTarget) -> object: def get_namespace_to_extract_functions_from(namespace_target: NamespaceTarget) -> object: - # pylint: disable=protected-access if namespace_target == NamespaceTarget.TORCH_NN_FUNCTIONAL: return torch.nn.functional if namespace_target == NamespaceTarget.TORCH_TENSOR: @@ -50,7 +49,6 @@ def get_namespace_to_extract_functions_from(namespace_target: NamespaceTarget) - if namespace_target == NamespaceTarget.TORCH: return torch._C._VariableFunctions raise RuntimeError("{} namespace wasn't found in {}".format(namespace_target, NamespaceTarget)) - # pylint: enable=protected-access class FunctionsToPatchWithoutTracing: @@ -194,7 +192,7 @@ def torch_jit_script_wrapper(*args, **kwargs): def rcb_wrapper(name): value = rcb(name) if hasattr(value, "_original_op"): - value = value._original_op # pylint: disable=protected-access + value = value._original_op return value kwargs["_rcb"] = rcb_wrapper @@ -211,7 +209,6 @@ def torch_jit_trace_make_module_wrapper(*args, **kwargs): def torch_jit_script_if_tracing(fn): - # pylint: disable=protected-access @functools.wraps(fn) def wrapper(*args, **kwargs): if not is_tracing(): @@ -244,7 +241,7 @@ def __init__(self, name: str, namespace, op): def patch_torch_jit(): # This import statement is required, otherwise we get a # "RuntimeError: undefined value torch" inside the real torch.jit.script - # pylint:disable=unused-import,redefined-outer-name,reimported,protected-access + import torch global _ORIG_JIT_SCRIPT diff --git a/nncf/torch/dynamic_graph/scope.py b/nncf/torch/dynamic_graph/scope.py index fa9770ad7ac..abc5c3da040 100644 --- a/nncf/torch/dynamic_graph/scope.py +++ b/nncf/torch/dynamic_graph/scope.py @@ -97,7 +97,7 @@ def from_str(string: str) -> "Scope": def get_iteration_scopes(self) -> List[str]: results = [] - from nncf.torch.layers import ITERATION_MODULES # pylint: disable=cyclic-import + from nncf.torch.layers import ITERATION_MODULES for scope_element in self.scope_elements: if scope_element.calling_module_class_name in ITERATION_MODULES.registry_dict: diff --git a/nncf/torch/dynamic_graph/scope_access.py b/nncf/torch/dynamic_graph/scope_access.py index 9837e1b9444..f84d9e6b0fb 100644 --- a/nncf/torch/dynamic_graph/scope_access.py +++ b/nncf/torch/dynamic_graph/scope_access.py @@ -23,7 +23,7 @@ def get_module_by_scope(model: torch.nn.Module, scope: Scope) -> Optional[torch. # The module used is being created in-place every time and never stored in the model, # happens for nn.Softmax in BERT implementations. return None - # pylint: disable=protected-access + next_module = curr_module._modules.get(scope_element.calling_field_name) if next_module is None: raise RuntimeError( diff --git a/nncf/torch/dynamic_graph/trace_tensor.py b/nncf/torch/dynamic_graph/trace_tensor.py index a776185aa44..18b9c750168 100644 --- a/nncf/torch/dynamic_graph/trace_tensor.py +++ b/nncf/torch/dynamic_graph/trace_tensor.py @@ -60,7 +60,7 @@ class TracedTensor(torch.Tensor): def from_torch_tensor(tensor, tensor_meta: TensorMeta): tensor.tensor_meta = tensor_meta tensor.__class__ = TracedTensor - # pylint:disable=protected-access + tensor._nncf_expired = False return tensor @@ -85,14 +85,14 @@ def as_subclass(self, cls: "TracedTensor") -> "TracedTensor": # NOTE: This disables the __torch_function__ API altogether when using NNCF. # TODO: make NNCF utilize the __torch_function__ API instead. - # pylint:disable=protected-access + if hasattr(torch._C, "_disabled_torch_function_impl"): __torch_function__ = torch._C._disabled_torch_function_impl def is_iterable(item): non_iterable_types = (str, bytes, bytearray, torch.Tensor, np.ndarray) - # pylint:disable=isinstance-second-argument-not-valid-type + return isinstance(item, Iterable) and not isinstance(item, non_iterable_types) diff --git a/nncf/torch/dynamic_graph/wrappers.py b/nncf/torch/dynamic_graph/wrappers.py index 33a1122020c..ee0a74355bb 100644 --- a/nncf/torch/dynamic_graph/wrappers.py +++ b/nncf/torch/dynamic_graph/wrappers.py @@ -81,7 +81,7 @@ def wrapped(*args, **kwargs): if operator_info.skip_trace: result = operator(*args, **kwargs) elif ctx.is_forwarding: - from nncf.torch.dynamic_graph.trace_functions import forward_trace_only # pylint: disable=cyclic-import + from nncf.torch.dynamic_graph.trace_functions import forward_trace_only result = forward_trace_only(operator, *args, **kwargs) else: @@ -112,14 +112,13 @@ def wrapped(*args, **kwargs): ctx.in_operator = False return result - # pylint: disable=protected-access wrapped._original_op = operator wrapped._operator_namespace = operator_info.operator_namespace return wrapped def wrap_module_call(module_call): - from nncf.torch.dynamic_graph.patch_pytorch import ORIGINAL_OPERATORS # pylint: disable=cyclic-import + from nncf.torch.dynamic_graph.patch_pytorch import ORIGINAL_OPERATORS NAMES_ORIGINAL_OPERATORS = [op.name for op in ORIGINAL_OPERATORS] @@ -199,7 +198,7 @@ def _collect_module_attrs_and_ignored_algorithms( ) -> Tuple[BaseLayerAttributes, List[str]]: layer_attrs = None ignored_algos = [] - from nncf.torch.graph.operator_metatypes import OP_NAMES_WITH_WEIGHTS # pylint:disable=cyclic-import + from nncf.torch.graph.operator_metatypes import OP_NAMES_WITH_WEIGHTS if op_name in OP_NAMES_WITH_WEIGHTS: curr_module = ctx.get_current_module() diff --git a/nncf/torch/exporter.py b/nncf/torch/exporter.py index 624457aed70..8f4d531d8f1 100644 --- a/nncf/torch/exporter.py +++ b/nncf/torch/exporter.py @@ -143,7 +143,7 @@ def _export_to_onnx(self, save_path: str, opset_version: int) -> None: input_names = self._input_names else: input_names = generate_input_names_list(len(input_tensor_list)) - # pylint:disable=unexpected-keyword-arg + with torch.no_grad(): # Should call this, otherwise the operations executed during export will end up in the graph. model.nncf.disable_dynamic_graph_building() diff --git a/nncf/torch/extensions/__init__.py b/nncf/torch/extensions/__init__.py index e4eab098dfc..c0549f5cf8b 100644 --- a/nncf/torch/extensions/__init__.py +++ b/nncf/torch/extensions/__init__.py @@ -101,7 +101,6 @@ def get(self, fn_name: str) -> Callable: async_result = pool.apply_async(self._loader.load) self._loaded_namespace = async_result.get(timeout=timeout) except MPTimeoutError as error: - # pylint: disable=line-too-long msg = textwrap.dedent( f"""\ The extension load function failed to execute within {timeout} seconds. diff --git a/nncf/torch/functions.py b/nncf/torch/functions.py index 13ee1438325..035e3966e96 100644 --- a/nncf/torch/functions.py +++ b/nncf/torch/functions.py @@ -21,7 +21,6 @@ def logit(x): return torch.log(x / (1 - x)) -# pylint:disable=abstract-method class STRound(torch.autograd.Function): @staticmethod def symbolic(g, input_, inplace=False): @@ -37,7 +36,6 @@ def backward(ctx: Any, *grad_outputs: Any) -> Any: return grad_outputs[0] -# pylint:disable=abstract-method class STThreshold(torch.autograd.Function): @staticmethod def forward(ctx, input_, threshold: float = 0.5): diff --git a/nncf/torch/graph/graph_builder.py b/nncf/torch/graph/graph_builder.py index 993bc6a21f4..14bb2326cbe 100644 --- a/nncf/torch/graph/graph_builder.py +++ b/nncf/torch/graph/graph_builder.py @@ -43,7 +43,6 @@ def build_graph( class GraphConverter: @staticmethod def convert(dynamic_graph: DynamicGraph, input_infos: List[ModelInputInfo] = None) -> PTNNCFGraph: - # pylint:disable=too-many-branches module_id_vs_known_op_addrs_map: Dict[int, Set[Scope]] = defaultdict(set) for dynamic_graph_node in dynamic_graph.get_all_nodes(): module_id_vs_known_op_addrs_map[dynamic_graph_node.calling_module_id].add( diff --git a/nncf/torch/graph/operator_metatypes.py b/nncf/torch/graph/operator_metatypes.py index 484685667bf..a05b8b7d85d 100644 --- a/nncf/torch/graph/operator_metatypes.py +++ b/nncf/torch/graph/operator_metatypes.py @@ -29,7 +29,6 @@ PT_OPERATOR_METATYPES = OperatorMetatypeRegistry("operator_metatypes") -# pylint: disable=too-many-lines class PTOperatorMetatype(OperatorMetatype): """ Base class for grouping PyTorch operators based on their semantic meaning. diff --git a/nncf/torch/graph/pattern_operations.py b/nncf/torch/graph/pattern_operations.py index 68611050081..7e0eb1d61b9 100644 --- a/nncf/torch/graph/pattern_operations.py +++ b/nncf/torch/graph/pattern_operations.py @@ -72,7 +72,7 @@ } # This type may be useful in the future -# pylint: disable=unused-variable + POOLING_OPERATIONS = { GraphPattern.METATYPE_ATTR: ["adaptive_avg_pool2d", "adaptive_avg_pool3d", "avg_pool2d", "avg_pool3d"], GraphPattern.LABEL_ATTR: "POOLING", diff --git a/nncf/torch/layers.py b/nncf/torch/layers.py index 134845ad128..c4e671bcb8b 100644 --- a/nncf/torch/layers.py +++ b/nncf/torch/layers.py @@ -38,7 +38,6 @@ def dict_update(src: Dict, dst: Dict, recursive: bool = True): def maybe_reapply_weight_norm(src: torch.nn.Module, dst: torch.nn.Module) -> torch.nn.Module: - # pylint:disable=protected-access for k, hook in src._forward_pre_hooks.items(): if isinstance(hook, WeightNorm): # The code below presumes that the `hook` object does not @@ -676,7 +675,6 @@ def forward(self, input_, hidden, batch_sizes): if flat_hidden: hidden = (hidden,) with forward_nncf_trace(): - # pylint:disable=unnecessary-comprehension batch_size_elements = [b for b in batch_sizes] for batch_size in batch_size_elements: step_input = input_[input_offset : input_offset + batch_size] diff --git a/nncf/torch/model_creation.py b/nncf/torch/model_creation.py index 45652a702a6..d6a28e8f938 100644 --- a/nncf/torch/model_creation.py +++ b/nncf/torch/model_creation.py @@ -33,8 +33,6 @@ from nncf.torch.compression_method_api import PTCompressionAlgorithmBuilder from nncf.torch.dynamic_graph.graph_tracer import create_input_infos from nncf.torch.nncf_network import NNCFNetwork - -# pylint:disable=too-many-branches from nncf.torch.utils import is_dist_avail_and_initialized from nncf.torch.utils import is_main_process from nncf.torch.utils import maybe_convert_legacy_names_in_compress_state @@ -143,7 +141,7 @@ def create_compressed_model( try: if is_legacy_model_state_dict: - from nncf.torch import load_state # pylint: disable=cyclic-import + from nncf.torch import load_state state_dict_to_load = compression_state.get("state_dict", compression_state) load_state(compressed_model, state_dict_to_load, is_resume=True) diff --git a/nncf/torch/nested_objects_traversal.py b/nncf/torch/nested_objects_traversal.py index 5736fab0b04..8fa02139405 100644 --- a/nncf/torch/nested_objects_traversal.py +++ b/nncf/torch/nested_objects_traversal.py @@ -33,10 +33,10 @@ def is_named_tuple(obj) -> bool: def maybe_get_iterator(obj): it = None - # pylint:disable=isinstance-second-argument-not-valid-type + if isinstance(obj, Mapping): it = iteritems - # pylint:disable=isinstance-second-argument-not-valid-type + elif isinstance(obj, (Sequence, Set)) and not isinstance(obj, string_types): it = enumerate return it @@ -120,8 +120,7 @@ def objwalk(obj, unary_predicate: Callable[[Any], bool], apply_fn: Callable, mem Walks through the indexable container hierarchy of obj and replaces all sub-objects matching a criterion with the result of a given function application. """ - # pylint:disable=too-many-nested-blocks - # pylint:disable=too-many-branches + if memo is None: memo = set() @@ -129,7 +128,7 @@ def objwalk(obj, unary_predicate: Callable[[Any], bool], apply_fn: Callable, mem named_tuple_fields = None if is_named_tuple(obj): named_tuple_class = obj.__class__ - # pylint:disable=protected-access + named_tuple_fields = obj._fields was_tuple = is_tuple(obj) diff --git a/nncf/torch/nncf_module_replacement.py b/nncf/torch/nncf_module_replacement.py index 281ea83255a..fdaaaf0d8bd 100644 --- a/nncf/torch/nncf_module_replacement.py +++ b/nncf/torch/nncf_module_replacement.py @@ -246,7 +246,6 @@ def _replace_module_by_scope(base_model: torch.nn.Module, scope: Scope, replaced curr_module = base_model owning_module = base_model for scope_element in scope[1:]: # omit first scope element which corresponds to base module - # pylint: disable=protected-access child_module = curr_module._modules.get(scope_element.calling_field_name) if child_module is None: raise RuntimeError( @@ -265,7 +264,6 @@ def _replace_module_by_scope(base_model: torch.nn.Module, scope: Scope, replaced nncf_logger.debug(f"Extending module at {str(scope)}...") last_calling_field_name = scope[-1].calling_field_name if isinstance(owning_module, nn.Sequential): - # pylint:disable=protected-access owning_module._modules[last_calling_field_name] = replaced_module else: setattr(owning_module, last_calling_field_name, replaced_module) diff --git a/nncf/torch/nncf_network.py b/nncf/torch/nncf_network.py index 9d0d5bdcf8c..191dff642ee 100644 --- a/nncf/torch/nncf_network.py +++ b/nncf/torch/nncf_network.py @@ -8,7 +8,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=too-many-lines + import functools import inspect import types @@ -128,7 +128,6 @@ class NNCFNetworkInterface(torch.nn.Module): when saving/loading checkpoints """ - # pylint:disable=too-many-public-methods MODEL_STATE_VERSION_ATTR = "_nncf_model_state_version" MODEL_STATE_VERSION = 1 @@ -360,8 +359,8 @@ def reset_nncf_modules(self): def get_clean_shallow_copy(self) -> "NNCFNetwork": # WARNING: Will reset pre- and post-ops of the underlying model. Use save_nncf_module_additions # and load_nncf_module_additions to preserve these, or temporary_clean_view(). - from nncf.torch.utils import load_module_state # pylint: disable=cyclic-import - from nncf.torch.utils import save_module_state # pylint: disable=cyclic-import + from nncf.torch.utils import load_module_state + from nncf.torch.utils import save_module_state saved_state = save_module_state(self._model_ref) new_interface = NNCFNetworkInterface( @@ -374,7 +373,7 @@ def get_clean_shallow_copy(self) -> "NNCFNetwork": self._target_scopes, wrap_outputs_fn=self._wrap_outputs_fn, ) - self._model_ref._nncf = new_interface # pylint:disable=protected-access + self._model_ref._nncf = new_interface self._model_ref.nncf.reset_nncf_modules() load_module_state(self._model_ref, saved_state) return self._model_ref @@ -562,7 +561,7 @@ def sort_compression_modules(self, compression_module_type: ExtraCompressionModu if compression_module_type not in self._extra_module_types: raise RuntimeError("Module type {} was not registered".format(compression_module_type)) module_dict = self.__getattr__(attr_name) - # pylint: disable=protected-access + module_dict._modules = OrderedDict(sorted(module_dict._modules.items())) self.__setattr__(attr_name, module_dict) @@ -817,7 +816,7 @@ def __call__( ignored_scopes, target_scopes, wrap_outputs_fn, - ) # pylint:disable=protected-access + ) # The new class will also have an adjusted metaclass to avoid a "metaclass conflict" upon # class creation original_metaclass = type(original_model.__class__) @@ -853,7 +852,7 @@ def __call__( # its forward method, which it effectively doesn't have. Employing a special iterator allows to hide the # NNCFInterface object during iteration. def nncf_safe_iter(self: torch.nn.Sequential): - return NNCFSkippingIter(iter(self._modules.values())) # pylint:disable=protected-access + return NNCFSkippingIter(iter(self._modules.values())) original_model.__class__.__iter__ = nncf_safe_iter return original_model @@ -925,7 +924,7 @@ def forward(self, *args, **kwargs): Wraps the original forward call, doing additional actions before and after the call to facilitate model graph tracing and calling compression-related hooks. """ - # pylint:disable=protected-access + with self.nncf._compressed_context as ctx: ctx.base_module_thread_local_replica = self args, kwargs = replicate_same_tensors((args, kwargs)) @@ -1012,7 +1011,6 @@ class LoadStateListener: """ def __init__(self, model: "NNCFNetwork", all_quantizations: Dict[str, torch.nn.Module]): - # pylint: disable=protected-access self.hook = model._register_load_state_dict_pre_hook( functools.partial(self.hook_fn, quantize_modules=list(all_quantizations.values())) ) diff --git a/nncf/torch/pruning/base_algo.py b/nncf/torch/pruning/base_algo.py index 79c7fbe9924..7bf6cffaedb 100644 --- a/nncf/torch/pruning/base_algo.py +++ b/nncf/torch/pruning/base_algo.py @@ -54,7 +54,7 @@ def __init__(self, config, should_init: bool = True): self._prunable_types = self.get_op_types_of_pruned_modules() - from nncf.common.pruning.node_selector import PruningNodeSelector # pylint: disable=cyclic-import + from nncf.common.pruning.node_selector import PruningNodeSelector self.pruning_node_selector = PruningNodeSelector( PT_PRUNING_OPERATOR_METATYPES, diff --git a/nncf/torch/pruning/filter_pruning/algo.py b/nncf/torch/pruning/filter_pruning/algo.py index b59aad5817c..316310e481c 100644 --- a/nncf/torch/pruning/filter_pruning/algo.py +++ b/nncf/torch/pruning/filter_pruning/algo.py @@ -128,7 +128,6 @@ def __init__( pruned_norms_operators: List[Tuple[NNCFNode, FilterPruningMask, torch.nn.Module]], config: NNCFConfig, ): - # pylint:disable=too-many-statements super().__init__(target_model, prunable_types, pruned_module_groups, config) params = self.pruning_config.get("params", {}) self._pruned_norms_operators = pruned_norms_operators diff --git a/nncf/torch/quantization/adjust_padding.py b/nncf/torch/quantization/adjust_padding.py index 2a114f235bf..9af55732655 100644 --- a/nncf/torch/quantization/adjust_padding.py +++ b/nncf/torch/quantization/adjust_padding.py @@ -66,8 +66,6 @@ def is_config_applicable(qconfig: QuantizerConfig): def add_adjust_padding_nodes(bitwidth_graph: nx.DiGraph, model: NNCFNetwork) -> nx.DiGraph(): - # pylint:disable=protected-access - NewNodeArgs = namedtuple("NewNodeArgs", ("node_key", "attr", "parent_node_key")) nncf_graph = model.nncf.get_graph() args = [] diff --git a/nncf/torch/quantization/algo.py b/nncf/torch/quantization/algo.py index f0aad112574..8f99260679d 100644 --- a/nncf/torch/quantization/algo.py +++ b/nncf/torch/quantization/algo.py @@ -8,7 +8,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# pylint:disable=too-many-lines + """ Contains builder and controller class definitions for the quantization algorithm. """ @@ -347,9 +347,7 @@ def generate_setup(self) -> SingleConfigQuantizerSetup: insertion_point_graph = self._target_model.nncf.get_insertion_point_graph() if self._debug_interface: self._debug_interface.visualize_insertion_point_graph(insertion_point_graph) - from nncf.common.quantization.quantizer_propagation.solver import ( - QuantizerPropagationSolver, # pylint: disable=cyclic-import - ) + from nncf.common.quantization.quantizer_propagation.solver import QuantizerPropagationSolver scales_unification_map = {PTCatMetatype: UNIFICATION_PRODUCING_METATYPES} ignored_scopes_for_solver = { @@ -648,7 +646,7 @@ def _get_transformation_layout(self, target_model: NNCFNetwork) -> PTTransformat # NOTE: Order of activations must be the same to correctly broadcast parameters (e.g. scales) in distributed # mode (see call of `_dist_broadcast_coalesced` in torch/nn/parallel/distributed.py for more details) - # pylint: disable=protected-access + target_model.nncf.sort_compression_modules(ExtraCompressionModuleType.EXTERNAL_QUANTIZER) if self._debug_interface is not None: @@ -707,7 +705,6 @@ def _get_single_config_quantizer_setup(self, target_model) -> SingleConfigQuanti self._build_time_metric_infos = setup_generator.get_build_time_metric_infos() return single_config_quantizer_setup - # pylint: disable=too-many-branches def _get_quantizer_setup(self, target_model: NNCFNetwork) -> PTQuantizerSetup: if self._legacy_single_config_quantizer_setup_from_comp_state is None: single_config_quantizer_setup = self._get_single_config_quantizer_setup(target_model) @@ -1136,8 +1133,6 @@ def _quantize_at_points_by_single_module( insertion commands registering this module for quantization at spots described by insertion_points. """ - # pylint:disable=too-many-branches - # pylint:disable=too-many-statements target_model_graph = target_model.nncf.get_original_graph() if not insertion_points: diff --git a/nncf/torch/quantization/debug_interface.py b/nncf/torch/quantization/debug_interface.py index 1f048be8ff5..2772546eded 100644 --- a/nncf/torch/quantization/debug_interface.py +++ b/nncf/torch/quantization/debug_interface.py @@ -46,7 +46,7 @@ def __init__(self): } self.graph_size = 0 - from nncf.common.utils.debug import DEBUG_LOG_DIR # pylint: disable=cyclic-import + from nncf.common.utils.debug import DEBUG_LOG_DIR self.dump_dir = Path(DEBUG_LOG_DIR) / Path("debug_dumps") self.dump_dir.mkdir(parents=True, exist_ok=True) @@ -78,7 +78,7 @@ def pre_forward_actions(self, module: NNCFNetwork): def post_forward_actions(self, module: NNCFNetwork): self.register_forward_call() - # pylint:disable=protected-access + ctx = module.nncf.get_tracing_context() self.set_graph_size(ctx.graph.get_nodes_count()) diff --git a/nncf/torch/quantization/extensions.py b/nncf/torch/quantization/extensions.py index 1ade5a28225..e59abde027b 100644 --- a/nncf/torch/quantization/extensions.py +++ b/nncf/torch/quantization/extensions.py @@ -63,7 +63,7 @@ def load(cls): ) except ExtensionLoaderTimeoutException as e: raise e - except Exception as e: # pylint:disable=broad-except + except Exception as e: nncf_logger.warning( f"Could not compile CPU quantization extensions. " f"Falling back on torch native operations - " diff --git a/nncf/torch/quantization/layers.py b/nncf/torch/quantization/layers.py index fafd1353918..b0f815c55de 100644 --- a/nncf/torch/quantization/layers.py +++ b/nncf/torch/quantization/layers.py @@ -9,7 +9,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint:disable=too-many-lines from abc import ABC from abc import abstractmethod @@ -281,7 +280,6 @@ def add_quantization_point(self, qp_id: QuantizationPointId, qp: PTQuantizationP class BaseQuantizer(nn.Module, ABC): - # pylint:disable=too-many-public-methods def __init__(self, qspec: PTQuantizerSpec): super().__init__() self._narrow_range = qspec.narrow_range @@ -315,7 +313,6 @@ class LoadStateListener: """ def __init__(self, module): - # pylint: disable=protected-access self.hook = module._register_load_state_dict_pre_hook(partial(self.hook_fn, module=module)) def hook_fn( diff --git a/nncf/torch/quantization/metrics.py b/nncf/torch/quantization/metrics.py index fc7d6adcc0c..ea83f45ff0b 100644 --- a/nncf/torch/quantization/metrics.py +++ b/nncf/torch/quantization/metrics.py @@ -171,7 +171,7 @@ def collect(self) -> MemoryConsumptionStatistics: memory_consumption_fp_model = {} memory_consumption_compressed_model = {} - # pylint: disable=protected-access + original_nx_graph = original_graph._nx_graph nx.set_edge_attributes(original_nx_graph, 32, "precision") @@ -191,7 +191,6 @@ def collect(self) -> MemoryConsumptionStatistics: return stats def _get_precision_for_activation_tensor(self, u_node: str, v_node: str, original_nx_graph: nx.DiGraph) -> int: - # pylint: disable=protected-access pred_u_nodes = original_nx_graph._pred[u_node] precision_enter_activation_tensor = max( [0] + [original_nx_graph.edges[pred_u_node, u_node]["precision"] for pred_u_node in pred_u_nodes] @@ -241,18 +240,16 @@ def __init__( self._target_device = target_device def collect(self) -> QuantizationConfigurationStatistics: - # pylint: disable=too-many-branches merged_original_graph = self.get_merged_original_graph_with_patterns( self._compressed_model.nncf.get_original_graph() ) self.stats.quantized_edges_in_cfg = 0 nx.set_edge_attributes(merged_original_graph, False, self.QUANTIZED_EDGES_ATTR) nx.set_edge_attributes(merged_original_graph, False, self.PASSED_EDGES_ATTR) - # pylint: disable=protected-access + input_nodes = [node for node in merged_original_graph.nodes if len(merged_original_graph._pred[node]) == 0] queue = deque() for input_node in input_nodes: - # pylint: disable=protected-access next_nodes = merged_original_graph._succ[input_node] for next_node_key in next_nodes: edge = merged_original_graph.edges[input_node, next_node_key] @@ -261,7 +258,7 @@ def collect(self) -> QuantizationConfigurationStatistics: self.stats.quantized_edges_in_cfg += 1 queue.appendleft(next_node_key) visited_nodes = {} - # pylint: disable=too-many-nested-blocks + while len(queue) != 0: node_key = queue.pop() if node_key in visited_nodes: @@ -310,7 +307,6 @@ def collect(self) -> QuantizationConfigurationStatistics: return self.stats def _all_enter_edges_in_node_of_type(self, graph, node_key, type_edge): - # pylint: disable=protected-access prev_nodes = graph._pred[node_key] retval = True for prev_node_key in prev_nodes: @@ -321,7 +317,6 @@ def _all_enter_edges_in_node_of_type(self, graph, node_key, type_edge): return retval def _marking_edges(self, graph, node_key, queue, mark=True): - # pylint: disable=protected-access next_nodes = graph._succ[node_key] for next_node_key in next_nodes: edge = graph.edges[node_key, next_node_key] @@ -333,7 +328,7 @@ def _marking_edges(self, graph, node_key, queue, mark=True): def get_merged_original_graph_with_patterns(self, original_graph: PTNNCFGraph): pattern = PatternsManager.get_full_hw_pattern_graph(backend=BackendType.TORCH, device=self._target_device) - # pylint: disable=protected-access + matches = find_subgraphs_matching_pattern(original_graph._nx_graph, pattern) merged_graph = deepcopy(original_graph._nx_graph) nx.set_node_attributes(merged_graph, False, self.IS_MERGED_GRAPH_ATTR) @@ -357,7 +352,7 @@ def get_merged_original_graph_with_patterns(self, original_graph: PTNNCFGraph): merged_nodes = [] for node_key in match: merged_node_key += node_key + "\n" - # pylint: disable=protected-access + merged_nodes.append(original_graph._nx_graph.nodes[node_key]) merged_graph.remove_node(node_key) merged_node_attrs = { diff --git a/nncf/torch/quantization/precision_init/autoq_init.py b/nncf/torch/quantization/precision_init/autoq_init.py index 4a4a176e677..a6bc3dadaed 100644 --- a/nncf/torch/quantization/precision_init/autoq_init.py +++ b/nncf/torch/quantization/precision_init/autoq_init.py @@ -119,8 +119,8 @@ def __init__( self._hw_cfg_type = params.hw_cfg_type def apply_init(self) -> SingleConfigQuantizerSetup: - from nncf.common.utils.debug import DEBUG_LOG_DIR # pylint: disable=cyclic-import - from nncf.torch.automl.environment.quantization_env import QuantizationEnv # pylint: disable=cyclic-import + from nncf.common.utils.debug import DEBUG_LOG_DIR + from nncf.torch.automl.environment.quantization_env import QuantizationEnv if self._dump_autoq_data or is_debug(): dump_dir = self._init_args.config.get("log_dir", None) @@ -153,9 +153,7 @@ def apply_init(self) -> SingleConfigQuantizerSetup: start_ts = datetime.now() - from nncf.torch.automl.environment.quantization_env import ( - QuantizationEnvParams, # pylint: disable=cyclic-import - ) + from nncf.torch.automl.environment.quantization_env import QuantizationEnvParams env_params = QuantizationEnvParams( compression_ratio=self._params.compression_ratio, @@ -217,7 +215,6 @@ def apply_init(self) -> SingleConfigQuantizerSetup: return final_quantizer_setup def _search(self, agent: DDPG, env: "QuantizationEnv") -> Tuple[pd.Series, float]: # noqa: F821 - # pylint: disable=too-many-branches,too-many-statements best_reward = -math.inf episode = 0 episode_reward = 0.0 diff --git a/nncf/torch/quantization/precision_init/bitwidth_graph.py b/nncf/torch/quantization/precision_init/bitwidth_graph.py index 0416a6fc533..cd1faf732ac 100644 --- a/nncf/torch/quantization/precision_init/bitwidth_graph.py +++ b/nncf/torch/quantization/precision_init/bitwidth_graph.py @@ -33,8 +33,6 @@ def __init__( groups_of_adjacent_quantizers: GroupsOfAdjacentQuantizers, add_flops=False, ): - # pylint:disable=too-many-branches - # pylint:disable=too-many-statements nncf_graph = model.nncf.get_graph() self._nx_graph = nncf_graph.get_graph_for_structure_analysis() if add_flops: @@ -127,7 +125,6 @@ def _paint_activation_quantizer_node( bitwidth_color_map: Dict[int, str], groups_of_adjacent_quantizers: GroupsOfAdjacentQuantizers, ): - # pylint:disable=too-many-branches affected_insertion_points_list = quantizer_info.affected_insertions for target_point in affected_insertion_points_list: diff --git a/nncf/torch/quantization/precision_init/hawq_debug.py b/nncf/torch/quantization/precision_init/hawq_debug.py index 694ea76c501..2ebef87350a 100644 --- a/nncf/torch/quantization/precision_init/hawq_debug.py +++ b/nncf/torch/quantization/precision_init/hawq_debug.py @@ -25,8 +25,6 @@ from nncf.torch.quantization.adjust_padding import add_adjust_padding_nodes from nncf.torch.quantization.layers import QUANTIZATION_MODULES from nncf.torch.quantization.precision_init.adjacent_quantizers import GroupsOfAdjacentQuantizers - -# pylint:disable=unused-import from nncf.torch.quantization.precision_init.definitions import QConfigSequenceForHAWQToEvaluate from nncf.torch.quantization.precision_init.perturbations import PerturbationObserver from nncf.torch.quantization.precision_init.perturbations import Perturbations @@ -47,7 +45,7 @@ def __init__( self._num_weights = len(traces_per_layer.traces_order) self._perturbations = perturbations - from nncf.common.utils.debug import DEBUG_LOG_DIR # pylint: disable=cyclic-import + from nncf.common.utils.debug import DEBUG_LOG_DIR self._dump_dir = Path(DEBUG_LOG_DIR) / Path("hawq_dumps") self._dump_dir.mkdir(parents=True, exist_ok=True) @@ -220,7 +218,7 @@ def dump_bitwidth_graph( model: NNCFNetwork, groups_of_adjacent_quantizers: GroupsOfAdjacentQuantizers, ): - from nncf.torch.quantization.precision_init.bitwidth_graph import BitwidthGraph # pylint: disable=cyclic-import + from nncf.torch.quantization.precision_init.bitwidth_graph import BitwidthGraph bw_graph = BitwidthGraph(algo_ctrl, model, groups_of_adjacent_quantizers).get() nx_graph = add_adjust_padding_nodes(bw_graph, model) diff --git a/nncf/torch/quantization/precision_init/hawq_init.py b/nncf/torch/quantization/precision_init/hawq_init.py index c21cdd684a8..36741f47c15 100644 --- a/nncf/torch/quantization/precision_init/hawq_init.py +++ b/nncf/torch/quantization/precision_init/hawq_init.py @@ -354,7 +354,7 @@ def apply_init(self) -> SingleConfigQuantizerSetup: groups_of_adjacent_quantizers = new_ctrl.groups_of_adjacent_quantizers hawq_debugger.dump_bitwidth_graph(new_ctrl, new_model, groups_of_adjacent_quantizers) bitwidth_per_scope = self.get_bitwidth_per_scope(final_quantizer_setup) - from nncf.common.utils.debug import DEBUG_LOG_DIR # pylint: disable=cyclic-import + from nncf.common.utils.debug import DEBUG_LOG_DIR Path(DEBUG_LOG_DIR).mkdir(parents=True, exist_ok=True) with safe_open(Path(DEBUG_LOG_DIR) / "bitwidth_per_scope.json", "w") as outfile: diff --git a/nncf/torch/quantization/quantize_functions.py b/nncf/torch/quantization/quantize_functions.py index a82721b4c59..47091e032f7 100644 --- a/nncf/torch/quantization/quantize_functions.py +++ b/nncf/torch/quantization/quantize_functions.py @@ -21,7 +21,6 @@ from nncf.torch.utils import add_domain -# pylint:disable=abstract-method class QuantizeSymmetric(torch.autograd.Function): @staticmethod def forward(ctx, input_, scale, level_low, level_high, levels): @@ -73,7 +72,6 @@ def backward(ctx: Any, *grad_outputs: Any) -> Any: return grad_input, grad_scale, None, None, None -# pylint:disable=abstract-method class QuantizeAsymmetric(torch.autograd.Function): @staticmethod def forward(ctx, input_, input_low, input_range, level_low, level_high, levels): @@ -133,7 +131,6 @@ def _quantize_autograd_to_range(input_, input_low, input_high, levels): return output -# pylint:disable=abstract-method class ExportQuantizeToFakeQuantize(torch.autograd.Function): @staticmethod def symbolic( @@ -160,7 +157,6 @@ def backward(ctx: Any, *grad_outputs: Any) -> Any: return grad_outputs[0] -# pylint:disable=abstract-method class ExportQuantizeToONNXQuantDequant(torch.autograd.Function): @staticmethod def symbolic(g, input_, y_scale, y_zero_point, axis): @@ -212,7 +208,6 @@ def asymmetric_quantize(input_, levels, level_low, level_high, input_low, input_ return QuantizeAsymmetric.apply(input_, input_low_tuned, input_range_tuned, level_low, level_high, levels) -# pylint:disable=abstract-method class TuneRange(torch.autograd.Function): """ Makes sure that the zero-point quantum in the quantized domain points exactly to floating point zero, diff --git a/nncf/torch/sparsity/rb/algo.py b/nncf/torch/sparsity/rb/algo.py index dfaa3151a26..6e0f17de14a 100644 --- a/nncf/torch/sparsity/rb/algo.py +++ b/nncf/torch/sparsity/rb/algo.py @@ -84,7 +84,6 @@ def __init__(self, target_model: NNCFNetwork, sparsified_module_info: List[Spars def set_sparsity_level(self, sparsity_level, target_sparsified_module_info: SparseModuleInfo = None): if target_sparsified_module_info is None: - # pylint:disable=no-value-for-parameter self._loss.set_target_sparsity_loss(sparsity_level) else: sparse_op = target_sparsified_module_info.operand diff --git a/nncf/torch/sparsity/rb/layers.py b/nncf/torch/sparsity/rb/layers.py index e3d17145e73..f6d32872a8a 100644 --- a/nncf/torch/sparsity/rb/layers.py +++ b/nncf/torch/sparsity/rb/layers.py @@ -54,7 +54,6 @@ def loss(self): class MaskCalculationHook: def __init__(self, module): - # pylint: disable=protected-access self.hook = module._register_state_dict_hook(self.hook_fn) def hook_fn(self, module, destination, prefix, local_metadata): diff --git a/nncf/torch/tensor_statistics/collectors.py b/nncf/torch/tensor_statistics/collectors.py index 4089fb77f2e..9b23a3e1209 100644 --- a/nncf/torch/tensor_statistics/collectors.py +++ b/nncf/torch/tensor_statistics/collectors.py @@ -43,7 +43,6 @@ from nncf.torch.tensor_statistics.statistics import PTPercentileTensorStatistic -# pylint: disable=too-many-public-methods class PTNNCFCollectorTensorProcessor(NNCFCollectorTensorProcessor): """ A realization of the processing methods for PTNNCFTensors. @@ -139,7 +138,7 @@ def stack(x: Union[List[NNCFTensor], Deque[NNCFTensor]], axis: int = 0) -> NNCFT @staticmethod def unstack(x: NNCFTensor, axis: int = 0) -> List[NNCFTensor]: tensor = x.tensor - if list(tensor.shape) == []: # pylint: disable=C1803 + if list(tensor.shape) == []: tensor = tensor.unsqueeze(0) tensor_list = torch.unbind(tensor, dim=axis) return [PTNNCFTensor(t) for t in tensor_list] diff --git a/nncf/torch/utils.py b/nncf/torch/utils.py index 646e939282e..8e3a735d6be 100644 --- a/nncf/torch/utils.py +++ b/nncf/torch/utils.py @@ -114,13 +114,11 @@ def manual_seed(seed): def is_tracing_state(): - # pylint: disable=protected-access return torch._C._get_tracing_state() is not None class no_jit_trace: def __enter__(self): - # pylint: disable=protected-access self.state = torch._C._get_tracing_state() torch._C._set_tracing_state(None) @@ -282,7 +280,7 @@ def compute_FLOPs_hook(module, input_, output, dict_to_save, module_node_name: N def add_domain(name_operator: str) -> str: - from nncf.torch.compression_method_api import DOMAIN_CUSTOM_OPS_NAME # pylint: disable=cyclic-import + from nncf.torch.compression_method_api import DOMAIN_CUSTOM_OPS_NAME return DOMAIN_CUSTOM_OPS_NAME + "::" + name_operator @@ -383,7 +381,7 @@ def maybe_convert_legacy_names_in_compress_state(compression_state: Dict[str, An if not controller_state or "quantization" not in controller_state: return - from nncf.torch.quantization.algo import QUANTIZER_BUILDER_STATE_VERSION_SAVE_NAME # pylint: disable=cyclic-import + from nncf.torch.quantization.algo import QUANTIZER_BUILDER_STATE_VERSION_SAVE_NAME if not controller_state["quantization"].get(QUANTIZER_BUILDER_STATE_VERSION_SAVE_NAME): qips = controller_state["quantization"]["quantizer_setup"]["quantization_points"] diff --git a/tests/common/accuracy_control/test_evaluator.py b/tests/common/accuracy_control/test_evaluator.py index 080a24a5ab6..07085b2966c 100644 --- a/tests/common/accuracy_control/test_evaluator.py +++ b/tests/common/accuracy_control/test_evaluator.py @@ -83,7 +83,6 @@ def test_determine_mode(ts: TestCase): def _validation_fn(dummy_model, dummy_dataset): return (ts.metric_value, ts.values_for_each_item) - # pylint: disable=W0212 if ts.raise_exception: with pytest.raises(RuntimeError): _ = Evaluator.determine_mode(None, Dataset([None]), _validation_fn) diff --git a/tests/common/conftest.py b/tests/common/conftest.py index 656c5a25b69..8d504511550 100644 --- a/tests/common/conftest.py +++ b/tests/common/conftest.py @@ -9,5 +9,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint:disable=unused-import + from tests.shared.logging import nncf_caplog # noqa: F401 diff --git a/tests/common/experimental/test_reducers_and_aggregators.py b/tests/common/experimental/test_reducers_and_aggregators.py index e307fb73f84..e7dd055e01c 100644 --- a/tests/common/experimental/test_reducers_and_aggregators.py +++ b/tests/common/experimental/test_reducers_and_aggregators.py @@ -213,7 +213,6 @@ def test_noop_aggregator(self): for _ in range(3): aggregator.register_reduced_input(self.get_nncf_tensor(input_)) - # pylint: disable=protected-access assert aggregator._collected_samples == 3 aggregated = aggregator.aggregate() assert len(aggregated) == 3 @@ -227,7 +226,6 @@ def test_shape_aggregator(self): for _ in range(3): aggregator.register_reduced_input(self.get_nncf_tensor(input_)) - # pylint: disable=protected-access assert aggregator._collected_samples == 1 assert ref_shape == aggregator.aggregate() diff --git a/tests/common/experimental/test_statistic_collector.py b/tests/common/experimental/test_statistic_collector.py index ba99c65d328..3caad7fcd9a 100644 --- a/tests/common/experimental/test_statistic_collector.py +++ b/tests/common/experimental/test_statistic_collector.py @@ -27,8 +27,6 @@ from nncf.experimental.common.tensor_statistics.collectors import TensorReducerBase from nncf.experimental.common.tensor_statistics.collectors import TensorType -# pylint: disable=(protected-access) - class NumpyNNCFTensor(NNCFTensor): def __init__(self, tensor: np.array, dummy_device: Optional[str] = None): diff --git a/tests/common/quantization/data_generators.py b/tests/common/quantization/data_generators.py index 42f612ecb62..2db33bc92f9 100644 --- a/tests/common/quantization/data_generators.py +++ b/tests/common/quantization/data_generators.py @@ -391,7 +391,7 @@ def scatter_plot( :param save_to_file: Save plot to file as image, defaults to None. """ import pandas as pd - import plotly.express as px # pylint:disable=import-error + import plotly.express as px column_names = list(data.keys()) for column in column_names: diff --git a/tests/common/quantization/mock_graphs.py b/tests/common/quantization/mock_graphs.py index 1234cd33287..46887158950 100644 --- a/tests/common/quantization/mock_graphs.py +++ b/tests/common/quantization/mock_graphs.py @@ -81,7 +81,6 @@ def mark_input_ports_lexicographically_based_on_input_node_key(graph: nx.DiGraph def get_nncf_graph_from_mock_nx_graph(nx_graph: nx.DiGraph, nncf_graph_cls=NNCFGraph) -> NNCFGraph: - # pylint:disable=too-many-branches mock_graph = nncf_graph_cls() key_vs_id = {} edge_vs_output_idx_and_creator_id: Dict[Tuple[str, str], Tuple[int, int]] = {} diff --git a/tests/common/quantization/test_quantizer_propagation_graph.py b/tests/common/quantization/test_quantizer_propagation_graph.py index 45fe13a42a2..affc7df8bc2 100644 --- a/tests/common/quantization/test_quantizer_propagation_graph.py +++ b/tests/common/quantization/test_quantizer_propagation_graph.py @@ -45,8 +45,6 @@ from tests.common.quantization.mock_graphs import get_two_branch_mock_model_graph from tests.common.quantization.mock_graphs import mark_input_ports_lexicographically_based_on_input_node_key -# pylint:disable=too-many-lines - def get_edge_paths(graph, start_node_key, finish_node_key) -> List[List[Tuple]]: node_paths = list(nx.all_simple_paths(graph, start_node_key, finish_node_key)) @@ -62,7 +60,6 @@ def get_edge_paths_for_propagation(graph, start_node_key, finish_node_key) -> Li class TestQuantizerPropagationStateGraph: - # pylint:disable=too-many-public-methods @staticmethod @pytest.fixture() def mock_qp_graph(): @@ -1837,6 +1834,5 @@ def test_create_quantizer_setup_with_output_quant_as_weights_ops( ], ) def test_get_weight_and_activation_qconfig_list_intersection(weight_configs, activation_configs, reference_configs): - # pylint: disable=protected-access resulted_configs = QPSG._get_weight_and_activation_qconfig_list_intersection(weight_configs, activation_configs) assert resulted_configs == reference_configs diff --git a/tests/common/quantization/test_quantizer_propagation_solver.py b/tests/common/quantization/test_quantizer_propagation_solver.py index 3193776aca1..f50b7a484eb 100644 --- a/tests/common/quantization/test_quantizer_propagation_solver.py +++ b/tests/common/quantization/test_quantizer_propagation_solver.py @@ -9,7 +9,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint:disable=too-many-lines + from collections import Counter from collections import namedtuple from itertools import permutations @@ -198,7 +198,6 @@ def __init__( class TestQuantizerPropagationSolver: - # pylint:disable=too-many-public-methods def test_setup_initial_quantizers_in_quant_prop_graph(self): ops_to_quantize = [ BatchNormTestMetatype.name, @@ -1560,7 +1559,6 @@ def test_handling_upward_branching_path_with_no_transition_creates_no_extra_quan _ = quant_prop_solver.propagation_step(pq, quant_prop_graph) finished_pqs = quant_prop_solver.get_finished_propagating_quantizers() - # pylint:disable=no-member assert quant_prop_graph.remove_propagating_quantizer.call_count == 1 assert quant_prop_graph.clone_propagating_quantizer.call_count == 1 assert len(finished_pqs) == 1 diff --git a/tests/common/test_framework_detection.py b/tests/common/test_framework_detection.py index c6f0f4c9736..6df26d0f91d 100644 --- a/tests/common/test_framework_detection.py +++ b/tests/common/test_framework_detection.py @@ -20,8 +20,8 @@ import nncf -SUPPORTED_FRAMEWORKS = nncf._SUPPORTED_FRAMEWORKS # pylint:disable=protected-access -_REAL_FIND_SPEC = importlib._bootstrap._find_spec # pylint:disable=protected-access +SUPPORTED_FRAMEWORKS = nncf._SUPPORTED_FRAMEWORKS +_REAL_FIND_SPEC = importlib._bootstrap._find_spec class FailForModules: diff --git a/tests/common/test_logging.py b/tests/common/test_logging.py index 870afab404c..189122ee5ba 100644 --- a/tests/common/test_logging.py +++ b/tests/common/test_logging.py @@ -55,7 +55,7 @@ def test_set_log_file(messages, expected): assert actual_line.rstrip("\n") == expected_line handlers_to_remove = [] - # pylint: disable=no-member + for handler in nncf_logger.handlers: if isinstance(handler, logging.FileHandler) and str(tmp_dir) in handler.baseFilename: handler.close() # so that the log file is released and temp dir can be deleted diff --git a/tests/common/test_monkey_patching.py b/tests/common/test_monkey_patching.py index f3e44594519..245d78862f0 100644 --- a/tests/common/test_monkey_patching.py +++ b/tests/common/test_monkey_patching.py @@ -14,12 +14,12 @@ CORRECT_WRAPPER_STACK = "base" -def wrapper1(self, fn, *args, **kwargs): # pylint: disable=unused-argument +def wrapper1(self, fn, *args, **kwargs): kwargs["wrapper_stack"] += "_wrapper1" return fn(*args, **kwargs) -def wrapper2(self, fn, *args, **kwargs): # pylint: disable=unused-argument +def wrapper2(self, fn, *args, **kwargs): kwargs["wrapper_stack"] += "_wrapper2" return fn(*args, **kwargs) @@ -44,7 +44,7 @@ def assert_wrapper_stack_class(cls, wrapper_stack=None): def test_patcher(): global CORRECT_WRAPPER_STACK - def wrapper3(self, fn, *args, **kwargs): # pylint: disable=unused-argument + def wrapper3(self, fn, *args, **kwargs): kwargs["wrapper_stack"] += "_wrapper3" return fn(*args, **kwargs) diff --git a/tests/common/test_statistics_aggregator.py b/tests/common/test_statistics_aggregator.py index 980ea2328d7..29b6db51c03 100644 --- a/tests/common/test_statistics_aggregator.py +++ b/tests/common/test_statistics_aggregator.py @@ -48,7 +48,6 @@ class BCStatsCollectors(Enum): RAW = "raw" -# pylint: disable=too-many-public-methods class TemplateTestStatisticsAggregator: @abstractmethod def get_min_max_algo_backend_cls(self) -> Type[MinMaxAlgoBackend]: @@ -783,7 +782,7 @@ def test_statistic_merging(self, test_params, key, dataset_samples, inplace_stat dataset = self.get_dataset(dataset_samples) statistics_aggregator = self.get_statistics_aggregator(dataset) - # pylint: disable=protected-access + merged_statistics = statistics_aggregator._get_merged_statistic_points(statistics_points, model, nncf_graph) merged_stats_checkers_map = { "split_concat": self._check_split_concat_merged_stats, diff --git a/tests/cross_fw/examples/run_example.py b/tests/cross_fw/examples/run_example.py index 790994dec25..afecbce45ea 100644 --- a/tests/cross_fw/examples/run_example.py +++ b/tests/cross_fw/examples/run_example.py @@ -16,9 +16,6 @@ from tests.shared.paths import PROJECT_ROOT -# pylint: disable=maybe-no-member -# pylint: disable=import-error - def post_training_quantization_mobilenet_v2(example_root_dir: str) -> Dict[str, float]: sys.path.append(example_root_dir) diff --git a/tests/cross_fw/install/install_checks_tf.py b/tests/cross_fw/install/install_checks_tf.py index 11dea551a3c..fe283bb8d67 100644 --- a/tests/cross_fw/install/install_checks_tf.py +++ b/tests/cross_fw/install/install_checks_tf.py @@ -11,13 +11,14 @@ import tensorflow as tf -# Do not remove - these imports are for testing purposes. -# pylint:disable=unused-import import nncf # noqa: F401 from nncf.common.compression import BaseCompressionAlgorithmController from nncf.tensorflow.helpers.model_creation import create_compressed_model from tests.tensorflow.quantization.utils import get_basic_quantization_config +# Do not remove - these imports are for testing purposes. + + inputs = tf.keras.Input(shape=(3, 3, 1)) outputs = tf.keras.layers.Conv2D(filters=3, kernel_size=3)(inputs) model = tf.keras.Model(inputs=inputs, outputs=outputs) diff --git a/tests/cross_fw/install/install_checks_torch.py b/tests/cross_fw/install/install_checks_torch.py index c15983c08d8..dde6ae290da 100644 --- a/tests/cross_fw/install/install_checks_torch.py +++ b/tests/cross_fw/install/install_checks_torch.py @@ -19,8 +19,8 @@ package_type = sys.argv[2] # Do not remove - these imports are for testing purposes. -# pylint:disable=unused-import -# pylint:disable=wrong-import-position + + import nncf # noqa: F401, E402 from nncf.torch import create_compressed_model # noqa: F401, E402 diff --git a/tests/onnx/benchmarking/run_ptq.py b/tests/onnx/benchmarking/run_ptq.py index a7354a979cc..91c2f7d4728 100644 --- a/tests/onnx/benchmarking/run_ptq.py +++ b/tests/onnx/benchmarking/run_ptq.py @@ -23,12 +23,9 @@ from nncf.scopes import IgnoredScope from tests.onnx.opset_converter import convert_opset_version -# pylint: disable=unused-import # This import need to register custom Conerter from tests.onnx.quantization.common import find_ignored_scopes -# pylint: disable=redefined-outer-name,protected-access - def process_fn(data_item, model_evaluator: ModelEvaluator, has_batch_dim: Optional[bool] = False): _, batch_annotation, batch_input, _ = data_item diff --git a/tests/onnx/models.py b/tests/onnx/models.py index 671a4ad8d31..72516621cfe 100644 --- a/tests/onnx/models.py +++ b/tests/onnx/models.py @@ -20,8 +20,6 @@ OPSET_VERSION = 13 ALL_SYNTHETIC_MODELS = Registry("ONNX_SYNTHETIC_MODELS") -# pylint: disable=no-member, too-many-lines - def create_initializer_tensor( name: str, tensor_array: np.ndarray, data_type: onnx.TensorProto = onnx.TensorProto.FLOAT diff --git a/tests/onnx/opset_converter.py b/tests/onnx/opset_converter.py index 5a38aff7364..512535b0512 100644 --- a/tests/onnx/opset_converter.py +++ b/tests/onnx/opset_converter.py @@ -10,7 +10,7 @@ # limitations under the License. import onnx -from onnx.version_converter import ConvertError # pylint: disable=no-name-in-module +from onnx.version_converter import ConvertError from onnx.version_converter import convert_version from nncf.common.logging import nncf_logger @@ -28,7 +28,7 @@ def convert_opset_version(model: onnx.ModelProto, opset_version: int = TARGET_OP :param opset_version: target Opset Version. :return: Converted ONNX model or Original ONNX model. """ - # pylint: disable=no-member + try: modified_model = convert_version(model, opset_version) onnx.checker.check_model(modified_model) diff --git a/tests/onnx/quantization/test_classification_models_graph.py b/tests/onnx/quantization/test_classification_models_graph.py index 034d0a55bc0..7db2d90d091 100644 --- a/tests/onnx/quantization/test_classification_models_graph.py +++ b/tests/onnx/quantization/test_classification_models_graph.py @@ -15,8 +15,6 @@ from torchvision import models from nncf.parameters import TargetDevice - -# pylint: disable=no-member from tests.onnx.conftest import ONNX_MODEL_DIR from tests.onnx.quantization.common import ModelToTest from tests.onnx.quantization.common import compare_nncf_graph diff --git a/tests/onnx/quantization/test_min_max.py b/tests/onnx/quantization/test_min_max.py index f5f1710268d..2c6a1cf78e2 100644 --- a/tests/onnx/quantization/test_min_max.py +++ b/tests/onnx/quantization/test_min_max.py @@ -21,8 +21,6 @@ from nncf.onnx.graph.node_utils import get_reduction_shape from nncf.onnx.graph.transformations.commands import ONNXTargetPoint -# pylint: disable=protected-access - @dataclass class TestCase: diff --git a/tests/onnx/quantization/test_ptq_params.py b/tests/onnx/quantization/test_ptq_params.py index d0a88ad8cc8..99277cdd6c7 100644 --- a/tests/onnx/quantization/test_ptq_params.py +++ b/tests/onnx/quantization/test_ptq_params.py @@ -36,8 +36,6 @@ from tests.post_training.test_templates.models import NNCFGraphToTestMatMul from tests.post_training.test_templates.test_ptq_params import TemplateTestPTQParams -# pylint: disable=protected-access - def get_hw_patterns(device: TargetDevice = TargetDevice.ANY) -> GraphPattern: return PatternsManager.get_full_hw_pattern_graph(backend=BackendType.ONNX, device=device) diff --git a/tests/onnx/quantization/test_ptq_regression.py b/tests/onnx/quantization/test_ptq_regression.py index d113dcc6d10..358dc5ac9f3 100644 --- a/tests/onnx/quantization/test_ptq_regression.py +++ b/tests/onnx/quantization/test_ptq_regression.py @@ -26,7 +26,6 @@ import nncf MODELS = [ - # pylint: disable=line-too-long ( "https://github.com/onnx/models/raw/main/vision/classification/mobilenet/model/mobilenetv2-12.onnx", "mobilenetv2-12", diff --git a/tests/onnx/quantization/test_quantizer_config.py b/tests/onnx/quantization/test_quantizer_config.py index 8702f4a42f0..eb24f752b16 100644 --- a/tests/onnx/quantization/test_quantizer_config.py +++ b/tests/onnx/quantization/test_quantizer_config.py @@ -29,9 +29,6 @@ ParamsCls = TemplateTestQuantizerConfig.TestGetStatisticsCollectorParameters -# pylint: disable=protected-access - - class TestQuantizerConfig(TemplateTestQuantizerConfig): def get_algo_backend(self): return ONNXMinMaxAlgoBackend() diff --git a/tests/onnx/test_e2e_ptq.py b/tests/onnx/test_e2e_ptq.py index 0d2f353982b..b3604af8c45 100644 --- a/tests/onnx/test_e2e_ptq.py +++ b/tests/onnx/test_e2e_ptq.py @@ -9,7 +9,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=redefined-outer-name import json import math diff --git a/tests/onnx/test_model_transformer.py b/tests/onnx/test_model_transformer.py index da039ee2d1a..3d1290da13c 100644 --- a/tests/onnx/test_model_transformer.py +++ b/tests/onnx/test_model_transformer.py @@ -68,7 +68,7 @@ def test_quantizer_insertion(target_layers, should_raise, quantizer_number): num_q = 0 num_dq = 0 - # pylint:disable=no-member + for node in transformed_model.graph.node: op_type = node.op_type if op_type == "QuantizeLinear": @@ -125,7 +125,6 @@ def test_inserted_quantizer_parameters(test_parameters): transformed_model = model_transformer.transform(transformation_layout) onnx.checker.check_model(transformed_model) - # pylint:disable=no-member for node in transformed_model.graph.node: op_type = node.op_type if op_type == "QuantizeLinear": diff --git a/tests/onnx/weightless_model.py b/tests/onnx/weightless_model.py index 6f34347ba38..cf5c8597e6e 100644 --- a/tests/onnx/weightless_model.py +++ b/tests/onnx/weightless_model.py @@ -16,11 +16,9 @@ import numpy as np import onnx -from onnx import TensorProto # pylint:disable=no-name-in-module +from onnx import TensorProto from onnx.external_data_helper import uses_external_data -# pylint: disable=no-member - def load_model_topology_with_zeros_weights(model_path: Union[str, Path]) -> onnx.ModelProto: """ diff --git a/tests/openvino/conftest.py b/tests/openvino/conftest.py index 738ba7efc44..025c3278f58 100644 --- a/tests/openvino/conftest.py +++ b/tests/openvino/conftest.py @@ -11,7 +11,6 @@ from pathlib import Path -# pylint:disable=unused-import import pytest from tests.shared.case_collection import COMMON_SCOPE_MARKS_VS_OPTIONS diff --git a/tests/openvino/datasets_helpers.py b/tests/openvino/datasets_helpers.py index 8b1044ee9d4..631c2114a04 100644 --- a/tests/openvino/datasets_helpers.py +++ b/tests/openvino/datasets_helpers.py @@ -100,7 +100,6 @@ def get_dataset_for_test(dataset_name: str, data_dir: Path) -> Path: raise RuntimeError(f"Unknown dataset: {dataset_name}.") -# pylint: disable=protected-access def get_nncf_dataset_from_ac_config(model_path, config_path, data_dir, framework="openvino", device="CPU"): args = [ "-c", diff --git a/tests/openvino/native/common.py b/tests/openvino/native/common.py index 709ebf6c324..fdb4f534f45 100644 --- a/tests/openvino/native/common.py +++ b/tests/openvino/native/common.py @@ -50,8 +50,6 @@ def load_json(stats_path): class NumpyEncoder(json.JSONEncoder): """Special json encoder for numpy types""" - # pylint: disable=W0221, E0202 - def default(self, o): if isinstance(o, np.integer): return int(o) diff --git a/tests/openvino/native/quantization/test_fq_params_calculation.py b/tests/openvino/native/quantization/test_fq_params_calculation.py index 180eb7190c9..7d92d9f74f6 100644 --- a/tests/openvino/native/quantization/test_fq_params_calculation.py +++ b/tests/openvino/native/quantization/test_fq_params_calculation.py @@ -56,7 +56,6 @@ def get_fq_nodes_stats_algo(model): return nodes -# pylint: disable=protected-access def quantize_model(ov_model, q_params): dataset = get_dataset_for_test(ov_model) graph = GraphConverter.create_nncf_graph(ov_model) diff --git a/tests/openvino/native/quantization/test_graphs.py b/tests/openvino/native/quantization/test_graphs.py index 9073a4bb581..6d0a7c3102e 100644 --- a/tests/openvino/native/quantization/test_graphs.py +++ b/tests/openvino/native/quantization/test_graphs.py @@ -133,7 +133,6 @@ def test_omz_models_sq_placement(model_name_params, tmp_path): compare_nncf_graphs(quantized_model, path_ref_graph) -# pylint: disable=protected-access def smooth_quant_model(ov_model: ov.Model, q_params: Dict, quantize=True): dataset = get_dataset_for_test(ov_model) graph = GraphConverter.create_nncf_graph(ov_model) diff --git a/tests/openvino/native/quantization/test_ptq_params.py b/tests/openvino/native/quantization/test_ptq_params.py index e1d170b72b4..192d3b5b008 100644 --- a/tests/openvino/native/quantization/test_ptq_params.py +++ b/tests/openvino/native/quantization/test_ptq_params.py @@ -46,7 +46,6 @@ def get_ignored_patterns(device: TargetDevice = TargetDevice.ANY) -> GraphPatter return PatternsManager.get_full_ignored_pattern_graph(backend=BackendType.OPENVINO, device=device) -# pylint: disable=protected-access @pytest.mark.parametrize("target_device", [TargetDevice.CPU, TargetDevice.GPU, TargetDevice.VPU]) def test_target_device(target_device): min_max_algo = MinMaxQuantization(target_device=target_device) diff --git a/tests/openvino/native/quantization/test_quantizer_config.py b/tests/openvino/native/quantization/test_quantizer_config.py index 773f5996604..f1774cf89e8 100644 --- a/tests/openvino/native/quantization/test_quantizer_config.py +++ b/tests/openvino/native/quantization/test_quantizer_config.py @@ -31,9 +31,6 @@ ParamsCls = TemplateTestQuantizerConfig.TestGetStatisticsCollectorParameters -# pylint: disable=protected-access - - class TestQuantizerConfig(TemplateTestQuantizerConfig): def get_algo_backend(self): return OVMinMaxAlgoBackend() diff --git a/tests/openvino/native/test_model_utils.py b/tests/openvino/native/test_model_utils.py index 75992fc24e3..28d2bbe6694 100644 --- a/tests/openvino/native/test_model_utils.py +++ b/tests/openvino/native/test_model_utils.py @@ -18,8 +18,6 @@ from tests.common.quantization.mock_graphs import create_mock_graph from tests.common.quantization.mock_graphs import get_nncf_graph_from_mock_nx_graph -# pylint:disable=protected-access - def get_nncf_graph_for_test(edge_shape, dtype): nodes = [ diff --git a/tests/openvino/tools/calibrate.py b/tests/openvino/tools/calibrate.py index 59e793ac1e3..ecb589aa1ca 100644 --- a/tests/openvino/tools/calibrate.py +++ b/tests/openvino/tools/calibrate.py @@ -8,7 +8,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# pylint:disable=too-many-lines + import functools import json @@ -733,7 +733,6 @@ def get_allow_reshape_input(accuracy_checker_config) -> bool: return False -# pylint:disable=too-many-branches def maybe_reshape_model(model, dataset, subset_size, input_to_tensor_name): dataset_inputs_shapes = defaultdict(set) for input_dict in islice(dataset.get_inference_data(), subset_size): @@ -801,7 +800,6 @@ def maybe_reshape_model(model, dataset, subset_size, input_to_tensor_name): return model, model_inputs_shapes -# pylint: disable=protected-access def get_transform_fn(model_evaluator: ModelEvaluator, ov_model): if model_evaluator.launcher._lstm_inputs: compiled_original_model = ov.Core().compile_model(ov_model) diff --git a/tests/post_training/pipelines/base.py b/tests/post_training/pipelines/base.py index bc97a6a1b4b..99ee92d0017 100644 --- a/tests/post_training/pipelines/base.py +++ b/tests/post_training/pipelines/base.py @@ -294,7 +294,7 @@ def cleanup_torchscript_cache(): After run torch.jit.trace in convert_model, PyTorch does not clear the trace cache automatically. """ - # pylint: disable=protected-access + torch._C._jit_clear_class_registry() torch.jit._recursive.concrete_type_store = torch.jit._recursive.ConcreteTypeStore() torch.jit._state._clear_class_state() diff --git a/tests/post_training/test_quantize_conformance.py b/tests/post_training/test_quantize_conformance.py index 34327625ba4..fa62eafd77b 100644 --- a/tests/post_training/test_quantize_conformance.py +++ b/tests/post_training/test_quantize_conformance.py @@ -85,7 +85,7 @@ def test_ptq_quantization(test_case_name, data, output, result, no_eval): pipeline = pipeline_cls(**pipeline_kwargs) pipeline.run() - # pylint:disable=broad-except + except Exception as e: err_msg = str(e) traceback.print_exc() diff --git a/tests/post_training/test_templates/models.py b/tests/post_training/test_templates/models.py index 24203fbeb21..5d83db95117 100644 --- a/tests/post_training/test_templates/models.py +++ b/tests/post_training/test_templates/models.py @@ -19,7 +19,6 @@ from tests.common.quantization.test_filter_constant_nodes import get_nncf_graph_from_mock_nx_graph -# pylint: disable=protected-access class NNCFGraphToTest: def __init__( self, diff --git a/tests/post_training/test_templates/test_bias_correction.py b/tests/post_training/test_templates/test_bias_correction.py index 68c72301707..b8146cf0827 100644 --- a/tests/post_training/test_templates/test_bias_correction.py +++ b/tests/post_training/test_templates/test_bias_correction.py @@ -30,7 +30,6 @@ TTensor = TypeVar("TTensor") -# pylint: disable=protected-access class TemplateTestBCAlgorithm: @staticmethod @abstractmethod diff --git a/tests/post_training/test_templates/test_channel_alignment.py b/tests/post_training/test_templates/test_channel_alignment.py index 0ad51ff76c7..950852ef3c2 100644 --- a/tests/post_training/test_templates/test_channel_alignment.py +++ b/tests/post_training/test_templates/test_channel_alignment.py @@ -32,8 +32,6 @@ from tests.post_training.test_templates.models import NNCFGraphCA from tests.post_training.test_templates.models import NNCFGraphCAWithBias -# pylint: disable=protected-access - EPS = 1e-3 VALID_CONV_LAYER_ATTR = ConvolutionLayerAttributes( @@ -285,8 +283,6 @@ def _get_nncf_graph(self, num_biases: int) -> NNCFGraph: @pytest.mark.parametrize("empty_statistics", [False, True]) @pytest.mark.parametrize("num_biases", [0, 1, 2]) - # pylint: disable=too-many-statements - # pylint: disable=too-many-branches def test_transformation_layout(self, empty_statistics, num_biases, mocker): mocked_transformer = mocker.MagicMock() self.mock_model_transformer_factory(mocker, mocked_transformer) diff --git a/tests/post_training/test_templates/test_fast_bias_correction.py b/tests/post_training/test_templates/test_fast_bias_correction.py index c4ea71d6551..d60ba274902 100644 --- a/tests/post_training/test_templates/test_fast_bias_correction.py +++ b/tests/post_training/test_templates/test_fast_bias_correction.py @@ -65,7 +65,7 @@ def test_reshape_bias_shift(self, bias_value: list, bias_shift: list, channel_ax bias_shift = self.list_to_backend_type(data=bias_shift) algo = FastBiasCorrection(subset_size=1, inplace_statistics=False) - # pylint: disable=protected-access + algo._backend_entity = self.get_backend() new_bias_shift = algo._reshape_bias_shift(bias_shift, bias_value, channel_axis) assert list(new_bias_shift.shape) == ref_shape diff --git a/tests/post_training/test_templates/test_ptq_params.py b/tests/post_training/test_templates/test_ptq_params.py index 71a14d8ad76..4dbc05a5492 100644 --- a/tests/post_training/test_templates/test_ptq_params.py +++ b/tests/post_training/test_templates/test_ptq_params.py @@ -86,9 +86,6 @@ def __init__(self, metatypes: Dict[TestMetatype, OperatorMetatype]): self.weight_quantization_target_point_names.append(node.node_name) -# pylint: disable=protected-access - - class TemplateTestPTQParams: @abstractmethod def get_algo_backend(self): diff --git a/tests/post_training/test_templates/test_quantizer_config.py b/tests/post_training/test_templates/test_quantizer_config.py index 48e5b585084..8afbeae00a2 100644 --- a/tests/post_training/test_templates/test_quantizer_config.py +++ b/tests/post_training/test_templates/test_quantizer_config.py @@ -39,7 +39,6 @@ from tests.post_training.test_templates.models import NNCFGraphToTestSumAggregation -# pylint: disable=protected-access,too-many-branches class TemplateTestQuantizerConfig: @abstractmethod def get_algo_backend(self): diff --git a/tests/post_training/test_templates/test_smooth_quant.py b/tests/post_training/test_templates/test_smooth_quant.py index 5ea93677f66..119acc31726 100644 --- a/tests/post_training/test_templates/test_smooth_quant.py +++ b/tests/post_training/test_templates/test_smooth_quant.py @@ -125,7 +125,6 @@ def test_smooth_quant_algo(self, model_cls, reference_values, tmpdir): self.check_scales(quantized_model, reference_values) - # pylint:disable=protected-access def test_get_abs_max_channel_collector(self): backend = self.get_backend() reduction_axes = (3, 2, 1) @@ -167,7 +166,6 @@ def test_get_abs_max_channel_collector(self): ), ), ) - # pylint:disable=protected-access def test__get_nodes_to_smooth_data(self, model_cls, references, tmpdir): model = self.backend_specific_model(model_cls(), tmpdir) nncf_graph = NNCFGraphFactory.create(model) @@ -218,7 +216,6 @@ def test_get_activation_channel_axis(self, node_metatype, layer_attributes, port node = NNCFNode(attributes) try: - # pylint: disable=protected-access activation_channel_axis = backend.get_activation_channel_axis(node, port_id) except RuntimeError as e: if isinstance(e, reference_value): @@ -238,7 +235,6 @@ def test_get_weight_channel_axis(self, node_metatype, layer_attributes, port_id, node = NNCFNode(attributes) try: - # pylint: disable=protected-access activation_channel_axis = backend.get_weight_channel_axis(node, port_id) except RuntimeError as e: if isinstance(e, reference_value): diff --git a/tests/shared/command.py b/tests/shared/command.py index 1a82f77dd69..99f94f5789e 100644 --- a/tests/shared/command.py +++ b/tests/shared/command.py @@ -79,7 +79,7 @@ def target(): self.process.wait() self.exec_time = time.time() - start_time - except Exception as e: # pylint:disable=broad-except + except Exception as e: self.thread_exc = e thread = threading.Thread(target=target) diff --git a/tests/shared/helpers.py b/tests/shared/helpers.py index ddcf96a82c0..1fc87b46672 100644 --- a/tests/shared/helpers.py +++ b/tests/shared/helpers.py @@ -172,8 +172,6 @@ def load_json(stats_path: Path): class NumpyEncoder(json.JSONEncoder): """Special json encoder for numpy types""" - # pylint: disable=W0221, E0202 - def default(self, o): if isinstance(o, np.integer): return int(o) diff --git a/tests/shared/install_fixtures.py b/tests/shared/install_fixtures.py index 079ba293901..5cdefe52722 100644 --- a/tests/shared/install_fixtures.py +++ b/tests/shared/install_fixtures.py @@ -16,8 +16,6 @@ @pytest.fixture(scope="function") -def tmp_venv_with_nncf( - tmp_path, package_type: str, venv_type: str, extras: Set[str] -): # pylint:disable=redefined-outer-name +def tmp_venv_with_nncf(tmp_path, package_type: str, venv_type: str, extras: Set[str]): venv_path = create_venv_with_nncf(tmp_path, package_type, venv_type, extra_reqs=extras) return venv_path diff --git a/tests/shared/nx_graph.py b/tests/shared/nx_graph.py index 1387a90207a..eaef4c96974 100644 --- a/tests/shared/nx_graph.py +++ b/tests/shared/nx_graph.py @@ -55,7 +55,6 @@ def __init__( self.edge_end_id = edge_end_id def __lt__(self, other: "LineOrder"): - # pylint:disable=too-many-return-statements if self.node_id is not None: if other.node_id is None: return True diff --git a/tests/shared/paths.py b/tests/shared/paths.py index 61d4aade112..feac4cae35f 100644 --- a/tests/shared/paths.py +++ b/tests/shared/paths.py @@ -14,7 +14,7 @@ from pathlib import Path TEST_ROOT = Path(__file__).absolute().parents[1] -PROJECT_ROOT = TEST_ROOT.parent.absolute() # pylint:disable=no-member +PROJECT_ROOT = TEST_ROOT.parent.absolute() EXAMPLES_DIR = PROJECT_ROOT / "examples" GITHUB_REPO_URL = "https://github.com/openvinotoolkit/nncf/" diff --git a/tests/shared/patterns.py b/tests/shared/patterns.py index 274e4c59394..ffb9711d5e3 100644 --- a/tests/shared/patterns.py +++ b/tests/shared/patterns.py @@ -15,8 +15,6 @@ from nncf.common.graph.patterns.manager import PatternsManager from nncf.common.utils.backend import BackendType -# pylint: disable=protected-access - def check_hw_patterns(backend: BackendType, reasons: Dict[HWFusedPatternNames, str]): backend_patterns = PatternsManager._get_backend_hw_patterns_map(backend) diff --git a/tests/shared/test_templates/template_test_nncf_tensor.py b/tests/shared/test_templates/template_test_nncf_tensor.py index 461deb14fce..ac86e498262 100644 --- a/tests/shared/test_templates/template_test_nncf_tensor.py +++ b/tests/shared/test_templates/template_test_nncf_tensor.py @@ -9,7 +9,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=too-many-function-args import operator from abc import abstractmethod @@ -47,7 +46,6 @@ } -# pylint: disable=too-many-public-methods class TemplateTestNNCFTensorOperators: @staticmethod @abstractmethod diff --git a/tests/tensorflow/experimental/test_models/resnet.py b/tests/tensorflow/experimental/test_models/resnet.py index 938ea10d8ea..be6468eb8b6 100644 --- a/tests/tensorflow/experimental/test_models/resnet.py +++ b/tests/tensorflow/experimental/test_models/resnet.py @@ -14,9 +14,6 @@ import tensorflow as tf -# pylint:disable=too-many-lines -# pylint:disable=too-many-statements -# pylint:disable=abstract-method def make_divisible( value: float, divisor: int, diff --git a/tests/tensorflow/helpers.py b/tests/tensorflow/helpers.py index a1ef3a4bcaf..91904bb311d 100644 --- a/tests/tensorflow/helpers.py +++ b/tests/tensorflow/helpers.py @@ -220,7 +220,7 @@ def remove_node_by_name(node_name: str, tf_graph: tf.Graph) -> tf.Graph: graph_def.node[idx].input.pop(port_idx) graph_def.node[idx].input.extend(incoming_edges) - with tf.Graph().as_default() as graph: # pylint:disable=not-context-manager + with tf.Graph().as_default() as graph: tf.graph_util.import_graph_def(graph_def, name="") return graph diff --git a/tests/tensorflow/pruning/test_algorithm.py b/tests/tensorflow/pruning/test_algorithm.py index 151b2342331..b82a373198c 100644 --- a/tests/tensorflow/pruning/test_algorithm.py +++ b/tests/tensorflow/pruning/test_algorithm.py @@ -126,6 +126,6 @@ def test_collect_output_shapes(model_fn, ref_output_shapes): model = model_fn(input_shape) model.compile() _, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) - # pylint:disable=protected-access + output_shapes = collect_output_shapes(compression_ctrl.model, compression_ctrl._original_graph) assert output_shapes == ref_output_shapes diff --git a/tests/tensorflow/pruning/test_flops_pruning.py b/tests/tensorflow/pruning/test_flops_pruning.py index 893afc9834c..7d5c9c69863 100644 --- a/tests/tensorflow/pruning/test_flops_pruning.py +++ b/tests/tensorflow/pruning/test_flops_pruning.py @@ -128,7 +128,7 @@ def test_flops_calulation_for_spec_layers( assert compression_ctrl.full_params_num == ref_full_params assert compression_ctrl.current_flops == ref_current_flops assert compression_ctrl.current_params_num == ref_current_params - # pylint:disable=protected-access + original_graph = compression_ctrl._original_graph pruning_groups = compression_ctrl._pruned_layer_groups_info shape_pruner = ShapePruningProcessor( diff --git a/tests/tensorflow/pruning/test_tensor_processor.py b/tests/tensorflow/pruning/test_tensor_processor.py index 0ec75d388ba..b917eef0cb6 100644 --- a/tests/tensorflow/pruning/test_tensor_processor.py +++ b/tests/tensorflow/pruning/test_tensor_processor.py @@ -74,7 +74,6 @@ def test_elementwise_mask_propagation(all_close): def test_split(): - # pylint: disable=E1120 tensor_data = [0.0, 1.0, 2.0, 3.0] tf_variable = tf.Variable(tensor_data) tf_output = tf.split(tf_variable, 2) diff --git a/tests/tensorflow/quantization/test_algorithm_quantization.py b/tests/tensorflow/quantization/test_algorithm_quantization.py index ee50ca40b63..b26438ca564 100644 --- a/tests/tensorflow/quantization/test_algorithm_quantization.py +++ b/tests/tensorflow/quantization/test_algorithm_quantization.py @@ -42,12 +42,10 @@ def compare_qspecs(qspec: TFQuantizerSpec, quantizer): assert qspec.half_range == quantizer.half_range assert isinstance(quantizer, NNCF_QUANTIZATION_OPERATIONS.get(qspec.mode)) if qspec.mode == QuantizationMode.SYMMETRIC: - # pylint: disable=protected-access assert qspec.signedness_to_force == quantizer.signedness_to_force def get_quantizers(model): - # pylint: disable=protected-access activation_quantizers = [layer._quantizer for layer in model.layers if isinstance(layer, FakeQuantize)] weight_quantizers = [] for layer in model.layers: @@ -253,7 +251,7 @@ def get_quantize_inputs_test_model(input_shapes): inputs = [] for i, input_shape in enumerate(input_shapes): inputs.append(tf.keras.Input(shape=input_shape[1:], name="input_{}".format(i + 1))) - # pylint: disable=unbalanced-tuple-unpacking + input_1, input_2, input_3, input_4, input_5 = inputs conv1 = layers.Conv2D(filters=8, kernel_size=3) @@ -292,7 +290,7 @@ def get_quantize_inputs_test_model(input_shapes): x_45 = conv6(x_45) x_45 = layers.Flatten()(x_45) in_5_flat = layers.Flatten()(input_5) - # pylint: disable=E1120 + x_45 = tf.pad(x_45, [[0, 0], [0, in_5_flat.shape[1] - x_45.shape[1]]]) x_45 += in_5_flat x = tf.concat([x_1, x_2, x_3, x_45], -1) @@ -637,7 +635,7 @@ def test_quantize_pre_post_processing(layer_name, input_type, data_type): channel_axes = get_channel_axis(layer_desk.input_type, layer_name, layer_desk.layer) q.setup_input_transformation(layer_desk.shape, channel_axes) - # pylint: disable=protected-access + preprocess = q._pre_processing_fn(layer_desk.inputs) postprocess = q._post_processing_fn(preprocess) assert tf.math.reduce_all(preprocess == layer_desk.inputs_transformed) diff --git a/tests/tensorflow/quantization/test_builder_state.py b/tests/tensorflow/quantization/test_builder_state.py index 639cae509b2..70b01b0221d 100644 --- a/tests/tensorflow/quantization/test_builder_state.py +++ b/tests/tensorflow/quantization/test_builder_state.py @@ -74,7 +74,7 @@ def test_quantization_configs__on_resume_with_compression_state(tmp_path, mocker builder = QuantizationBuilder(config) builder.load_state(compression_state_to_load["builder_state"]) - # pylint:disable=protected-access + loaded_quantizer_setup = builder._quantizer_setup assert _quantization_setup_cmp(loaded_quantizer_setup, saved_quantizer_setup) @@ -151,7 +151,7 @@ def test_checkpoint_callback_make_checkpoints(mocker, tmp_path): builder = QuantizationBuilder(config) builder.load_state(new_compression_state["builder_state"]) - # pylint:disable=protected-access + new_quantizer_setup = builder._quantizer_setup assert _quantization_setup_cmp(quantizer_setup, new_quantizer_setup) diff --git a/tests/tensorflow/quantization/test_overflow_issue.py b/tests/tensorflow/quantization/test_overflow_issue.py index 672961f5f37..83cd2df8728 100644 --- a/tests/tensorflow/quantization/test_overflow_issue.py +++ b/tests/tensorflow/quantization/test_overflow_issue.py @@ -46,7 +46,7 @@ def check_quantized_values_equals(y_train, y_val, eps, range_len, narrow_range): ids=["full_range", "narrow_range"], ) def test_min_adj(bits, low, range_, narrow_range, ref): - res = Quantizer._min_adj(bits, low, range_, narrow_range).numpy() # pylint: disable=protected-access + res = Quantizer._min_adj(bits, low, range_, narrow_range).numpy() assert abs(res - ref) < EPS @@ -61,7 +61,7 @@ def get_weights_for_overflow_issue_test(low, range_len, narrow_range, init_w_as_ mid_points = [-(i + 1 / 2) * quant_len for i in range(127)] else: # Range with zero - min_adj = Quantizer._min_adj(7, low, range_len, narrow_range).numpy() # pylint: disable=protected-access + min_adj = Quantizer._min_adj(7, low, range_len, narrow_range).numpy() mid_points = [min_adj + (i + 1 / 2) * quant_len for i in range(127)] new_w = mid_points * int(np.round(0.5 + DIM_SPLIT / 128)) @@ -115,7 +115,7 @@ def test_symmetric_quantized_weights_equal_after_fix_applied( assert (np.abs(np.abs(w_int7 - new_w) - quant_len / 2) < 1e-6).all(), "Middle points calculated incorrectly" apply_overflow_fix_to_layer(layer, "kernel", quantizer) - assert not quantizer._half_range # pylint: disable=protected-access + assert not quantizer._half_range w_int8 = layer(tf.ones((1, 1))).numpy() check_quantized_values_equals(w_int7, w_int8, EPS, range_len, narrow_range) @@ -159,7 +159,7 @@ def test_asymmetric_quantized_weights_equal_after_fix_applied( assert (np.abs(np.abs(w_int7 - new_w) - quant_len / 2) < EPS).all(), "Middle points calculated incorrectly" apply_overflow_fix_to_layer(layer, "kernel", quantizer) - assert not quantizer._half_range # pylint: disable=protected-access + assert not quantizer._half_range w_int8 = layer(tf.ones((1, 1))).numpy() check_quantized_values_equals(w_int7, w_int8, EPS, range_len, narrow_range) diff --git a/tests/tensorflow/quantization/test_unified_scales.py b/tests/tensorflow/quantization/test_unified_scales.py index dd35e981b98..8702271ba11 100644 --- a/tests/tensorflow/quantization/test_unified_scales.py +++ b/tests/tensorflow/quantization/test_unified_scales.py @@ -25,7 +25,7 @@ def get_single_concat_test_model(input_shapes): inputs = [] for i, input_shape in enumerate(input_shapes): inputs.append(tf.keras.Input(shape=input_shape[1:], name="input_{}".format(i + 1))) - # pylint: disable=unbalanced-tuple-unpacking + input_1, input_2 = inputs x_1 = layers.Multiply()([input_1, input_1]) @@ -40,7 +40,7 @@ def get_double_concat_test_model(input_shapes): inputs = [] for i, input_shape in enumerate(input_shapes): inputs.append(tf.keras.Input(shape=input_shape[1:], name="input_{}".format(i + 1))) - # pylint: disable=unbalanced-tuple-unpacking + input_1, input_2 = inputs x_1 = input_1 * input_1 @@ -56,7 +56,7 @@ def get_unet_like_test_model(input_shapes): inputs = [] for i, input_shape in enumerate(input_shapes): inputs.append(tf.keras.Input(shape=input_shape[1:], name="input_{}".format(i + 1))) - # pylint: disable=unbalanced-tuple-unpacking + input_1, _ = inputs conv_1 = layers.Conv2D(filters=8, kernel_size=1)(input_1) @@ -168,7 +168,7 @@ def get_eltwise_quantizer_linking_test_model(input_shapes): inputs = [] for i, input_shape in enumerate(input_shapes): inputs.append(tf.keras.Input(shape=input_shape[1:], name="input_{}".format(i + 1))) - # pylint: disable=unbalanced-tuple-unpacking + input_1, input_2 = inputs def path(input_1, input_2): diff --git a/tests/tensorflow/sparsity/magnitude/test_algorithm.py b/tests/tensorflow/sparsity/magnitude/test_algorithm.py index edbcc46aa35..1da2c93a031 100644 --- a/tests/tensorflow/sparsity/magnitude/test_algorithm.py +++ b/tests/tensorflow/sparsity/magnitude/test_algorithm.py @@ -46,8 +46,8 @@ def test_can_create_magnitude_sparse_algo__with_defaults(): assert len(conv_names) == len(wrappers) assert len(conv_names) == len(correct_wrappers) - assert compression_ctrl._threshold == approx(0.24, 0.1) # pylint: disable=protected-access - # pylint: disable=protected-access + assert compression_ctrl._threshold == approx(0.24, 0.1) + assert isinstance(compression_ctrl._weight_importance_fn, type(normed_magnitude)) for i, wrapper in enumerate(wrappers): @@ -103,7 +103,7 @@ def test_magnitude_sparse_algo_sets_threshold(weight_importance, sparsity_level, _, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) if sparsity_level: compression_ctrl.set_sparsity_level(sparsity_level) - assert compression_ctrl._threshold == pytest.approx(threshold, 0.01) # pylint: disable=protected-access + assert compression_ctrl._threshold == pytest.approx(threshold, 0.01) def test_can_create_magnitude_algo__without_levels(): diff --git a/tests/tensorflow/sparsity/rb/test_algorithm.py b/tests/tensorflow/sparsity/rb/test_algorithm.py index bd2a7ad7430..5808f2e2dfd 100644 --- a/tests/tensorflow/sparsity/rb/test_algorithm.py +++ b/tests/tensorflow/sparsity/rb/test_algorithm.py @@ -126,7 +126,7 @@ def test_can_set_sparse_layers_to_loss(): _, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) loss = compression_ctrl.loss assert isinstance(loss, SparseLoss) - # pylint: disable=protected-access + for op, _ in loss._target_ops: assert isinstance(op, RBSparsifyingWeight) @@ -142,7 +142,7 @@ def test_loss_has_correct_ops(): config = get_basic_sparsity_config() compress_model, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) wrappers = collect_wrapped_layers(compress_model) - # pylint: disable=protected-access + target_ops = {op[0].name: op for op in compression_ctrl.loss._target_ops} for wrapper in wrappers: for ops in wrapper.weights_attr_ops.values(): @@ -164,7 +164,7 @@ def test_sparse_algo_does_not_replace_not_conv_layer(): config = get_basic_sparsity_config() _, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) assert isinstance(compression_ctrl, RBSparsityController) - # pylint: disable=protected-access + target_ops = compression_ctrl.loss._target_ops assert len(target_ops) == 1 assert isinstance(target_ops[0][0], RBSparsifyingWeight) @@ -197,7 +197,6 @@ def test_sparse_algo_can_collect_sparse_ops(): config = get_basic_sparsity_config() _, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) - # pylint: disable=protected-access assert len(compression_ctrl.loss._target_ops) == 2 @@ -222,7 +221,6 @@ def test_scheduler_can_do_epoch_step__with_rb_algo(): assert not loss.disabled - # pylint: disable=protected-access for op, op_weights in loss._target_ops: assert op.get_trainable_weight(op_weights) diff --git a/tests/tensorflow/sparsity/rb/test_components.py b/tests/tensorflow/sparsity/rb/test_components.py index f96f5eb120b..6404589051a 100644 --- a/tests/tensorflow/sparsity/rb/test_components.py +++ b/tests/tensorflow/sparsity/rb/test_components.py @@ -65,7 +65,6 @@ def wrapper(*args, **kwargs): else: thread_id = "dummy" - # pylint: disable=redundant-keyword-arg tf.print(thread_id, args[1], output_stream=f"file://{MASKS_SEEDS_PATH}") mask = fn(*args, **kwargs) return mask @@ -180,7 +179,7 @@ def test_calc_loss(self, model_name, frozen, raising, local_mode): trainable = model.layers[1].ops_weights[op.name]["trainable"] assert tf.equal(trainable, tf.constant(not frozen)) cls = SparseLoss - # pylint: disable=protected-access + loss = cls(algo.loss._target_ops) try: assert loss() == 0 diff --git a/tests/tensorflow/test_api_behavior.py b/tests/tensorflow/test_api_behavior.py index 100e90a6395..63332344b54 100644 --- a/tests/tensorflow/test_api_behavior.py +++ b/tests/tensorflow/test_api_behavior.py @@ -12,7 +12,6 @@ from nncf.tensorflow.loss import TFZeroCompressionLoss -# pylint: disable=use-implicit-booleaness-not-comparison def test_tf_zero_loss_state(): loss = TFZeroCompressionLoss() assert loss.get_state() == {} diff --git a/tests/tensorflow/test_init.py b/tests/tensorflow/test_init.py index 602f306a89c..190d5277784 100644 --- a/tests/tensorflow/test_init.py +++ b/tests/tensorflow/test_init.py @@ -64,7 +64,6 @@ def make_table_row(expected, metric, diff, error_message, metrics_type_, key): @pytest.mark.init @pytest.mark.parametrize("eval_test_struct", RunTest.param_list, ids=RunTest.ids_list) def test_init(self, sota_checkpoints_dir, sota_data_dir, eval_test_struct: EvalRunParamsStruct): - # pylint: disable=too-many-branches if sota_data_dir is None: pytest.skip("Path to datasets is not set") diff --git a/tests/tensorflow/test_model_converter.py b/tests/tensorflow/test_model_converter.py index 04b67569492..d39997b3a8e 100644 --- a/tests/tensorflow/test_model_converter.py +++ b/tests/tensorflow/test_model_converter.py @@ -94,7 +94,7 @@ def get_model_with_reshapes_and_concats(batch_size=None): x = layers.Reshape((16, -1))(x) ones = tf.ones_like(x) t1 = layers.concatenate([x, ones]) - # pylint: disable=E1120,E1123 + t2 = tf.concat([x, ones], axis=-1) y = tf.concat([t1, t2], axis=-1) y = tf.transpose(y, [2, 0, 1]) diff --git a/tests/tensorflow/test_models/inception_v3.py b/tests/tensorflow/test_models/inception_v3.py index 09043353870..bb4e0a30b23 100644 --- a/tests/tensorflow/test_models/inception_v3.py +++ b/tests/tensorflow/test_models/inception_v3.py @@ -18,7 +18,6 @@ NUM_CLASSES = 1000 -# pylint: disable=R0915 def InceptionV3(input_shape=None): input_shape = imagenet_utils.obtain_input_shape( input_shape, default_size=299, min_size=75, data_format=backend.image_data_format(), require_flatten=True diff --git a/tests/tensorflow/test_models/maskrcnn.py b/tests/tensorflow/test_models/maskrcnn.py index 1835052a38b..b309988c23b 100644 --- a/tests/tensorflow/test_models/maskrcnn.py +++ b/tests/tensorflow/test_models/maskrcnn.py @@ -15,7 +15,7 @@ from tests.shared.paths import PROJECT_ROOT -def MaskRCNN(input_shape=None): # pylint: disable=W0613 +def MaskRCNN(input_shape=None): path_to_config = PROJECT_ROOT / "examples" / "tensorflow" / "segmentation" / "configs" / "mask_rcnn_coco.json" config_from_json = SampleConfig.from_json(path_to_config) diff --git a/tests/tensorflow/test_models/retinanet.py b/tests/tensorflow/test_models/retinanet.py index 96fa92cdcfb..be618a740e0 100644 --- a/tests/tensorflow/test_models/retinanet.py +++ b/tests/tensorflow/test_models/retinanet.py @@ -15,7 +15,7 @@ from tests.shared.paths import PROJECT_ROOT -def RetinaNet(input_shape=None): # pylint: disable=W0613 +def RetinaNet(input_shape=None): path_to_config = PROJECT_ROOT / "examples" / "tensorflow" / "object_detection" / "configs" / "retinanet_coco.json" config_from_json = SampleConfig.from_json(path_to_config) diff --git a/tests/tensorflow/test_models/sequential_model.py b/tests/tensorflow/test_models/sequential_model.py index 07c445a59bb..fb30c2b97a5 100644 --- a/tests/tensorflow/test_models/sequential_model.py +++ b/tests/tensorflow/test_models/sequential_model.py @@ -11,7 +11,7 @@ from tensorflow.keras import Sequential from tensorflow.keras import layers -from tensorflow.keras.initializers import Constant # pylint: disable=no-name-in-module +from tensorflow.keras.initializers import Constant def SequentialModel(**kwargs): diff --git a/tests/tensorflow/test_models/shared_layers_model.py b/tests/tensorflow/test_models/shared_layers_model.py index d4f86b7494d..ddbdb498be1 100644 --- a/tests/tensorflow/test_models/shared_layers_model.py +++ b/tests/tensorflow/test_models/shared_layers_model.py @@ -16,7 +16,7 @@ def SharedLayersModel(input_shape): inputs = tf.keras.Input(input_shape) x0 = layers.Conv2D(8, 3, name="c0")(inputs) - # pylint: disable=E1124, E1120 + x0s1, x0s2 = tf.split(x0, 2, axis=-1) x1 = layers.Conv2D(2, 3, name="c1")(x0s1) x2 = layers.Conv2D(2, 3, name="c2")(x0s2) diff --git a/tests/tensorflow/test_models/xception.py b/tests/tensorflow/test_models/xception.py index 89ccbf75d12..e10bbdada18 100644 --- a/tests/tensorflow/test_models/xception.py +++ b/tests/tensorflow/test_models/xception.py @@ -18,7 +18,6 @@ NUM_CLASSES = 1000 -# pylint: disable=R0915 def Xception(input_shape=None): input_shape = imagenet_utils.obtain_input_shape( input_shape, default_size=299, min_size=71, data_format=backend.image_data_format(), require_flatten=True diff --git a/tests/tensorflow/test_sota_checkpoints.py b/tests/tensorflow/test_sota_checkpoints.py index c26fd981983..99ae82190db 100644 --- a/tests/tensorflow/test_sota_checkpoints.py +++ b/tests/tensorflow/test_sota_checkpoints.py @@ -474,7 +474,6 @@ def make_table_row( @pytest.mark.eval @pytest.mark.parametrize("eval_test_struct", RunTest.param_list, ids=RunTest.ids_list) def test_eval(self, sota_checkpoints_dir, sota_data_dir, eval_test_struct: EvalRunParamsStruct): - # pylint: disable=too-many-branches if sota_data_dir is None: pytest.skip("Path to datasets is not set") @@ -574,7 +573,6 @@ def test_eval(self, sota_checkpoints_dir, sota_data_dir, eval_test_struct: EvalR @pytest.mark.oveval @pytest.mark.parametrize("eval_test_struct", RunTest.ov_param_list, ids=RunTest.ov_ids_list) def test_openvino_eval(self, eval_test_struct: EvalRunParamsStruct, sota_checkpoints_dir, ov_data_dir, openvino): - # pylint: disable=too-many-branches if not openvino: pytest.skip() # WA to avoid OS error diff --git a/tests/torch/accuracy_aware_training/test_training_loop.py b/tests/torch/accuracy_aware_training/test_training_loop.py index 30e51d56a3f..aa0f4dbbebf 100644 --- a/tests/torch/accuracy_aware_training/test_training_loop.py +++ b/tests/torch/accuracy_aware_training/test_training_loop.py @@ -227,7 +227,7 @@ def configure_optimizers_fn(): validate_fn=partial(mock_validate_fn, init_step=False), configure_optimizers_fn=configure_optimizers_fn, ) - assert len(acc_aware_training_loop.runner._best_checkpoints) == 0 # pylint: disable=protected-access + assert len(acc_aware_training_loop.runner._best_checkpoints) == 0 possible_checkpoint_compression_rates = ( acc_aware_training_loop.runner.get_compression_rates_with_positive_acc_budget() @@ -552,7 +552,7 @@ def configure_optimizers_fn(): early_stopping_training_loop = EarlyExitCompressionTrainingLoop( config, compression_ctrl, uncompressed_model_accuracy=original_metric, dump_checkpoints=False ) - assert early_stopping_training_loop.runner._best_checkpoint is None # pylint: disable=protected-access + assert early_stopping_training_loop.runner._best_checkpoint is None model = early_stopping_training_loop.run( model, @@ -560,7 +560,7 @@ def configure_optimizers_fn(): validate_fn=partial(mock_validate_fn, init_step=False), configure_optimizers_fn=configure_optimizers_fn, ) - assert early_stopping_training_loop.runner._best_checkpoint is not None # pylint: disable=protected-access + assert early_stopping_training_loop.runner._best_checkpoint is not None @pytest.mark.parametrize( diff --git a/tests/torch/binarization/test_timeout_extension_loader.py b/tests/torch/binarization/test_timeout_extension_loader.py index 7f74c511b0b..5aeccbcf9e6 100644 --- a/tests/torch/binarization/test_timeout_extension_loader.py +++ b/tests/torch/binarization/test_timeout_extension_loader.py @@ -33,7 +33,6 @@ def test_timeout_extension_loader_isolated(tmp_path, use_cuda): os.environ[EXTENSION_LOAD_TIMEOUT_ENV_VAR] = "1" os.environ["TORCH_EXTENSIONS_DIR"] = tmp_path.as_posix() - # pylint: disable=protected-access build_dir = Path(quant_func._loader.get_build_dir()) lock_file = build_dir / "lock" lock_file.touch() diff --git a/tests/torch/conftest.py b/tests/torch/conftest.py index 390af04bf7c..a75b519847a 100644 --- a/tests/torch/conftest.py +++ b/tests/torch/conftest.py @@ -15,13 +15,13 @@ try: import torch -except: # pylint: disable=bare-except # noqa: E722 +except: # noqa: E722 torch = None from nncf.common.quantization.structs import QuantizationMode from tests.shared.case_collection import COMMON_SCOPE_MARKS_VS_OPTIONS from tests.shared.case_collection import skip_marked_cases_if_options_not_specified -from tests.shared.install_fixtures import tmp_venv_with_nncf # pylint:disable=unused-import # noqa: F401 -from tests.shared.logging import nncf_caplog # pylint:disable=unused-import # noqa: F401 +from tests.shared.install_fixtures import tmp_venv_with_nncf # noqa: F401 +from tests.shared.logging import nncf_caplog # noqa: F401 pytest.register_assert_rewrite("tests.torch.helpers") @@ -242,7 +242,7 @@ def runs_subprocess_in_precommit(): # memory which has not been cached (and thus remains reserved) in the owning pytest process by PyTorch, # and the tests below may fail with an OOM. To avoid this, need to call torch.cuda.empty_cache() # each time a GPU-powered subprocess is executed during a test. - # pylint: disable=W0702,W0621 + try: import torch diff --git a/tests/torch/extensions_build_checks.py b/tests/torch/extensions_build_checks.py index d76dc4f1260..2727ba21b54 100644 --- a/tests/torch/extensions_build_checks.py +++ b/tests/torch/extensions_build_checks.py @@ -18,17 +18,13 @@ mode = sys.argv[1] if mode == "cpu": # Do not remove - the import here is for testing purposes. - # pylint: disable=wrong-import-position - from nncf.torch import force_build_cpu_extensions - # pylint: enable=wrong-import-position + from nncf.torch import force_build_cpu_extensions force_build_cpu_extensions() elif mode == "cuda": - # pylint: disable=wrong-import-position from nncf.torch import force_build_cuda_extensions - # pylint: enable=wrong-import-position # Set CUDA Architecture # See cmake/Modules_CUDA_fix/upstream/FindCUDA/select_compute_arch.cmake os.environ["TORCH_CUDA_ARCH_LIST"] = "7.5+PTX" diff --git a/tests/torch/helpers.py b/tests/torch/helpers.py index e89a524bfd4..3705b42f622 100644 --- a/tests/torch/helpers.py +++ b/tests/torch/helpers.py @@ -19,7 +19,7 @@ import numpy as np import onnx import torch -from onnx import numpy_helper # pylint: disable=no-name-in-module +from onnx import numpy_helper from torch import nn from torch.nn import Module from torch.nn import functional as F @@ -46,9 +46,6 @@ TensorType = Union[torch.Tensor, np.ndarray, numbers.Number] -# pylint: disable=no-member - - def fill_conv_weight(conv, value, dim=2): conv.weight.data.fill_(value) # TODO: Fill it right diff --git a/tests/torch/modules/test_rnn.py b/tests/torch/modules/test_rnn.py index 56adecdec8f..dbe87841f75 100644 --- a/tests/torch/modules/test_rnn.py +++ b/tests/torch/modules/test_rnn.py @@ -231,8 +231,8 @@ def test_export_lstm_cell(tmp_path): assert os.path.exists(test_path) onnx_num = 0 - model = onnx.load(test_path) # pylint: disable=no-member - # pylint: disable=no-member + model = onnx.load(test_path) + for node in model.graph.node: if node.op_type == "FakeQuantize": onnx_num += 1 @@ -449,7 +449,7 @@ def test_export_stacked_bi_lstm(tmp_path): assert os.path.exists(test_path) onnx_num = 0 - # pylint: disable=no-member + model = onnx.load(test_path) for node in model.graph.node: if node.op_type == "FakeQuantize": diff --git a/tests/torch/nas/test_all_elasticity.py b/tests/torch/nas/test_all_elasticity.py index 761de0593a3..51fd84aa74e 100644 --- a/tests/torch/nas/test_all_elasticity.py +++ b/tests/torch/nas/test_all_elasticity.py @@ -68,7 +68,7 @@ def test_bn_adaptation_on_minimal_subnet_width_stage(): model, ctrl = create_bnas_model_and_ctrl_by_test_desc(RESNET50_2_MANUAL_BLOCKS_DESC) multi_elasticity_handler = ctrl.multi_elasticity_handler - # pylint: disable=protected-access + bn_adaptation = ctrl._bn_adaptation multi_elasticity_handler.enable_all() diff --git a/tests/torch/nas/test_elastic_depth.py b/tests/torch/nas/test_elastic_depth.py index bf506f05b5b..edf1e580210 100644 --- a/tests/torch/nas/test_elastic_depth.py +++ b/tests/torch/nas/test_elastic_depth.py @@ -72,7 +72,7 @@ def __init__(self, depth=3): def forward(self, x): output = self.conv1(x) - # pylint: disable=protected-access + for name, module in self.branch_with_blocks._modules.items(): if name not in self._skipped_layers: output = module(output) @@ -227,7 +227,7 @@ def test_can_export_model_with_one_skipped_block_resnet18(tmp_path): ctrl.export_model(str(onnx_model_without_block_path)) # load onnx graphs - # pylint:disable=no-member + load_model_fn = onnx.load_model onnx_resnet18_without_one_block = load_model_fn(onnx_model_without_block_path) onnx_resnet18_orig = load_model_fn(orig_onnx_model_path) @@ -534,7 +534,6 @@ def test_check_dinamic_graph_not_grow(): ] compressed_model, _ = create_compressed_model_and_algo_for_test(model, nncf_config) - # pylint: disable=protected-access ctx = compressed_model.nncf.get_tracing_context() ctx.set_elastic_blocks(skipped_blocks) nodes_count = ctx.graph.get_nodes_count() @@ -563,7 +562,7 @@ def test_validate_depth_config(): check = [[1, 4], [1, 3], [2], [0], [1, 9], [1], [2], [3], [2, 3], [5, 6, 7, 8, 9]] valid_1 = [[1, 4], [1], [], [], [1, 9], [1], [], [], [], [9]] - # pylint: disable=protected-access + for i, valid_value in enumerate(valid_1): assert valid_value == depth_handler._remove_inconsistent_blocks(check[i]) diff --git a/tests/torch/nas/test_elastic_kernel.py b/tests/torch/nas/test_elastic_kernel.py index c015104cac7..ad011c193cf 100644 --- a/tests/torch/nas/test_elastic_kernel.py +++ b/tests/torch/nas/test_elastic_kernel.py @@ -96,7 +96,7 @@ def test_elastic_kernel_with_custom_transition_matrix(): kernel_handler, supernet = create_single_conv_kernel_supernet() device = next(iter(supernet.parameters())).device custom_transition_matrix = torch.ones([3**2, 3**2]).to(device) - # pylint: disable=protected-access + elastic_kernel_op = kernel_handler._elastic_kernel_ops[0] elastic_kernel_op.__setattr__(f"{5}to{3}_matrix", Parameter(custom_transition_matrix)) input_ = torch.ones([1, 1, 5, 5]).to(device) diff --git a/tests/torch/nas/test_lr_scheduler.py b/tests/torch/nas/test_lr_scheduler.py index 7e77a8e9ff0..c6dcd351b8a 100644 --- a/tests/torch/nas/test_lr_scheduler.py +++ b/tests/torch/nas/test_lr_scheduler.py @@ -28,7 +28,6 @@ ) -# pylint: disable=protected-access class TestLRScheduler: def test_warmup_lr(self, mocker): warmup_lr = mocker.patch( diff --git a/tests/torch/nas/test_onnx_export.py b/tests/torch/nas/test_onnx_export.py index c4c2de4abae..1429556ad46 100644 --- a/tests/torch/nas/test_onnx_export.py +++ b/tests/torch/nas/test_onnx_export.py @@ -23,7 +23,6 @@ from tests.torch.nas.test_all_elasticity import create_bnas_model_and_ctrl_by_test_desc -# pylint: disable=no-member def check_onnx_weights(ctrl, path_to_onnx, ref_orig_weights, expected_num_nodes): ctrl.export_model(path_to_onnx) onnx_model = onnx.load(path_to_onnx) diff --git a/tests/torch/nas/test_ps_controller.py b/tests/torch/nas/test_ps_controller.py index a1b0ce0275d..3300c003188 100644 --- a/tests/torch/nas/test_ps_controller.py +++ b/tests/torch/nas/test_ps_controller.py @@ -26,7 +26,7 @@ from tests.torch.nas.helpers import move_model_to_cuda_if_available from tests.torch.nas.models.synthetic import ThreeConvModel from tests.torch.nas.models.synthetic import ThreeConvModelMode -from tests.torch.nas.test_scheduler import fixture_schedule_params # pylint: disable=unused-import # noqa: F401 +from tests.torch.nas.test_scheduler import fixture_schedule_params # noqa: F401 class PSControllerTestDesc(NamedTuple): @@ -106,7 +106,6 @@ def run_train(training_ctrl, model, mock_dataloader, calc_loss_fn): return output_storage -# pylint: disable=protected-access class TestProgressiveTrainingController: @pytest.mark.parametrize( "bn_adapt_section_is_called", diff --git a/tests/torch/nas/test_scheduler.py b/tests/torch/nas/test_scheduler.py index 48c844e6299..086fcc19937 100644 --- a/tests/torch/nas/test_scheduler.py +++ b/tests/torch/nas/test_scheduler.py @@ -127,7 +127,7 @@ def test_epoch_step(self, schedule_params, mocker): } ) mock_handler = MultiElasticityHandler(handlers, mock_nncf_network) - # pylint:disable=protected-access + is_handler_enabled_map = mock_handler._is_handler_enabled_map mock_elasticity_ctrl = mocker.stub() mock_elasticity_ctrl.multi_elasticity_handler = mock_handler diff --git a/tests/torch/nas/test_search.py b/tests/torch/nas/test_search.py index 0dc1ee1c374..1a88569a4cf 100644 --- a/tests/torch/nas/test_search.py +++ b/tests/torch/nas/test_search.py @@ -24,7 +24,7 @@ from tests.torch.nas.creators import create_bnas_model_and_ctrl_by_test_desc from tests.torch.nas.creators import create_bootstrap_training_model_and_ctrl from tests.torch.nas.models.synthetic import ThreeConvModel -from tests.torch.nas.test_all_elasticity import fixture_nas_model_name # pylint: disable=unused-import # noqa: F401 +from tests.torch.nas.test_all_elasticity import fixture_nas_model_name # noqa: F401 class SearchTestDesc(NamedTuple): diff --git a/tests/torch/pruning/experimental/test_nodes_grouping.py b/tests/torch/pruning/experimental/test_nodes_grouping.py index 75e00c88894..990a3a0f2c3 100644 --- a/tests/torch/pruning/experimental/test_nodes_grouping.py +++ b/tests/torch/pruning/experimental/test_nodes_grouping.py @@ -140,7 +140,7 @@ class GroupTestDesc: ref_groups: Optional[List[PruningGroup]] = None def __str__(self) -> str: - return self.model_desc.model_name # pylint: disable=no-member + return self.model_desc.model_name SYNTHETIC_DESCS = [ diff --git a/tests/torch/pruning/filter_pruning/test_algo.py b/tests/torch/pruning/filter_pruning/test_algo.py index 6dd544f86ed..723c6a84973 100644 --- a/tests/torch/pruning/filter_pruning/test_algo.py +++ b/tests/torch/pruning/filter_pruning/test_algo.py @@ -445,7 +445,7 @@ def test_collect_output_shapes(model, ref_output_shapes): config["compression"]["pruning_init"] = 0.0 model = model() _, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) - # pylint:disable=protected-access + graph = compression_ctrl._model.nncf.get_original_graph() output_shapes = collect_output_shapes(graph) assert output_shapes == ref_output_shapes @@ -724,7 +724,7 @@ def test_flops_calculator(model_module, all_weights, pruning_flops_target, ref_f assert pruning_algo.current_params_num == ref_params_num # Check num of sparse by node - # pylint:disable=protected-access + num_of_sparse_by_node = pruning_algo._calculate_num_of_sparse_elements_by_node() assert len(num_of_sparse_by_node) == len(refs["num_of_sparse_by_node"]) @@ -820,7 +820,6 @@ def test_func_calculation_flops_for_conv(model): graph = pruned_model.nncf.get_original_graph() - # pylint:disable=protected-access for node_name, ref_shape in compression_controller._output_shapes.items(): # ref_shape get from tracing graph node = graph.get_node_by_name(node_name) @@ -844,7 +843,7 @@ def test_disconnected_graph(): 'DisconectedGraphModel/NNCFConv2d[conv3]/conv2d_0': ((8, 8), 1), 'DisconectedGraphModel/NNCFLinear[fc]/linear_0': ((1, 3), None), } # fmt: skip - # pylint:disable=protected-access + collected_shapes = compression_controller._output_shapes for name, (shape, mask_sum) in nodes_output_mask_map.items(): node = graph.get_node_by_name(name) diff --git a/tests/torch/pruning/filter_pruning/test_flops_pruning.py b/tests/torch/pruning/filter_pruning/test_flops_pruning.py index 05effe99572..ed5b4955b6b 100644 --- a/tests/torch/pruning/filter_pruning/test_flops_pruning.py +++ b/tests/torch/pruning/filter_pruning/test_flops_pruning.py @@ -99,7 +99,7 @@ def test_init_params_for_flops_calculation(model, ref_params): _, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) assert compression_ctrl.nodes_flops == ref_params["nodes_flops"] - # pylint: disable=protected-access + inp_channels, out_channels = get_prunable_layers_in_out_channels(compression_ctrl._graph) assert inp_channels == ref_params["in_channels"] assert out_channels == ref_params["out_channels"] diff --git a/tests/torch/pruning/filter_pruning/test_legr.py b/tests/torch/pruning/filter_pruning/test_legr.py index 5f615badb03..08e316c5a28 100644 --- a/tests/torch/pruning/filter_pruning/test_legr.py +++ b/tests/torch/pruning/filter_pruning/test_legr.py @@ -27,7 +27,6 @@ def create_default_legr_config(): return config -# pylint:disable=protected-access def test_legr_coeffs_loading(tmp_path): file_name = tmp_path / "ranking_coeffs.json" model = PruningTestModel() diff --git a/tests/torch/pruning/helpers.py b/tests/torch/pruning/helpers.py index 6361a48b2f7..e3501aaca91 100644 --- a/tests/torch/pruning/helpers.py +++ b/tests/torch/pruning/helpers.py @@ -24,8 +24,6 @@ from tests.torch.helpers import fill_linear_weight from tests.torch.test_models.pnasnet import CellB -# pylint: disable=too-many-lines - class PruningTestModel(nn.Module): CONV_1_NODE_NAME = "PruningTestModel/NNCFConv2d[conv1]/conv2d_0" diff --git a/tests/torch/pruning/test_model_pruning_analysis.py b/tests/torch/pruning/test_model_pruning_analysis.py index dc113553a3f..93225970ce9 100644 --- a/tests/torch/pruning/test_model_pruning_analysis.py +++ b/tests/torch/pruning/test_model_pruning_analysis.py @@ -8,7 +8,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=too-many-lines + from collections import Counter from functools import partial @@ -70,7 +70,6 @@ from tests.torch.pruning.helpers import get_basic_pruning_config -# pylint: disable=protected-access def create_nncf_model_and_pruning_builder( model: torch.nn.Module, config_params: Dict ) -> Tuple[NNCFNetwork, FilterPruningBuilder]: @@ -957,7 +956,7 @@ def test_nodes_cluster(): # test clean cluster.clean_cluster() - assert cluster.elements == [] # pylint: disable=use-implicit-booleaness-not-comparison + assert cluster.elements == [] assert cluster.importance == 0 diff --git a/tests/torch/pruning/test_utils.py b/tests/torch/pruning/test_utils.py index 7c1ce469a0c..c7860676355 100644 --- a/tests/torch/pruning/test_utils.py +++ b/tests/torch/pruning/test_utils.py @@ -21,7 +21,6 @@ from tests.torch.pruning.helpers import get_basic_pruning_config -# pylint: disable=protected-access @pytest.mark.parametrize( "total,sparsity_rate,multiple_of,ref", [(20, 0.2, None, 4), (20, 0.2, 8, 4), (20, 0.1, 2, 2), (20, 0.1, 5, 0), (20, 0.5, None, 4)], diff --git a/tests/torch/ptq/test_calculation_quantizer_params.py b/tests/torch/ptq/test_calculation_quantizer_params.py index cea666d0065..5b37790349f 100644 --- a/tests/torch/ptq/test_calculation_quantizer_params.py +++ b/tests/torch/ptq/test_calculation_quantizer_params.py @@ -39,9 +39,6 @@ from tests.torch.helpers import get_all_inputs_for_graph_node from tests.torch.helpers import get_nodes_by_type -# pylint: disable=protected-access -# pylint: disable=too-many-function-args - INPUT_SHAPE = (2, 3, 4, 5) diff --git a/tests/torch/ptq/test_fq_params_calculation.py b/tests/torch/ptq/test_fq_params_calculation.py index 1dcb3d5d065..1e12e532634 100644 --- a/tests/torch/ptq/test_fq_params_calculation.py +++ b/tests/torch/ptq/test_fq_params_calculation.py @@ -32,9 +32,6 @@ REFERENCE_SCALES_DIR = TEST_ROOT / "torch" / "data" / "reference_scales" -# pylint: disable=protected-access - - def min_max_quantize_model( original_model: torch.nn.Module, quantization_params: Dict[str, Any] = None ) -> torch.nn.Module: diff --git a/tests/torch/ptq/test_ptq_params.py b/tests/torch/ptq/test_ptq_params.py index cdc09a7b81a..403c94eb536 100644 --- a/tests/torch/ptq/test_ptq_params.py +++ b/tests/torch/ptq/test_ptq_params.py @@ -48,8 +48,6 @@ from tests.torch.ptq.helpers import get_single_conv_nncf_graph from tests.torch.ptq.helpers import get_single_no_weight_matmul_nncf_graph -# pylint: disable=protected-access - def get_hw_patterns(device: TargetDevice = TargetDevice.ANY) -> GraphPattern: return PatternsManager.get_full_hw_pattern_graph(backend=BackendType.TORCH, device=device) diff --git a/tests/torch/ptq/test_quantizer_config.py b/tests/torch/ptq/test_quantizer_config.py index 951f79149d7..2c1a764d30b 100644 --- a/tests/torch/ptq/test_quantizer_config.py +++ b/tests/torch/ptq/test_quantizer_config.py @@ -30,9 +30,6 @@ ParamsCls = TemplateTestQuantizerConfig.TestGetStatisticsCollectorParameters -# pylint: disable=protected-access - - class TestQuantizerConfig(TemplateTestQuantizerConfig): def get_algo_backend(self): return PTMinMaxAlgoBackend() diff --git a/tests/torch/ptq/test_strip.py b/tests/torch/ptq/test_strip.py index eaf59c75abe..e1e068909b0 100644 --- a/tests/torch/ptq/test_strip.py +++ b/tests/torch/ptq/test_strip.py @@ -24,7 +24,6 @@ from tests.torch.helpers import RandomDatasetMock -# pylint: disable=too-many-branches def check_fq(model: NNCFNetwork, striped: bool): compression_module_type = ExtraCompressionModuleType.EXTERNAL_QUANTIZER if model.nncf.is_compression_module_registered(compression_module_type): diff --git a/tests/torch/pytorch_patch_isolated.py b/tests/torch/pytorch_patch_isolated.py index c4648573883..3f347eceb00 100644 --- a/tests/torch/pytorch_patch_isolated.py +++ b/tests/torch/pytorch_patch_isolated.py @@ -34,11 +34,10 @@ def remove_comments_from_source(source): @pytest.mark.skipif(ISOLATION_RUN_ENV_VAR not in os.environ, reason="Should be run via isolation proxy") def test_jit_if_tracing_script_source_equals(): - # pylint: disable=protected-access # Get original torch.jit._script_if_tracing source torch_source = remove_comments_from_source(inspect.getsource(torch.jit._script_if_tracing)) - import nncf.torch # pylint: disable=unused-import # noqa: F401 + import nncf.torch # noqa: F401 # Get torch.jit._script_if_tracing source after patching was performed nncf_source = remove_comments_from_source(inspect.getsource(torch.jit._script_if_tracing)) @@ -69,7 +68,7 @@ def test_jit_script_exception_preserves_patching_isolated(): try: torch.jit.script(compressed_model) # supposed to fail since torch.jit.script does not support NNCF models - except: # pylint:disable=bare-except # noqa: E722 + except: # noqa: E722 pass # torch.nn.Module.__call__ is one of the fundamental patched functions, if the code object points to NNCF code, diff --git a/tests/torch/quantization/extensions/test_timeout_extension_loader.py b/tests/torch/quantization/extensions/test_timeout_extension_loader.py index f28f226045e..81ff5dc3f53 100644 --- a/tests/torch/quantization/extensions/test_timeout_extension_loader.py +++ b/tests/torch/quantization/extensions/test_timeout_extension_loader.py @@ -33,7 +33,6 @@ def test_timeout_extension_loader_isolated(tmp_path, use_cuda): os.environ[EXTENSION_LOAD_TIMEOUT_ENV_VAR] = "1" os.environ["TORCH_EXTENSIONS_DIR"] = tmp_path.as_posix() - # pylint: disable=protected-access build_dir = Path(quant_func._loader.get_build_dir()) lock_file = build_dir / "lock" lock_file.touch() diff --git a/tests/torch/quantization/test_adjust_padding.py b/tests/torch/quantization/test_adjust_padding.py index 857332b0398..e5ef520ab30 100644 --- a/tests/torch/quantization/test_adjust_padding.py +++ b/tests/torch/quantization/test_adjust_padding.py @@ -187,7 +187,7 @@ def test_onnx_export_to_fake_quantize_with_adjust_pad(tmp_path): num_model_nodes = 0 num_adjust_pad_nodes = 0 num_other_nodes = 0 - # pylint:disable=no-member + for node in onnx_model_proto.graph.node: op_type = node.op_type if op_type == "FakeQuantize": diff --git a/tests/torch/quantization/test_algo_quantization.py b/tests/torch/quantization/test_algo_quantization.py index 41abb2ef68e..c3e42f11173 100644 --- a/tests/torch/quantization/test_algo_quantization.py +++ b/tests/torch/quantization/test_algo_quantization.py @@ -67,7 +67,7 @@ def compare_qspecs(qspec: PTQuantizerSpec, quantizer: BaseQuantizer): assert qspec.num_bits == quantizer.num_bits assert isinstance(quantizer, QUANTIZATION_MODULES.get(qspec.mode)) assert qspec.scale_shape == quantizer.scale_shape - # pylint:disable=protected-access + assert qspec.signedness_to_force == quantizer._signedness_to_force diff --git a/tests/torch/quantization/test_hawq_precision_init.py b/tests/torch/quantization/test_hawq_precision_init.py index 155cdbee42d..6ebe2200c39 100644 --- a/tests/torch/quantization/test_hawq_precision_init.py +++ b/tests/torch/quantization/test_hawq_precision_init.py @@ -69,8 +69,6 @@ from tests.torch.quantization.quantization_helpers import get_quantization_config_without_range_init from tests.torch.quantization.quantization_helpers import get_squeezenet_quantization_config from tests.torch.quantization.quantization_helpers import post_compression_test_distr_init - -# pylint:disable=unused-import from tests.torch.test_compressed_graph import get_full_path_to_the_graph from tests.torch.test_models import inception_v3 from tests.torch.test_models import squeezenet1_1 @@ -383,7 +381,6 @@ def test_hawq_precision_init(_seed, dataset_dir, tmp_path, mocker, params): # There may be less traces required to be calculated during HAWQ than there are weightable layers. def side_effect_fn(self, max_iter=500, tolerance=1e-5): - # pylint:disable=protected-access return pregen_traces_for_all_layers[: len(self._parameter_handler.parameters)] mocked_trace.side_effect = side_effect_fn @@ -492,7 +489,6 @@ def test_hawq_on_single_conv_without_quantizers(_seed, dataset_dir, tmp_path, pa sample_normal_patch = mocker.patch(f"{ph_import}.sample_normal_like_params", autospec=True) def mock_sampling_fn(self): - # pylint:disable=protected-access return list(map(lambda x: torch.from_numpy(random_sample(x.shape)).to(device=self._device), self.parameters)) sample_rademacher_patch.side_effect = mock_sampling_fn diff --git a/tests/torch/quantization/test_logarithm_scale.py b/tests/torch/quantization/test_logarithm_scale.py index 96cb6631ca9..41b7ed22fd3 100644 --- a/tests/torch/quantization/test_logarithm_scale.py +++ b/tests/torch/quantization/test_logarithm_scale.py @@ -94,7 +94,7 @@ def test_logarithm_scale_parameter(logarithm_scale_setting_1, logarithm_scale_se sd1 = model1.state_dict() for k, v0 in sd0.items(): - v1 = sd1[k] # pylint: disable=E1136 + v1 = sd1[k] diff = (v1 - v0).abs().sum().item() / v1.numel() assert diff < 1e-6, "symmetric {} logarithm_scales {} param {} is corrupted mean({}-{})={}".format( symmetric, logarithm_scales, k, v0, v1, diff diff --git a/tests/torch/quantization/test_onnx_export.py b/tests/torch/quantization/test_onnx_export.py index 0a857f4530c..dfae2ea966f 100644 --- a/tests/torch/quantization/test_onnx_export.py +++ b/tests/torch/quantization/test_onnx_export.py @@ -52,7 +52,7 @@ def test_onnx_export_to_fake_quantize(tmp_path): num_fq = 0 num_model_nodes = 0 num_other_nodes = 0 - # pylint:disable=no-member + for node in onnx_model_proto.graph.node: op_type = node.op_type if op_type == "FakeQuantize": @@ -78,7 +78,7 @@ def test_onnx_export_to_quantize_dequantize(tmp_path): num_dq = 0 num_model_nodes = 0 num_other_nodes = 0 - # pylint:disable=no-member + for node in onnx_model_proto.graph.node: op_type = node.op_type if op_type == "QuantizeLinear": @@ -123,7 +123,7 @@ def test_onnx_export_to_quantize_dequantize_per_channel( else: quantizer.input_low = torch.nn.Parameter(torch.rand_like(quantizer.input_low)) quantizer.input_range = torch.nn.Parameter(torch.rand_like(quantizer.input_range)) - # pylint: disable=protected-access + quantizer._export_mode = export_mode x = torch.rand(INPUT_TENSOR_SHAPE) @@ -149,9 +149,6 @@ def forward(self, x): return x -# pylint: disable=no-member - - def get_weight_fq_for_conv_node(node: onnx.NodeProto, graph: onnx.GraphProto): weight_input_tensor_id = node.input[1] matches = [x for x in graph.node if weight_input_tensor_id in x.output] @@ -173,7 +170,7 @@ def test_target_compression_idx(tmp_path): model = TargetCompressionIdxTestModel() nncf_config = get_config_for_export_mode(should_be_onnx_standard=False) onnx_model_proto = load_exported_onnx_version(nncf_config, model, path_to_storage_dir=tmp_path) - onnx_graph = onnx_model_proto.graph # pylint:disable=no-member + onnx_graph = onnx_model_proto.graph conv_nodes = get_nodes_by_type(onnx_model_proto, "Conv") assert len(conv_nodes) == 1 conv_node = next(iter(conv_nodes)) @@ -238,7 +235,7 @@ def test_branching_fqs_are_not_chained(tmp_path, export_mode): quantizer_nodes = get_nodes_by_type(onnx_model_proto, target_node_type) # Quantizer nodes should, for this model, immediately be followed by the quantized operation. Chained quantizers # mean that the ONNX export was incorrect. - # pylint:disable=no-member + follower_node_lists = [get_successors(x, onnx_model_proto.graph) for x in quantizer_nodes] follower_nodes = [] for lst in follower_node_lists: @@ -318,10 +315,10 @@ def test_export_quantized_weights_with_middle_quants(tmp_path, is_half_range, qu onnx_checkpoint_path = str(tmp_path / "two_conv_model_int8.onnx") compression_ctrl.export_model(onnx_checkpoint_path) - model_onnx = onnx.load(onnx_checkpoint_path) # pylint: disable=no-member + model_onnx = onnx.load(onnx_checkpoint_path) fq_nodes = get_nodes_by_type(model_onnx, "FakeQuantize") - # pylint:disable=no-member + inputs = [get_all_inputs_for_graph_node(fq_node, model_onnx.graph) for fq_node in fq_nodes] for quantizer, fq_parametres in zip(quantizers, inputs[1::2]): @@ -351,7 +348,7 @@ def test_torch_onnx_export(tmp_path): num_fq = 0 num_model_nodes = 0 num_other_nodes = 0 - # pylint:disable=no-member + for node in onnx_model_proto.graph.node: op_type = node.op_type if op_type == "FakeQuantize": diff --git a/tests/torch/quantization/test_overflow_issue_export.py b/tests/torch/quantization/test_overflow_issue_export.py index 9898d55450b..04d24f9eea9 100644 --- a/tests/torch/quantization/test_overflow_issue_export.py +++ b/tests/torch/quantization/test_overflow_issue_export.py @@ -54,7 +54,7 @@ def test_is_correct_overflow_issue_levels(num_bits, mode, scale_shape, half_rang quantizer = SymmetricQuantizer(qspec) if mode == QuantizationMode.SYMMETRIC else AsymmetricQuantizer(qspec) - assert quantizer._half_range == half_range # pylint: disable=protected-access + assert quantizer._half_range == half_range assert quantizer.levels == assert_vals[0] assert quantizer.level_low == assert_vals[1] assert quantizer.level_high == assert_vals[2] @@ -67,13 +67,13 @@ def helper_to_test_if_overflow_fix_was_applied(nncf_config, target_device): _, compression_ctrl = create_compressed_model_and_algo_for_test(model, nncf_config) for quantizer in compression_ctrl.weight_quantizers.values(): - assert quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert quantizer.quantizer_module_ref._half_range assert quantizer.quantizer_module_ref.levels == 128 assert quantizer.quantizer_module_ref.level_low == -64 assert quantizer.quantizer_module_ref.level_high == 63 for quantizer in compression_ctrl.non_weight_quantizers.values(): - assert not quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert not quantizer.quantizer_module_ref._half_range def helper_to_test_if_overflow_fix_was_applied_only_to_first_conv_later(nncf_config, target_device): @@ -84,11 +84,11 @@ def helper_to_test_if_overflow_fix_was_applied_only_to_first_conv_later(nncf_con for idx, quantizer in enumerate(compression_ctrl.weight_quantizers.values()): if idx == 0: - assert quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert quantizer.quantizer_module_ref._half_range else: - assert not quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert not quantizer.quantizer_module_ref._half_range for quantizer in compression_ctrl.non_weight_quantizers.values(): - assert not quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert not quantizer.quantizer_module_ref._half_range def helper_to_test_if_overflow_fix_wasnt_applied(nncf_config, target_device): @@ -98,9 +98,9 @@ def helper_to_test_if_overflow_fix_wasnt_applied(nncf_config, target_device): _, compression_ctrl = create_compressed_model_and_algo_for_test(model, nncf_config) for quantizer in compression_ctrl.weight_quantizers.values(): - assert not quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert not quantizer.quantizer_module_ref._half_range for quantizer in compression_ctrl.non_weight_quantizers.values(): - assert not quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert not quantizer.quantizer_module_ref._half_range def test_config_option_disable_overflow_fix(): @@ -193,7 +193,7 @@ def are_symmetric_fq_nodes_are_exported_correct_with_overflow_fix(tmp_path, comp with torch.no_grad(): for quantizer in quantizers: assert quantizer.quantizer_module_ref.levels == levels - assert quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert quantizer.quantizer_module_ref._half_range assert quantizer.quantizer_module_ref.level_low == level_low assert quantizer.quantizer_module_ref.level_high == level_high quantizer.quantizer_module_ref.scale = torch.nn.Parameter( @@ -203,11 +203,11 @@ def are_symmetric_fq_nodes_are_exported_correct_with_overflow_fix(tmp_path, comp onnx_checkpoint_path = str(tmp_path / "model.onnx") compression_ctrl.export_model(onnx_checkpoint_path, input_names=["input"]) - onnx_model = onnx.load(onnx_checkpoint_path) # pylint: disable=no-member + onnx_model = onnx.load(onnx_checkpoint_path) # Find weight tensors in ONNX model fq_nodes = get_nodes_by_type(onnx_model, "FakeQuantize") - # pylint:disable=no-member + inputs = [get_all_inputs_for_graph_node(fq_node, onnx_model.graph) for fq_node in fq_nodes] level_high_ratio = (2 * level_high + 1) / level_high @@ -234,7 +234,7 @@ def are_asymmetric_fq_nodes_are_exported_correct_with_overflow_fix(tmp_path, com with torch.no_grad(): for quantizer in quantizers: assert quantizer.quantizer_module_ref.levels == levels - assert quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert quantizer.quantizer_module_ref._half_range assert quantizer.quantizer_module_ref.level_low == level_low assert quantizer.quantizer_module_ref.level_high == level_high quantizer.quantizer_module_ref.input_range = torch.nn.Parameter( @@ -244,11 +244,11 @@ def are_asymmetric_fq_nodes_are_exported_correct_with_overflow_fix(tmp_path, com onnx_checkpoint_path = str(tmp_path / "model.onnx") compression_ctrl.export_model(onnx_checkpoint_path, input_names=["input"]) - onnx_model = onnx.load(onnx_checkpoint_path) # pylint: disable=no-member + onnx_model = onnx.load(onnx_checkpoint_path) # Find weight tensors in ONNX model fq_nodes = get_nodes_by_type(onnx_model, "FakeQuantize") - # pylint:disable=no-member + inputs = [get_all_inputs_for_graph_node(fq_node, onnx_model.graph) for fq_node in fq_nodes] level_high_ratio = (2 * level_high + 1) / level_high @@ -335,16 +335,16 @@ def test_are_qdq_exported_per_tensor_weights_tensors_clipped(tmp_path): assert quantizer.quantizer_module_ref.levels == 128 assert quantizer.quantizer_module_ref.level_low == -64 assert quantizer.quantizer_module_ref.level_high == 63 - assert quantizer.quantizer_module_ref._half_range # pylint: disable=protected-access + assert quantizer.quantizer_module_ref._half_range onnx_checkpoint_path = str(tmp_path / "model.onnx") compression_ctrl.export_model(onnx_checkpoint_path, input_names=["input"], save_format="onnx_13") - onnx_model = onnx.load(onnx_checkpoint_path) # pylint: disable=no-member + onnx_model = onnx.load(onnx_checkpoint_path) # Find weight tensors in ONNX model quantize_nodes = get_nodes_by_type(onnx_model, "QuantizeLinear") - # pylint:disable=no-member + inputs = [get_all_inputs_for_graph_node(fq_node, onnx_model.graph) for fq_node in quantize_nodes] level_high_ratio = 127.0 / 63.0 diff --git a/tests/torch/quantization/test_range_init.py b/tests/torch/quantization/test_range_init.py index 5dec4eb8d06..96f4668e771 100644 --- a/tests/torch/quantization/test_range_init.py +++ b/tests/torch/quantization/test_range_init.py @@ -63,10 +63,6 @@ from tests.torch.quantization.quantization_helpers import get_squeezenet_quantization_config from tests.torch.quantization.quantization_helpers import post_compression_test_distr_init -# pylint:disable=unused-import -# pylint:disable=protected-access -# pylint:disable=too-many-lines - def scale_signed_dumping_worker(gpu, ngpus_per_node, config, tmp_path): distributed_init_test_default(gpu, ngpus_per_node, config) @@ -898,7 +894,6 @@ def __call__(self, *args, **kwargs): return retval -# pylint:disable=redefined-outer-name def test_per_layer_range_init_collectors_are_called_the_required_number_of_times( range_init_call_count_test_struct, mocker ): diff --git a/tests/torch/quantization/test_scheduler.py b/tests/torch/quantization/test_scheduler.py index 9ebcdc7d9a9..25eabf35b92 100644 --- a/tests/torch/quantization/test_scheduler.py +++ b/tests/torch/quantization/test_scheduler.py @@ -46,7 +46,6 @@ def statistics(self, quickly_collected_only: bool = False): class QuantizationCtrlBaseSpy: - # pylint:disable=no-member def __init__(self, mocker): self._mocked_ctrl = QuantizationControllerBaseForTest(mocker.stub) mocker.patch.object(self._mocked_ctrl, "enable_weight_quantization") diff --git a/tests/torch/quantization/test_unified_scales.py b/tests/torch/quantization/test_unified_scales.py index 49544db5b34..f98757f824f 100644 --- a/tests/torch/quantization/test_unified_scales.py +++ b/tests/torch/quantization/test_unified_scales.py @@ -34,8 +34,6 @@ from tests.torch.quantization.quantization_helpers import get_quantization_config_without_range_init from tests.torch.quantization.test_onnx_export import get_successors -# pylint: disable=no-member - def make_op_address_for_coalescing_test(scope_str: str) -> OperationAddress: op_address = OperationAddress.from_str(scope_str) @@ -572,7 +570,6 @@ def group_nodes_by_output_target(nodes: List[onnx.NodeProto], graph: onnx.GraphP return list(output_nodes.values()) def test_unified_scales_are_identical_in_onnx(self, tmp_path): - # pylint:disable=no-member nncf_config = get_quantization_config_without_range_init(model_size=1) nncf_config["compression"]["quantize_outputs"] = True nncf_config["input_info"] = [ @@ -631,7 +628,6 @@ def test_unified_scales_are_identical_in_onnx(self, tmp_path): assert curr_values == ref_values # All inputs for unified scale quantizers must be equal def test_weight_and_act_quantizer_scale_unification(self, tmp_path): - # pylint:disable=no-member nncf_config = get_quantization_config_without_range_init(model_size=1) nncf_config["input_info"] = [ {"sample_size": [1, 5], "type": "long", "filler": "zeros"}, diff --git a/tests/torch/sparsity/magnitude/test_algo.py b/tests/torch/sparsity/magnitude/test_algo.py index 63701aef36c..d0428a4e020 100644 --- a/tests/torch/sparsity/magnitude/test_algo.py +++ b/tests/torch/sparsity/magnitude/test_algo.py @@ -51,7 +51,7 @@ def test_can_create_magnitude_sparse_algo__with_defaults(): nncf_stats = compression_ctrl.statistics() for layer_info in nncf_stats.magnitude_sparsity.thresholds: assert layer_info.threshold == approx(0.24, 0.1) - # pylint: disable=protected-access + assert isinstance(compression_ctrl._weight_importance_fn, type(normed_magnitude)) for sparse_module in sparse_model_conv.values(): diff --git a/tests/torch/sparsity/movement/helpers/run_recipe.py b/tests/torch/sparsity/movement/helpers/run_recipe.py index 261cc1268b7..4afac63c7c8 100644 --- a/tests/torch/sparsity/movement/helpers/run_recipe.py +++ b/tests/torch/sparsity/movement/helpers/run_recipe.py @@ -20,7 +20,6 @@ import torch.nn import torch.nn.functional as F import torch.utils.data -from datasets import Dataset # pylint: disable=no-name-in-module from transformers import AutoModelForAudioClassification from transformers import AutoModelForImageClassification from transformers import AutoModelForSequenceClassification @@ -34,6 +33,7 @@ from transformers import SwinConfig from transformers import Wav2Vec2Config +from datasets import Dataset from nncf import NNCFConfig from nncf.experimental.torch.sparsity.movement.scheduler import MovementSchedulerParams from nncf.torch.dynamic_graph.graph_tracer import ModelInputInfo diff --git a/tests/torch/sparsity/movement/helpers/trainer.py b/tests/torch/sparsity/movement/helpers/trainer.py index 7da241bf712..ffab20c772f 100644 --- a/tests/torch/sparsity/movement/helpers/trainer.py +++ b/tests/torch/sparsity/movement/helpers/trainer.py @@ -14,7 +14,6 @@ import numpy as np import torch -from datasets import Dataset # pylint: disable=no-name-in-module from transformers import TrainingArguments from transformers.trainer import Trainer from transformers.trainer_callback import TrainerCallback @@ -22,6 +21,7 @@ from transformers.trainer_callback import TrainerState from transformers.trainer_utils import PREFIX_CHECKPOINT_DIR +from datasets import Dataset from nncf.api.compression import CompressionAlgorithmController from nncf.common.compression import BaseCompressionAlgorithmController from nncf.common.utils.tensorboard import prepare_for_tensorboard diff --git a/tests/torch/sparsity/movement/helpers/utils.py b/tests/torch/sparsity/movement/helpers/utils.py index c56dd1f6e67..5df93ec24b9 100644 --- a/tests/torch/sparsity/movement/helpers/utils.py +++ b/tests/torch/sparsity/movement/helpers/utils.py @@ -67,7 +67,6 @@ def initialize_sparsifier_parameters_by_linspace( operand.bias_importance.copy_(bias_init_tensor) -# pylint: disable=protected-access def force_update_sparsifier_binary_masks_by_threshold(operand: MovementSparsifier, threshold: Optional[float] = None): if threshold is not None: operand.importance_threshold = threshold diff --git a/tests/torch/sparsity/movement/test_algo.py b/tests/torch/sparsity/movement/test_algo.py index a8f0515e50d..694a56cd4c0 100644 --- a/tests/torch/sparsity/movement/test_algo.py +++ b/tests/torch/sparsity/movement/test_algo.py @@ -730,7 +730,6 @@ def test_adaptive_init_importance_threshold_update(self, tmp_path): ) class CheckInitImportanceThresholdCallback(CompressionCallback): - # pylint: disable=protected-access def on_step_begin(self, args: TrainingArguments, state: TrainerState, control: TrainerControl, **kwargs): super().on_step_begin(args, state, control, **kwargs) if state.global_step < recipe.scheduler_params.warmup_start_epoch * steps_per_epoch: diff --git a/tests/torch/sparsity/movement/test_model_saving.py b/tests/torch/sparsity/movement/test_model_saving.py index c20a5cc6255..557f64cf895 100644 --- a/tests/torch/sparsity/movement/test_model_saving.py +++ b/tests/torch/sparsity/movement/test_model_saving.py @@ -18,7 +18,6 @@ import pytest import torch from addict import Dict -from datasets import Dataset # pylint: disable=no-name-in-module from onnx import numpy_helper from openvino.runtime import Core from openvino.runtime import serialize @@ -29,6 +28,7 @@ from scipy.special import softmax from transformers.trainer_utils import PREFIX_CHECKPOINT_DIR +from datasets import Dataset from nncf.torch import create_compressed_model from nncf.torch.checkpoint_loading import load_state from tests.torch.helpers import PTTensorListComparator @@ -224,7 +224,7 @@ def test_ngraph_pruning(self, tmp_path: Path, desc: dict): # Zero out first 75% elements ctrl.reset_independent_structured_mask() - groups = ctrl._structured_mask_handler._structured_mask_ctx_groups # pylint: disable=protected-access + groups = ctrl._structured_mask_handler._structured_mask_ctx_groups for group in groups: for ctx in group.structured_mask_contexts: shape = ctx.independent_structured_mask.shape diff --git a/tests/torch/sparsity/movement/test_scheduler.py b/tests/torch/sparsity/movement/test_scheduler.py index 81cfb334b79..d5a003885ae 100644 --- a/tests/torch/sparsity/movement/test_scheduler.py +++ b/tests/torch/sparsity/movement/test_scheduler.py @@ -104,7 +104,7 @@ def test_error_on_wrong_config(self, desc: dict): ), ], ) - def test_warn_on_improper_config(self, desc: dict, nncf_caplog): # pylint:disable=redefined-outer-name + def test_warn_on_improper_config(self, desc: dict, nncf_caplog): with nncf_caplog.at_level(logging.WARNING, logger=nncf_logger.name): _ = MovementSchedulerParams.from_dict(desc["params"]) assert desc["match"] in nncf_caplog.text @@ -245,7 +245,6 @@ def test_get_state(self, steps_per_epoch: Optional[int], adaptive_init_threshold "_steps_per_epoch": ref_steps_per_epoch, } - # pylint: disable=protected-access @pytest.mark.parametrize( "steps_per_epoch", [2, 4, 9, None], ids=["epoch3", "epoch1", "epoch0", "epoch0_unknown_steps_per_epoch"] ) @@ -376,7 +375,6 @@ def assert_controller_structured_masking_calls(is_called_once: bool): class TestSchedulerInferStepsPerEpoch: - # pylint: disable=protected-access def test_can_infer_steps_per_epoch(self): params = MovementSchedulerParams( power=2, @@ -456,7 +454,7 @@ def test_set_init_importance_threshold(self, desc: dict): scheduler.step() for minfo in compression_ctrl.sparsified_module_info: force_update_sparsifier_binary_masks_by_threshold(minfo.operand) - init_importance_threshold = scheduler._init_importance_threshold # pylint: disable=protected-access + init_importance_threshold = scheduler._init_importance_threshold assert init_importance_threshold == approx(ref_threshold, abs=1e-4) stat = compression_ctrl.statistics().movement_sparsity assert stat.model_statistics.sparsity_level_for_layers == approx(ref_sparsity, abs=1e-4) @@ -483,5 +481,5 @@ def test_calc_init_threshold_correctness(self, target_sparsity: float, ref_thres for minfo in compression_ctrl.sparsified_module_info: initialize_sparsifier_parameters_by_linspace(minfo.operand, 0.0, 999.0) scheduler: MovementPolynomialThresholdScheduler = compression_ctrl.scheduler - threshold = scheduler._calc_init_threshold_from_controller(target_sparsity) # pylint: disable=protected-access + threshold = scheduler._calc_init_threshold_from_controller(target_sparsity) assert threshold == approx(ref_threshold) diff --git a/tests/torch/sparsity/movement/test_structured_mask.py b/tests/torch/sparsity/movement/test_structured_mask.py index 0349762472e..d3a918ffe69 100644 --- a/tests/torch/sparsity/movement/test_structured_mask.py +++ b/tests/torch/sparsity/movement/test_structured_mask.py @@ -173,9 +173,7 @@ def test_structured_mask_setter_with_wrong_shape(self, is_dependent_mask: bool): f"Some tests may fail with error", ) @pytest.mark.parametrize("is_dependent_mask", [True, False], ids=["dependent", "independent"]) - def test_structured_mask_setter_with_device_change( - self, is_dependent_mask: bool, nncf_caplog - ): # pylint: disable=redefined-outer-name + def test_structured_mask_setter_with_device_change(self, is_dependent_mask: bool, nncf_caplog): mask_name = "dependent_structured_mask" if is_dependent_mask else "independent_structured_mask" operand = MovementSparsifier(mock_linear_nncf_node(1, 1)) ctx = StructuredMaskContext(operand, "linear", (1, 1), True) @@ -346,7 +344,6 @@ def test_string_representation(self, num_contexts: int): class TestStructuredMaskHandler: - # pylint: disable=protected-access @pytest.mark.parametrize( "run_recipe", STRUCTURED_MASK_SUPPORTED_RECIPES, ids=[r.model_family for r in STRUCTURED_MASK_SUPPORTED_RECIPES] ) @@ -425,7 +422,6 @@ def test_report_structured_sparsity(self, tmp_path, mocker, max_num_of_kept_head assert re.fullmatch(r"\[[0-9]+ items\]", item) is not None assert Path(tmp_path, f"{file_name}.csv").is_file() - # pylint: disable=protected-access def _get_handler_from_ctrl(self, compression_ctrl) -> Tuple[StructuredMaskHandler, List[StructuredMaskContext]]: handler = compression_ctrl._structured_mask_handler all_ctxes = [] diff --git a/tests/torch/sparsity/movement/test_training_with_third_party.py b/tests/torch/sparsity/movement/test_training_with_third_party.py index 6286cb6ad07..f353ac6bf33 100644 --- a/tests/torch/sparsity/movement/test_training_with_third_party.py +++ b/tests/torch/sparsity/movement/test_training_with_third_party.py @@ -30,7 +30,6 @@ def temp_folder(tmp_path_factory): @pytest.mark.usefixtures("temp_folder") class TestMovementWithTransformers: - # pylint:disable=redefined-outer-name @pytest.fixture(autouse=True) def setup(self, temp_folder): self.temp_folder = temp_folder diff --git a/tests/torch/sparsity/movement/training_scripts/run_glue.py b/tests/torch/sparsity/movement/training_scripts/run_glue.py index 09a6bf6c737..9ead89557cb 100644 --- a/tests/torch/sparsity/movement/training_scripts/run_glue.py +++ b/tests/torch/sparsity/movement/training_scripts/run_glue.py @@ -12,12 +12,13 @@ from pathlib import Path from typing import Dict, List, Optional, Tuple -import datasets import evaluate import jstyleson import numpy as np from transformers.training_args import ParallelMode +import datasets + # isort: off from nncf import NNCFConfig from nncf.api.compression import CompressionAlgorithmController @@ -144,7 +145,7 @@ def get_compression_logs(self) -> Optional[List[Dict[str, float]]]: def prepare_dataset(args, training_args): - raw_datasets = datasets.load_dataset("glue", args.task_name) # pylint: disable=no-member + raw_datasets = datasets.load_dataset("glue", args.task_name) num_labels = len(raw_datasets["train"].features["label"].names) tokenizer = AutoTokenizer.from_pretrained(args.model_name_or_path) diff --git a/tests/torch/sparsity/rb/test_algo.py b/tests/torch/sparsity/rb/test_algo.py index b5d8e057649..45d83697959 100644 --- a/tests/torch/sparsity/rb/test_algo.py +++ b/tests/torch/sparsity/rb/test_algo.py @@ -84,7 +84,7 @@ def test_can_set_sparse_layers_to_loss(): _, compression_ctrl = create_compressed_model_and_algo_for_test(model, config) loss = compression_ctrl.loss assert isinstance(loss, SparseLoss) - # pylint: disable=protected-access + for layer in loss._sparse_layers: assert isinstance(layer, RBSparsifyingWeight) @@ -221,7 +221,6 @@ def test_create_rb_algo_with_per_layer_loss(): config["compression"] = {"algorithm": "rb_sparsity", "params": {"sparsity_level_setting_mode": "local"}} _, compression_ctrl = create_compressed_model_and_algo_for_test(MockModel(), config) - # pylint: disable=protected-access assert isinstance(compression_ctrl._loss, SparseLossForPerLayerSparsity) @@ -230,7 +229,6 @@ def test_rb_sparsity__can_set_sparsity_level_for_module(): config["compression"] = {"algorithm": "rb_sparsity", "params": {"sparsity_level_setting_mode": "local"}} _, compression_ctrl = create_compressed_model_and_algo_for_test(BasicConvTestModel(), config) - # pylint: disable=protected-access assert list(compression_ctrl._loss.per_layer_target.values())[0] == 1 compression_ctrl.set_sparsity_level(0.7, compression_ctrl.sparsified_module_info[0]) diff --git a/tests/torch/sparsity/test_common.py b/tests/torch/sparsity/test_common.py index 6a2dd30fbd9..24d7ca223ec 100644 --- a/tests/torch/sparsity/test_common.py +++ b/tests/torch/sparsity/test_common.py @@ -360,7 +360,6 @@ def test_scheduler_get_state(scheduler_cls): assert new_scheduler.current_step == 4 assert new_scheduler.current_epoch == 0 if scheduler_cls == PolynomialSparsityScheduler: - # pylint: disable=protected-access assert new_scheduler._steps_per_epoch == 5 if scheduler_cls == AdaptiveSparsityScheduler: assert new_scheduler.num_bad_epochs == 1 diff --git a/tests/torch/test_algo_common.py b/tests/torch/test_algo_common.py index ba405187237..949a5863d30 100644 --- a/tests/torch/test_algo_common.py +++ b/tests/torch/test_algo_common.py @@ -302,8 +302,8 @@ def test_can_export_compressed_model_with_input_output_names(tmp_path): assert os.path.exists(test_path) - onnx_model = onnx.load(test_path) # pylint: disable=no-member - # pylint: disable=no-member + onnx_model = onnx.load(test_path) + curr_input_names = [node.name for node in onnx_model.graph.input] curr_output_names = [node.name for node in onnx_model.graph.output] @@ -326,10 +326,10 @@ def test_can_export_compressed_model_with_specified_domain_for_custom_ops(tmp_pa assert os.path.exists(test_path) - onnx_model = onnx.load(test_path) # pylint: disable=no-member + onnx_model = onnx.load(test_path) count_custom_ops = 0 - # pylint: disable=no-member + for op_node in onnx_model.graph.node: if op_node.op_type == "FakeQuantize": assert op_node.domain == DOMAIN_CUSTOM_OPS_NAME diff --git a/tests/torch/test_api_behavior.py b/tests/torch/test_api_behavior.py index 709d84a5734..1f82a57c2e2 100644 --- a/tests/torch/test_api_behavior.py +++ b/tests/torch/test_api_behavior.py @@ -94,7 +94,6 @@ def test_range_init_is_called( ) # autospec=True will patch the function as an instance method bn_adaptation_spy = mocker.patch("nncf.torch.initialization.DataLoaderBNAdaptationRunner.run") - # pylint:disable=protected-access def fn(self) -> SingleConfigQuantizerSetup: return self._algo.get_quantizer_setup_for_current_state() diff --git a/tests/torch/test_compressed_graph.py b/tests/torch/test_compressed_graph.py index 07dfdbfa458..f63941646ef 100644 --- a/tests/torch/test_compressed_graph.py +++ b/tests/torch/test_compressed_graph.py @@ -86,7 +86,6 @@ def get_basic_quantization_config( return config -# pylint:disable=redefined-outer-name def get_basic_quantization_config_with_hw_config_type(hw_config_type, input_sample_size): config = get_empty_config(input_sample_sizes=input_sample_size) config["target_device"] = hw_config_type @@ -120,7 +119,7 @@ def check_graph(graph: PTNNCFGraph, path_to_dot: str, graph_dir: str, sort_dot_g :param sort_dot_graph: If True the dumped graph will be sorted, if False - otherwise. :return: None """ - # pylint:disable=protected-access + nx_graph = graph.get_graph_for_structure_analysis() path_to_dot = get_full_path_to_the_graph(path_to_dot, graph_dir) compare_nx_graph_with_reference(nx_graph, path_to_dot, sort_dot_graph=sort_dot_graph) @@ -808,9 +807,7 @@ def hw_config_type(request): return type_hw -# pylint:disable=too-many-branches @pytest.mark.parametrize("desc", TEST_HW_MODELS_DESC, ids=[m.model_name for m in TEST_HW_MODELS_DESC]) -# pylint:disable=redefined-outer-name def test_compressed_graph_models_hw(desc, hw_config_type): model = desc.model_builder() config = get_basic_quantization_config_with_hw_config_type( @@ -819,7 +816,6 @@ def test_compressed_graph_models_hw(desc, hw_config_type): input_info_list = create_input_infos(config) compressed_model = NNCFNetwork(model, input_infos=input_info_list) - # pylint:disable=protected-access quantization_builder = QuantizationBuilder(config, should_init=False) single_config_quantizer_setup = quantization_builder._get_single_config_quantizer_setup(compressed_model) sketch_graph = compressed_model.nncf.get_original_graph() @@ -839,7 +835,6 @@ def prepare_potential_quantizer_graph(graph: PTNNCFGraph, quantizer_setup: Singl pre_hooked_quantizers_activations_attr: Dict[NNCFNodeName, Tuple[int, str]] = {} post_hooked_quantizers_activations_attr: Dict[NNCFNodeName, str] = {} - # pylint:disable=protected-access for qp in quantizer_setup.quantization_points.values(): if qp.is_weight_quantization_point(): target_node_name = qp.insertion_point.target_node_name diff --git a/tests/torch/test_graph_building.py b/tests/torch/test_graph_building.py index 859fa6a7157..0c5283d8b4f 100644 --- a/tests/torch/test_graph_building.py +++ b/tests/torch/test_graph_building.py @@ -92,7 +92,7 @@ def forward(self, x): graph = tracer.trace_graph(mod) unique_op_exec_contexts = set() - # pylint:disable=protected-access + for _, node in graph._nx_graph.nodes.items(): node_op_address = node[DynamicGraph.OP_EXEC_CONTEXT_NODE_ATTR].op_address assert node_op_address not in unique_op_exec_contexts @@ -211,7 +211,6 @@ def test_activation_shape_tracing(input_shape: Tuple): (f"8 /{MODEL_OUTPUT_OP_NAME}_0", [final_shape], []), ] for node_id, ref_input_shapes, ref_output_shapes in ref_node_ids_and_io_edge_shapes: - # pylint:disable=protected-access input_edges = graph.get_nncf_graph_pattern_io( [ node_id, diff --git a/tests/torch/test_load_model_state.py b/tests/torch/test_load_model_state.py index 14e2b6786a0..2df68c0b362 100644 --- a/tests/torch/test_load_model_state.py +++ b/tests/torch/test_load_model_state.py @@ -509,7 +509,7 @@ def test_match_key(desc: MatchKeyDesc, mocker, nncf_caplog): num_loaded_layers = len(new_dict) assert num_loaded_layers == desc.num_loaded - # pylint: disable=protected-access + assert key_matcher._processed_keys._keys == desc.processed_keys._keys if desc.expects_error: with pytest.raises(RuntimeError): diff --git a/tests/torch/test_model_transformer.py b/tests/torch/test_model_transformer.py index 4ba712ec18d..c694a94df3d 100644 --- a/tests/torch/test_model_transformer.py +++ b/tests/torch/test_model_transformer.py @@ -152,7 +152,6 @@ def test_single_insertions(self, setup, target_point: PTTargetPoint): self.compressed_model.nncf.insert_at_point(insertion_point, [hook]) - # pylint:disable=protected-access if insertion_point.insertion_type == PTInsertionType.OPERATOR_PRE_HOOK: ctx = self.compressed_model.nncf.get_tracing_context() pre_hook_id = PreHookId(insertion_point.op_address, input_port_id=insertion_point.input_port_id) @@ -177,10 +176,8 @@ def check_order(iterable1: List, iterable2: List, ordering: List): for idx, order in enumerate(ordering): assert iterable1[idx] is iterable2[order] - # pylint:disable=undefined-variable @pytest.mark.parametrize("case", priority_test_cases, ids=[x[1].name + "-" + x[0] for x in priority_test_cases]) def test_priority(self, case, setup): - # pylint:disable=too-many-branches priority_type = case[0] insertion_type = case[1] @@ -232,7 +229,6 @@ def test_priority(self, case, setup): elif priority_type == "different": order = [2, 0, 1] - # pylint:disable=protected-access if insertion_type == TargetType.OPERATOR_PRE_HOOK: ctx = self.compressed_model.nncf.get_tracing_context() pre_hook_id = PreHookId( @@ -536,7 +532,6 @@ def test_quantizer_insertion_transformations(target_type, node_name, input_port_ assert transformed_model.nncf.is_compression_module_registered(compression_module_type) if target_type == TargetType.OPERATION_WITH_WEIGHTS: - # pylint: disable=protected-access op = transformed_model.conv1.pre_ops._modules["0"] assert isinstance(op, UpdateWeight) assert isinstance(op.op, BaseOp) diff --git a/tests/torch/test_models/sr_small_model.py b/tests/torch/test_models/sr_small_model.py index 65b160ca999..dd7cf9302f7 100644 --- a/tests/torch/test_models/sr_small_model.py +++ b/tests/torch/test_models/sr_small_model.py @@ -24,7 +24,6 @@ def __init__(self, channels): in_channels=channels, out_channels=channels, kernel_size=3, stride=1, padding=1, bias=False ) - # pylint: disable=arguments-differ def forward(self, x): identity_data = x output = self.relu(x) @@ -106,7 +105,6 @@ def __init__(self, scale=3, num_of_ch_enc=16, num_of_ch_dec=8, num_of_res_blocks in_channels=num_of_ch_dec, out_channels=3, kernel_size=3, stride=1, padding=1, bias=True ) - # pylint: disable=arguments-differ def forward(self, x): input_ = x[0] cubic = x[1] diff --git a/tests/torch/test_nncf_network.py b/tests/torch/test_nncf_network.py index f7a6bb7b064..fb5ce53fbe2 100644 --- a/tests/torch/test_nncf_network.py +++ b/tests/torch/test_nncf_network.py @@ -140,7 +140,6 @@ def test_weight_normed_modules_are_replaced_correctly(): assert isinstance(wrapped_conv.weight_v, torch.nn.Parameter) assert not isinstance(wrapped_conv.weight, torch.nn.Parameter) - # pylint:disable=protected-access assert len(wrapped_conv._forward_pre_hooks) == 1 @@ -185,7 +184,6 @@ def test_custom_module_registering(): assert RegisteredUserModule in UNWRAPPED_USER_MODULES.registry_dict.values() assert UnregisteredUserModule not in UNWRAPPED_USER_MODULES.registry_dict.values() - # pylint: disable=protected-access modules = [nncf_model.registered_user_module, nncf_model.unregistered_user_module.conv] base_modules = [RegisteredUserModule, torch.nn.Conv2d] names = ["NNCFUserRegisteredUserModule", "NNCFConv2d"] @@ -236,7 +234,6 @@ def test_get_weighted_original_graph_nodes(): assert set(weighted_nodes) == set(ref_weighted_nodes) -# pylint: disable=protected-access def test_get_op_nodes_in_scope(): model = TwoConvTestModel() nncf_model: NNCFNetwork = NNCFNetwork(deepcopy(model), input_infos=[ModelInputInfo([1, 1, 4, 4])]) @@ -360,10 +357,10 @@ def test_setting_attrs(): model = ModelWithAttr() assert model.CLASS_ATTR == 0 assert model.instance_attr == 0 - # pylint:disable=protected-access + assert model._input_infos == 0 nncf_network = NNCFNetwork(model, input_infos=[ModelInputInfo([1])]) - # pylint:disable=protected-access + assert nncf_network._input_infos == 0 nncf_network.instance_attr = 1 @@ -447,8 +444,8 @@ def test_temporary_clean_view(): ) sd_after_tmp_clean_view = sparse_quantized_model.state_dict() for key in old_sd.keys(): - assert key in sd_after_tmp_clean_view # pylint: disable=E1135 - assert torch.all(torch.eq(sd_after_tmp_clean_view[key], old_sd[key])) # pylint: disable=E1136 + assert key in sd_after_tmp_clean_view + assert torch.all(torch.eq(sd_after_tmp_clean_view[key], old_sd[key])) sparse_quantized_model.nncf.rebuild_graph() graph_after_tmp_clean_view = sparse_quantized_model.nncf.get_graph() assert graph_after_tmp_clean_view == old_graph @@ -724,7 +721,7 @@ def test_safety_change_scope_in_get_nncf_modules(): class EmbeddingWithSharedWeights(torch.nn.Embedding): - def forward(self, x, run_as_matmul=False): # pylint: disable=arguments-renamed + def forward(self, x, run_as_matmul=False): if run_as_matmul: return F.linear(x, self.weight) return super().forward(x) diff --git a/tests/torch/test_no_nncf_trace_patching.py b/tests/torch/test_no_nncf_trace_patching.py index da256222491..837faa1ff27 100644 --- a/tests/torch/test_no_nncf_trace_patching.py +++ b/tests/torch/test_no_nncf_trace_patching.py @@ -51,9 +51,9 @@ def test_no_trace_model_patching(): # Not patching anything: all output nodes are traced _, compressed_model = create_compressed_model(TestModel(True), config) - assert len(compressed_model.nncf.get_original_graph().get_output_nodes()) == 2 # pylint: disable=protected-access + assert len(compressed_model.nncf.get_original_graph().get_output_nodes()) == 2 # Patching a function results with no_nncf_trace in method not producing an output node disable_tracing(TestModel.ambiguous_op) _, compressed_model = create_compressed_model(TestModel(False), get_empty_config()) - assert len(compressed_model.nncf.get_original_graph().get_output_nodes()) == 1 # pylint: disable=protected-access + assert len(compressed_model.nncf.get_original_graph().get_output_nodes()) == 1 diff --git a/tests/torch/test_onnx_export.py b/tests/torch/test_onnx_export.py index f5b321e3da3..89c5cc22674 100644 --- a/tests/torch/test_onnx_export.py +++ b/tests/torch/test_onnx_export.py @@ -73,7 +73,6 @@ def test_io_nodes_naming_scheme(tmp_path): assert node.output[0] == f"output.{idx}" -# pylint: disable=protected-access @pytest.mark.parametrize( "save_format, refs", ( @@ -86,7 +85,6 @@ def test_io_nodes_naming_scheme(tmp_path): ), ) def test_exporter_parser_format(save_format: str, refs: Any): - # pylint: disable=broad-except try: save_format, args = PTExporter.parse_format(save_format) except Exception as e: @@ -108,7 +106,7 @@ def test_exported_version(tmp_path: str, save_format: str, ref_opset: int): onnx_checkpoint_path = tmp_path / "model.onnx" compression_ctrl.export_model(onnx_checkpoint_path, save_format) model_proto = onnx.load_model(onnx_checkpoint_path) - # pylint: disable=no-member + assert model_proto.opset_import[0].version == ref_opset diff --git a/tests/torch/test_sanity_sample.py b/tests/torch/test_sanity_sample.py index 9e206c0b127..d0b90dc8bab 100644 --- a/tests/torch/test_sanity_sample.py +++ b/tests/torch/test_sanity_sample.py @@ -487,7 +487,6 @@ def test_cpu_only_mode_produces_cpu_only_model(config, tmp_path, mocker): with set_num_threads_locally(1) if config["sample_type"] == "semantic_segmentation" else nullcontext(): sample.main(arg_list) - # pylint: disable=no-member if config["sample_type"] == "classification": if is_staged_quantization(config["sample_config"]): import examples.torch.classification.staged_quantization_worker as staged_worker diff --git a/tests/torch/test_sanity_third_party.py b/tests/torch/test_sanity_third_party.py index a18a38129bc..85da106eeb6 100644 --- a/tests/torch/test_sanity_third_party.py +++ b/tests/torch/test_sanity_third_party.py @@ -9,7 +9,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint:disable=no-name-in-module + import os import subprocess import sys @@ -112,7 +112,6 @@ def install_env(self, pip_cache_dir): pip_runner.run_pip("install -e .", cwd=PROJECT_ROOT) -# pylint:disable=redefined-outer-name class TestTransformers: @pytest.fixture(autouse=True) def setup(self, temp_folder): diff --git a/tests/torch/test_sota_checkpoints.py b/tests/torch/test_sota_checkpoints.py index d67a3cfd981..4b4b212ed16 100644 --- a/tests/torch/test_sota_checkpoints.py +++ b/tests/torch/test_sota_checkpoints.py @@ -162,7 +162,6 @@ def process_line(decoded_line: str, error_lines: List): err_string = "\n".join(error_lines) if error_lines else None return exit_code, err_string - # pylint:disable=unused-variable @staticmethod def get_onnx_model_file_path(name): onnx_name = str(name + ".onnx") @@ -322,7 +321,6 @@ def threshold_check( within_thresholds = True return color, within_thresholds - # pylint:disable=unused-variable @staticmethod def write_common_metrics_file(per_model_metric_file_dump_path: Path): metric_value = OrderedDict() @@ -499,7 +497,6 @@ def test_eval(self, sota_checkpoints_dir, sota_data_dir, eval_test_struct: EvalR self.color_dict[eval_test_struct.model_name_], is_accuracy_within_thresholds = retval assert is_accuracy_within_thresholds - # pylint:disable=too-many-branches @pytest.mark.convert @pytest.mark.parametrize("eval_test_struct", param_list, ids=ids_list) @pytest.mark.parametrize("onnx_type", ["fq", "q_dq"]) diff --git a/tests/torch/test_tracing_context.py b/tests/torch/test_tracing_context.py index caa6def6252..4f05c75f9bb 100644 --- a/tests/torch/test_tracing_context.py +++ b/tests/torch/test_tracing_context.py @@ -73,7 +73,7 @@ def test_scope_and_call_counters_are_reset_on_exceptions(): model(torch.ones([1])) assert not ctx.module_call_stack assert not ctx.relative_scopes_stack - # pylint:disable=protected-access + assert not ctx._threading.thread_local.operator_counters diff --git a/tests/torch/test_utils.py b/tests/torch/test_utils.py index 00d6cecb62a..e8137af98c1 100644 --- a/tests/torch/test_utils.py +++ b/tests/torch/test_utils.py @@ -58,7 +58,6 @@ def test_training_mode_switcher(_seed, model: nn.Module): randomly_change_model_state(model) saved_state = save_module_state(model) with training_mode_switcher(model, True): - # pylint: disable=unnecessary-pass pass compare_saved_model_state_and_current_model_state(model, saved_state) @@ -80,7 +79,6 @@ def check_were_only_bn_training_state_changed(model: nn.Module, saved_state: _Mo randomly_change_model_state(model) saved_state = save_module_state(model) - # pylint: disable=protected-access with runner._bn_training_state_switcher(): check_were_only_bn_training_state_changed(model, saved_state) diff --git a/tools/benchmark_binarize_layers.py b/tools/benchmark_binarize_layers.py index 3de77a4b86c..229288a321b 100644 --- a/tools/benchmark_binarize_layers.py +++ b/tools/benchmark_binarize_layers.py @@ -32,7 +32,8 @@ # reference impl -# pylint:disable=abstract-method + + class ReferenceXNORBinarize(torch.autograd.Function): @staticmethod def forward(ctx, x): @@ -46,7 +47,6 @@ def backward(ctx: Any, *grad_outputs: Any) -> Any: return grad_outputs[0] -# pylint:disable=abstract-method class ReferenceDOREFABinarize(torch.autograd.Function): @staticmethod def forward(ctx, x): @@ -60,7 +60,6 @@ def backward(ctx: Any, *grad_outputs: Any) -> Any: return grad_outputs[0] -# pylint:disable=abstract-method class ReferenceActivationBinarize(torch.autograd.Function): @staticmethod def forward(ctx, input_, scale, threshold): diff --git a/tools/benchmark_quantize_layers.py b/tools/benchmark_quantize_layers.py index 7d58785daa0..e1554e2a131 100644 --- a/tools/benchmark_quantize_layers.py +++ b/tools/benchmark_quantize_layers.py @@ -216,7 +216,7 @@ def get_module(params_struct: ParamStruct) -> BaseQuantizer: args=(world_size, module, input_size, num_runs, param_struct.dtype, output), ) run_data = output[0] - except: # pylint:disable=bare-except # noqa: E722 + except: # noqa: E722 run_data = {"time": -1} else: run_data = call_fn(module, input_size, param_struct.device, num_runs, dtype=param_struct.dtype) diff --git a/tools/clip_dot.py b/tools/clip_dot.py index e14164a9a20..f4dcac13eb6 100644 --- a/tools/clip_dot.py +++ b/tools/clip_dot.py @@ -9,7 +9,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint:skip-file + import sys from argparse import ArgumentParser diff --git a/tools/collect_pylint_input_files_for_backend.py b/tools/collect_backend_specific_file_names.py similarity index 100% rename from tools/collect_pylint_input_files_for_backend.py rename to tools/collect_backend_specific_file_names.py diff --git a/tools/onnx_tranformer.py b/tools/onnx_tranformer.py index ada970c9195..fdba64fa72f 100644 --- a/tools/onnx_tranformer.py +++ b/tools/onnx_tranformer.py @@ -28,11 +28,11 @@ def main(argv): parser.add_argument("-o", "--output-model", help="Path to output model file", required=True) args = parser.parse_args(args=argv) - model = onnx.load(args.input_model) # pylint: disable=no-member + model = onnx.load(args.input_model) rename_quantize(model) - onnx.save(model, args.output_model) # pylint: disable=no-member + onnx.save(model, args.output_model) if __name__ == "__main__": diff --git a/tools/optimize_tf_graph.py b/tools/optimize_tf_graph.py index b83e1a12066..c4c56cfd2d4 100644 --- a/tools/optimize_tf_graph.py +++ b/tools/optimize_tf_graph.py @@ -26,7 +26,7 @@ def to_frozen_graph(model: tf.keras.Model): func = saving_utils.trace_model_call(model) concrete_func = func.get_concrete_function() - graph_captures = concrete_func.graph._captures # pylint: disable=protected-access + graph_captures = concrete_func.graph._captures captured_inputs = [t_name.name for t_val, t_name in graph_captures.values()] input_names = [ @@ -42,7 +42,7 @@ def to_frozen_graph(model: tf.keras.Model): concrete_func, lower_control_flow=False, aggressive_inlining=True ) graph_def = frozen_func.graph.as_graph_def(add_shapes=True) - with tf.Graph().as_default(): # pylint: disable=not-context-manager + with tf.Graph().as_default(): tf.import_graph_def(graph_def, name="") frozen_graph = tf_optimize_grappler(input_names, output_names, graph_def) diff --git a/tools/pb_to_tb.py b/tools/pb_to_tb.py index 9b418f8dff5..811e094462b 100644 --- a/tools/pb_to_tb.py +++ b/tools/pb_to_tb.py @@ -9,7 +9,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint:skip-file + import shutil from pathlib import Path diff --git a/tools/update_eval_results.py b/tools/update_eval_results.py index 116821c9787..54e31a572ca 100644 --- a/tools/update_eval_results.py +++ b/tools/update_eval_results.py @@ -10,8 +10,6 @@ # limitations under the License. import argparse - -# pylint:skip-file import json import sys from collections import OrderedDict @@ -20,7 +18,6 @@ from pathlib import Path from typing import Dict, List, Optional, Tuple -# pylint:disable=import-error from mdutils import MdUtils from tests.shared.metric_thresholds import DIFF_FP32_MAX_GLOBAL