LinearQAT
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Description
Constructs the QAT operator of Linear.
Prototype
- API for construction from scratch:
1qat = amct_pytorch.nn.module.quantization.linear.LinearQAT(in_features, out_features, bias, device, dtype, config)
- API for construction based on the native operator:
1qat = amct_pytorch.nn.module.quantization.linear.LinearQAT.from_float(mod, config)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
in_features |
Input |
Number of input features. An int. |
out_features |
Input |
Number of output features. An int. |
bias |
Input |
Whether to enable bias items to participate in learning. A bool. Other data types (such as integers, strings, and lists) are converted based on the Python truth value judgment rules. Default: True. |
device |
Input |
Running device. Default: None |
dtype |
Input |
Torch data type. Torch data type. Only torch.float32 is supported. |
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 |
Parameter |
Input/Output |
Description |
|---|---|---|
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
- Construction from scratch: returns the constructed QAT single-operator instance.
- Construction based on native operators: returns the QAT single-operator converted from torch.nn.Module.
Example
- 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)