File size: 717 Bytes
eb5a5f6
 
 
 
 
 
 
 
 
 
 
673c9f2
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
import torch
from math_model import QuantLinear

torch.manual_seed(0)

batch_size = 1
out_ch = 128
in_ch = 64

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

print(quant_params)

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