A hybrid approximation and error compensation method for neural networks based on approximate multiplication
By performing layer-by-layer or weight-by-weight hybrid approximation and error compensation in the neural network, the problems of resource waste and accuracy loss in neural networks under different application scenarios are solved, and more efficient hardware resource utilization and accuracy recovery are achieved.
Patent Information
- Application Number
- CN202210715089.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-23
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2042-06-23
AI Technical Summary
Existing technologies fail to effectively implement hybrid approximation and error compensation in different application scenarios in neural networks, resulting in a waste of hardware resources and loss of accuracy.
Design a neural network hybrid approximation and error compensation method based on approximate multiplication. By analyzing the structure of the neural network model, an appropriate approximate multiplier is selected to perform layer-by-layer or weight-by-weight hybrid approximation, and an error compensation strategy is adopted to reduce accuracy loss. .
It achieves finer-grained neural network division, reduces hardware resource consumption and accuracy loss, and improves the computational efficiency and accuracy recovery capabilities of the neural network.
Smart Images

Figure CN115099405B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial neural network and computing technology, and in particular to a neural network hybrid approximation and error compensation method based on approximate multiplication. Background Art
[0002] As a typical artificial intelligence algorithm, deep neural network is widely used to solve classification, detection and recognition problems. With the complexity and diversification of application scenarios, the network is developing towards a deeper and larger scale, and the demand for computing power and memory is also increasing. With the further study of deep learning methods, the newly developed deep neural networks are becoming more and more complex, and the hardware performance requirements for their function realization are getting higher and higher. At present, the number of parameters of some mainstream neural networks has reached hundreds of megabits, and the amount of calculation has reached billions or even tens of billions. For example, VGG16 has 16 layers, composed of 138 million parameters, and requires a total of 15.5G multiplication and accumulation calculations. However, the complexity of neural networks is still growing rapidly. From a hardware perspective, the bottleneck of computing power restricts the development of neural networks.
[0003] Previous work has used the redundancy of the network as a starting point, using regular or irregular pruning techniques to compress the neural network model, and then retraining to restore accuracy through mask covering. In this way, the model can be compressed to resource-constrained devices such as drones or other portable multimedia devices at the cost of a certain loss of accuracy. With the introduction of various pruning techniques, model compression has reached its limit. Some current work focuses on the inherent fault tolerance of neural networks and begins to combine approximate computing techniques in the network. Due to its unique hierarchical distribution structure and training method, deep neural networks can tolerate a certain degree of error. Therefore, approximations within a certain range will only cause a small loss of accuracy after the retraining step. What is more impressive is that some approximate multipliers will improve the classification accuracy of the neural network due to their own error characteristics. This means that only a small loss of network accuracy or no loss of accuracy is required to significantly reduce the power consumption, area and latency of the hardware.
[0004] While the use of approximate computing units in neural networks brings hardware acceleration, it also poses new challenges. Taking the replacement of multipliers as an example, using the same approximate multiplier globally in the network will introduce errors. This error will accumulate as the number of network layers increases, and may even cause the network to fail to converge.
[0005] The invention with publication number CN107153522A discloses a dynamic precision configurable approximate multiplier for artificial neural network calculation. Under the control of an external control signal, the dynamic precision configurable approximate multiplier can realize the dynamic configuration of the precision of the multiplication operation according to the input characteristics of the data, and give an approximate result of the accurate result. The precision loss caused by the dynamic precision configurable approximate multiplier is within an acceptable range, while the calculation speed of the multiplication is improved, the power consumption is greatly reduced, and the calculation requirements of the artificial neural network are met. The invention with publication number CN113253973A discloses an approximate calculation device and method suitable for pre-classification of neural network data and weights. The weight parameters of the neural network are pre-processed, and fine classification is performed according to the number of consecutive '0's starting from the lowest bit. The input data is simply classified according to the same characteristics. The combination of the two is used as an important basis for configuring the approximate scheme; by controlling the approximate line position of the full adder addition tree accumulation circuit and the low-bit or approximate adder accumulation circuit, an approximate calculation array with different approximate degrees is configured. In view of the fact that the weight parameters of neural network models are often known and fixed, the weight parameters are finely pre-classified and finely simple binary classified according to the characteristics of the input system data. The two are combined to dynamically select approximate multiplication operation arrays with different configurations, so that the selection of approximate schemes can accurately and in real time match the characteristics of the corresponding data and weights, overcoming the blindness, lag and complexity of existing approximate multiplication dynamic configuration schemes.
[0006] However, the aforementioned inventions do not involve hybrid approximation in different application scenarios to achieve a finer-grained division of the network, and do not involve error compensation strategies in such hybrid approximation cases. Summary of the invention
[0007] In view of the deficiencies in the prior art, the present invention provides a neural network hybrid approximation and error compensation method based on approximate multiplication, designs two hybrid approximation schemes, divides the network at a finer granularity, and selects different approximate multipliers for replacement in layers or weights; at the same time, an error compensation strategy is proposed for the accuracy recovery of approximate neural networks.
[0008] To achieve the above object, the present invention adopts the following technical solutions:
[0009] A neural network hybrid approximation and error compensation method based on approximate multiplication, the neural network hybrid approximation and error compensation method comprising the following steps:
[0010] S1, analyze the network structure of the imported neural network model to obtain all the convolutional layers and fully connected layers it contains; combined with the performance parameters of the hardware accelerator loaded by the neural network, call an approximate multiplier database composed of several approximate multipliers as the corresponding search space, and the number of approximate multipliers in the search space is adapted to the size of the convolution kernel;
[0011] S2, adding the binary truth tables of all known approximate multipliers in the search space to the inference path of the neural network model, and performing hybrid approximation on the exact multiplication used by the convolutional layer and the fully connected layer in the neural network model according to the actual needs of the application scenario corresponding to the neural network model: where the inference path of the neural network model refers to the forward transmission and operation of the neural network parameters, including a series of multiplication accumulation, normalization and pooling;
[0012] When the application scenario aims to save more hardware resources, layer-by-layer hybrid approximation is adopted; specifically, the pre-trained neural network model is divided into layers, and the corresponding approximate multipliers are selected from the approximate multiplier database layer by layer. Each layer uses the weight distribution D before the approximate multiplier and the equivalent weight distribution D after the selected approximate multiplier. * The correlation coefficient ρ between them is greater than the preset correlation coefficient threshold, and layer-by-layer mixed approximation is performed;
[0013] When the application scenario aims to obtain higher network accuracy, weight-by-weight hybrid approximation is used; specifically, the pre-trained neural network model is divided by weight, and for each weight, an approximate multiplier with the smallest variance-related quality factor is selected from the approximate multiplier database to perform weight-by-weight hybrid approximation;
[0014] S3, loading the neural network model into the corresponding hardware accelerator, and in the operation process of the neural network model, using the selected approximate multiplier to calculate all the exact multiplications in the convolution layer and the fully connected layer of the neural network model; wherein, error compensation is performed on the hybrid approximated neural network model, and the error compensation process includes:
[0015] Taking the minimum root mean square error distance of the approximate multiplier as the constraint, the weights are fine-tuned and updated in the neural network inference stage; the calculation formula of the root mean square error distance RMS_ED is:
[0016]
[0017] Where M is an N-bit approximate multiplier, a p and b q are the two input operands of the approximate multiplier, p = 0, 1, 2, ..., 2 N -1,q=0,1,2,…,2 N -1.
[0018] Furthermore, the neural network hybrid approximation and error compensation method further comprises the following steps:
[0019] The binary truth table to be evaluated is added to the reasoning path of the neural network model, the actual accuracy loss of the neural network after hybrid approximation and error compensation is calculated, and the binary truth table to be evaluated is evaluated according to the calculated actual accuracy loss.
[0020] Furthermore, in step S2, the process of layer-by-layer hybrid approximation includes the following sub-steps:
[0021] S21, divide the pre-trained neural network model into layers, and obtain the layer set L = {L1, L2, ..., L i ,…,L m}; Get the weight distribution D of the pre-trained neural network model = {D1, D2, ..., D i ,…,D m}; Statistically obtain the approximate multiplier database M = {M1, M2, ..., M j ,…,M n};
[0022] S22, select one of the approximate multipliers M in the approximate multiplier database j , and place them in each layer of the neural network model to calculate the approximate multiplier M j The equivalent weight distribution of the corresponding neural network model
[0023] S23, repeating step S22 until the equivalent weight distribution of the neural network model corresponding to all approximate multipliers is calculated;
[0024] S24, select layer L i , calculated using the approximate multiplier M j The previous weight distribution and the use of approximate multipliers M j The correlation coefficient between the equivalent weight distributions is ρ ij ;
[0025] S25, screen to obtain the correlation coefficient ρ ij The approximate multiplier greater than the correlation coefficient threshold α is used as the layer L i corresponding alternative approximate multipliers;
[0026] S26, repeat steps S24-S25 until the approximate multiplier screening of all layers is completed.
[0027] Furthermore, in step S2, the layer-by-layer hybrid approximation process further includes the following sub-steps:
[0028] The power consumption and area corresponding to each candidate approximate multiplier are calculated, and the approximate multipliers whose power consumption is greater than a power consumption threshold or whose area is greater than an area threshold are eliminated from the candidate approximate multipliers.
[0029] Furthermore, in step S2, the layer-by-layer hybrid approximation process further includes the following sub-steps:
[0030] Select the correlation coefficient ρ ij The smallest approximate multiplier M j As layer L i An approximate multiplier of .
[0031] Furthermore, in step S2, the process of weighted hybrid approximation includes the following steps:
[0032] The pre-trained neural network model is divided by weight to obtain the weight set W = {w1,w2,…,w k ,…,w h}; Statistically obtain the approximate multiplier database M = {M1, M2, ..., M j ,…,M n};
[0033] For each weight w k , each approximate multiplier M is calculated according to the following formula j The variance of is associated with the quality factor:
[0034] VFOM(M j |w k ,x)=PDP j ×delay j ×area j ×VED j
[0035] In the formula, w k and x is the approximate multiplier M j The two input operands, PDP j 、delay j and area j is the approximate multiplier M j Hardware evaluation indicators, representing power delay product, delay and area; VED j is the approximate multiplier M j The error evaluation index represents the error distance variance;
[0036] Select the approximate multiplier with the smallest variance-related quality factor as the weight w k The approximate multiplier M optimal .
[0037] Furthermore, in step S3, the process of performing error compensation on the hybrid approximated neural network model includes the following steps:
[0038] In the case of a fixed N-bit multiplier, for each weight w of the neural network model, another multiplier multiplied with it is traversed in a uniform distribution, and the resulting error distance variances are accumulated one by one to obtain the variance sum E; then w is [0,2 N -1], each time the weight is updated, E is compared successively until w is found that minimizes E * , as the updated weight.
[0039] The beneficial effects of the present invention are:
[0040] Compared with the existing algorithms that use noise to simulate approximate multipliers, the present invention can measure the accuracy loss caused by the application of approximate multipliers to the neural network with the method closest to the actual situation, and can more accurately guide the design of network-friendly multipliers. Compared with the existing application methods of approximate multipliers in the network, hybrid approximation can not only achieve smaller accuracy loss, but also save more hardware energy consumption. A large number of retraining steps are necessary to restore accuracy. Selecting a suitable learning rate, learning strategy, and iterative rounds is very time-consuming even when retraining on a GPU. Therefore, compared with the existing retraining algorithms, the present invention saves more computing power and time costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is the overall technical route for applying the approximate multiplier of the embodiment of the present invention in a neural network.
[0042] Figure 2 It is a schematic diagram of the process of a layer-by-layer hybrid approximate neural network according to an embodiment of the present invention.
[0043] Figure 3 It is a flow chart of a weighted hybrid approximate neural network according to an embodiment of the present invention.
[0044] Figure 4 This is the schematic diagram of the error compensation algorithm based on RMS_ED.
[0045] Figure 5 It is a schematic diagram of a processing unit array based on a hybrid approximate multiplier. DETAILED DESCRIPTION
[0046] The present invention will now be described in further detail with reference to the accompanying drawings.
[0047] It should be noted that the terms such as "upper", "lower", "left", "right", "front", "back", etc. cited in the invention are only for the convenience of description and are not used to limit the scope of implementation of the present invention. Changes or adjustments in their relative relationships should be regarded as the scope of implementation of the present invention without substantially changing the technical content.
[0048] The embodiment of the present invention proposes a neural network hybrid approximation and error compensation method based on approximate multiplication, and the neural network hybrid approximation and error compensation method comprises the following steps:
[0049] S1, analyze the network structure of the imported neural network model to obtain all the convolutional layers and fully connected layers it contains; combined with the performance parameters of the hardware accelerator loaded by the neural network, call the approximate multiplier database composed of several approximate multipliers as the corresponding search space, and the number of approximate multipliers in the search space is adapted to the size of the convolution kernel.
[0050] S2, add the binary truth tables of all known approximate multipliers in the search space to the reasoning path of the neural network model, and perform hybrid approximation on the precise multiplication used in the convolutional layer and the fully connected layer in the neural network model according to the actual needs of the application scenarios corresponding to the neural network model: wherein, the reasoning path of the neural network model refers to the forward transmission and operation of the neural network parameters, including a series of multiplication and accumulation, normalization and pooling, etc., and the present invention only approximates the multiplication therein.
[0051] When the application scenario aims to save more hardware resources, layer-by-layer hybrid approximation is adopted; specifically, the pre-trained neural network model is divided into layers, and the corresponding approximate multipliers are selected from the approximate multiplier database layer by layer. Each layer uses the weight distribution D before the approximate multiplier and the equivalent weight distribution D after the selected approximate multiplier. * The correlation coefficient ρ between them is greater than the preset correlation coefficient threshold, and layer-by-layer mixed approximation is performed.
[0052] When the application scenario aims to obtain higher network accuracy, weight-by-weight hybrid approximation is adopted; specifically, the pre-trained neural network model is divided according to weights, and for each weight, the approximate multiplier with the smallest variance-associated quality factor is selected from the approximate multiplier database to perform weight-by-weight hybrid approximation.
[0053] S3, loading the neural network model into the corresponding hardware accelerator, and in the operation process of the neural network model, using the selected approximate multiplier to calculate all the exact multiplications in the convolution layer and the fully connected layer of the neural network model; wherein, error compensation is performed on the hybrid approximated neural network model, and the error compensation process includes:
[0054] Taking the minimum root mean square error distance of the approximate multiplier as the constraint, the weights are fine-tuned and updated in the neural network inference stage; the calculation formula of the root mean square error distance RMS_ED is:
[0055]
[0056] Where M is an N-bit approximate multiplier, a p and bq are the two input operands of the approximate multiplier, p = 0, 1, 2, ..., 2 N -1,q=0,1,2,…,2 N -1.
[0057] like Figure 1 As shown, the neural network hybrid approximation and error compensation method of this embodiment first analyzes the network structure of the neural network model. A deep neural network usually includes a convolution layer, a pooling layer, and a fully connected layer. The convolution layer and the fully connected layer of the neural network can be further refined into a series of multiplication and accumulation operations. This embodiment mainly approximates the multiplication in these two layers, and the technical focus is on how to select an approximate multiplier to perform the multiplication therein.
[0058] The neural network model of this embodiment can adopt multi-layer perceptron (MLP) and convolutional neural network (CNN). In this embodiment, the application scenario of the neural network model is not specifically limited, but there will be some constraints on hardware resources or network accuracy. For example, when the same neural network model with the function of identifying small targets in an image runs on a PC, the hardware resources are sufficient. At this time, it may put forward more requirements on network accuracy and tend to select approximate multipliers that can improve network accuracy for multiplication operations; when it runs on a drone, the hardware resources are insufficient. At this time, it is more inclined to select some approximate multipliers that can save more hardware resources for multiplication operations. For another example, two different neural network models running on a PC at the same time, one for action recognition and the other for small target recognition, may have different requirements for network accuracy. Assuming that the neural network model for action recognition has a lower requirement for network accuracy, a layer-by-layer hybrid approximation method can be used to save more hardware resources for the neural network for small target recognition, so that the latter adopts a weight-by-weight hybrid approximation method to improve the accuracy of small target recognition, thereby realizing a reasonable allocation of hardware resources.
[0059] In this embodiment, existing approximate multipliers, such as logarithmic multipliers, Booth multipliers, and the EvoApproxLib multiplier library automatically generated by synthesis, can all be called. However, due to the limited scale of the hardware accelerator, while confirming the network structure of the neural network model, we also need to simultaneously confirm the scale parameters or performance parameters loaded into the hardware accelerator. The scale parameters or performance parameters of the hardware accelerator include the number of logic units, the number of computing units, and on-chip storage space, etc. This embodiment roughly selects several approximate multiplier databases that are compatible with the neural network model and hardware resources based on the hardware performance of the multiplier; for example, when the approximate multiplier library database is screened based on hardware power consumption and area, the smaller the area, the more approximate multipliers that can be deployed on the hardware accelerator; and the smaller the power consumption, the more power-saving the approximate multiplier is. Correspondingly, the calculation accuracy of a single approximate multiplier may be limited, etc. Preferably, the number of approximate multipliers in the search space can be adapted to the size of the convolution kernel, and the hybrid approximation effect is better, such as Figure 5 As shown in the figure, when a 3×3 convolution kernel is convolved, nine products are accumulated each time. The highest mixing rate is when the 9 weights in the convolution kernel use different approximate multipliers respectively. Therefore, we can set the approximate multipliers in the search space to 2-9.
[0060] Exemplarily, this embodiment only needs to call the binary truth table of the approximate multiplier in the deep learning framework, without the need to fully reproduce the approximate circuit on the hardware. Therefore, it is scalable and can realize the call of any approximate multiplier. In addition, the binary truth table can be customized to add to the reasoning path, and the design of the approximate multiplier can be guided by the accuracy loss of the network. Specifically, the binary truth table to be evaluated is added to the reasoning path of the neural network model, the actual accuracy loss of the neural network after mixed approximation and error compensation is calculated, and the binary truth table to be evaluated is evaluated according to the calculated actual accuracy loss.
[0061] The reasoning path of the neural network model refers to the forward propagation and operation (multiplication accumulation and pooling sampling) of the parameters in the neural network, excluding back propagation (derivation and gradient descent); in this embodiment, the binary truth table is added to the multiplication operation in the forward propagation.
[0062] use Figure 1 The proposed calling method calls different approximate multipliers multiple times in a network. Based on the special hierarchical distribution structure characteristics of the network, this embodiment proposes a layer-by-layer hybrid approximation method and a weight-by-weight hybrid approximation method.
[0063] Figure 2 This is a block diagram of a layer-by-layer hybrid approximation method for a neural network. In step S2, the layer-by-layer hybrid approximation process includes the following sub-steps:
[0064] S21, divide the pre-trained neural network model into layers, and obtain the layer set L = {L1, L2, ..., L i ,…,L m}; Get the weight distribution D of the pre-trained neural network model = {D1, D2, ..., D i ,…,D m}; Statistically obtain the approximate multiplier database M = {M1, M2, ..., M j ,…,M n}.
[0065] S22, select one of the approximate multipliers M in the approximate multiplier database j , and place them in each layer of the neural network model to calculate the approximate multiplier M j The equivalent weight distribution of the corresponding neural network model
[0066] S23, repeat step S22 until the equivalent weight distribution of the neural network model corresponding to all approximate multipliers is calculated.
[0067] S24, select layer L i , calculated using the approximate multiplier M j The previous weight distribution and the use of approximate multipliers M j The correlation coefficient between the equivalent weight distributions is ρ ij .
[0068] S25, screen to obtain the correlation coefficient ρ ij The approximate multiplier greater than the correlation coefficient threshold α is used as the layer L i The corresponding alternative approximate multiplier.
[0069] S26, repeat steps S24-S25 until the approximate multiplier screening of all layers is completed.
[0070] The neural network is pre-trained to obtain the weight distribution of each layer of the network D = {D1, D2, ..., D i ,…,D m}, the weights of each layer basically satisfy the Gaussian distribution, and different approximate multipliers are applied to the neural network to obtain the equivalent approximate weight distribution of each layer Basically satisfying the noisy Gaussian distribution, the correlation coefficients between the new and old weights are compared, and the approximate multipliers with correlation coefficients greater than the set threshold are selected for each layer. In order to save hardware resources, thresholds p% and a% are further set for the power consumption and area saving of the multipliers, and a suitable set of multipliers is screened for each layer, and finally a series of hybrid approximate neural networks are generated, or the threshold setting is cancelled, and the approximate multiplier with the best correlation coefficient or the lowest hardware energy consumption is directly selected for each layer.
[0071] Figure 3 This is a block diagram of the weight-by-weight hybrid approximation method for a neural network.
[0072] In step S2, the process of weighted hybrid approximation includes the following steps:
[0073] The pre-trained neural network model is divided by weight to obtain the weight set W = {w1,w2,…,w k ,…,w h}; Statistically obtain the approximate multiplier database M = {M1, M2, ..., M j ,…,M n}.
[0074] For each weight w k , each approximate multiplier M is calculated according to the following formula j The variance of is associated with the quality factor:
[0075] VFOM(M j |w k ,x)=PDP j ×delay j ×area j ×VED j
[0076] In the formula, w k and x is the approximate multiplier M j The two input operands, PDP j 、delay j and area j There are three commonly used approximate multipliers M j Hardware evaluation indicators, representing power delay product, delay and area; VED j is the approximate multiplier M j The error evaluation indicator represents the error distance variance.
[0077] Select the approximate multiplier with the smallest variance-related quality factor as the weight w k The approximate multiplier M optimal .
[0078] In order to further reduce the loss of accuracy, the network is divided into finer granularity. Through continuous iterative comparison, the pre-trained neural network model can select the approximate multiplier with the smallest quality factor associated with the error distance variance under the condition of fixed weights. The calculation of the quality factor is related to the hardware indicators PDP, delay and area, as well as the error indicator VED. Therefore, there is no need to set separate thresholds for power consumption and area.
[0079] Compared with the neural network that uses a single approximation method for the entire network, the accuracy loss of the hybrid approximation neural network has been improved, but it is still a certain distance away from the accurate network. Figure 4 An algorithm for restoring network accuracy is presented. The error compensation method based on the root mean square error distance is used to restore the accuracy of the neural network after hybrid approximation. In the case of a fixed multiplier, for each weight w, another multiplier multiplied with it is traversed in a uniform distribution, and the resulting error distance variance is accumulated successively to obtain E. Then w is subjected to the [0,2 N -1], each time the weight is updated, E is compared successively until w is found that minimizes E * It is necessary to point out that the implementation of this method is based on finding the minimum approximation error rather than the minimum accuracy loss. Therefore, it is not necessary to obtain the accuracy of the network online all the time. It can be run offline and the weight data can be fine-tuned and updated before network inference. Compared with continuous online retraining, this method can save a lot of computing power and time costs.
[0080] In order to verify the hardware benefits of the hybrid approximation scheme proposed in this invention, Figure 5 A processing element array based on hybrid approximate multipliers is shown. On the left is an m×n processing element (PE) array, and on the right is a PE processing process, including multiplication and accumulation operations and nonlinear activation, where the multiplication in the multiplication and accumulation module uses a hybrid approximate multiplier.
[0081] The above are only preferred embodiments of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should be regarded as the protection scope of the present invention.
Claims
1. A neural network hybrid approximation and error compensation method based on approximate multiplication, characterized in that: The neural network hybrid approximation and error compensation method comprises the following steps: S1, analyze the network structure of the imported neural network model to obtain all the convolutional layers and fully connected layers it contains; combined with the performance parameters of the hardware accelerator loaded by the neural network, call an approximate multiplier database composed of several approximate multipliers as the corresponding search space, and the number of approximate multipliers in the search space is adapted to the size of the convolution kernel; S2, adding the binary truth tables of all known approximate multipliers in the search space to the inference path of the neural network model, and performing hybrid approximation on the exact multiplication used by the convolutional layer and the fully connected layer in the neural network model according to the actual needs of the application scenario corresponding to the neural network model: where the inference path of the neural network model refers to the forward transmission and operation of the neural network parameters; When the application scenario aims to save more hardware resources, layer-by-layer hybrid approximation is adopted; specifically, the pre-trained neural network model is divided into layers, and the corresponding approximate multipliers are selected from the approximate multiplier database layer by layer. Each layer uses the weight distribution D before the approximate multiplier and the equivalent weight distribution D after the selected approximate multiplier. * The correlation coefficient ρ between them is greater than the preset correlation coefficient threshold, and layer-by-layer mixed approximation is performed; When the application scenario aims to obtain higher network accuracy, weight-by-weight hybrid approximation is used; specifically, the pre-trained neural network model is divided by weight, and for each weight, an approximate multiplier with the smallest variance-related quality factor is selected from the approximate multiplier database to perform weight-by-weight hybrid approximation; S3, loading the neural network model into the corresponding hardware accelerator, and in the operation process of the neural network model, using the selected approximate multiplier to calculate all the exact multiplications in the convolution layer and the fully connected layer of the neural network model; wherein, error compensation is performed on the hybrid approximated neural network model, and the error compensation process includes: Taking the minimum root mean square error distance of the approximate multiplier as the constraint, the weights are fine-tuned and updated in the neural network inference stage; the calculation formula of the root mean square error distance RMS_ED is: Where M is an N-bit approximate multiplier, a p and b q are the two input operands of the approximate multiplier, p = 0, 1, 2, ..., 2 N -1,q=0,1,2,…,2 N -1.
2. The neural network hybrid approximation and error compensation method based on approximate multiplication according to claim 1 is characterized in that: The neural network hybrid approximation and error compensation method also includes the following steps: The binary truth table to be evaluated is added to the reasoning path of the neural network model, the actual accuracy loss of the neural network after hybrid approximation and error compensation is calculated, and the binary truth table to be evaluated is evaluated according to the calculated actual accuracy loss.
3. The neural network hybrid approximation and error compensation method based on approximate multiplication according to claim 1, characterized in that: In step S2, the layer-by-layer hybrid approximation process includes the following sub-steps: S21, divide the pre-trained neural network model into layers, and obtain the layer set L = {L1, L2, ..., L i ,…,L m }; Get the weight distribution D of the pre-trained neural network model = {D1, D2, ..., D i ,…,D m }; Statistically obtain the approximate multiplier database M = {M1, M2, ..., M j ,…,M n }; S22, select one of the approximate multipliers M in the approximate multiplier database j , and place them in each layer of the neural network model to calculate the approximate multiplier M j The equivalent weight distribution of the corresponding neural network model S23, repeating step S22 until the equivalent weight distribution of the neural network model corresponding to all approximate multipliers is calculated; S24, select layer L i , calculated using the approximate multiplier M j The previous weight distribution and the use of approximate multipliers M j The correlation coefficient between the equivalent weight distributions is ρ ij ; S25, screen to obtain the correlation coefficient ρ ij The approximate multiplier greater than the correlation coefficient threshold α is used as the layer L i corresponding alternative approximate multipliers; S26, repeat steps S24-S25 until the approximate multiplier screening of all layers is completed.
4. The neural network hybrid approximation and error compensation method based on approximate multiplication according to claim 3 is characterized in that: In step S2, the layer-by-layer hybrid approximation process further includes the following sub-steps: The power consumption and area corresponding to each candidate approximate multiplier are calculated, and the approximate multipliers whose power consumption is greater than a power consumption threshold or whose area is greater than an area threshold are eliminated from the candidate approximate multipliers.
5. The neural network hybrid approximation and error compensation method based on approximate multiplication according to claim 3 is characterized in that: In step S2, the layer-by-layer hybrid approximation process further includes the following sub-steps: Select the correlation coefficient ρ ij The smallest approximate multiplier M j As layer L i An approximate multiplier of .
6. The neural network hybrid approximation and error compensation method based on approximate multiplication according to claim 1, characterized in that: In step S2, the process of weighted hybrid approximation includes the following steps: The pre-trained neural network model is divided by weight to obtain the weight set W = {w1,w2,…,w k ,…,w h }; Statistically obtain the approximate multiplier database M = {M1, M2, ..., M j ,…,M n }; For each weight w k , each approximate multiplier M is calculated according to the following formula j The variance of is associated with the quality factor: VFOM(M j |w k ,x)=PDP j ×delay j ×area j ×VED j In the formula, w k and x is the approximate multiplier M j The two input operands, PDP j 、delay j and area j is the approximate multiplier M j Hardware evaluation indicators, representing power delay product, delay and area; VED j is the approximate multiplier M j The error evaluation index represents the error distance variance; Select the approximate multiplier with the smallest variance-related quality factor as the weight w k The approximate multiplier M optimal .
7. The neural network hybrid approximation and error compensation method based on approximate multiplication according to claim 1, characterized in that: In step S3, the process of performing error compensation on the hybrid approximated neural network model includes the following steps: In the case of a fixed N-bit multiplier, for each weight w of the neural network model, another multiplier multiplied with it is traversed in a uniform distribution, and the resulting error distance variances are accumulated one by one to obtain the variance sum E; then w is [0,2 N -1], each time the weight is updated, E is compared successively until w is found that minimizes E * , as the updated weight.
