@@ -86,6 +86,8 @@ def apply(self, model):
86
86
dw = False
87
87
if group == ifm_ch and ofm_ch == ifm_ch :
88
88
W_sparse = np .zeros ((ofm_ch , ifm_ch , k_h , k_w )) # (OFM, IFM, k_H, k_W)
89
+ # TODO: if the convolution is quantized with a non-zero zeropoint we
90
+ # should be using the zeropoint value here instead of np.zeros
89
91
for ch in range (ifm_ch ):
90
92
W_sparse [ch ][ch ] = W_conv [ch ][0 ] # W_conv = [OFM, IFM, k_H, k_W]
91
93
W_conv = W_sparse .astype (np .float32 )
@@ -116,14 +118,15 @@ def apply(self, model):
116
118
if conv_weight_q_scale_name is not None :
117
119
# required for convs with quantized weights
118
120
scale_weight_q = model .get_initializer (conv_weight_q_scale_name )
119
- # scale shape is originally [OFM, IFM, k_H, k_W]
120
- # transpose into [OFM, k_H, k_W, IFM]
121
- scale_weight_q = scale_weight_q .transpose (0 , 2 , 3 , 1 )
122
- # reshape into [OFM][k_h*k_w*IFM] matrix
123
- scale_weight_q = scale_weight_q .reshape (ofm_ch , - 1 )
124
- # transpose to be shape-compatible with weight matrix
125
- scale_weight_q = scale_weight_q .T
126
- model .set_initializer (conv_weight_q_scale_name , scale_weight_q )
121
+ if scale_weight_q .ndim > 0 :
122
+ # scale shape is originally [OFM, IFM, k_H, k_W]
123
+ # transpose into [OFM, k_H, k_W, IFM]
124
+ scale_weight_q = scale_weight_q .transpose (0 , 2 , 3 , 1 )
125
+ # reshape into [OFM][k_h*k_w*IFM] matrix
126
+ scale_weight_q = scale_weight_q .reshape (ofm_ch , - 1 )
127
+ # transpose to be shape-compatible with weight matrix
128
+ scale_weight_q = scale_weight_q .T
129
+ model .set_initializer (conv_weight_q_scale_name , scale_weight_q )
127
130
128
131
# create new intermediate values
129
132
inp_trans_out = helper .make_tensor_value_info (
0 commit comments