Skip to content

Commit 0a8e3e7

Browse files
Apply comments
1 parent 022908a commit 0a8e3e7

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

optimum/intel/openvino/configuration.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,13 @@ def __init__(
658658
self.overflow_fix = overflow_fix
659659
self.smooth_quant_alpha = smooth_quant_alpha
660660
self.activation_format = activation_format
661+
662+
f8_formats = ["f8e4m3", "f8e5m2"]
663+
if self.activation_format in f8_formats and self.weight_format in f8_formats:
664+
logger.info(
665+
f"{self.activation_format} for activations and {self.weight_format} weights were found. A symmetrical scheme will be used."
666+
)
667+
self.sym = True
661668
self.post_init()
662669

663670
def post_init(self):
@@ -674,16 +681,6 @@ def post_init(self):
674681
f"SmoothQuant alpha parameter must be in range [0, 1], but found {self.smooth_quant_alpha}"
675682
)
676683

677-
if not self.sym:
678-
if self.activation_format != "int8":
679-
raise ValueError(
680-
f"Asymmetric quantization can not be performed in {self.activation_format} activation format."
681-
)
682-
if self.weight_format != "int8":
683-
raise ValueError(
684-
f"Asymmetric quantization can not be performed in {self.weight_format} weight format."
685-
)
686-
687684

688685
class OVConfig(BaseConfig):
689686
CONFIG_NAME = "openvino_config.json"
@@ -708,8 +705,7 @@ def __init__(
708705
"compression", None
709706
) # A field for backward-compatability of training-time compression parameters
710707
if self.quantization_config is not None:
711-
if isinstance(self.quantization_config, OVWeightQuantizationConfig):
712-
self.dtype = self.quantization_config.weight_format
708+
self.dtype = self.quantization_config.weight_format
713709
else:
714710
self.dtype = dtype
715711

tests/openvino/test_exporters_cli.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class OVCLIExportTestCase(unittest.TestCase):
123123
"text-generation",
124124
"llama",
125125
"f8e4m3",
126-
"--dataset wikitext2 --num-samples 1 --smooth-quant-alpha 0.9 --trust-remote-code --sym",
126+
"--dataset wikitext2 --num-samples 1 --smooth-quant-alpha 0.9 --trust-remote-code",
127127
(13,),
128128
(16,),
129129
),
@@ -418,7 +418,7 @@ def test_exporters_cli_full_quantization(
418418
model_type: str,
419419
quant_mode: str,
420420
option: str,
421-
expected_num_fq_nodes_per_model: Tuple[int],
421+
expected_num_f_nodes_per_model: Tuple[int],
422422
expected_num_weight_nodes_per_model: Tuple[int],
423423
):
424424
with TemporaryDirectory() as tmpdir:
@@ -432,10 +432,10 @@ def test_exporters_cli_full_quantization(
432432
models = [model]
433433
if task == "automatic-speech-recognition":
434434
models = [model.encoder, model.decoder, model.decoder_with_past]
435-
self.assertEqual(len(expected_num_fq_nodes_per_model), len(models))
435+
self.assertEqual(len(expected_num_f_nodes_per_model), len(models))
436436
for i, model in enumerate(models):
437437
actual_num_f_nodes, actual_num_weight_nodes = get_num_quantized_nodes(model)
438-
self.assertEqual(expected_num_fq_nodes_per_model[i], actual_num_f_nodes)
438+
self.assertEqual(expected_num_f_nodes_per_model[i], actual_num_f_nodes)
439439
self.assertEqual(expected_num_weight_nodes_per_model[i], actual_num_weight_nodes[quant_mode])
440440

441441
def test_exporters_cli_int4_with_local_model_and_default_config(self):

0 commit comments

Comments
 (0)