Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MinMax algorithm for OpenVINO backend #1444

Merged
merged 33 commits into from
Jan 19, 2023

Conversation

l-bat
Copy link
Collaborator

@l-bat l-bat commented Dec 20, 2022

Changes

  • Added OpenVINO backend support for the MinMax algorithm.

Reason for changes

  • Extension of the set of algorithms for the OpenVINO backend.

Related tickets

  • 98622

Tests

  • TBD

@github-actions github-actions bot added experimental NNCF Common Pull request that updates NNCF Common NNCF OpenVINO Pull requests that updates NNCF OpenVINO labels Dec 20, 2022
@l-bat l-bat marked this pull request as draft December 20, 2022 11:48
@@ -31,18 +31,42 @@ def get_all_aliases(cls) -> List[str]:
return cls.op_names


@dataclass
class OpWeightDef:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is needed at all to keep only one property of operation? If not, maybe it is more reasonable just to keep his inside operation, e.g. to have weight_channel_axis within the operation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

deleted

"""
Contains the information about the weight of the operation.

:param weight_channel_axis: Axis for weight per-channel quantization, meaning the number of output filters.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest using the plural term, like weights and activations everywhere because this is what we use to describe the DL model content, not weight and activation of the model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Class has been deleted

@@ -44,14 +45,19 @@ def transform(self, transformation_layout: TransformationLayout) -> ov.Model:
:param transformations: lisf of the TransformationCommand transformations.
"""
output_insert_transformations = []
quantizer_insert_transformations = []
Copy link
Contributor

Choose a reason for hiding this comment

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

following the name below _apply_quantizer_insertion_transformations, you should call it like quantizer_insertion_transformations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

:param graph: NNCFGraph.
"""
ov_dtype = node.get_element_type().get_type_name()
nncf_dtype = GraphConverter.convert_ov_dtype_to_nncf_dtype(ov_dtype)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest renaming convert_ov_dtype_to_nncf_dtype to convert_to_nncf_dtype

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed

ov_dtype = node.get_element_type().get_type_name()
nncf_dtype = GraphConverter.convert_ov_dtype_to_nncf_dtype(ov_dtype)
node_type = node.get_type_name()
metatype = OV_OPERATION_METATYPES.get_operator_metatype_by_op_name(node_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Some discrepancy between the naming operation and operator.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

model_type: Optional[ModelType] = None,
ignored_scope: Optional[IgnoredScope] = None) -> ov.Model:
"""
Implementation of the `quantize()` method for the OpenVINO backend via the Model API.
Copy link
Contributor

@AlexKoff88 AlexKoff88 Dec 20, 2022

Choose a reason for hiding this comment

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

Model API is something that exists in OMZ. I would call it like ...for the OpenVINO backend via the OpenVINO Runtime API.

from nncf.experimental.openvino_native.statistics.statistics import OVMeanTensorStatistic


class OVNNCFCollectorTensorProcessor(NNCFCollectorTensorProcessor):
Copy link
Contributor

Choose a reason for hiding this comment

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

Did I get right that we use an external statistic collection mechanism now? Any plans for the in-place statistics?

Copy link
Contributor

Choose a reason for hiding this comment

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

@l-bat, could you file a ticket based on this comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ticket: 100927

@l-bat l-bat force-pushed the lb/quant_ov_native branch 2 times, most recently from 51d3503 to 7a38b99 Compare January 4, 2023 14:18
@l-bat l-bat marked this pull request as ready for review January 9, 2023 16:18
@l-bat l-bat force-pushed the lb/quant_ov_native branch from 7107431 to d73e13d Compare January 9, 2023 16:32
Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

Cool staff! Please rebase your PR on develop.

from nncf.experimental.openvino_native.statistics.statistics import OVMeanTensorStatistic


class OVNNCFCollectorTensorProcessor(NNCFCollectorTensorProcessor):
Copy link
Contributor

Choose a reason for hiding this comment

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

@l-bat, could you file a ticket based on this comment?

@l-bat l-bat force-pushed the lb/quant_ov_native branch from eddd407 to 2393314 Compare January 16, 2023 14:09
Copy link
Collaborator

@nikita-malininn nikita-malininn left a comment

Choose a reason for hiding this comment

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

Looks great 👍

Comment on lines 15 to 16
from dataclasses import dataclass
import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from dataclasses import dataclass
import numpy as np
from dataclasses import dataclass
import numpy as np

@@ -11,15 +11,20 @@
limitations under the License.
"""
import os
import json
Copy link
Contributor

Choose a reason for hiding this comment

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

Imports should be grouped in the following order:

  • Standard library imports.
  • Related third-party imports.
  • Local application/library-specific imports.

You should put a blank line between each group of imports.

https://github.com/openvinotoolkit/nncf/blob/develop/docs/styleguide/PyGuide.md#22-imports

@l-bat l-bat force-pushed the lb/quant_ov_native branch 2 times, most recently from 9a38c1b to 803b9fc Compare January 18, 2023 17:25
@l-bat l-bat force-pushed the lb/quant_ov_native branch from 803b9fc to 40d14d4 Compare January 18, 2023 18:05
Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

LGTM. Please, reply on minor comments from my side.

@l-bat
Copy link
Collaborator Author

l-bat commented Jan 19, 2023

run tensorflow pre-commit tests

@@ -37,27 +52,40 @@ def __init__(self, model: ov.Model):
super().__init__(model)
self._model = model.clone()
self.name_to_node_mapping = {op.get_friendly_name(): op for op in self._model.get_ops()}
self._model_precision = ModelPrecision.FP32
Copy link
Contributor

Choose a reason for hiding this comment

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

Even after MO we can have mixed precision when some subgraphs can be still in FP32 while most of the model is in FP16. I wonder why precision is so important on the model level.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found the answer below but still, I am not sure that we can judge based on the type of the first constant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ticket: 101738

return nncf_graph


class OVWeightedLayerAttributes(BaseLayerAttributes):
Copy link
Contributor

Choose a reason for hiding this comment

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

The name does not reflect the content. It can be OVConstPortId or so.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I promise I will rename it in the next PR

@alexsu52 alexsu52 merged commit 8079233 into openvinotoolkit:develop Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental NNCF Common Pull request that updates NNCF Common NNCF OpenVINO Pull requests that updates NNCF OpenVINO
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants