52
52
}
53
53
54
54
55
- class replace_properties_values :
55
+ class _replace_properties_values :
56
56
"""
57
57
A context manager for temporarily overriding an object's properties
58
58
"""
@@ -74,7 +74,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
74
74
setattr (self .obj , property_name , old_property_value )
75
75
76
76
77
- def is_serializable (obj ):
77
+ def _is_serializable (obj ):
78
78
try :
79
79
json .dumps (obj )
80
80
return True
@@ -92,22 +92,22 @@ def __init__(
92
92
self ,
93
93
dataset : Optional [Union [str , List [str ], nncf .Dataset , datasets .Dataset ]] = None ,
94
94
ignored_scope : Optional [Union [dict , nncf .IgnoredScope ]] = None ,
95
- subset_size : Optional [int ] = None ,
95
+ num_samples : Optional [int ] = None ,
96
96
):
97
97
"""
98
98
Args:
99
99
dataset (`str or List[str] or nncf.Dataset or datasets.Dataset`, *optional*):
100
100
The dataset used for data-aware weight compression or quantization with NNCF.
101
101
ignored_scope (`dict or nncf.IgnoredScope`, *optional*):
102
102
An ignored scope that defines the list of model nodes to be ignored during quantization.
103
- subset_size (`int`, *optional*):
103
+ num_samples (`int`, *optional*):
104
104
The maximum number of samples composing the calibration dataset.
105
105
"""
106
106
self .dataset = dataset
107
107
if isinstance (ignored_scope , dict ):
108
108
ignored_scope = nncf .IgnoredScope (** ignored_scope )
109
109
self .ignored_scope = ignored_scope
110
- self .subset_size = subset_size
110
+ self .num_samples = num_samples
111
111
112
112
def post_init (self ):
113
113
if not (self .dataset is None or isinstance (self .dataset , (str , list , nncf .Dataset , datasets .Dataset ))):
@@ -121,22 +121,22 @@ def post_init(self):
121
121
f"{ type (self .dataset )} "
122
122
)
123
123
124
- def to_dict_without_properties (self , property_names : Union [List [str ], Tuple [str ]]) -> Dict [str , Any ]:
124
+ def _to_dict_without_properties (self , property_names : Union [List [str ], Tuple [str ]]) -> Dict [str , Any ]:
125
125
"""
126
126
Calls to_dict() with given properties overwritten with None. Useful for hiding non-serializable properties.
127
127
"""
128
128
if len (property_names ) == 0 :
129
129
return super ().to_dict ()
130
- with replace_properties_values (self , property_names , [None ] * len (property_names )):
130
+ with _replace_properties_values (self , property_names , [None ] * len (property_names )):
131
131
result = super ().to_dict ()
132
132
return result
133
133
134
134
def to_dict (self ) -> Dict [str , Any ]:
135
- properties_to_omit = [] if is_serializable (self .dataset ) else ["dataset" ]
135
+ properties_to_omit = [] if _is_serializable (self .dataset ) else ["dataset" ]
136
136
if isinstance (self .ignored_scope , nncf .IgnoredScope ):
137
- with replace_properties_values (self , ["ignored_scope" ], [self .ignored_scope .__dict__ ]):
138
- return self .to_dict_without_properties (properties_to_omit )
139
- return self .to_dict_without_properties (properties_to_omit )
137
+ with _replace_properties_values (self , ["ignored_scope" ], [self .ignored_scope .__dict__ ]):
138
+ return self ._to_dict_without_properties (properties_to_omit )
139
+ return self ._to_dict_without_properties (properties_to_omit )
140
140
141
141
142
142
class OVConfig (BaseConfig ):
@@ -180,21 +180,21 @@ def add_input_info(self, model_inputs: Dict, force_batch_one: bool = False):
180
180
for name , value in model_inputs .items ()
181
181
]
182
182
183
- def to_dict_safe (self , to_diff_dict : bool = False ) -> Dict [str , Any ]:
183
+ def _to_dict_safe (self , to_diff_dict : bool = False ) -> Dict [str , Any ]:
184
184
if self .quantization_config is None :
185
185
# Parent to_dict() implementation does not support quantization_config being None
186
- with replace_properties_values (self , ("quantization_config" ,), (OVQuantizationConfigBase (),)):
186
+ with _replace_properties_values (self , ("quantization_config" ,), (OVQuantizationConfigBase (),)):
187
187
result = super ().to_diff_dict () if to_diff_dict else super ().to_dict ()
188
188
del result ["quantization_config" ]
189
189
else :
190
190
result = super ().to_diff_dict () if to_diff_dict else super ().to_dict ()
191
191
return result
192
192
193
193
def to_dict (self ) -> Dict [str , Any ]:
194
- return self .to_dict_safe (to_diff_dict = False )
194
+ return self ._to_dict_safe (to_diff_dict = False )
195
195
196
196
def to_diff_dict (self ) -> Dict [str , Any ]:
197
- return self .to_dict_safe (to_diff_dict = True )
197
+ return self ._to_dict_safe (to_diff_dict = True )
198
198
199
199
200
200
class OVQuantizationMethod (str , Enum ):
@@ -236,7 +236,7 @@ class OVWeightQuantizationConfig(OVQuantizationConfigBase):
236
236
preserve the accuracy of the model, the more sensitive layers receives a higher precision.
237
237
ignored_scope (`dict`, *optional*):
238
238
An ignored scope that defined the list of model control flow graph nodes to be ignored during quantization.
239
- subset_size (`int`, *optional*):
239
+ num_samples (`int`, *optional*):
240
240
The maximum number of samples composing the calibration dataset.
241
241
quant_method (`str`, defaults of OVQuantizationMethod.DEFAULT):
242
242
Weight compression method to apply.
@@ -253,19 +253,18 @@ def __init__(
253
253
all_layers : Optional [bool ] = None ,
254
254
sensitivity_metric : Optional [str ] = None ,
255
255
ignored_scope : Optional [Union [dict , nncf .IgnoredScope ]] = None ,
256
- subset_size : Optional [int ] = None ,
256
+ num_samples : Optional [int ] = None ,
257
257
quant_method : Optional [Union [QuantizationMethod , OVQuantizationMethod ]] = OVQuantizationMethod .DEFAULT ,
258
258
** kwargs ,
259
259
):
260
- super ().__init__ (dataset , ignored_scope , subset_size )
260
+ super ().__init__ (dataset , ignored_scope , num_samples )
261
261
self .bits = bits
262
262
self .sym = sym
263
263
self .tokenizer = tokenizer
264
264
self .group_size = group_size or (- 1 if bits == 8 else 128 )
265
265
self .ratio = ratio
266
266
self .all_layers = all_layers
267
267
self .sensitivity_metric = sensitivity_metric
268
- self .subset_size = subset_size
269
268
self .quant_method = quant_method
270
269
self .post_init ()
271
270
@@ -305,8 +304,8 @@ def post_init(self):
305
304
)
306
305
307
306
def to_dict (self ) -> Dict [str , Any ]:
308
- if not is_serializable (self .tokenizer ):
309
- return self .to_dict_without_properties (("tokenizer" ,))
307
+ if not _is_serializable (self .tokenizer ):
308
+ return self ._to_dict_without_properties (("tokenizer" ,))
310
309
return super ().to_dict ()
311
310
312
311
@@ -316,7 +315,7 @@ def __init__(
316
315
self ,
317
316
dataset : Union [str , List [str ], nncf .Dataset , datasets .Dataset ],
318
317
ignored_scope : Optional [Union [dict , nncf .IgnoredScope ]] = None ,
319
- subset_size : Optional [int ] = 300 ,
318
+ num_samples : Optional [int ] = 300 ,
320
319
preset : nncf .QuantizationPreset = None ,
321
320
model_type : nncf .ModelType = nncf .ModelType .TRANSFORMER ,
322
321
fast_bias_correction : bool = True ,
@@ -332,7 +331,7 @@ def __init__(
332
331
A dataset used for quantization parameters calibration. Required parameter.
333
332
ignored_scope (`dict or nncf.IgnoredScope`, *optional*):
334
333
An ignored scope that defines the list of model nodes to be ignored during quantization.
335
- subset_size (`int`, *optional*):
334
+ num_samples (`int`, *optional*):
336
335
The maximum number of samples composing the calibration dataset.
337
336
preset (`nncf.QuantizationPreset`, *optional*):
338
337
A preset controls the quantization mode (symmetric and asymmetric).
@@ -345,10 +344,10 @@ def __init__(
345
344
Model type is needed to specify additional patterns in the model. Supported only `transformer` now.
346
345
fast_bias_correction (`bool`, defaults to True):
347
346
Whether to apply fast or full bias correction algorithm.
348
- overflow_fix (`bool `, default to OverflowFix.DISABLE):
347
+ overflow_fix (`nncf.OverflowFix `, default to OverflowFix.DISABLE):
349
348
Parameter for controlling overflow fix setting.
350
349
"""
351
- super ().__init__ (dataset , ignored_scope , subset_size )
350
+ super ().__init__ (dataset , ignored_scope , num_samples )
352
351
self .preset = preset
353
352
self .model_type = model_type
354
353
self .fast_bias_correction = fast_bias_correction
@@ -370,7 +369,7 @@ def to_dict(self) -> Dict[str, Any]:
370
369
# TODO: remove code below once NNCF is updated to 2.10
371
370
overflow_fix_value = None if self .overflow_fix is None else self .overflow_fix .value
372
371
preset_value = None if self .preset is None else self .preset .value
373
- with replace_properties_values (self , ("overflow_fix" , "preset" ), (overflow_fix_value , preset_value )):
372
+ with _replace_properties_values (self , ("overflow_fix" , "preset" ), (overflow_fix_value , preset_value )):
374
373
return super ().to_dict ()
375
374
376
375
0 commit comments