[mypy] Fix mypy issue for some files#4103
Open
AlexanderDokuchaev wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
SubgraphDatafor bias correction subgraph specification and updates tests to use it. - Refines backend/algorithm type hints (e.g.,
Tensorreturns, metatype lists aslist[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_dataas 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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