@@ -159,7 +159,7 @@ def augment_graph(self):
159
159
if should_be_dump :
160
160
# add input tensors which should be dump
161
161
for input in node .input :
162
- if len (input ) != 0 : # to prevent input is ""
162
+ if len (input ) != 0 : # to prevent input is ""
163
163
initializer_tensor = self .model_wrapper .get_initializer (input )
164
164
if initializer_tensor is None :
165
165
tensors_to_dump .add (input )
@@ -174,7 +174,7 @@ def augment_graph(self):
174
174
for augment_node_type in self .augment_nodes :
175
175
if augment_node_type in ["DequantizeLinear" ]:
176
176
# insert DequantizeLinear node as output
177
- if tensor .endswith ("_scale" ) or tensor .endswith ("_zero_point" ): # pragma: no cover
177
+ if tensor .endswith ("_scale" ) or tensor .endswith ("_zero_point" ): # pragma: no cover
178
178
continue
179
179
180
180
if not self .dynamically_quantized :
@@ -333,8 +333,9 @@ def _collect_data(ort_inputs):
333
333
# per iteration in the future.
334
334
if calibrator .method_name == "minmax" :
335
335
calibrator .collect (output )
336
- activation_tensors_calib_range [node_output_names [output_idx ]] = \
337
- [list (calibrator .calib_range )]
336
+ activation_tensors_calib_range [node_output_names [output_idx ]] = [
337
+ list (calibrator .calib_range )
338
+ ]
338
339
name_to_calibrator [node_output_names [output_idx ]] = calibrator
339
340
else :
340
341
intermediate_tensor .setdefault ((node_output_names [output_idx ], node_name ), []).append (
@@ -376,7 +377,7 @@ def _collect_data(ort_inputs):
376
377
self ._dataloder_for_next_split_model = ort_inputs_for_next_split_model
377
378
378
379
return activation_tensors_calib_range
379
-
380
+
380
381
def get_weight_tensors_calib_range (self ):
381
382
"""Get calib ranges of weight tensors.
382
383
@@ -405,8 +406,10 @@ def get_weight_tensors_calib_range(self):
405
406
)
406
407
if should_be_dump :
407
408
for input in node .input :
408
- if ((self .already_quantized and input .replace ("_dequantized" , "_quantized" ) in initializers ) or
409
- (not self .already_quantized and input in initializers )) and len (input ) != 0 :
409
+ if (
410
+ (self .already_quantized and input .replace ("_dequantized" , "_quantized" ) in initializers )
411
+ or (not self .already_quantized and input in initializers )
412
+ ) and len (input ) != 0 :
410
413
added_outputs .add (input )
411
414
412
415
for tensor in added_outputs :
@@ -429,13 +432,13 @@ def get_weight_tensors_calib_range(self):
429
432
continue
430
433
431
434
initializer_tensor = numpy_helper .to_array (initializer_tensor )
432
- calibrator = CALIBRATOR ["minmax" ]() # use minmax method to calibrate initializer tensors
435
+ calibrator = CALIBRATOR ["minmax" ]() # use minmax method to calibrate initializer tensors
433
436
calibrator .collect (initializer_tensor )
434
437
weight_tensors_calib_range [initializer_tensor_name ] = [list (calibrator .calib_range )]
435
438
calibrator .clear ()
436
439
del calibrator
437
440
return weight_tensors_calib_range
438
-
441
+
439
442
def get_intermediate_outputs (self , q_config = None , activation_only = False , weight_only = False ):
440
443
"""Gather intermediate model outputs after running inference."""
441
444
output_dicts = {}
@@ -631,7 +634,7 @@ def dump_tensor(self, activation=True, weight=False, format=None):
631
634
self .dynamically_quantized = "DynamicQuantizeLinear" in [node .op_type for node in self .model .graph .node ]
632
635
is_qdq = format == "qdq"
633
636
if activation :
634
- self .augment_graph (inspect_tensor = True ) # add activation tensors to model output
637
+ self .augment_graph (inspect_tensor = True ) # add activation tensors to model output
635
638
_ , output_dicts = self .get_intermediate_outputs (activation_only = not weight , weight_only = not activation )
636
639
iters = len (list (output_dicts .values ())[- 1 ])
637
640
map_node_activation = [{} for _ in range (iters )]
0 commit comments