GRUQAT
Applicable Products
Product |
Supported |
|---|---|
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Description
Constructs the QAT operator of GRU.
Prototype
- API for construction from scratch:
1qat = amct_pytorch.nn.module.quantization.gru.GRUQAT(input_size, hidden_size, num_layers=1, bias=True, batch_first=False, dropout=0.0, bidirectional=False, device=None, dtype=None, config=None)
- API for construction based on the native operator:
1qat = amct_pytorch.nn.module.quantization.gru.GRUQAT.from_float(mod, config)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
input_size |
Input |
Number of expected features in input x. An int. |
hidden_size |
Input |
Number of features in the hidden state (h). An int. |
num_layers |
Input |
Number of loop layers, that is, the number of LSTM operator layers. The value is 1 for a single-operator. An int. Default: 1 |
bias |
Input |
Whether to enable bias items to participate in learning. A bool. Default: True |
batch_first |
Input |
Whether to place batch_size in the first dimension. If the value is True, the input and output tensors are (batch, seq, feature). Otherwise, the input and output tensors are (seq, batch, feature). Note that this parameter takes effect only for the x input and does not take effect for the h and c inputs. (h in GRU) A bool. Default: False |
dropout |
Input |
Whether to introduce a Dropout layer to the output of each LSTM layer except the output layer. If the value is not 0, it is introduced. The value is 0 for a single-operator. An int or a float. Default: 0 |
bidirectional |
Input |
Whether the operator is a bidirectional LSTM operator. If the value is True, the LSTM is bidirectional. The value is False for a single-operator. A bool. Default: False |
device |
Input |
Running device. A string. 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. DEFAULT_QAT_CONF = {
"retrain_enable": True,
"retrain_data_config": {
"dst_type": "INT8", # INT8
"batch_num": 1, # Greater than 0
"fixed_min": True,
"clip_max": 1.0,
"clip_min": -1.0
},
"retrain_weight_config": {
"dst_type": "INT8", # INT8
"weights_retrain_algo": "arq_retrain", # arq_retrain/ulq_retrain
"channel_wise": True
}
}
A dict. Default: None |
Parameter |
Input/Output |
Description |
|---|---|---|
mod |
Input |
Native GRU 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 5
from amct_pytorch.nn.module.quantization.gru import GRUQAT GRUQAT(input_size=3, hidden_size=3, num_layers=1, bias=True, batch_first=True, dropout=0, bidirectional=False, device=None, dtype=None, config=None)
- Construction based on the native operator:
1 2 3 4 5 6 7 8
import torch from amct_pytorch.nn.module.quantization.gru import GRUQAT gru_op = torch.nn.lstm(input_size=1, hidden_size=1, num_layers=1, bias=True, batch_first=True, dropout=0, bidirectional=False, device=None, dtype=None, config=None) GRUQAT.from_float(mod=lstm_op, config=None)