Skip to content

[mypy] Add generic types for registry#4075

Open
AlexanderDokuchaev wants to merge 8 commits into
openvinotoolkit:developfrom
AlexanderDokuchaev:ad/mypy_registry_generic
Open

[mypy] Add generic types for registry#4075
AlexanderDokuchaev wants to merge 8 commits into
openvinotoolkit:developfrom
AlexanderDokuchaev:ad/mypy_registry_generic

Conversation

@AlexanderDokuchaev
Copy link
Copy Markdown
Collaborator

@AlexanderDokuchaev AlexanderDokuchaev commented May 15, 2026

Changes

Add generic type for Registry class
Removed is_subtype argument from OperatorMetatypeRegistry.registry method, cause it was need only for legacy operation types.
Removed add_name_as_attr as not used.
Changes names of registry objects to be more informable.

Reason for changes

Code quality

Related tickets

Tests

@AlexanderDokuchaev AlexanderDokuchaev marked this pull request as ready for review May 15, 2026 16:01
@AlexanderDokuchaev AlexanderDokuchaev requested a review from a team as a code owner May 15, 2026 16:01
Copilot AI review requested due to automatic review settings May 15, 2026 16:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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 Registry a Generic[TKey, TObject] with typed registry_dict, get(), and values().
  • 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

  • PTDepthwiseConv1dSubtype defines hw_config_name (singular), but the framework consistently reads op_meta.hw_config_names (see e.g. nncf/common/hardware/config.py). As a result, this metatype will have an empty hw_config_names and may be treated as unspecified in HW config / quantization logic. Rename the attribute to hw_config_names for 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"]}

Comment thread src/nncf/common/utils/registry.py
Comment thread src/nncf/onnx/hardware/fused_patterns.py
Copy link
Copy Markdown
Collaborator

@daniil-lyakhov daniil-lyakhov left a comment

Choose a reason for hiding this comment

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

Looks good, maybe we could allign the get_subtypes method across backends? Torch does list copy, and other backends don't. Otherwise ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants