Skip to content

Conversation

@andreyanufr
Copy link
Collaborator

@andreyanufr andreyanufr commented May 15, 2025

Changes

Implementation of compression to fixed codebook (LUT) values .

Reason for changes

CVS-167084

Related tickets

CVS-167084

Tests

tests/openvino/native/quantization/test_weights_compression.py

https://github.com/openvinotoolkit/nncf/actions/runs/16024264575

alexsu52 and others added 27 commits September 2, 2024 13:22
@github-actions github-actions bot added NNCF PT Pull requests that updates NNCF PyTorch NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF ONNX Pull requests that updates NNCF ONNX labels May 15, 2025
@github-actions github-actions bot removed NNCF PT Pull requests that updates NNCF PyTorch NNCF ONNX Pull requests that updates NNCF ONNX NNCF PTQ Pull requests that updates NNCF PTQ labels Jul 2, 2025
Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv left a comment

Choose a reason for hiding this comment

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

LGTM!

@andreyanufr andreyanufr requested a review from alexsu52 July 3, 2025 11:57
ranks = [advanced_parameters.lora_adapter_rank, advanced_parameters.lora_correction_params.adapter_rank]

if advanced_parameters.codebook_params.codebook is not None:
codebook = Tensor(advanced_parameters.codebook_params.codebook).as_numpy_tensor().data
Copy link
Collaborator

Choose a reason for hiding this comment

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

For what is it need Tensor(advanced_parameters.codebook_params.codebook).as_numpy_tensor().data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be sure that
if (codebook[:-1] >= codebook[1:]).any():
works correctly for all data types.

Comment on lines 457 to 463
return WeightCompressionConfig(
mode=self._mode,
group_size=self._group_size,
codebook_values=get_cb4_quantiles()
if self._mode == CompressWeightsMode.CB4_F8E4M3
else Tensor(self._advanced_parameters.codebook_params.codebook),
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return WeightCompressionConfig(
mode=self._mode,
group_size=self._group_size,
codebook_values=get_cb4_quantiles()
if self._mode == CompressWeightsMode.CB4_F8E4M3
else Tensor(self._advanced_parameters.codebook_params.codebook),
)
codebook_values = get_cb4_quantiles() if self._mode == CompressWeightsMode.CB4_F8E4M3 else Tensor(self._advanced_parameters.codebook_params.codebook)
return WeightCompressionConfig(
mode=self._mode,
group_size=self._group_size,
codebook_values=codebook_values,
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.


scale = fns.max(fns.abs(weight), axis=reduction_axes, keepdims=True)
if config.mode in [CompressWeightsMode.E2M1, CompressWeightsMode.CODEBOOK, CompressWeightsMode.CB4_F8E4M3]:
max_val = 6.0 if config.mode == CompressWeightsMode.E2M1 else max(np.abs(config.get_numpy_codebook()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use nncf.Tensor in common code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

)

if center_of_quantiles is None:
quantiles = np.array(quantiles)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't combine operations with backend specific types and nncf.Tensor in common code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@alexsu52 alexsu52 merged commit 71ae2c1 into openvinotoolkit:develop Jul 10, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Public API-impacting changes documentation Improvements or additions to documentation NNCF OpenVINO Pull requests that updates NNCF OpenVINO

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants