Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into dl/torch/levit
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-lyakhov committed Oct 25, 2023
2 parents 83ed84b + 8c10eea commit c5c58ee
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ install-tensorflow-dev: install-tensorflow-test install-pre-commit install-pylin
pip install -r examples/post_training_quantization/tensorflow/mobilenet_v2/requirements.txt

test-tensorflow:
pytest ${COVERAGE_ARGS} tests/common tests/tensorflow \
pytest ${COVERAGE_ARGS} tests/tensorflow \
--junitxml ${JUNITXML_PATH} \
$(DATA_ARG)

Expand Down Expand Up @@ -128,7 +128,7 @@ install-torch-dev: install-torch-test install-pre-commit install-pylint
pip install -r examples/post_training_quantization/torch/ssd300_vgg16/requirements.txt

test-torch:
pytest ${COVERAGE_ARGS} tests/common tests/torch -m "not weekly and not nightly" --junitxml ${JUNITXML_PATH} $(DATA_ARG)
pytest ${COVERAGE_ARGS} tests/torch -m "not weekly and not nightly" --junitxml ${JUNITXML_PATH} $(DATA_ARG)

test-torch-nightly:
pytest ${COVERAGE_ARGS} tests/torch -m nightly --junitxml ${JUNITXML_PATH} $(DATA_ARG)
Expand Down
8 changes: 4 additions & 4 deletions nncf/quantization/algorithms/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from abc import ABC
from abc import abstractmethod
from typing import Dict, Optional, TypeVar
from typing import List, Optional, TypeVar

from nncf import Dataset
from nncf.common.graph.graph import NNCFGraph
Expand All @@ -28,11 +28,11 @@ class Algorithm(ABC):

@property
@abstractmethod
def available_backends(self) -> Dict[str, BackendType]:
def available_backends(self) -> List[BackendType]:
"""
Returns dictionary of the available backends for the algorithm.
Returns list of the available backends for the algorithm.
:return: Dict of backends supported by the algorithm.
:return: List of backends supported by the algorithm.
"""

@abstractmethod
Expand Down
5 changes: 2 additions & 3 deletions nncf/quantization/algorithms/bias_correction/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from nncf.common.utils.backend import copy_model
from nncf.common.utils.backend import get_backend
from nncf.quantization.algorithms.algorithm import Algorithm
from nncf.quantization.algorithms.bias_correction.backend import ALGO_BACKENDS

TModel = TypeVar("TModel")

Expand Down Expand Up @@ -104,8 +103,8 @@ def __init__(
raise RuntimeError("BiasCorrection algorithm does not support apply_for_all_nodes=True yet")

@property
def available_backends(self) -> Dict[str, BackendType]:
return ALGO_BACKENDS.registry_dict
def available_backends(self) -> List[BackendType]:
return [BackendType.ONNX, BackendType.OPENVINO]

def _set_backend_entity(self, model: TModel) -> None:
"""
Expand Down
2 changes: 0 additions & 2 deletions nncf/quantization/algorithms/bias_correction/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
from nncf.common.graph.transformations.commands import TransformationCommand
from nncf.common.tensor import NNCFTensor
from nncf.common.tensor_statistics.collectors import TensorStatisticCollectorBase
from nncf.common.utils.registry import Registry

TModel = TypeVar("TModel")
OutputType = TypeVar("OutputType")
ALGO_BACKENDS = Registry("algo_backends")


# pylint:disable=too-many-public-methods
Expand Down
3 changes: 0 additions & 3 deletions nncf/quantization/algorithms/bias_correction/onnx_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from nncf.common.graph import NNCFGraph
from nncf.common.graph import NNCFNode
from nncf.common.graph.transformations.commands import TargetType
from nncf.common.utils.backend import BackendType
from nncf.onnx.graph.model_utils import remove_fq_from_inputs
from nncf.onnx.graph.node_utils import get_bias_value
from nncf.onnx.graph.node_utils import is_any_weight_quantized
Expand All @@ -33,12 +32,10 @@
from nncf.onnx.statistics.collectors import ONNXNNCFCollectorTensorProcessor
from nncf.onnx.statistics.collectors import ONNXRawStatisticCollector
from nncf.onnx.tensor import ONNXNNCFTensor
from nncf.quantization.algorithms.bias_correction.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.bias_correction.backend import BiasCorrectionAlgoBackend


# pylint:disable=too-many-public-methods
@ALGO_BACKENDS.register(BackendType.ONNX)
class ONNXBiasCorrectionAlgoBackend(BiasCorrectionAlgoBackend):
@property
def tensor_processor(self) -> ONNXNNCFCollectorTensorProcessor:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from nncf.common.graph import NNCFGraph
from nncf.common.graph import NNCFNode
from nncf.common.graph.transformations.commands import TargetType
from nncf.common.utils.backend import BackendType
from nncf.experimental.common.tensor_statistics.collectors import TensorCollector
from nncf.openvino.graph.metatypes.groups import FAKE_QUANTIZE_OPERATIONS
from nncf.openvino.graph.model_utils import insert_null_biases
Expand All @@ -33,12 +32,10 @@
from nncf.openvino.statistics.collectors import get_mean_statistic_collector
from nncf.openvino.statistics.collectors import get_raw_stat_collector
from nncf.openvino.tensor import OVNNCFTensor
from nncf.quantization.algorithms.bias_correction.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.bias_correction.backend import BiasCorrectionAlgoBackend


# pylint:disable=too-many-public-methods
@ALGO_BACKENDS.register(BackendType.OPENVINO)
class OVBiasCorrectionAlgoBackend(BiasCorrectionAlgoBackend):
@property
def tensor_processor(self) -> OVNNCFCollectorTensorProcessor:
Expand Down
7 changes: 3 additions & 4 deletions nncf/quantization/algorithms/channel_alignment/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, List, Optional, Tuple, TypeVar
from typing import List, Optional, Tuple, TypeVar

import numpy as np

Expand All @@ -28,7 +28,6 @@
from nncf.common.utils.backend import BackendType
from nncf.common.utils.backend import get_backend
from nncf.quantization.algorithms.algorithm import Algorithm
from nncf.quantization.algorithms.channel_alignment.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.channel_alignment.backend import ChannelAlignmentAlgoBackend
from nncf.quantization.algorithms.channel_alignment.backend import LayoutDescriptor

Expand Down Expand Up @@ -75,8 +74,8 @@ def __init__(
self._algorithm_key = f"CA_{hash(self)}"

@property
def available_backends(self) -> Dict[str, BackendType]:
return ALGO_BACKENDS.registry_dict
def available_backends(self) -> List[BackendType]:
return [BackendType.OPENVINO]

def _set_backend_entity(self, model: TModel) -> None:
"""
Expand Down
2 changes: 0 additions & 2 deletions nncf/quantization/algorithms/channel_alignment/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
from nncf.common.graph.transformations.commands import TargetPoint
from nncf.common.graph.transformations.commands import TargetType
from nncf.common.tensor_statistics.collectors import TensorStatisticCollectorBase
from nncf.common.utils.registry import Registry

TModel = TypeVar("TModel")
ALGO_BACKENDS = Registry("algo_backends")


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from nncf.common.graph.layer_attributes import ConvolutionLayerAttributes
from nncf.common.graph.transformations.commands import TargetType
from nncf.common.tensor_statistics.collectors import TensorStatisticCollectorBase
from nncf.common.utils.backend import BackendType
from nncf.experimental.common.tensor_statistics.collectors import MedianAggregator
from nncf.experimental.common.tensor_statistics.collectors import TensorCollector
from nncf.openvino.graph.layer_attributes import OVLayerAttributes
Expand All @@ -37,12 +36,10 @@
from nncf.openvino.statistics.collectors import OVNNCFCollectorTensorProcessor
from nncf.openvino.statistics.collectors import OVQuantileReducer
from nncf.openvino.statistics.statistics import OVMinMaxTensorStatistic
from nncf.quantization.algorithms.channel_alignment.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.channel_alignment.backend import ChannelAlignmentAlgoBackend
from nncf.quantization.algorithms.channel_alignment.backend import LayoutDescriptor


@ALGO_BACKENDS.register(BackendType.OPENVINO)
class OVChannelAlignmentAlgoBackend(ChannelAlignmentAlgoBackend):
@staticmethod
def target_point(target_type: TargetType, target_node_name: str, port_id: int) -> OVTargetPoint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from nncf.experimental.tensor import Tensor
from nncf.experimental.tensor import functions as fns
from nncf.quantization.algorithms.algorithm import Algorithm
from nncf.quantization.algorithms.fast_bias_correction.backend import ALGO_BACKENDS

TModel = TypeVar("TModel")
TTensor = TypeVar("TTensor")
Expand Down Expand Up @@ -92,8 +91,8 @@ def __init__(
raise RuntimeError("FastBiasCorrection algorithm does not support apply_for_all_nodes=True yet")

@property
def available_backends(self) -> Dict[str, BackendType]:
return ALGO_BACKENDS.registry_dict
def available_backends(self) -> List[BackendType]:
return [BackendType.ONNX, BackendType.OPENVINO, BackendType.TORCH]

def _set_backend_entity(self, model: TModel) -> None:
"""
Expand Down
2 changes: 0 additions & 2 deletions nncf/quantization/algorithms/fast_bias_correction/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
from nncf.common.graph.transformations.commands import TargetType
from nncf.common.graph.transformations.commands import TransformationCommand
from nncf.common.tensor_statistics.collectors import TensorStatisticCollectorBase
from nncf.common.utils.registry import Registry
from nncf.experimental.tensor import Tensor

TModel = TypeVar("TModel")
TTensor = TypeVar("TTensor")
OutputType = TypeVar("OutputType")
ALGO_BACKENDS = Registry("algo_backends")


class FastBiasCorrectionAlgoBackend(ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from nncf.common.graph import NNCFGraph
from nncf.common.graph import NNCFNode
from nncf.common.graph.transformations.commands import TargetType
from nncf.common.utils.backend import BackendType
from nncf.experimental.tensor import Tensor
from nncf.onnx.graph.node_utils import get_bias_value
from nncf.onnx.graph.node_utils import is_any_weight_quantized
Expand All @@ -28,11 +27,9 @@
from nncf.onnx.graph.transformations.commands import ONNXNullBiasInsertionCommand
from nncf.onnx.graph.transformations.commands import ONNXTargetPoint
from nncf.onnx.statistics.collectors import ONNXMeanStatisticCollector
from nncf.quantization.algorithms.fast_bias_correction.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.fast_bias_correction.backend import FastBiasCorrectionAlgoBackend


@ALGO_BACKENDS.register(BackendType.ONNX)
class ONNXFastBiasCorrectionAlgoBackend(FastBiasCorrectionAlgoBackend):
@property
def types_to_insert_bias(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from nncf.common.graph import NNCFGraph
from nncf.common.graph import NNCFNode
from nncf.common.graph.transformations.commands import TargetType
from nncf.common.utils.backend import BackendType
from nncf.experimental.common.tensor_statistics.collectors import TensorCollector
from nncf.experimental.tensor import Tensor
from nncf.openvino.graph.metatypes.groups import FAKE_QUANTIZE_OPERATIONS
Expand All @@ -28,11 +27,9 @@
from nncf.openvino.graph.transformations.commands import OVModelExtractionCommand
from nncf.openvino.graph.transformations.commands import OVTargetPoint
from nncf.openvino.statistics.collectors import get_mean_statistic_collector
from nncf.quantization.algorithms.fast_bias_correction.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.fast_bias_correction.backend import FastBiasCorrectionAlgoBackend


@ALGO_BACKENDS.register(BackendType.OPENVINO)
class OVFastBiasCorrectionAlgoBackend(FastBiasCorrectionAlgoBackend):
@staticmethod
def target_point(target_type: TargetType, target_node_name: str, port_id: int) -> OVTargetPoint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
from nncf.common.graph import NNCFNode
from nncf.common.graph.definitions import NNCFGraphNodeType
from nncf.common.graph.transformations.commands import TargetType
from nncf.common.utils.backend import BackendType
from nncf.experimental.common.tensor_statistics.collectors import TensorCollector
from nncf.experimental.tensor import Tensor
from nncf.quantization.algorithms.fast_bias_correction.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.fast_bias_correction.backend import FastBiasCorrectionAlgoBackend
from nncf.torch.graph.transformations.command_creation import create_bias_correction_command
from nncf.torch.graph.transformations.commands import PTBiasCorrectionCommand
Expand All @@ -35,7 +33,6 @@
from nncf.torch.tensor_statistics.collectors import get_mean_statistic_collector


@ALGO_BACKENDS.register(BackendType.TORCH)
class PTFastBiasCorrectionAlgoBackend(FastBiasCorrectionAlgoBackend):
TARGET_TYPE_TO_PT_INS_TYPE_MAP = {
TargetType.PRE_LAYER_OPERATION: TargetType.OPERATOR_PRE_HOOK,
Expand Down
5 changes: 2 additions & 3 deletions nncf/quantization/algorithms/min_max/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
from nncf.quantization.advanced_parameters import QuantizationParameters
from nncf.quantization.advanced_parameters import changes_asdict
from nncf.quantization.algorithms.algorithm import Algorithm
from nncf.quantization.algorithms.min_max.backend import ALGO_BACKENDS
from nncf.quantization.fake_quantize import calculate_quantizer_parameters
from nncf.quantization.fake_quantize import get_quantizer_narrow_range
from nncf.quantization.passes import transform_to_inference_graph
Expand Down Expand Up @@ -177,8 +176,8 @@ def _reset_cache(self):
self._unified_scale_groups = []

@property
def available_backends(self) -> Dict[str, BackendType]:
return ALGO_BACKENDS.registry_dict
def available_backends(self) -> List[BackendType]:
return [BackendType.ONNX, BackendType.OPENVINO, BackendType.TORCH]

def _get_quantizer_constraints(
self, group: QuantizerGroup, preset: QuantizationPreset, quantization_params: Optional[QuantizationParameters]
Expand Down
2 changes: 0 additions & 2 deletions nncf/quantization/algorithms/min_max/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
from nncf.common.quantization.structs import QuantizerConfig
from nncf.common.tensor_statistics.collectors import TensorStatisticCollectorBase
from nncf.common.tensor_statistics.statistics import MinMaxTensorStatistic
from nncf.common.utils.registry import Registry
from nncf.parameters import ModelType
from nncf.parameters import TargetDevice
from nncf.quantization.fake_quantize import FakeQuantizeParameters
from nncf.quantization.range_estimator import RangeEstimatorParameters

TModel = TypeVar("TModel")
ALGO_BACKENDS = Registry("algo_backends")


# pylint:disable=too-many-public-methods
Expand Down
3 changes: 0 additions & 3 deletions nncf/quantization/algorithms/min_max/onnx_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from nncf.common.hardware.config import HWConfig
from nncf.common.quantization.structs import QuantizationMode
from nncf.common.quantization.structs import QuantizerConfig
from nncf.common.utils.backend import BackendType
from nncf.onnx.graph.metatypes import onnx_metatypes as om
from nncf.onnx.graph.metatypes.groups import MATMUL_METATYPES
from nncf.onnx.graph.node_utils import get_input_edges_mapping
Expand All @@ -39,14 +38,12 @@
from nncf.parameters import TargetDevice
from nncf.quantization.advanced_parameters import AggregatorType
from nncf.quantization.advanced_parameters import StatisticsType
from nncf.quantization.algorithms.min_max.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.min_max.backend import MinMaxAlgoBackend
from nncf.quantization.fake_quantize import FakeQuantizeParameters
from nncf.quantization.range_estimator import RangeEstimatorParameters


# pylint:disable=too-many-public-methods
@ALGO_BACKENDS.register(BackendType.ONNX)
class ONNXMinMaxAlgoBackend(MinMaxAlgoBackend):
@property
def mat_mul_metatypes(self) -> List[OperatorMetatype]:
Expand Down
3 changes: 0 additions & 3 deletions nncf/quantization/algorithms/min_max/openvino_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from nncf.common.quantization.structs import QuantizationMode
from nncf.common.quantization.structs import QuantizerConfig
from nncf.common.tensor_statistics.collectors import ReductionAxes
from nncf.common.utils.backend import BackendType
from nncf.experimental.common.tensor_statistics.collectors import AGGREGATORS_MAP
from nncf.experimental.common.tensor_statistics.collectors import TensorCollector
from nncf.openvino.graph.layer_attributes import OVLayerAttributes
Expand All @@ -40,13 +39,11 @@
from nncf.parameters import TargetDevice
from nncf.quantization.advanced_parameters import RangeEstimatorParameters
from nncf.quantization.advanced_parameters import StatisticsType
from nncf.quantization.algorithms.min_max.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.min_max.backend import MinMaxAlgoBackend
from nncf.quantization.fake_quantize import FakeQuantizeParameters


# pylint:disable=too-many-public-methods
@ALGO_BACKENDS.register(BackendType.OPENVINO)
class OVMinMaxAlgoBackend(MinMaxAlgoBackend):
@property
def mat_mul_metatypes(self) -> List[OperatorMetatype]:
Expand Down
3 changes: 0 additions & 3 deletions nncf/quantization/algorithms/min_max/torch_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
from nncf.common.hardware.config import HWConfig
from nncf.common.quantization.structs import QuantizationMode
from nncf.common.quantization.structs import QuantizerConfig
from nncf.common.utils.backend import BackendType
from nncf.experimental.common.tensor_statistics.collectors import AGGREGATORS_MAP
from nncf.experimental.common.tensor_statistics.collectors import TensorCollector
from nncf.parameters import ModelType
from nncf.parameters import TargetDevice
from nncf.quantization.advanced_parameters import StatisticsType
from nncf.quantization.algorithms.min_max.backend import ALGO_BACKENDS
from nncf.quantization.algorithms.min_max.backend import MinMaxAlgoBackend
from nncf.quantization.fake_quantize import FakeQuantizeParameters
from nncf.quantization.range_estimator import RangeEstimatorParameters
Expand All @@ -50,7 +48,6 @@


# pylint:disable=too-many-public-methods
@ALGO_BACKENDS.register(BackendType.TORCH)
class PTMinMaxAlgoBackend(MinMaxAlgoBackend):
TARGET_TYPE_TO_PT_INS_TYPE_MAP = {
TargetType.PRE_LAYER_OPERATION: TargetType.OPERATOR_PRE_HOOK,
Expand Down
Loading

0 comments on commit c5c58ee

Please sign in to comment.