Skip to content
Draft
Changes from all 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
20 changes: 19 additions & 1 deletion backends/openvino/quantizer/observers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright (c) Intel Corporation
#
# Licensed under the BSD License (the "License"); you may not use this file
Expand All @@ -19,6 +19,9 @@
module_insertion,
node_removal,
)
from nncf.quantization.algorithms.weight_compression.parameters import ( # type: ignore[import-untyped]
CompressedWeight
)
from nncf.quantization.algorithms.weight_compression.config import ( # type: ignore[import-untyped]
WeightCompressionParameters,
)
Expand Down Expand Up @@ -71,11 +74,26 @@
wc_param = self._wc_param
wc_config = wc_param.compression_config
reduction_axes = wc_param.reduction_axes
q_weight, scale, zp = do_integer_quantization(
nncf_compressed_weight = do_integer_quantization(
NNCFTensor(weight), wc_config, reduction_axes=reduction_axes
)

q_weight, scale, zp = None, None, None
if isinstance(nncf_compressed_weight, CompressedWeight):
q_weight = nncf_compressed_weight.tensor
scale = nncf_compressed_weight.scale
zp = nncf_compressed_weight.zero_point
if isinstance(nncf_compressed_weight, tuple):
# depreceate this part. For backwards compatibility with older NNCF commit
q_weight, scale, zp = nncf_compressed_weight

if not all(val is not None for val in (q_weight, scale)):
msg = f"Could not calculate quantization parameters for weight compression observer. " \
f"None values: { {name: val for name, val in [('quantized_weight', q_weight), ('scale', scale)] if val is None} }"
raise ValueError(msg)

zp = zp.data if zp is not None else None
return q_weight.data, scale.data, zp

Check failure on line 96 in backends/openvino/quantizer/observers.py

View workflow job for this annotation

GitHub Actions / lintrunner-mypy

MYPY union-attr

Item "None" of "Any | None" has no attribute "data" To disable, use ` # type: ignore[union-attr]`

def forward(self, x: torch.Tensor) -> torch.Tensor:
return x
Expand Down
Loading