@@ -57,9 +57,6 @@ def new_const(self, value, shape=None, dtype="float32", source_name=None):
5757 self .const_ctr += 1
5858 self .exprs [name ] = relax .const (value , dtype )
5959 self .params [name ] = (self .exprs [name ], value )
60- #self.exprs[name] = relax.Var(
61- # name_hint=name, struct_info=relax.TensorStructInfo(shape=shape, dtype=dtype)
62- #)
6360
6461 return self .exprs [name ]
6562
@@ -610,7 +607,9 @@ def convert_qnn_fused_activation_function(
610607 if fused_activation_fn == ActivationFunctionType .RELU6 :
611608 return relax .op .clip (expr , a_min = max (qmin , quantize (0 )), a_max = min (qmax , quantize (6.0 )))
612609 if fused_activation_fn == ActivationFunctionType .RELU_N1_TO_1 :
613- return relax .op .clip (expr , a_min = max (qmin , quantize (- 1.0 )), a_max = min (qmax , quantize (1.0 )))
610+ return relax .op .clip (
611+ expr , a_min = max (qmin , quantize (- 1.0 )), a_max = min (qmax , quantize (1.0 ))
612+ )
614613 if fused_activation_fn == ActivationFunctionType .RELU :
615614 return relax .op .clip (expr , a_min = max (qmin , quantize (0.0 )), a_max = qmax )
616615
@@ -662,7 +661,10 @@ def convert_reshape(self, op):
662661 target_expr = self .get_expr (shape_tensor .tensor_idx )
663662 target_value , success = try_infer_value (
664663 target_expr ,
665- parameters = {k : tvm .runtime .tensor (np .array (v )) for k , v in self .exp_tab .params .items ()},
664+ parameters = {
665+ k : tvm .runtime .tensor (np .array (v )) for k , v in self .exp_tab .params .items ()
666+ },
667+
666668 )
667669 if success :
668670 # convert to flattened list
@@ -1155,7 +1157,9 @@ def convert_relu_n1_to_1(self, op):
11551157 qmin = float (tvm .tir .op .min_value (input_tensor_type_str ).value )
11561158 qmax = float (tvm .tir .op .max_value (input_tensor_type_str ).value )
11571159
1158- out = relax .op .clip (in_expr , a_min = max (qmin , quantize (- 1.0 )), a_max = min (qmax , quantize (1.0 )))
1160+ out = relax .op .clip (
1161+ in_expr , a_min = max (qmin , quantize (- 1.0 )), a_max = min (qmax , quantize (1.0 ))
1162+ )
11591163 else :
11601164 out = relax .op .clip (in_expr , a_min = - 1 , a_max = 1 )
11611165
@@ -2910,7 +2914,9 @@ def convert_unidirectional_sequence_lstm(self, op):
29102914 relax .op .const (input_forget_weights_default_values .tolist ()), 1
29112915 )
29122916 input_cell_weights_default_values = self .get_tensor_value (input_cell_weights )
2913- input_cell_weights_op = relax .op .split (_op .const (input_cell_weights_default_values .tolist ()), 1 )
2917+ input_cell_weights_op = relax .op .split (
2918+ _op .const (input_cell_weights_default_values .tolist ()), 1
2919+ )
29142920 weights_dict ["w_inp" ] = relax .op .concat (
29152921 [
29162922 relax .op .squeeze (input_input_weights_op [0 ]),
@@ -2936,7 +2942,9 @@ def convert_unidirectional_sequence_lstm(self, op):
29362942 relax .op .const (recurrent_forget_weights_values .tolist ()), 1
29372943 )
29382944 recurrent_cell_weights_values = self .get_tensor_value (recurrent_cell_weights )
2939- recurrent_cell_weights_op = relax .op .split (_op .const (recurrent_cell_weights_values .tolist ()), 1 )
2945+ recurrent_cell_weights_op = relax .op .split (
2946+ _op .const (recurrent_cell_weights_values .tolist ()), 1
2947+ )
29402948 weights_dict ["w_hid" ] = relax .op .concat (
29412949 [
29422950 recurrent_input_weights_op [0 ],
@@ -3063,10 +3071,14 @@ def convert_batch_matmul(self, op):
30633071 )
30643072
30653073 a_broadcasted_shape = _fold_constant (
3066- relax .op .concat ([out_batch , relax .op .strided_slice (shape_a , [rank_a - 2 ], [rank_a ])], 0 )
3074+ relax .op .concat (
3075+ [out_batch , relax .op .strided_slice (shape_a , [rank_a - 2 ], [rank_a ])], 0
3076+ )
30673077 )
30683078 b_broadcasted_shape = _fold_constant (
3069- relax .op .concat ([out_batch , relax .op .strided_slice (shape_b , [rank_b - 2 ], [rank_b ])], 0 )
3079+ relax .op .concat (
3080+ [out_batch , relax .op .strided_slice (shape_b , [rank_b - 2 ], [rank_b ])], 0
3081+ )
30703082 )
30713083 if not tvm .ir .structural_equal (shape_a , a_broadcasted_shape ):
30723084 input_a = relax .op .transform .broadcast_to (input_a , a_broadcasted_shape )
@@ -3574,7 +3586,9 @@ def convert_detection_postprocess(self, op):
35743586 non_max_suppression_attrs ["max_output_size" ] = custom_options ["max_detections" ]
35753587 non_max_suppression_attrs ["invalid_to_bottom" ] = False
35763588
3577- ret = relax .op .vision .non_max_suppression (ret [0 ], ret [1 ], ret [1 ], ** non_max_suppression_attrs )
3589+ ret = relax .op .vision .non_max_suppression (
3590+ ret [0 ], ret [1 ], ret [1 ], ** non_max_suppression_attrs
3591+ )
35783592 ret = relax .op .vision .get_valid_counts (ret , 0 )
35793593 valid_count = ret [0 ]
35803594 # keep only the top 'max_detections' rows
@@ -4246,9 +4260,12 @@ def from_tflite(model, shape_dict=None, dtype_dict=None, op_converter=OperatorCo
42464260 for model_input in model_inputs :
42474261 model_input_name = get_tensor_name (subgraph , model_input )
42484262 shape = _shape_dict [model_input_name ] if model_input_name in _shape_dict else None
4249- dtype = _dtype_dict [model_input_name ] if model_input_name in _dtype_dict else "float32"
4263+ dtype = (
4264+ _dtype_dict [model_input_name ] if model_input_name in _dtype_dict else "float32"
4265+ )
42504266 input_var = relax .Var (
4251- name_hint = model_input_name , struct_info = relax .TensorStructInfo (shape = shape , dtype = dtype )
4267+ name_hint = model_input_name ,
4268+ struct_info = relax .TensorStructInfo (shape = shape , dtype = dtype ),
42524269 )
42534270 exp_tab .set_expr (model_input_name , input_var )
42544271 input_list .append (input_var )
@@ -4270,7 +4287,7 @@ def from_tflite(model, shape_dict=None, dtype_dict=None, op_converter=OperatorCo
42704287 _ , param_value_list = map (list , zip (* exp_tab .params .values ()))
42714288 func_attrs = {}
42724289 func_attrs ["num_input" ] = len (input_list )
4273- func_attrs ["params" ] = [ tvm .runtime .tensor (arr ) for arr in param_value_list ]
4290+ func_attrs ["params" ] = [tvm .runtime .tensor (arr ) for arr in param_value_list ]
42744291 relax_mod ["main" ] = relax_mod ["main" ].with_attrs (func_attrs )
42754292
42764293 return relax_mod
0 commit comments