# Sequential Characteristics Based Operators Disassembly Quantization Method for LSTM Layers
## 3 Proposed Methodology
### LSTM Sequential Quantization Design  
The LSTM layer is disassembled and becomes a collection of many regular layers, and the quantization calibration method of the regular layers can also be applied. That is, all quantization calibration sets are first fed into the regular layers in front of the LSTM, and the activation quantization threshold is selected according to the distribution of layer-by-layer output data. When encountering an LSTM layer, regardless of the size of the time step, the input quantization calibration set is repeatedly fed into each time step of the LSTMas input to each computational unit in the LSTM. Finally, each output tensor sequence is combined into a single output as the output of the LSTM layer. However, since the LSTM layer processes datasets that have sequential characteristics, once processed according to the basic methods as shown in Figure 2, it is very easy to cause a large loss of quantization accuracy. Our basic quantization algorithm is described in detail as follows. When the quantization algorithm generates quantization parameters of regular layers and LSTM layers, a pseudo-quantization operation is inserted into the weight and output of each layer. That is, the floating-point value is first quantized to a low-bit integer and then inversely quantized back to a floating-point value. Each time, the pseudo-quantized values are used to perform operator calculations, such as convolution, pooling, upsampling, etc. After the calculation is completed, pseudo-quantization is performed again, and the quantization parameters are counted and sent to the next layer. The output of the current layer is used as the input of the next layer and so on. Note that the first layer requires additional pseudo-quantization operations on the input. The overall flow chart of the quantization algorithm for neural network models that integrates the LSTM layer is shown in Figure 2.  
In this section, the quantization calibration process is designed as a sequential-characteristics-based combination strategy for LSTM quantization calibration. The neural network model integrating LSTM layers has both regular layers and LSTM layers. The quantization calibration set of the network model built only for regular layers is relatively simple. Many diverse image groups with different categories, backgrounds, angles, and lightings are selected. The data processed by LSTM are generally sequential; that is, the data collected at different times for the described phenomenon over time. Therefore, this paper designs the sequential-characteristics-based combination strategy of sequential and diverse image groups. Assuming that the time step of the LSTM layer is \(T\), the model input size is \(C\times H\times W\). Thus, \(N\) diverse image datasets groups of different categories, different backgrounds, different angles, and different lightings are selected. Each group contains \(T\) groups of sequential datasets with training consistency; that is, the dimension of the quantized calibration set is \(N\times T\). On the one hand, the combined \(N\times T\) images are used for the quantization calibration of regular layers. On the other hand, when encountering the LSTM layer, according to the time step of LSTM, \(N\) diverse image groups are gradually sent to  
Figure 2: Overall flow chart of the quantization algorithm. each time step, where each diverse image group has sequential characteristics. The specific quantization calibration process is shown in Figure 3.  
More precisely, when generating the quantization parameters, firstly all the \(N\times T\) groups data are sent to the regular layer, the activation quantization threshold is selected according to the output data distribution of this layer, and the data dimension of each layer \(l\) is \(N\times T\times C_{l}\times H_{l}\times W_{l}\).