Skip to content

Fixed compression range for asymmetric compression if all values ​​are positive or negative.#4074

Merged
AlexanderDokuchaev merged 57 commits into
openvinotoolkit:developfrom
andreyanufr:aanuf/fix_for_asym
Jun 19, 2026
Merged

Fixed compression range for asymmetric compression if all values ​​are positive or negative.#4074
AlexanderDokuchaev merged 57 commits into
openvinotoolkit:developfrom
andreyanufr:aanuf/fix_for_asym

Conversation

@andreyanufr

@andreyanufr andreyanufr commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Changes

Fixed compression range for asymmetric compression if all values ​​are positive or negative.

Reason for changes

For vector [-22. -21. -20. -19. -18. -17. -16. -15.] current implementation gives decompressed values after integer_quantize_dequantize_weight(..) equal to [-7. -7. -7. -7. -7. -7. -7. -7. ] bacause zero_point before clamp equal to
-22 / scale = -22 * 255/(-15 + 22) = 804 and after clamp is 0, but min value is -22/scale = -804 and max value is -15/scale = -548, and after clamp all values equal to zero.

But if add 0 to range of values: [-22. -21. -20. -19. -18. -17. -16. -15. 0.] then scale = 22/256, zero_point = -255, min_value=-255, max_value=0 and we have correct range.

Related tickets

CVS-186919

Tests

Test examples - success

alexsu52 and others added 30 commits September 2, 2024 13:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a quantization range bug in asymmetric weight compression where input weights whose [min, max] range does not include zero (all-positive or all-negative values) produced degenerate decompressed outputs. The fix forces the quantization range to always span zero by clamping min_values <= 0 and max_values >= 0 before computing the scale and zero point. The change is mirrored in both the reference NumPy/Tensor path and the optimized OpenVINO graph builder.

Changes:

  • In the reference asymmetric path, clamp min_values and max_values so the range always includes zero before calling calculate_scale_zero_point.
  • In the optimized OpenVINO model builder, perform the equivalent opset.minimum/opset.maximum against a 0.0 constant when computing min/max.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/nncf/quantization/algorithms/weight_compression/weight_lowering.py Adds zero-inclusive clamping to min/max inside the asymmetric branch of calculate_integer_quantization_params.
src/nncf/openvino/optimized_functions/models.py Adds equivalent zero-inclusive clamping to min/max in _build_integer_quantization_model, but unconditionally rather than only for asymmetric mode.

Comment thread src/nncf/openvino/optimized_functions/models.py Outdated
Comment on lines +321 to +323
zero = fns.zeros_like(min_values)
min_values = fns.minimum(zero, min_values)
max_values = fns.maximum(zero, max_values)
@andreyanufr andreyanufr marked this pull request as draft May 15, 2026 14:55
@github-actions github-actions Bot added the NNCF OpenVINO Pull requests that updates NNCF OpenVINO label May 21, 2026
@github-actions github-actions Bot added NNCF PT Pull requests that updates NNCF PyTorch NNCF ONNX Pull requests that updates NNCF ONNX labels May 22, 2026
@andreyanufr andreyanufr marked this pull request as ready for review May 22, 2026 13:55
@andreyanufr andreyanufr requested a review from Copilot May 26, 2026 09:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread tests/torch/function_hook/quantization/test_fq_lora.py

@AlexanderDokuchaev AlexanderDokuchaev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please rename PR and run wc and ptq conformance tests

Comment thread tests/torch/function_hook/quantization/test_fq_lora.py Outdated
Comment thread tests/torch/function_hook/quantization/test_weights_compression.py
Comment thread src/nncf/openvino/optimized_functions/models.py
Comment thread src/nncf/openvino/optimized_functions/models.py
@andreyanufr andreyanufr changed the title Aanuf/fix for asym Fixed compression range for asymmetric compression if all values ​​are positive or negative. Jun 8, 2026
@AlexanderDokuchaev AlexanderDokuchaev merged commit f98ec35 into openvinotoolkit:develop Jun 19, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NNCF ONNX Pull requests that updates NNCF ONNX NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants