LSTM model optimization method, accelerator, device and medium

By obtaining the weight matrix sparsity and input sequence sparsity of the LSTM network, judging the operation mode and performing corresponding calculations, the problem of high computational complexity and high power consumption of the LSTM model in embedded applications is solved, and the efficiency and efficiency of the hardware accelerator are improved. Scope of application.

CN113537465BActive Publication Date: 2024-10-08SHENZHEN ECHIEV AUTONOMOUS DRIVING TECH CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202110770411.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-07
Publication Date
2024-10-08
Estimated Expiration
2041-07-07

AI Technical Summary

Technical Problem

Traditional computing platforms cannot effectively carry the huge amount of data calculations of the LSTM model, resulting in high computational complexity and high power consumption in embedded applications, making it difficult to deploy, especially in fields with high latency requirements such as autonomous driving.

Method used

By obtaining the pruned LSTM network weight matrix, calculate the weight sparsity and the input sequence sparsity, determine the operation mode, and perform corresponding calculations according to the sparse or dense operation mode, including the balance adjustment of the weight matrix and the blocking of the input sequence. parallel computing.

Benefits of technology

It improves the computing efficiency and energy efficiency ratio of the LSTM hardware accelerator, enhances the overall performance and scope of application, and realizes simple and easy-to-deploy hardware acceleration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113537465B_ABST
    Figure CN113537465B_ABST
Patent Text Reader

Abstract

The present invention discloses an LSTM model optimization method, an accelerator, a device and a medium. The method comprises the following steps: obtaining a weight matrix of a pruned LSTM network; obtaining the weight sparsity of the weight matrix based on the weight matrix; obtaining the sparsity of an input sequence; judging an operation mode based on the weight sparsity and the sparsity of the input sequence; if the operation mode is judged to be a sparse operation mode, calculating the input sequence according to the sparse operation mode; the present invention aims to improve the energy efficiency ratio of an LSTM hardware accelerator, and is simple to implement and easy to deploy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer hardware acceleration, and in particular to an LSTM model optimization method, accelerator, device and medium. Background Art

[0002] The recurrent neural network (RNN) based on the long short-term memory (LSTM) model is a neural network model that processes sequence data. It effectively solves the gradient vanishing and explosion problems and is widely used in the field of intelligent cognition, such as speech recognition, behavior recognition, and natural language processing. However, in actual engineering application practice, it faces many problems. Traditional computing platforms cannot support such a large amount of data calculation as LSTM. In embedded applications, especially in fields with extremely high latency requirements such as autonomous driving, the LSTM model itself has a huge number of parameters, as well as a large amount of training data and inference test data. This leads to high computational complexity in training models and model inference, and the power consumption of the computing platform is also very high. This makes it difficult to deploy models in embedded devices with extremely high power consumption requirements.

[0003] In order to accelerate the hardware calculation after the LSTM model is sparsified, the industry has introduced the Delta algorithm. By utilizing the numerical similarity of sequence data, the sparsity of sequence data is constructed and mined, and the LSTM model is reconstructed and the algorithm is accelerated. However, this method is limited by the time dependence of sequence data and requires that the input data at adjacent moments have a high degree of similarity. The scope of application is obviously limited. In addition, the hardware acceleration of the Delta-based LSTM model reconstruction is complex to implement, which is not conducive to hardware deployment. Summary of the invention

[0004] In view of this, the embodiments of the present application provide an LSTM model optimization method, accelerator, device and medium. The present application aims to improve the energy efficiency ratio of the LSTM hardware accelerator, and is simple to implement and easy to deploy.

[0005] The present application provides a LSTM model optimization method, the method comprising:

[0006] Get the weight matrix of the pruned LSTM network;

[0007] Based on the weight matrix, obtaining the weight sparsity of the weight matrix;

[0008] Get the sparsity of the input sequence;

[0009] Determining an operation mode based on the sparsity of the weight and the sparsity of the input sequence;

[0010] If the operation mode is determined to be a sparse operation mode, the input sequence is calculated according to the sparse operation mode.

[0011] In one embodiment, judging the operation mode based on the weight sparsity and the sparsity of the input sequence includes:

[0012] If the weight sparsity is greater than or equal to the weight sparsity threshold and / or the sparsity of the input sequence is greater than or equal to the input sequence sparsity threshold, the sparse operation mode is determined.

[0013] In one embodiment, computing the input sequence according to the sparse operation mode includes:

[0014] Performing a balance adjustment on the weight matrix;

[0015] The input sequence is multiplied by the adjusted weight matrix.

[0016] In one embodiment, the balancing and adjusting the weight matrix includes:

[0017] Counting the number of valid weights in the weight matrix;

[0018] Dividing the number of effective weights by the number of rows of the weight matrix to obtain an average effective weight of each row;

[0019] Based on the average of the effective weights, the number of effective weights in each row of the weight matrix is ​​adjusted.

[0020] In one embodiment, obtaining the sparsity of the input sequence includes:

[0021] Zero value detection is performed on the number of zero values ​​or the number of consecutive zero values ​​of the input sequence within a preset number of operation cycles to obtain the sparsity of the input sequence.

[0022] In one embodiment, judging the operation mode based on the weight sparsity and the sparsity of the input sequence further includes:

[0023] If the weight sparsity is less than the weight sparsity threshold and / or the input sequence sparsity is less than the input sequence sparsity threshold, it is determined to be a dense operation mode;

[0024] Wherein, after the step of determining that the intensive operation mode is in progress, the method further includes:

[0025] If the operation mode is determined to be an intensive operation mode, the input sequence is calculated according to the intensive operation mode.

[0026] In one embodiment, the computing the input sequence according to the intensive computing mode includes:

[0027] Based on the number of vector dimensions of the input sequence and the number of nodes in the hidden layer of the LSTM network, the input sequence is divided into multiple blocks to generate multiple block vectors;

[0028] The multiple block vectors are calculated in parallel according to a pipeline control method.

[0029] In order to achieve the above object, a LSTM model optimization device is also provided, the device comprising:

[0030] A data acquisition module is used to acquire a weight matrix of the pruned LSTM network; based on the weight matrix, acquire the weight sparsity of the weight matrix; and acquire the sparsity of the input sequence;

[0031] An operation mode determination module, used for determining the operation mode based on the sparsity of the weight and the sparsity of the input sequence;

[0032] The calculation module is used to calculate the input sequence according to the sparse calculation mode if the calculation mode is determined to be a sparse calculation mode.

[0033] To achieve the above-mentioned purpose, an LSTM hardware accelerator is also provided, comprising a memory, a processor, and an LSTM model optimization method program stored in the memory and executable on the processor, wherein when the processor executes the LSTM model optimization method program, the steps of any of the above-mentioned LSTM model optimization methods are implemented.

[0034] In order to achieve the above-mentioned purpose, a computer storage medium is also provided, on which an LSTM model optimization method program is stored. When the LSTM model optimization method program is executed by a processor, the steps of any of the above-mentioned LSTM model optimization methods are implemented.

[0035] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: obtaining the weight matrix of the pruned LSTM network; obtaining the weight sparsity of the weight matrix based on the weight matrix; obtaining the sparsity of the input sequence; and providing data support for subsequent judgment of the operation mode by accurately obtaining the weight sparsity and the sparsity of the input sequence.

[0036] The operation mode is judged based on the sparsity of the weights and the sparsity of the input sequence; the sparse operation mode or the dense operation mode is judged by the sparsity of the weights and the sparsity of the input sequence, and the corresponding operation mode is calculated to improve the computing efficiency and speed of the LSTM hardware accelerator.

[0037] If the operation mode is determined to be a sparse operation mode, the input sequence is calculated according to the sparse operation mode; the input sequence is calculated according to the sparse operation mode. The judgment of the operation mode is completed by comparing the weight sparsity with the weight sparsity threshold and the sparsity of the input sequence with the input sequence sparsity threshold. When it is determined to be a sparse operation mode, the input sequence is calculated using the sparse operation mode to improve the adaptability of the LSTM hardware accelerator in sparse scenarios. The present invention significantly enhances the overall performance and scope of application of the LSTM hardware accelerator, improves the energy efficiency ratio of the LSTM hardware accelerator, and the implementation method is relatively simple, which is convenient for hardware deployment. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 This is the first embodiment of the LSTM model optimization method of this application;

[0039] Figure 2 The specific implementation steps of step S150 of the first embodiment of the LSTM model optimization method of this application;

[0040] Figure 3 This is a schematic diagram of the PE array involved in the LSTM model optimization method of this application;

[0041] Figure 4 The specific implementation steps of step S151 of the first embodiment of the LSTM model optimization method of this application;

[0042] Figure 5 The specific implementation steps of step S130 of the first embodiment of the calculation method of the LSTM hardware accelerator of this application;

[0043] Figure 6 This is the second embodiment of the LSTM model optimization method of this application;

[0044] Figure 7 The specific implementation steps of step S270 of the second embodiment of the LSTM model optimization method of this application;

[0045] Figure 8 This is a schematic diagram of the LSTM reconfigurable hardware accelerator system for this application;

[0046] Fig. 9 A schematic diagram of the LSTM model optimization device of this application;

[0047] Fig.10 Schematic diagram of the LSTM hardware accelerator for this application. DETAILED DESCRIPTION

[0048] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0049] The main solution of the embodiment of the present invention is: obtaining the weight matrix of the pruned LSTM network; based on the weight matrix, obtaining the weight sparsity of the weight matrix; obtaining the sparsity of the input sequence; based on the weight sparsity and the sparsity of the input sequence, judging the operation mode; if the operation mode is determined to be a sparse operation mode, the input sequence is calculated according to the sparse operation mode; the application aims to improve the energy efficiency ratio of the LSTM hardware accelerator, and is simple to implement and easy to deploy.

[0050] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0051] Reference Figure 1 , Figure 1 This is the first embodiment of the LSTM model optimization method of the present application, the method comprising:

[0052] Step S110: Obtain the weight matrix of the pruned LSTM network.

[0053] Specifically, the Recurrent Neural Network (RNN) based on the Long Short-Term Memory (LSTM) model is a neural network model that processes sequence data. It effectively solves the problems of gradient disappearance and explosion, and is widely used in the field of intelligent cognition, such as speech recognition, behavior recognition, and natural language processing.

[0054] Specifically, the pruning operation compresses the LSTM network to reduce the storage and computational costs of the LSTM network. The methods for compressing the LSTM network mainly include but are not limited to parameter pruning and sharing, low-rank factorization, transferred / compact convolutional filters, and knowledge distillation.

[0055] Specifically, the weight matrix is ​​a matrix composed of weights obtained after training and pruning the LSTM network using the dataset.

[0056] Step S120: Based on the weight matrix, obtain the weight sparsity of the weight matrix.

[0057] Specifically, the weight sparsity of the weight matrix can be calculated by counting the number of zero values ​​in the weight matrix, and the statistics can be performed offline.

[0058] Step S130: Obtain the sparsity of the input sequence.

[0059] Specifically, the input sequence may be data currently input into the LSTM network, wherein the sparsity of the input sequence needs to be counted online, and statistics are performed on the data currently input into the LSTM network; in addition, it should be noted that the sparsity of the input sequence is statistics on zero values ​​in the input sequence.

[0060] Step S140: judging the operation mode based on the sparsity of the weight and the sparsity of the input sequence.

[0061] Specifically, the operation modes include sparse operation mode and dense operation mode. The two operation modes have different calculation methods. Different calculation methods are performed on different types of input sequences, which ensures the correct calculation of the LSTM network, improves the calculation efficiency of the LSTM network, and saves calculation costs.

[0062] In one embodiment, judging the operation mode based on the weight sparsity and the sparsity of the input sequence includes:

[0063] If the weight sparsity is greater than or equal to the weight sparsity threshold and / or the sparsity of the input sequence is greater than or equal to the input sequence sparsity threshold, the sparse operation mode is determined.

[0064] The weight sparsity threshold and the input sequence sparsity threshold can be dynamically adjusted as needed, which is not limited here.

[0065] It should be further explained that if the weight sparsity is greater than or equal to the weight sparsity threshold and / or the sparsity of the input sequence is greater than or equal to the input sequence sparsity threshold, it is determined to be a sparse operation mode, including three situations: first, if the weight sparsity is greater than or equal to the weight sparsity threshold, it is determined to be a sparse operation mode; second, if the sparsity of the input sequence is greater than or equal to the input sequence sparsity threshold, it is determined to be a sparse operation mode; third, if the weight sparsity is greater than or equal to the weight sparsity threshold and the sparsity of the input sequence is greater than or equal to the input sequence sparsity threshold, it is determined to be a sparse operation mode; all three situations are applicable in this embodiment and are not limited here.

[0066] Step S150: If the operation mode is determined to be a sparse operation mode, the input sequence is calculated according to the sparse operation mode.

[0067] Specifically, after the input sequence is input into the LSTM network, calculations are performed according to the sparse operation mode.

[0068] In the above embodiment, the beneficial effects are: obtaining the weight matrix of the pruned LSTM network; based on the weight matrix, obtaining the weight sparsity of the weight matrix; obtaining the sparsity of the input sequence; by accurately obtaining the weight sparsity and the sparsity of the input sequence, providing data support for subsequent judgment of the operation mode.

[0069] The operation mode is judged based on the sparsity of the weights and the sparsity of the input sequence; the sparse operation mode or the dense operation mode is judged by the sparsity of the weights and the sparsity of the input sequence, and the corresponding operation mode is calculated to improve the calculation efficiency and speed of the LSTM model.

[0070] If the operation mode is determined to be a sparse operation mode, the input sequence is calculated according to the sparse operation mode; the input sequence is calculated according to the sparse operation mode. The judgment of the operation mode is completed by comparing the weight sparsity with the weight sparsity threshold and the sparsity of the input sequence with the input sequence sparsity threshold. When it is determined to be a sparse operation mode, the input sequence is calculated using the sparse operation mode to improve the adaptability of the LSTM hardware accelerator in sparse scenarios. The present invention significantly enhances the overall performance and scope of application of the LSTM hardware accelerator, improves the energy efficiency ratio of the LSTM hardware accelerator, and the implementation method is relatively simple, which is convenient for hardware deployment.

[0071] Reference Figure 2 , Figure 2 The specific implementation steps of step S150 of the first embodiment of the LSTM model optimization method of the present application, wherein the input sequence is calculated according to the sparse operation mode, including:

[0072] Step S151: performing a balance adjustment on the weight matrix.

[0073] Specifically, the unbalanced operation unit of the weight matrix is ​​optimized by online reconstructing the PE (processing element) operation unit, adjusting the order of the input sequence and the weight parameters, and rearranging the operation matrix.

[0074] Step S152: performing multiplication calculation on the input sequence and the adjusted weight matrix.

[0075] Specifically, the input sequence and the adjusted weight matrix are input into the PE array for calculation. The PE array can be composed of 4 PE sub-units, matrix-vector operation post-processing, nonlinear activation operation and element-vector dot multiplication operation. For details, refer to Figure 3 .

[0076] In the above embodiment, the beneficial effects are as follows: the input sequence and the adjusted weight matrix are input into the PE array for calculation, and the hardware accelerator PE computing unit is dynamically reconstructed online to improve the utilization rate of PE computing resources and the energy efficiency ratio of the LSTM hardware accelerator.

[0077] Reference Figure 4 , Figure 4 The specific implementation steps of step S151 of the first embodiment of the LSTM model optimization method of this application, wherein the balancing adjustment of the weight matrix comprises:

[0078] Step S1511: Count the number of valid weights in the weight matrix.

[0079] Specifically, the effective weight may be a non-zero element.

[0080] Step S1512: Divide the number of effective weights by the number of rows of the weight matrix to obtain the average effective weight of each row.

[0081] Step S1513: Based on the average of the effective weights, adjust the number of effective weights in each row of the weight matrix.

[0082] Specifically, due to the sparseness of the weight matrix caused by software-level pruning and other operations, the PE unit load imbalance problem is usually encountered during the PE unit operation process, resulting in unequal amounts of data allocated to each PE unit. Therefore, the PE unit with a small amount of allocated data completes the operation and is idle. After the PE unit with a large amount of allocated data completes the operation, the controller continues to instruct the storage unit to start reading the next group of data. The PE computing unit load imbalance problem causes a huge waste of timing resources.

[0083] If the pruned weight matrix is ​​determined to be calculated using the sparse operation mode, in another embodiment, the number of non-zero elements in each row can also be counted, and then the row order of the matrix can be reordered from most to least according to the number of non-zero elements in each row (that is, the rows with more non-zero elements are arranged first), and then each row of the matrix is ​​assigned to a specific PE, so that the amount of data to be processed by each PE is as equal as possible. The operation time of each PE is roughly synchronized, saving timing resources.

[0084] In the above embodiment, the beneficial effect is that the optimization efficiency of the LSTM model is improved and timing resources are saved by balancing and adjusting the weight matrix.

[0085] Reference Figure 5 , Figure 5The specific implementation steps of step S130 of the first embodiment of the LSTM model optimization method of this application, wherein obtaining the sparsity of the input sequence includes:

[0086] Step S131: performing zero value detection on the number of zero values ​​or the number of consecutive zero values ​​of the input sequence within a preset number of operation cycles to obtain the sparsity of the input sequence.

[0087] Specifically, the sparsity of the input sequence may be obtained by counting the zero values ​​in the input sequence. In this embodiment, the more zero values ​​there are in the input sequence, the higher the sparsity of the input sequence.

[0088] Specifically, statistics may be performed on the number of zero values ​​of the input sequence within one operation cycle, or statistics may be performed on the number of consecutive zero values ​​of the input sequence within one operation cycle. Specifically, the ratio of the number of zero values ​​of the input sequence within one operation cycle to the number of data in the input sequence may be used as the sparsity of the input sequence; or the number of consecutive zero values ​​of the input sequence within one operation cycle may be used as the sparsity of the input sequence. This is not limited here, and the preset number of operation cycles is not limited to one operation cycle, but may also be other numbers of operation cycles.

[0089] In the above embodiment, there are beneficial effects: the sparsity of the input sequence is correctly obtained, the correctness of the operation mode selection is ensured, and thus the calculation efficiency of the LSTM model is ensured.

[0090] Reference Figure 6 , Figure 6 This is the second embodiment of the LSTM model optimization method of the present application, and the method further includes:

[0091] Step S210: Obtain the weight matrix of the pruned LSTM network.

[0092] Step S220: Based on the weight matrix, obtain the weight sparsity of the weight matrix.

[0093] Step S230: Obtain the sparsity of the input sequence.

[0094] Step S240: If the weight sparsity is greater than or equal to the weight sparsity threshold and / or the sparsity of the input sequence is greater than or equal to the input sequence sparsity threshold, it is determined to be a sparse operation mode.

[0095] Step S250: Calculate the input sequence according to the sparse operation mode.

[0096] Step S260: If the weight sparsity is less than the weight sparsity threshold and / or the sparsity of the input sequence is less than the input sequence sparsity threshold, it is determined to be an intensive operation mode.

[0097] Step S270: Calculate the input sequence according to the intensive operation mode.

[0098] Specifically, the dense computing mode is different from the sparse computing mode, wherein the dense computing mode may use a block and pipeline computing structure.

[0099] Compared with the first embodiment, the second embodiment includes step S260 and step S270. The other steps have been described in the first embodiment and will not be described again.

[0100] In the above embodiment, the beneficial effects are as follows: the operation mode is judged by judging the sparsity of the weights and the sparsity of the input sequence, and the calculation operation is performed on the input sequence according to the corresponding operation mode, which greatly improves the energy efficiency of the LSTM hardware accelerator, and the implementation method is relatively simple, which is convenient for deployment in the end-side artificial intelligence chip that is sensitive to power consumption.

[0101] Reference Figure 7 , Figure 7 The specific implementation steps of step S270 of the second embodiment of the LSTM model optimization method of this application, wherein the input sequence is calculated according to the intensive operation mode, include:

[0102] Step S271: Based on the number of vector dimensions of the input sequence and the number of nodes in the hidden layer of the LSTM network, the input sequence is divided into multiple blocks to generate multiple block vectors.

[0103] Specifically, the number of blocks is obtained by referring to the number of vector dimensions of the input sequence and the number of nodes in the hidden layer of the LSTM network, and the input sequence is divided into multiple blocks according to the number of blocks to generate multiple block vectors.

[0104] Step S272: performing parallel calculations on the multiple block vectors in a pipeline control manner.

[0105] Specifically, the control method of the pipeline architecture can be that when the system processes data, each clock pulse receives the next instruction to process data. The pipeline mechanism increases the speed at which the system processes data.

[0106] In the above embodiment, the beneficial effect is that the intensive operation mode is executed on the input sequence that needs to execute the intensive operation mode, which greatly improves the calculation efficiency of the LSTM model and improves the energy efficiency ratio of the LSTM hardware accelerator.

[0107] This application protects a LSTM reconfigurable hardware accelerator system, such as Figure 8As shown in the figure, the LSTM reconfigurable hardware accelerator system is mainly composed of an ARM processor, an off-chip DDR synchronous dynamic memory, an LSTM hardware accelerator IP, and an AXI bus. The ARM processor writes the trained weights, biases, and stimulus data into the off-chip DDR memory, configures the accelerator IP through the AXI4-Lite interface, and retrieves the LSTM accelerator calculation results from the off-chip DDR memory for corresponding post-processing. The off-chip DDR memory is used to store weights, biases, stimulus, and calculation result data. The accelerator IP completes the LSTM hardware acceleration of the input stimulus data and writes the calculation results into the off-chip DDR memory through the AXI4 bus. The accelerator IP uses the standard AXI4 BUS and AXI4-Lite interfaces for input and output between the accelerator IP and the outside.

[0108] The present application protects an LSTM model optimization device 20, which comprises:

[0109] A data acquisition module is used to acquire a weight matrix of the pruned LSTM network; based on the weight matrix, acquire the weight sparsity of the weight matrix; and acquire the sparsity of the input sequence;

[0110] An operation mode determination module, used for determining the operation mode based on the sparsity of the weight and the sparsity of the input sequence;

[0111] The calculation module is used to calculate the input sequence according to the sparse calculation mode if the calculation mode is determined to be a sparse calculation mode.

[0112] Fig. 9 The device shown includes a data acquisition module 21, an operation mode determination module 22, a calculation module 23, and an application module 24. The device can execute Figure 1 , Figure 2 , Figures 4 to 7 For the method of the embodiment shown in the figure, the part not described in detail in this embodiment can be referred to Figure 1 , Figure 2 , Figures 4 to 7 The implementation process and technical effects of this technical solution refer to Figure 1 , Figure 2 , Figures 4 to 7 The description in the illustrated embodiment will not be repeated here.

[0113] The present application also protects a computer storage medium on which an LSTM model optimization method program is stored. When the LSTM model optimization method program is executed by a processor, the steps of any of the above-mentioned LSTM model optimization methods are implemented.

[0114] This application also protects an LSTM hardware accelerator, referring to Fig.10, which may include a design architecture that adopts a reconfigurable PE computing unit, and supports online adaptation and reconstruction of PE computing resources according to the density of the input sequence. The specific functions are described as follows:

[0115] System configuration module: For application scenarios, after the system is started, the offline generated configuration information is written into the on-chip SRAM or FF through AXI4-Lite. After the configuration is completed, the current LSTM accelerator configuration information is synchronously updated to the global control unit.

[0116] Main control and operation control unit: including configuration control, input sequence zero value detection and operation state control. Configuration control is to send configuration information to each module of the accelerator at the beginning of each operation. Input sequence zero value detection automatically outputs the calculation mode adopted by the current PE operation unit according to the zero value statistics of the input sequence and the weight sparsity of the system configuration. Operation state control includes independent control of two types of calculations: dense matrix and sparse matrix, and dispatches storage units and computing units to coordinate work.

[0117] Input and output data cache: completes data reading, data distribution and data output functions. Performs interactive transmission between off-chip DDR memory and on-chip data. Mainly includes stimulus reading, parameter reading and result reading, which are distributed to the PE array for calculation under the action of the main control and operation control unit, and the current calculation results are stored.

[0118] PE array: It consists of 4 PE sub-units, matrix-vector operation post-processing, nonlinear activation operation, and element-vector dot multiplication operation. According to the dense-sparse operation type output by the operation control unit, the PE operation unit is reconstructed online. For dense operation scenarios, the conventional block and pipeline calculation structure is adopted; for sparse operation scenarios, the non-balanced operation unit of the sparse weight matrix is ​​optimized by adjusting the row order of the weight matrix and rearranging the weight matrix. For details, refer to Figure 3 .

[0119] The present application also protects an LSTM hardware accelerator, comprising a memory, a processor, and an LSTM model optimization method program stored in the memory and executable on the processor, wherein the processor implements any of the steps of the LSTM model optimization method described above when executing the LSTM model optimization method program.

[0120] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0121] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0122] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0123] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0124] It should be noted that in the claims, any reference signs placed between brackets shall not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claim. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention may be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third etc. does not indicate any order. These words may be interpreted as names.

[0125] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0126] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A LSTM model optimization method, characterized in that: The method comprises: Get the weight matrix of the pruned LSTM network; Based on the weight matrix, obtaining the weight sparsity of the weight matrix; Get the sparsity of the input sequence; Determining an operation mode based on the sparsity of the weight and the sparsity of the input sequence; If the operation mode is determined to be a sparse operation mode, the input sequence is calculated according to the sparse operation mode; The calculating the input sequence according to the sparse operation mode includes: Performing a balance adjustment on the weight matrix; Multiplying the input sequence with the adjusted weight matrix; The balancing and adjusting the weight matrix includes: Counting the number of valid weights in the weight matrix; Dividing the number of effective weights by the number of rows of the weight matrix to obtain an average effective weight of each row; Based on the average of the effective weights, adjusting the number of effective weights in each row of the weight matrix; The step of multiplying the input sequence with the adjusted weight matrix comprises: Input the input sequence and the adjusted weight matrix into the PE array for calculation, and dynamically reconstruct the hardware accelerator PE operation unit online. The PE array consists of 4 PE sub-units, matrix-vector operation post-processing, nonlinear activation operation, and element-vector dot multiplication operation; The determining of the operation mode based on the weight sparsity and the sparsity of the input sequence further includes: If the weight sparsity is less than the weight sparsity threshold and / or the input sequence sparsity is less than the input sequence sparsity threshold, it is determined to be a dense operation mode; Wherein, after the step of determining that the intensive computing mode is in progress, the method further includes: If the operation mode is determined to be an intensive operation mode, the input sequence is calculated according to the intensive operation mode; The calculating the input sequence according to the intensive operation mode includes: Based on the number of vector dimensions of the input sequence and the number of nodes in the hidden layer of the LSTM network, the input sequence is divided into multiple blocks to generate multiple block vectors; The multiple block vectors are calculated in parallel according to a pipeline control method.

2. The LSTM model optimization method according to claim 1, characterized in that: The determining of the operation mode based on the weight sparsity and the input sequence sparsity includes: If the weight sparsity is greater than or equal to the weight sparsity threshold and / or the sparsity of the input sequence is greater than or equal to the input sequence sparsity threshold, the sparse operation mode is determined.

3. The LSTM model optimization method according to claim 1, characterized in that: The obtaining the sparsity of the input sequence includes: Zero value detection is performed on the number of zero values ​​or the number of consecutive zero values ​​of the input sequence within a preset number of operation cycles to obtain the sparsity of the input sequence.

4. A LSTM model optimization device, characterized in that: The device comprises: A data acquisition module is used to acquire a weight matrix of the pruned LSTM network; based on the weight matrix, acquire the weight sparsity of the weight matrix; and acquire the sparsity of the input sequence; An operation mode determination module, used for determining the operation mode based on the sparsity of the weight and the sparsity of the input sequence; a calculation module, configured to calculate the input sequence according to the sparse operation mode if the operation mode is determined to be a sparse operation mode; The calculating the input sequence according to the sparse operation mode includes: Performing a balance adjustment on the weight matrix; performing multiplication calculation on the input sequence and the adjusted weight matrix; The balancing and adjusting the weight matrix includes: Counting the number of effective weights in the weight matrix; dividing the number of effective weights by the number of rows of the weight matrix to obtain an average number of effective weights for each row; and adjusting the number of effective weights for each row of the weight matrix based on the average number of effective weights; The calculation module is further used to input the input sequence and the adjusted weight matrix into the PE array for calculation, and dynamically reconstruct the hardware accelerator PE operation unit online, wherein the PE array is composed of 4 PE sub-units, matrix-vector operation post-processing, nonlinear activation operation, and element-vector dot multiplication operation; The operation mode determination module is further configured to determine that the operation mode is intensive operation mode if the weight sparsity is less than a weight sparsity threshold and / or the input sequence sparsity is less than an input sequence sparsity threshold; The operation mode determination module is further configured to calculate the input sequence according to the intensive operation mode if the operation mode is determined to be an intensive operation mode; The calculating the input sequence according to the intensive operation mode includes: Based on the number of vector dimensions of the input sequence and the number of nodes in the hidden layer of the LSTM network, the input sequence is divided into multiple blocks to generate multiple block vectors; and the multiple block vectors are calculated in parallel according to a pipeline control method.

5. An LSTM hardware accelerator, characterized in that: It includes a memory, a processor, and an LSTM model optimization method program stored in the memory and executable on the processor. When the processor executes the LSTM model optimization method program, the steps of the LSTM model optimization method described in any one of claims 1 to 3 are implemented.

6. A computer storage medium, characterized in that: The computer storage medium stores an LSTM model optimization method program, and when the LSTM model optimization method program is executed by the processor, the steps of the LSTM model optimization method described in any one of claims 1-3 are implemented.

Citation Information

Patent Citations

  • Neural network compression and acceleration method, storage equipment and terminal

    CN107944555A

  • Acceleration method and accelerator applied to convolutional neural network

    CN108510063A

  • LSTM (Long Short-Term Memory) forward direction operation accelerator based on FPGA (Field Programmable Gate Array)

    CN108763159A

  • Sparse neural network processor based on systolic array

    CN110705703A

  • In-memory computing architecture for realizing acceleration and acceleration method thereof

    CN111026700A