Skip to content

Commit 714d77d

Browse files
Comments
1 parent 34d8fa7 commit 714d77d

File tree

10 files changed

+35
-101
lines changed

10 files changed

+35
-101
lines changed

src/nncf/experimental/quantization/structs.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from typing import Any, Literal, Optional
1313

14-
import nncf
1514
from nncf.common.quantization.structs import QuantizationScheme
1615
from nncf.common.quantization.structs import QuantizerConfig
1716
from nncf.config.schemata.defaults import QUANTIZATION_BITS
@@ -48,9 +47,6 @@ def __init__(
4847
:param dest_dtype: Target integer data type for quantized values.
4948
"""
5049
super().__init__(num_bits, mode, signedness_to_force, per_channel, narrow_range)
51-
if dest_dtype not in [TensorDataType.int8, TensorDataType.uint8]:
52-
msg = f"Quantization configurations with dest_dtype=={dest_dtype} are not supported."
53-
raise nncf.ParameterNotSupportedError(msg)
5450
self.dest_dtype = dest_dtype
5551

5652
def __str__(self) -> str:

src/nncf/quantization/algorithms/min_max/torch_fx_backend.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,16 @@ def _create_quantizer(
192192
quantizer_config: QuantizerConfig,
193193
channel_axis: int,
194194
parameters: FakeQuantizeParameters,
195-
target_type: TargetType,
196195
) -> FakeQuantize:
197196
per_channel = quantizer_config.per_channel
198197
dtype = None
199198
if isinstance(quantizer_config, ExtendedQuantizerConfig):
200199
dtype = quantizer_config.dest_dtype
200+
201+
if dtype not in [TensorDataType.int8, TensorDataType.uint8]:
202+
msg = f"Quantization configurations with dest_dtype=={dtype} are not supported."
203+
raise nncf.ParameterNotSupportedError(msg)
204+
201205
elif quantizer_config.mode != QuantizationScheme.SYMMETRIC:
202206
dtype = TensorDataType.uint8
203207
else:
@@ -281,7 +285,6 @@ def create_quantizer_insertion_command(
281285
quantizer_config,
282286
channel_axis,
283287
parameters,
284-
target_point.target_type,
285288
)
286289
transformation = qdq_insertion_transformation_builder(quantizer, [target_point])
287290
return FXApplyTransformationCommand(transformation)
@@ -299,7 +302,6 @@ def create_unified_scales_quantizers_insertion_commands(
299302
quantizer_config,
300303
channel_axis,
301304
parameters,
302-
target_points[0].target_type,
303305
)
304306

305307
transformations = []

tests/common/experimental/test_structs.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/post_training/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ def pytest_addoption(parser):
2222
parser.addoption("--subset-size", type=int, default=None, help="Set subset size")
2323
parser.addoption("--fp32", action="store_true", help="Test original model")
2424
parser.addoption("--cuda", action="store_true", help="Enable CUDA_TORCH backend")
25-
parser.addoption(
26-
"--x86quantizer", action="store_true", help="Enable X86_QUANTIZER_NNCF and X86_QUANTIZER_AO backends"
27-
)
2825
parser.addoption("--benchmark", action="store_true", help="Run benchmark_app")
2926
parser.addoption(
3027
"--torch-compile-validation",
@@ -82,11 +79,6 @@ def fixture_run_torch_cuda_backend(pytestconfig):
8279
return pytestconfig.getoption("cuda")
8380

8481

85-
@pytest.fixture(scope="session", name="run_with_x86_quantizer")
86-
def fixture_run_with_x86quantizer(pytestconfig):
87-
return pytestconfig.getoption("x86quantizer")
88-
89-
9082
@pytest.fixture(scope="session", name="run_benchmark_app")
9183
def fixture_run_benchmark_app(pytestconfig):
9284
return pytestconfig.getoption("benchmark")

tests/post_training/data/ptq_reference_data.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ torchvision/resnet18_backend_OV_QUANTIZER_NNCF:
5252
metric_value: 0.6946
5353
torchvision/resnet18_backend_OV_QUANTIZER_AO:
5454
metric_value: 0.6959
55-
torchvision/resnet18_backend_X86_QUANTIZER_NNCF:
56-
metric_value: 0.6946
57-
torchvision/resnet18_backend_X86_QUANTIZER_AO:
58-
metric_value: 0.6959
5955
torchvision/mobilenet_v3_small_BC_backend_FP32:
6056
metric_value: 0.6766
6157
torchvision/mobilenet_v3_small_BC_backend_OV:
@@ -78,10 +74,6 @@ torchvision/mobilenet_v3_small_BC_backend_OV_QUANTIZER_NNCF:
7874
metric_value: 0.6679
7975
torchvision/mobilenet_v3_small_BC_backend_OV_QUANTIZER_AO:
8076
metric_value: 0.6561
81-
torchvision/mobilenet_v3_small_BC_backend_X86_QUANTIZER_NNCF:
82-
metric_value: 0.0622
83-
torchvision/mobilenet_v3_small_BC_backend_X86_QUANTIZER_AO:
84-
metric_value: 0.0538
8577
torchvision/vit_b_16_backend_FP32:
8678
metric_value: 0.8107
8779
torchvision/vit_b_16_backend_OV:
@@ -102,10 +94,6 @@ torchvision/vit_b_16_backend_OV_QUANTIZER_NNCF:
10294
metric_value: 0.80922
10395
torchvision/vit_b_16_backend_OV_QUANTIZER_AO:
10496
metric_value: 0.2429
105-
torchvision/vit_b_16_backend_X86_QUANTIZER_NNCF:
106-
metric_value: 0.80922
107-
torchvision/vit_b_16_backend_X86_QUANTIZER_AO:
108-
metric_value: 0.1498
10997
torchvision/swin_v2_s_backend_FP32:
11098
metric_value: 0.83712
11199
torchvision/swin_v2_s_backend_OV:
@@ -126,10 +114,6 @@ torchvision/swin_v2_s_backend_OV_QUANTIZER_NNCF:
126114
metric_value: 0.8360
127115
torchvision/swin_v2_s_backend_OV_QUANTIZER_AO:
128116
metric_value: 0.8360
129-
torchvision/swin_v2_s_backend_X86_QUANTIZER_NNCF:
130-
metric_value: 0.8360
131-
torchvision/swin_v2_s_backend_X86_QUANTIZER_AO:
132-
metric_value: 0.8360
133117
timm/crossvit_9_240_backend_CUDA_TORCH:
134118
metric_value: 0.7275
135119
timm/crossvit_9_240_backend_FP32:

tests/post_training/experimental/sparsify_activations/test_sparsify_activations_conformance.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def test_sparsify_activations(
5858
batch_size,
5959
run_fp32_backend,
6060
run_torch_cuda_backend,
61-
False, # Do not run with X86Quantizers
6261
subset_size,
6362
run_benchmark_app,
6463
capsys,

tests/post_training/pipelines/base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class BackendType(Enum):
5959
CUDA_FX_TORCH = "CUDA_FX_TORCH"
6060
OV_QUANTIZER_NNCF = "OV_QUANTIZER_NNCF"
6161
OV_QUANTIZER_AO = "OV_QUANTIZER_AO"
62-
X86_QUANTIZER_NNCF = "X86_QUANTIZER_NNCF"
63-
X86_QUANTIZER_AO = "X86_QUANTIZER_AO"
6462
ONNX = "ONNX"
6563
OV = "OV"
6664
OPTIMUM = "OPTIMUM"
@@ -74,8 +72,6 @@ class BackendType(Enum):
7472
BackendType.CUDA_FX_TORCH,
7573
BackendType.OV_QUANTIZER_NNCF,
7674
BackendType.OV_QUANTIZER_AO,
77-
BackendType.X86_QUANTIZER_NNCF,
78-
BackendType.X86_QUANTIZER_AO,
7975
]
8076
OV_BACKENDS = [BackendType.OV, BackendType.OPTIMUM]
8177

tests/post_training/pipelines/image_classification_base.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
from torch.ao.quantization.quantize_pt2e import convert_pt2e
2828
from torch.ao.quantization.quantize_pt2e import prepare_pt2e
2929
from torch.ao.quantization.quantizer.quantizer import Quantizer as TorchAOQuantizer
30-
from torch.ao.quantization.quantizer.x86_inductor_quantizer import X86InductorQuantizer
31-
from torch.ao.quantization.quantizer.x86_inductor_quantizer import get_default_x86_inductor_quantization_config
3230
from torchvision import datasets
3331

3432
import nncf
@@ -195,16 +193,12 @@ def _compress(self):
195193

196194
quantizer = self._build_quantizer()
197195

198-
if self.backend in [BackendType.OV_QUANTIZER_NNCF, BackendType.X86_QUANTIZER_NNCF]:
196+
if self.backend in [BackendType.OV_QUANTIZER_NNCF]:
199197
self._compress_nncf_pt2e(quantizer)
200198
else:
201199
self._compress_torch_ao(quantizer)
202200

203201
def _build_quantizer(self) -> TorchAOQuantizer:
204-
if self.backend in [BackendType.X86_QUANTIZER_AO, BackendType.X86_QUANTIZER_NNCF]:
205-
quantizer = X86InductorQuantizer()
206-
quantizer.set_global(get_default_x86_inductor_quantization_config())
207-
return quantizer
208202
quantizer_kwargs = {}
209203
for key in (
210204
"mode",

tests/post_training/test_quantize_conformance.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ def fixture_report_data(output_dir, run_benchmark_app, forked):
125125
df.to_csv(output_file, index=False)
126126

127127

128-
def maybe_skip_test_case(
129-
test_model_param, run_fp32_backend, run_torch_cuda_backend, run_with_x86_quantizer, batch_size
130-
):
128+
def maybe_skip_test_case(test_model_param, run_fp32_backend, run_torch_cuda_backend, batch_size):
131129
if test_model_param["backend"] == BackendType.FP32 and not run_fp32_backend:
132130
pytest.skip("To run test for not quantized model use --fp32 argument")
133131
if (
@@ -137,11 +135,6 @@ def maybe_skip_test_case(
137135
pytest.skip(f"To run test for {test_model_param['backend'].value} backend use --cuda argument")
138136
if batch_size and batch_size > 1 and test_model_param.get("batch_size", 1) == 1:
139137
pytest.skip("The model does not support batch_size > 1. Please use --batch-size 1.")
140-
if (
141-
test_model_param["backend"] in [BackendType.X86_QUANTIZER_AO, BackendType.X86_QUANTIZER_NNCF]
142-
and not run_with_x86_quantizer
143-
):
144-
pytest.skip("To validate quantization with the X86Quantizer use the --x86quantizer argument")
145138
return test_model_param
146139

147140

@@ -209,7 +202,6 @@ def run_pipeline(
209202
batch_size: Optional[int],
210203
run_fp32_backend: bool,
211204
run_torch_cuda_backend: bool,
212-
run_with_x86_quantizer: bool,
213205
subset_size: Optional[int],
214206
run_benchmark_app: bool,
215207
capsys: pytest.CaptureFixture,
@@ -222,7 +214,7 @@ def run_pipeline(
222214
msg = f"{test_case_name} does not exist in 'reference_data.yaml'"
223215
raise nncf.ValidationError(msg)
224216
test_model_param = test_cases[test_case_name]
225-
maybe_skip_test_case(test_model_param, run_fp32_backend, run_torch_cuda_backend, run_with_x86_quantizer, batch_size)
217+
maybe_skip_test_case(test_model_param, run_fp32_backend, run_torch_cuda_backend, batch_size)
226218
pipeline_cls = test_model_param["pipeline_cls"]
227219
pipeline_kwargs = create_pipeline_kwargs(test_model_param, subset_size, test_case_name, reference_data)
228220
pipeline_kwargs.update(
@@ -280,7 +272,6 @@ def test_ptq_quantization(
280272
batch_size: Optional[int],
281273
run_fp32_backend: bool,
282274
run_torch_cuda_backend: bool,
283-
run_with_x86_quantizer: bool,
284275
subset_size: Optional[int],
285276
run_benchmark_app: bool,
286277
capsys: pytest.CaptureFixture,
@@ -298,7 +289,6 @@ def test_ptq_quantization(
298289
batch_size,
299290
run_fp32_backend,
300291
run_torch_cuda_backend,
301-
run_with_x86_quantizer,
302292
subset_size,
303293
run_benchmark_app,
304294
capsys,
@@ -335,7 +325,6 @@ def test_weight_compression(
335325
batch_size,
336326
run_fp32_backend,
337327
run_torch_cuda_backend,
338-
False, # Do not run with the X86Quantizer
339328
subset_size,
340329
run_benchmark_app,
341330
capsys,

tests/torch2/fx/test_calculation_quantizer_params.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
import pytest
1717
import torch
1818

19-
from nncf.common.graph.transformations.commands import TargetType
19+
import nncf
2020
from nncf.common.quantization.structs import QuantizationScheme as QuantizationMode
2121
from nncf.common.quantization.structs import QuantizerConfig
2222
from nncf.common.quantization.structs import QuantizerGroup
2323
from nncf.experimental.common.tensor_statistics.statistics import MinMaxTensorStatistic
2424
from nncf.experimental.quantization.structs import ExtendedQuantizerConfig
2525
from nncf.experimental.quantization.structs import IntDtype
2626
from nncf.quantization.algorithms.min_max.torch_fx_backend import FXMinMaxAlgoBackend
27+
from nncf.quantization.fake_quantize import FakeQuantizeParameters
2728
from nncf.quantization.fake_quantize import calculate_quantizer_parameters
2829
from nncf.tensor import Tensor
2930
from nncf.tensor.definitions import TensorDataType
@@ -414,12 +415,7 @@ def _get_quantizer(case_to_test: CaseQuantParams, qconfig: QuantizerConfig):
414415
fq_params = calculate_quantizer_parameters(case_to_test.stat, qconfig, case_to_test.quant_group, half_range=False)
415416

416417
ch_axis = 1 if case_to_test.per_channel and case_to_test.quant_group == QuantizerGroup.WEIGHTS else 0
417-
target_type = (
418-
TargetType.OPERATION_WITH_WEIGHTS
419-
if case_to_test.quant_group == QuantizerGroup.WEIGHTS
420-
else TargetType.PRE_LAYER_OPERATION
421-
)
422-
quantizer = FXMinMaxAlgoBackend._create_quantizer(qconfig, ch_axis, fq_params, target_type)
418+
quantizer = FXMinMaxAlgoBackend._create_quantizer(qconfig, ch_axis, fq_params)
423419

424420
assert quantizer.ch_axis == ch_axis
425421

@@ -436,3 +432,27 @@ def _check_q_min_q_max(quantizer, signed, narrow_range):
436432

437433
assert quantizer.quant_min == ref_quant_min
438434
assert quantizer.quant_max == ref_quant_max
435+
436+
437+
@pytest.mark.parametrize(
438+
"dest_dtype",
439+
[
440+
TensorDataType.float16,
441+
TensorDataType.bfloat16,
442+
TensorDataType.float32,
443+
TensorDataType.float64,
444+
TensorDataType.f8e4m3,
445+
TensorDataType.f8e5m2,
446+
TensorDataType.nf4,
447+
TensorDataType.int32,
448+
TensorDataType.int64,
449+
TensorDataType.uint4,
450+
TensorDataType.int4,
451+
None,
452+
],
453+
)
454+
def test_extended_q_config_non_supported_dest_dtype(dest_dtype):
455+
qconfig = ExtendedQuantizerConfig(dest_dtype=dest_dtype)
456+
params = FakeQuantizeParameters(-1.0, 1.0, -1.0, 1.0, 255)
457+
with pytest.raises(nncf.ParameterNotSupportedError):
458+
FXMinMaxAlgoBackend._create_quantizer(quantizer_config=qconfig, channel_axis=1, parameters=params)

0 commit comments

Comments
 (0)