Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ exclude = [
"src/nncf/quantization/algorithms/accuracy_control/rank_functions.py",
"src/nncf/quantization/algorithms/accuracy_control/ranker.py",
"src/nncf/quantization/algorithms/accuracy_control/subset_selection.py",
"src/nncf/quantization/algorithms/algorithm.py",
"src/nncf/quantization/algorithms/bias_correction/algorithm.py",
"src/nncf/quantization/algorithms/bias_correction/backend.py",
"src/nncf/quantization/algorithms/bias_correction/onnx_backend.py",
"src/nncf/quantization/algorithms/bias_correction/openvino_backend.py",
"src/nncf/quantization/algorithms/bias_correction/torch_fx_backend.py",
Expand Down
2 changes: 1 addition & 1 deletion src/nncf/common/utils/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_available_cpu_count(logical: bool = True) -> int:
return 1


def get_available_memory_amount() -> float:
def get_available_memory_amount() -> int:
"""
:return: Available memory amount (bytes)
"""
Expand Down
11 changes: 6 additions & 5 deletions src/nncf/quantization/algorithms/accuracy_control/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from nncf.quantization.algorithms.accuracy_control.backend import AccuracyControlAlgoBackend
from nncf.quantization.algorithms.accuracy_control.evaluator import Evaluator
from nncf.quantization.algorithms.accuracy_control.evaluator import MetricResults
from nncf.quantization.algorithms.accuracy_control.ranker import GroupToRank
from nncf.quantization.algorithms.accuracy_control.ranker import Ranker

TModel = TypeVar("TModel")
Expand Down Expand Up @@ -110,8 +111,8 @@ class QuantizationAccuracyRestorerReport:
:param num_iterations: Number of iterations performed.
"""

def __init__(self):
self.removed_groups = []
def __init__(self) -> None:
self.removed_groups: list[GroupToRank] = []
self.removed_all = False
self.reached_required_drop = False
self.num_quantized_operations = None
Expand Down Expand Up @@ -355,7 +356,7 @@ def _apply(
break

nncf_logger.info(
f"Accuracy drop with the new quantization scope is {float(current_accuracy_drop)} ({self.drop_type})"
f"Accuracy drop with the new quantization scope is {current_accuracy_drop} ({self.drop_type})"
)

# Continue greedy quantizer remove
Expand Down Expand Up @@ -479,9 +480,9 @@ def _print_report(report: QuantizationAccuracyRestorerReport, max_num_iterations
)

@staticmethod
def _print_completion_message(accuracy_drop: float, drop_type: DropType) -> None:
def _print_completion_message(accuracy_drop: float | None, drop_type: DropType) -> None:
if accuracy_drop is None or accuracy_drop < 0:
reason = "metric of the quantized model is greater than the metric of the initial model"
else:
reason = f"achieved required accuracy drop {float(accuracy_drop)} ({drop_type})"
reason = f"achieved required accuracy drop {accuracy_drop} ({drop_type})"
nncf_logger.info(f"Algorithm completed: {reason}")
14 changes: 7 additions & 7 deletions src/nncf/quantization/algorithms/accuracy_control/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AccuracyControlAlgoBackend(ABC):

@staticmethod
@abstractmethod
def get_op_with_weights_metatypes() -> list[OperatorMetatype]:
def get_op_with_weights_metatypes() -> list[type[OperatorMetatype]]:
"""
Returns a list of operation metatypes that can be reverted to representation
with int8 weights.
Expand All @@ -67,7 +67,7 @@ def get_op_with_weights_metatypes() -> list[OperatorMetatype]:

@staticmethod
@abstractmethod
def get_quantizer_metatypes() -> list[OperatorMetatype]:
def get_quantizer_metatypes() -> list[type[OperatorMetatype]]:
"""
Returns a list of quantizer metatypes.

Expand All @@ -76,7 +76,7 @@ def get_quantizer_metatypes() -> list[OperatorMetatype]:

@staticmethod
@abstractmethod
def get_const_metatypes() -> list[OperatorMetatype]:
def get_const_metatypes() -> list[type[OperatorMetatype]]:
"""
Returns a list of constant metatypes.

Expand All @@ -85,7 +85,7 @@ def get_const_metatypes() -> list[OperatorMetatype]:

@staticmethod
@abstractmethod
def get_quantizable_metatypes() -> list[OperatorMetatype]:
def get_quantizable_metatypes() -> list[type[OperatorMetatype]]:
"""
Returns a list of metatypes for operations that may be quantized.

Expand All @@ -104,7 +104,7 @@ def get_start_nodes_for_activation_path_tracing(nncf_graph: NNCFGraph) -> list[N

@staticmethod
@abstractmethod
def get_quantize_agnostic_metatypes() -> list[OperatorMetatype]:
def get_quantize_agnostic_metatypes() -> list[type[OperatorMetatype]]:
"""
Returns a list of quantize agnostic metatypes.

Expand All @@ -113,7 +113,7 @@ def get_quantize_agnostic_metatypes() -> list[OperatorMetatype]:

@staticmethod
@abstractmethod
def get_shapeof_metatypes() -> list[OperatorMetatype]:
def get_shapeof_metatypes() -> list[type[OperatorMetatype]]:
"""
Returns a list of shape of metatypes.

Expand Down Expand Up @@ -171,7 +171,7 @@ def get_weight_value(node_with_weight: NNCFNode, model: TModel, port_id: int) ->

@staticmethod
@abstractmethod
def get_weight_tensor_port_ids(node: NNCFNode) -> list[int | None]:
def get_weight_tensor_port_ids(node: NNCFNode) -> list[int]:
"""
Returns node's input port indices with weights tensors.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any

import numpy as np
import onnx
Expand Down Expand Up @@ -58,27 +59,27 @@ class ONNXAccuracyControlAlgoBackend(AccuracyControlAlgoBackend):
# Metatypes

@staticmethod
def get_op_with_weights_metatypes() -> list[ONNXOpMetatype]:
def get_op_with_weights_metatypes() -> list[type[ONNXOpMetatype]]:
return OPERATIONS_WITH_WEIGHTS

@staticmethod
def get_quantizer_metatypes() -> list[ONNXOpMetatype]:
def get_quantizer_metatypes() -> list[type[ONNXOpMetatype]]:
return QUANTIZE_DEQUANTIZE_OPERATIONS

@staticmethod
def get_const_metatypes() -> list[ONNXOpMetatype]:
def get_const_metatypes() -> list[type[ONNXOpMetatype]]:
return [onnx_metatypes.ONNXConstantMetatype]

@staticmethod
def get_quantizable_metatypes() -> list[ONNXOpMetatype]:
def get_quantizable_metatypes() -> list[type[ONNXOpMetatype]]:
return INPUTS_QUANTIZABLE_OPERATIONS

@staticmethod
def get_quantize_agnostic_metatypes() -> list[ONNXOpMetatype]:
def get_quantize_agnostic_metatypes() -> list[type[ONNXOpMetatype]]:
return QUANTIZE_AGNOSTIC_OPERATIONS + [onnx_metatypes.ONNXConcatMetatype]

@staticmethod
def get_shapeof_metatypes() -> list[ONNXOpMetatype]:
def get_shapeof_metatypes() -> list[type[ONNXOpMetatype]]:
return [onnx_metatypes.ONNXShapeMetatype]

@staticmethod
Expand All @@ -96,17 +97,17 @@ def is_node_with_weight(node: NNCFNode) -> bool:
return node.metatype in OPERATIONS_WITH_WEIGHTS and node.layer_attributes.has_weight()

@staticmethod
def get_bias_value(node_with_bias: NNCFNode, nncf_graph: NNCFGraph, model: onnx.ModelProto) -> np.ndarray:
def get_bias_value(node_with_bias: NNCFNode, nncf_graph: NNCFGraph, model: onnx.ModelProto) -> np.ndarray[Any, Any]:
return get_bias_value(node_with_bias, model)

@staticmethod
def get_weight_value(node_with_weight: NNCFNode, model: onnx.ModelProto, port_id: int) -> np.ndarray:
def get_weight_value(node_with_weight: NNCFNode, model: onnx.ModelProto, port_id: int) -> np.ndarray[Any, Any]:
assert node_with_weight.layer_attributes.has_weight()
weight_name = node_with_weight.layer_attributes.weight_attrs[port_id]["name"]
return get_tensor_value(model, weight_name)

@staticmethod
def get_weight_tensor_port_ids(node: NNCFNode) -> list[int | None]:
def get_weight_tensor_port_ids(node: NNCFNode) -> list[int]:
return list(node.layer_attributes.weight_attrs.keys())

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# limitations under the License.


from typing import Any

import numpy as np
import openvino as ov
from openvino import Type
Expand Down Expand Up @@ -47,7 +49,7 @@ def __init__(self, model: ov.Model, use_fp32_precision: bool = True):
if use_fp32_precision:
config = {inference_precision: Type.f32}
self._compiled_model = ov.compile_model(model, device_name="CPU", config=config)
self._engine = None
self._engine: OVCompiledModelEngine | None = None

@property
def model_for_inference(self) -> ov.CompiledModel:
Expand All @@ -68,27 +70,27 @@ class OVAccuracyControlAlgoBackend(AccuracyControlAlgoBackend):
# Metatypes

@staticmethod
def get_op_with_weights_metatypes() -> list[OVOpMetatype]:
def get_op_with_weights_metatypes() -> list[type[OVOpMetatype]]:
return OPERATIONS_WITH_WEIGHTS

@staticmethod
def get_quantizer_metatypes() -> list[OVOpMetatype]:
def get_quantizer_metatypes() -> list[type[OVOpMetatype]]:
return FAKE_QUANTIZE_OPERATIONS

@staticmethod
def get_const_metatypes() -> list[OVOpMetatype]:
def get_const_metatypes() -> list[type[OVOpMetatype]]:
return CONSTANT_OPERATIONS

@staticmethod
def get_quantizable_metatypes() -> list[OVOpMetatype]:
def get_quantizable_metatypes() -> list[type[OVOpMetatype]]:
return INPUTS_QUANTIZABLE_OPERATIONS

@staticmethod
def get_quantize_agnostic_metatypes() -> list[OVOpMetatype]:
def get_quantize_agnostic_metatypes() -> list[type[OVOpMetatype]]:
return QUANTIZE_AGNOSTIC_OPERATIONS + [OVConcatMetatype]

@staticmethod
def get_shapeof_metatypes() -> list[OVOpMetatype]:
def get_shapeof_metatypes() -> list[type[OVOpMetatype]]:
return SHAPEOF_OPERATIONS

@staticmethod
Expand All @@ -106,15 +108,15 @@ def is_node_with_weight(node: NNCFNode) -> bool:
return node.metatype in OPERATIONS_WITH_WEIGHTS and isinstance(node.layer_attributes, OVLayerAttributes)

@staticmethod
def get_bias_value(node_with_bias: NNCFNode, nncf_graph: NNCFGraph, model: ov.Model) -> np.ndarray:
def get_bias_value(node_with_bias: NNCFNode, nncf_graph: NNCFGraph, model: ov.Model) -> np.ndarray[Any, Any]:
return get_bias_value(node_with_bias, nncf_graph, model)

@staticmethod
def get_weight_value(node_with_weight: NNCFNode, model: ov.Model, port_id: int) -> np.ndarray:
def get_weight_value(node_with_weight: NNCFNode, model: ov.Model, port_id: int) -> np.ndarray[Any, Any]:
return get_weight_value(node_with_weight, model, port_id)

@staticmethod
def get_weight_tensor_port_ids(node: NNCFNode) -> list[int | None]:
def get_weight_tensor_port_ids(node: NNCFNode) -> list[int]:
return node.layer_attributes.get_const_port_ids()

@staticmethod
Expand Down
Loading