Skip to content

[mypy] Fix mypy issue for some files#4103

Open
AlexanderDokuchaev wants to merge 5 commits into
openvinotoolkit:developfrom
AlexanderDokuchaev:ad/mypy_4
Open

[mypy] Fix mypy issue for some files#4103
AlexanderDokuchaev wants to merge 5 commits into
openvinotoolkit:developfrom
AlexanderDokuchaev:ad/mypy_4

Conversation

@AlexanderDokuchaev

@AlexanderDokuchaev AlexanderDokuchaev commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Changes

Fix some issute from mypy, unfortunalty it's not all, only part (too many issues for one pr).
Add SubgraphData class to use instead of dict

Reason for changes

Code quality

Related tickets

Tests

@github-actions github-actions Bot added NNCF PT Pull requests that updates NNCF PyTorch NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF ONNX Pull requests that updates NNCF ONNX labels Jun 16, 2026
@AlexanderDokuchaev AlexanderDokuchaev marked this pull request as ready for review June 17, 2026 10:49
Copilot AI review requested due to automatic review settings June 17, 2026 10:49
@AlexanderDokuchaev AlexanderDokuchaev requested a review from a team as a code owner June 17, 2026 10:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves type safety and mypy compatibility across several quantization algorithms by tightening type hints, updating backend interfaces, and replacing loosely-typed subgraph dictionaries with a structured SubgraphData dataclass for bias-correction-related test expectations.

Changes:

  • Introduces SubgraphData for bias correction subgraph specification and updates tests to use it.
  • Refines backend/algorithm type hints (e.g., Tensor returns, metatype lists as list[type[...]], explicit container element types).
  • Adjusts bias-correction model extraction command construction for OpenVINO/ONNX backends and updates mypy excludes.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/torch/fx/test_bias_correction.py Updates expected bias-correction subgraph descriptors to use SubgraphData.
tests/openvino/native/test_bias_correction.py Updates expected bias-correction subgraph descriptors to use SubgraphData.
tests/onnx/quantization/test_bias_correction.py Updates expected bias-correction subgraph descriptors to use SubgraphData.
src/nncf/quantization/algorithms/fast_bias_correction/backend.py Tightens typing for ModelTransformer usage in extract_submodel.
src/nncf/quantization/algorithms/fast_bias_correction/algorithm.py Adds/strengthens type annotations for backend entity and intermediate containers.
src/nncf/quantization/algorithms/bias_correction/openvino_backend.py Updates model extraction command construction and bias correction command signature typing.
src/nncf/quantization/algorithms/bias_correction/onnx_backend.py Updates model extraction command construction, typing, and some container annotations.
src/nncf/quantization/algorithms/bias_correction/backend.py Updates backend interface typing (e.g., Tensor return type and added graph param).
src/nncf/quantization/algorithms/bias_correction/algorithm.py Adds SubgraphData and refactors subgraph handling to use the dataclass + improved typing.
src/nncf/quantization/algorithms/accuracy_control/openvino_backend.py Refines type hints for metatype lists, ndarray returns, and weight port ids.
src/nncf/quantization/algorithms/accuracy_control/onnx_backend.py Refines type hints for metatype lists, ndarray returns, and weight port ids.
src/nncf/quantization/algorithms/accuracy_control/backend.py Updates abstract backend API typing for metatype lists and weight port ids.
src/nncf/quantization/algorithms/accuracy_control/algorithm.py Strengthens report typing and makes accuracy-drop logging/type handling more consistent.
src/nncf/common/utils/os.py Fixes return type annotation for available memory to int (bytes).
pyproject.toml Removes some mypy excludes to expand mypy coverage.
Comments suppressed due to low confidence (2)

src/nncf/quantization/algorithms/bias_correction/backend.py:129

  • The docstring still states that the bias is returned in NumPy format, but the method is now typed to return an nncf Tensor. This is misleading for backend implementers and readers.
    def get_bias_value(node: NNCFNode, model: TModel, nncf_graph: NNCFGraph) -> Tensor:
        """
        Returns bias value in the NumPy format of provided node.

        :param node: Node of NNCFGraph with bias value.

src/nncf/quantization/algorithms/bias_correction/algorithm.py:397

  • The docstring still refers to subgraph_data as a dictionary, but it is now a SubgraphData instance.
        Creates the list of the dictionaries that contains the input data for the model execution.

        :param model: TModel instance.
        :param subgraph_data: A dictionary with the necessary data for current node.
        :param statistic_points: StatisticPointsContainer instance.
        :return: List of the dictionaries with the input data.

Comment thread src/nncf/quantization/algorithms/bias_correction/onnx_backend.py
Comment thread src/nncf/quantization/algorithms/bias_correction/algorithm.py
Comment thread src/nncf/quantization/algorithms/bias_correction/algorithm.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NNCF ONNX Pull requests that updates NNCF ONNX NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants