Skip to content

Commit 2108986

Browse files
anzr299Copilotsuryasidd
authored
[OpenVINO] Pin NNCF to a PyPi Version (pytorch#18684)
### Summary 1. Pin NNCF to a pypi version. 2. Fix breaking changes. A recent change in an NNCF function, which returns quantization parameters, breaks the OpenVINO quantizer observers. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Surya Siddharth Pemmaraju <surya.siddharth.pemmaraju@intel.com>
1 parent 45ff0bd commit 2108986

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎backends/openvino/quantizer/observers.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
from nncf.quantization.algorithms.weight_compression.config import ( # type: ignore[import-untyped]
2323
WeightCompressionParameters,
2424
)
25+
from nncf.quantization.algorithms.weight_compression.parameters import ( # type: ignore[import-untyped]
26+
CompressedWeight,
27+
)
2528
from nncf.quantization.algorithms.weight_compression.weight_lowering import ( # type: ignore[import-untyped]
2629
do_integer_quantization,
2730
)
@@ -71,9 +74,26 @@ def calculate_qparams( # type: ignore[override]
7174
wc_param = self._wc_param
7275
wc_config = wc_param.compression_config
7376
reduction_axes = wc_param.reduction_axes
74-
q_weight, scale, zp = do_integer_quantization(
77+
nncf_compressed_weight = do_integer_quantization(
7578
NNCFTensor(weight), wc_config, reduction_axes=reduction_axes
7679
)
80+
81+
q_weight, scale, zp = None, None, None
82+
if not isinstance(nncf_compressed_weight, CompressedWeight):
83+
raise TypeError(
84+
f"Expected the output of weight compression to be of type CompressedWeight, but got {type(nncf_compressed_weight)}"
85+
)
86+
q_weight = nncf_compressed_weight.tensor
87+
scale = nncf_compressed_weight.scale
88+
zp = nncf_compressed_weight.zero_point
89+
90+
if not all(val is not None for val in (q_weight, scale)):
91+
msg = (
92+
f"Could not calculate quantization parameters for weight compression observer. "
93+
f"None values: { {name: val for name, val in [('quantized_weight', q_weight), ('scale', scale)] if val is None} }"
94+
)
95+
raise ValueError(msg)
96+
7797
zp = zp.data if zp is not None else None
7898
return q_weight.data, scale.data, zp
7999

‎backends/openvino/requirements.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
git+https://github.com/openvinotoolkit/nncf@b101e7e#egg=nncf
1+
nncf==3.1.0

0 commit comments

Comments
 (0)