forked from megvii-research/FQ-ViT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
executable file
·43 lines (36 loc) · 1.47 KB
/
config.py
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
36
37
38
39
40
41
42
43
from models import BIT_TYPE_DICT
class Config:
def __init__(self, ptf=True, lis=True, quant_method='minmax'):
'''
ptf stands for Power-of-Two Factor activation quantization for Integer Layernorm.
lis stands for Log-Int-Softmax.
These two are proposed in our "FQ-ViT: Post-Training Quantization for Fully Quantized Vision Transformer".
'''
self.BIT_TYPE_W = BIT_TYPE_DICT['int8']
self.BIT_TYPE_A = BIT_TYPE_DICT['uint8']
self.OBSERVER_W = 'minmax'
self.OBSERVER_A = quant_method
self.QUANTIZER_W = 'uniform'
self.QUANTIZER_A = 'uniform'
self.QUANTIZER_A_LN = 'uniform'
self.CALIBRATION_MODE_W = 'channel_wise'
self.CALIBRATION_MODE_A = 'layer_wise'
self.CALIBRATION_MODE_S = 'layer_wise'
if lis:
self.INT_SOFTMAX = True
self.BIT_TYPE_S = BIT_TYPE_DICT['uint4']
self.OBSERVER_S = 'minmax'
self.QUANTIZER_S = 'log2'
else:
self.INT_SOFTMAX = False
self.BIT_TYPE_S = BIT_TYPE_DICT['uint8']
self.OBSERVER_S = self.OBSERVER_A
self.QUANTIZER_S = self.QUANTIZER_A
if ptf:
self.INT_NORM = True
self.OBSERVER_A_LN = 'ptf'
self.CALIBRATION_MODE_A_LN = 'channel_wise'
else:
self.INT_NORM = False
self.OBSERVER_A_LN = self.OBSERVER_A
self.CALIBRATION_MODE_A_LN = self.CALIBRATION_MODE_A