LinearQAT
Function Usage
Constructs the QAT operator of Linear.
Prototype
API for operator construction from scratch:
amct_pytorch.nn.module.quantization.linear.LinearQAT(in_features, out_features, bias, device, dtype, config)
API for construction based on the native operator:
amct_pytorch.nn.module.quantization.linear.LinearQAT.from_float(mod, config)
Command-Line Options
Option |
Input/Output |
Meaning |
Restriction |
|---|---|---|---|
in_features |
Input |
Number of input features. |
An int. This parameter is mandatory. |
out_features |
Input |
Number of output features. |
Type: int This parameter is mandatory. |
bias |
Input |
Indicates whether to enable bias items to participate in learning. |
Type: bool The default value is True. |
device |
Input |
Running device. |
Default: None |
dtype |
Input |
Torch data type. |
Torch data type. Only torch.float32 is supported. |
config |
Input |
The following is a configuration example. For details about quantization configuration parameters, see Quantization Configuration Parameters. config = {
"retrain_enable":true,
"retrain_data_config": {
"dst_type": "INT8",
"batch_num": 10,
"fixed_min": False,
"clip_min": -1.0,
"clip_max": 1.0
},
"retrain_weight_config": {
"dst_type": "INT8",
"weights_retrain_algo": "arq_retrain",
"channel_wise": False
}
}
|
A dict. Default: None |
Option |
Input/Output |
Description |
Restriction |
|---|---|---|---|
mod |
Input |
Native Linear operator to be quantized. |
A torch.nn.Module. |
config |
Input |
Quantization configuration. The following is a configuration example. For details about quantization configuration parameters, see Quantization Configuration Parameters. config = {
"retrain_enable":true,
"retrain_data_config": {
"dst_type": "INT8",
"batch_num": 10,
"fixed_min": False,
"clip_min": -1.0,
"clip_max": 1.0
},
"retrain_weight_config": {
"dst_type": "INT8",
"weights_retrain_algo": "arq_retrain",
"channel_wise": False
}
}
|
A dict. Default: None |
Returns
A QAT operator of Linear for subsequent quantization perception training.
Examples
Construction from scratch:
1 2 3 4 | from amct_pytorch.nn.module.quantization.linear import LinearQAT LinearQAT(in_features=1, out_features=1, bias=True, device=None, dtype=None, config=None) |
Construction based on the native operator:
1 2 3 4 5 6 | import torch from amct_pytorch.nn.module.quantization.linear import LinearQAT linear_op = torch.nn.Linear(in_features=1, out_features=1, bias=True, device=None, dtype=None) LinearQAT.from_float(mod=linear_op, config=None) |