File size: 751 Bytes
eb5a5f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673c9f2
eb5a5f6
673c9f2
eb5a5f6
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import torch
from math_model import QuantConv2d

torch.manual_seed(0)

batch_size = 1
out_ch = 8
in_ch = 4
k = 3
h = 5
w = 5

quant_params = {
    'smoothquant_mul': torch.rand((in_ch,)),
    'smoothquant_mul_shape': (1,in_ch,1,1),
    'weight_scale': torch.rand((out_ch,)),
    'weight_scale_shape': (out_ch,1,1,1),
    'weight_zp': torch.randint(-255, 0, (out_ch,)),
    'weight_zp_shape': (out_ch,1,1,1),
    'input_scale': torch.rand((1,)),
    'input_scale_shape': tuple(),
    'input_zp': torch.zeros((1,)),
    'input_zp_shape': tuple(),
}

print(quant_params)

l = QuantConv2d(in_ch, out_ch, k, quant_params)
i = torch.rand((batch_size,in_ch,h,w))
o_qdq = l(i)
o_qop = l(i, qop=True)
print(o_qdq.shape)
print(o_qop.shape)
print(o_qdq - o_qop)