[mypy] Add generic types for registry#4075
Open
AlexanderDokuchaev wants to merge 8 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves static typing (mypy) across NNCF’s registry-based pattern/metatype registration by making Registry generic, updating pattern registries to use explicit key/value types, and simplifying pattern retrieval in the patterns manager.
Changes:
- Made
RegistryaGeneric[TKey, TObject]with typedregistry_dict,get(), andvalues(). - Added typed registries for ignored/hw-fused pattern creators across Torch/ONNX/OpenVINO (
Callable[[], GraphPattern]) and adjusted related helper signatures. - Updated operator metatype registries/usages to work without
is_subtype, and expanded mypy coverage to include the updated pattern modules.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/nncf/torch/quantization/ignored_patterns.py | Types PT_IGNORED_PATTERNS and metatype-list parameters for mypy. |
| src/nncf/torch/hardware/fused_patterns.py | Types PT_HW_FUSED_PATTERNS registry as pattern-name → creator callable. |
| src/nncf/torch/graph/operator_metatypes.py | Removes is_subtype usage in metatype registration decorators. |
| src/nncf/openvino/quantization/ignored_patterns.py | Types OPENVINO_IGNORED_PATTERNS and metatype-list parameters using the common OperatorMetatype. |
| src/nncf/openvino/hardware/fused_patterns.py | Types OPENVINO_HW_FUSED_PATTERNS and adds a missing -> GraphPattern annotation. |
| src/nncf/openvino/graph/metatypes/openvino_metatypes.py | Removes is_subtype usage in metatype registration decorators. |
| src/nncf/onnx/quantization/ignored_patterns.py | Types ONNX_IGNORED_PATTERNS registry as pattern-name → creator callable. |
| src/nncf/onnx/hardware/fused_patterns.py | Types ONNX_HW_FUSED_PATTERNS registry as pattern-name → creator callable. |
| src/nncf/onnx/graph/metatypes/onnx_metatypes.py | Removes is_subtype usage in metatype registration decorators. |
| src/nncf/common/utils/registry.py | Introduces generic Registry[TKey, TObject] and updates method signatures accordingly. |
| src/nncf/common/graph/patterns/manager.py | Removes redundant casts by relying on typed registries’ registry_dict. |
| src/nncf/common/graph/operator_metatypes.py | Types OperatorMetatypeRegistry and updates registration logic to align with generic Registry. |
| pyproject.toml | Adds additional pattern modules to mypy’s files list for strict checking. |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/nncf/torch/graph/operator_metatypes.py:185
PTDepthwiseConv1dSubtypedefineshw_config_name(singular), but the framework consistently readsop_meta.hw_config_names(see e.g.nncf/common/hardware/config.py). As a result, this metatype will have an emptyhw_config_namesand may be treated as unspecified in HW config / quantization logic. Rename the attribute tohw_config_namesfor consistency and correct behavior.
@PT_OPERATOR_METATYPES.register()
class PTDepthwiseConv1dSubtype(PTDepthwiseConvOperatorSubtype):
name = "Conv1DOp"
hw_config_name = [HWOpName.DEPTHWISE_CONVOLUTION]
module_to_function_names = {NamespaceTarget.TORCH_NN_FUNCTIONAL: ["conv1d"]}
d03652d to
75e35e4
Compare
anzr299
approved these changes
May 19, 2026
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
Add generic type for Registry class
Removed
is_subtypeargument fromOperatorMetatypeRegistry.registrymethod, cause it was need only for legacy operation types.Removed
add_name_as_attras not used.Changes names of registry objects to be more informable.
Reason for changes
Code quality
Related tickets
Tests