100
100
101
101
class OVQuantizerTest (unittest .TestCase ):
102
102
SUPPORTED_ARCHITECTURES_TORCH_MODEL = (
103
- (OVModelForSequenceClassification , "bert" , 32 , 35 , False ),
104
- (OVModelForSequenceClassification , "bert" , 32 , 35 , True ),
105
- (OVModelForCausalLM , "gpt2" , 41 if is_transformers_version ("<" , "4.42.0" ) else 31 , 22 , False ),
106
- (OVModelForCausalLM , "gpt2" , 41 if is_transformers_version ("<" , "4.42.0" ) else 31 , 22 , True ),
103
+ (OVModelForSequenceClassification , "bert" , 32 , 35 ),
104
+ (OVModelForCausalLM , "gpt2" , 41 if is_transformers_version ("<" , "4.42.0" ) else 31 , 22 ),
107
105
)
108
106
SUPPORTED_ARCHITECTURES_OV_MODEL = (
109
- (OVModelForSequenceClassification , "bert" , 32 , 35 , False ),
110
- (OVModelForSequenceClassification , "bert" , 32 , 35 , True ),
111
- (OVModelForCausalLM , "gpt2" , 31 , 22 , False ),
112
- (OVModelForCausalLM , "gpt2" , 31 , 22 , True ),
107
+ (OVModelForSequenceClassification , "bert" , 32 , 35 ),
108
+ (OVModelForCausalLM , "gpt2" , 31 , 22 ),
113
109
)
114
110
SUPPORTED_ARCHITECTURES_OV_MODEL_WITH_AUTO_DATASET = [
115
111
(
@@ -275,7 +271,9 @@ def get_calibration_dataset(
275
271
)
276
272
return calibration_dataset
277
273
278
- @parameterized .expand (SUPPORTED_ARCHITECTURES_TORCH_MODEL )
274
+ @parameterized .expand (
275
+ [(* it [0 ], it [1 ]) for it in itertools .product (SUPPORTED_ARCHITECTURES_TORCH_MODEL , [False , True ])]
276
+ )
279
277
def test_automodel_static_quantization (
280
278
self , model_cls , model_name , expected_fake_nodes , expected_int8_nodes , from_dataset_instance
281
279
):
@@ -323,7 +321,9 @@ def preprocess_function(examples, tokenizer):
323
321
loaded_config = OVConfig .from_pretrained (tmp_dir )
324
322
self .assertEqual (ov_config .quantization_config .to_dict (), loaded_config .quantization_config .to_dict ())
325
323
326
- @parameterized .expand (SUPPORTED_ARCHITECTURES_OV_MODEL )
324
+ @parameterized .expand (
325
+ [(* it [0 ], it [1 ]) for it in itertools .product (SUPPORTED_ARCHITECTURES_OV_MODEL , [False , True ])]
326
+ )
327
327
def test_ovmodel_static_quantization (
328
328
self , model_cls , model_name , expected_fake_nodes , expected_int8_nodes , from_dataset_instance
329
329
):
@@ -915,12 +915,22 @@ def test_stable_diffusion_with_weight_compression(self):
915
915
)
916
916
check_optimization_not_applicable_to_optimized_model (int8_pipe , quantization_config )
917
917
918
- @parameterized .expand (SUPPORTED_ARCHITECTURES_WITH_HYBRID_QUANTIZATION [- 1 :])
918
+ @parameterized .expand (
919
+ [
920
+ (* it [0 ], it [1 ])
921
+ for it in itertools .product (SUPPORTED_ARCHITECTURES_WITH_HYBRID_QUANTIZATION [- 1 :], [False , True ])
922
+ ]
923
+ )
919
924
def test_ovmodel_hybrid_quantization_with_custom_dataset (
920
- self , model_cls , model_type , expected_fake_nodes , expected_int8_nodes
925
+ self ,
926
+ model_cls ,
927
+ model_type ,
928
+ expected_fake_nodes ,
929
+ expected_int8_nodes ,
930
+ dataset_via_config ,
921
931
):
922
932
model_id = MODEL_NAMES [model_type ]
923
- # TODO: provide list-of-strings-dataset through quantization config instead
933
+ # TODO: Run only dataset_via_config=True after v1.25
924
934
dataset = [
925
935
"dream rose covered with clean crystal, sharp edges, transparent, beautiful, highly detailed, high render"
926
936
]
@@ -929,6 +939,8 @@ def test_ovmodel_hybrid_quantization_with_custom_dataset(
929
939
quantization_config = OVWeightQuantizationConfig (bits = 8 , num_samples = 3 , quant_method = "hybrid" )
930
940
self .assertEqual (quantization_config .quant_method , OVQuantizationMethod .HYBRID )
931
941
942
+ quantization_config .dataset = dataset if dataset_via_config else None
943
+ dataset = None if dataset_via_config else dataset
932
944
quantizer .quantize (ov_config = OVConfig (quantization_config = quantization_config ), calibration_dataset = dataset )
933
945
num_fake_nodes , num_weight_nodes = get_num_quantized_nodes (
934
946
model .unet if model .unet is not None else model .transformer
0 commit comments