-
Notifications
You must be signed in to change notification settings - Fork 284
Rework HWConfig #3793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AlexanderDokuchaev
merged 7 commits into
openvinotoolkit:develop
from
AlexanderDokuchaev:ad/rework_hw
Jan 5, 2026
Merged
Rework HWConfig #3793
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c40eb5f
init
AlexanderDokuchaev d766f56
Merge branch 'develop' into ad/rework_hw
AlexanderDokuchaev 03eff80
t
AlexanderDokuchaev 4613019
Merge branch 'develop' into ad/rework_hw
AlexanderDokuchaev 180cc53
Merge branch 'develop' into ad/rework_hw
AlexanderDokuchaev aa8494e
Merge branch 'develop' into ad/rework_hw
AlexanderDokuchaev 02d6e37
c
AlexanderDokuchaev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Copyright (c) 2025 Intel Corporation | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from dataclasses import dataclass | ||
| from dataclasses import field | ||
| from typing import Any | ||
|
|
||
| from nncf.common.quantization.structs import QuantizationScheme | ||
| from nncf.common.quantization.structs import QuantizerConfig | ||
| from nncf.parameters import StrEnum | ||
|
|
||
| SCALES = "scales" | ||
| UNIFIED = "unified" | ||
| ADJUST_PADDING = "adjust_padding" | ||
|
|
||
|
|
||
| class Granularity(StrEnum): | ||
| PER_CHANNEL = "per_channel" | ||
| PER_TENSOR = "per_tensor" | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True, slots=True) | ||
| class QConfigSpace: | ||
| """ | ||
| A class to represent the configuration space for quantization. | ||
|
|
||
| :param bits: Number of bits for quantization. | ||
| :param mode: Available quantization schemes. | ||
| :param granularity: Granularity options for quantization. | ||
| :param narrow_range: Indicates narrow range quantization. | ||
| :param signedness_to_force: Optional signedness enforcement. | ||
| """ | ||
|
|
||
| bits: int | ||
| mode: tuple[QuantizationScheme, ...] | ||
| granularity: tuple[Granularity, ...] | ||
| narrow_range: tuple[bool, ...] | ||
| signedness_to_force: bool | None = None | ||
|
|
||
| def get_all_qconfigs(self) -> list[QuantizerConfig]: | ||
| """ | ||
| Generate a list of all possible QuantizerConfig instances based on the current | ||
| settings of mode, granularity, narrow_range, and other parameters. | ||
|
|
||
| :return: A list of QuantizerConfig objects, each representing | ||
| a unique combination of the quantization parameters. | ||
| """ | ||
| ret = [] | ||
| for mode in self.mode: | ||
| for granularity in self.granularity: | ||
| for narrow_range in self.narrow_range: | ||
| ret.append( | ||
| QuantizerConfig( | ||
| num_bits=self.bits, | ||
| mode=mode, | ||
| per_channel=granularity == Granularity.PER_CHANNEL, | ||
| narrow_range=narrow_range, | ||
| signedness_to_force=self.signedness_to_force, | ||
| ) | ||
| ) | ||
| return ret | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True, slots=True) | ||
| class OpDesc: | ||
| """ | ||
| Represents the description of an operation. | ||
|
|
||
| :param type: The type of the operation. | ||
| :param activations: A tuple containing the quantization configuration for the activations of the operation. | ||
| :param weights: A tuple containing the quantization configuration for the weights of the operation. | ||
| :param attributes: A dictionary of additional attributes. | ||
| """ | ||
|
|
||
| type: str | ||
| activations: tuple[QConfigSpace, ...] = field(default_factory=tuple) | ||
| weights: tuple[QConfigSpace, ...] = field(default_factory=tuple) | ||
| attributes: dict[str, Any] = field(default_factory=dict) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # Copyright (c) 2025 Intel Corporation | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| from nncf.common.hardware.defines import Granularity | ||
| from nncf.common.hardware.defines import QConfigSpace | ||
| from nncf.common.quantization.structs import QuantizationScheme | ||
|
|
||
| q8_a_sym = QConfigSpace( | ||
| bits=8, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_TENSOR,), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q8_a = QConfigSpace( | ||
| bits=8, | ||
| mode=(QuantizationScheme.SYMMETRIC, QuantizationScheme.ASYMMETRIC), | ||
| granularity=(Granularity.PER_TENSOR,), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q8_a_ch = QConfigSpace( | ||
| bits=8, | ||
| mode=(QuantizationScheme.SYMMETRIC, QuantizationScheme.ASYMMETRIC), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q8_w_sym = QConfigSpace( | ||
| bits=8, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(True,), | ||
| signedness_to_force=True, | ||
| ) | ||
|
|
||
| q8_w_sym_any_nr = QConfigSpace( | ||
| bits=8, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(True, False), | ||
| signedness_to_force=True, | ||
| ) | ||
|
|
||
| q8_w_asym = QConfigSpace( | ||
| bits=8, | ||
| mode=(QuantizationScheme.ASYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q16_a_sym = QConfigSpace( | ||
| bits=16, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_TENSOR,), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q16_a = QConfigSpace( | ||
| bits=16, | ||
| mode=(QuantizationScheme.SYMMETRIC, QuantizationScheme.ASYMMETRIC), | ||
| granularity=(Granularity.PER_TENSOR,), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q16_a_ch = QConfigSpace( | ||
| bits=16, | ||
| mode=(QuantizationScheme.SYMMETRIC, QuantizationScheme.ASYMMETRIC), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q16_w_sym = QConfigSpace( | ||
| bits=16, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(True,), | ||
| signedness_to_force=True, | ||
| ) | ||
|
|
||
| q16_w_sym_any_nr = QConfigSpace( | ||
| bits=16, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(True, False), | ||
| signedness_to_force=True, | ||
| ) | ||
|
|
||
| q16_w_asym = QConfigSpace( | ||
| bits=16, | ||
| mode=(QuantizationScheme.ASYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q4_tn = QConfigSpace( | ||
| bits=4, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_TENSOR,), | ||
| narrow_range=(False,), | ||
| ) | ||
| q4_ch = QConfigSpace( | ||
| bits=4, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL,), | ||
| narrow_range=(False,), | ||
| ) | ||
| q4_w = QConfigSpace( | ||
| bits=4, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(False,), | ||
| ) | ||
| q2_ch = QConfigSpace( | ||
| bits=2, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL,), | ||
| narrow_range=(False,), | ||
| ) | ||
|
|
||
| q2_w = QConfigSpace( | ||
| bits=2, | ||
| mode=(QuantizationScheme.SYMMETRIC,), | ||
| granularity=(Granularity.PER_CHANNEL, Granularity.PER_TENSOR), | ||
| narrow_range=(False,), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Copyright (c) 2025 Intel Corporation | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.