Method and device for training neural network model based on storage and computing integrated chip
By initializing the weight parameters and quantization adjustment values on the storage-computing integrated chip, and combining it with the V-type ReLU activation function and gradient descent algorithm, the training accuracy and stability issues of the storage-computing integrated chip are solved, achieving efficient neural network training and performance optimization.
Patent Information
- Application Number
- CN202411890369.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2044-12-20
AI Technical Summary
Traditional neural network training methods are not suitable for integrated storage and computing chips, resulting in poor training accuracy and stability. In addition, there are noise differences and nonlinear current-voltage characteristics between integrated storage and computing chips, making it difficult to achieve effective training on the chip.
Initialize the weight parameters of the neural network model on the integrated storage and computing chip, quantize the weight adjustment value to a preset integer range by adjusting the conductance value, and use the V-type relu activation function combined with the gradient descent algorithm for training until the convergence conditions are met.
It achieves efficient training of neural network models on a storage and computing integrated chip, ensures training accuracy and stability, reduces the risk of chip damage, optimizes neural network performance, and significantly reduces training time.
Smart Images

Figure CN119962597B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of storage-computing integrated chips, and more specifically, to a method and apparatus for training a neural network model based on a storage-computing integrated chip. Background Art
[0002] Traditional storage-computing integrated chips only serve as inference devices in neural network training. Model training must first be performed on a traditional AI (Artificial Intelligence) accelerator on the PC (Personal Computer) side, and then the trained model is placed on the storage-computing integrated chip for inference. Training and inference are separate.
[0003] Most existing neural network model training methods are designed for traditional computing architectures. Not only are these training methods based on floating-point numbers, which offer a wide dynamic range and high precision, but integrated storage and computing chips use integer parameters, which have limited precision and a small range. Therefore, traditional training methods are unsuitable for integrated storage and computing architectures. Furthermore, the current-voltage characteristics of integrated storage and computing chips are typically nonlinear, complicating the calculation of gradients and weight updates during neural network training, especially in the backpropagation algorithm, making it difficult to ensure training accuracy and stability.
[0004] Furthermore, the noise characteristics of the integrated storage and computing chip itself lead to differences between different chips, which need to be fitted during PC training. In addition, the offset of each chip's ADC (Analog to Digital Converter) is different, and the output leakage current of each array is different. These differences lead to slightly different weight storage and calculation values for each chip. Therefore, if an on-chip training method based on the integrated storage and computing chip can be implemented, these characteristic difference noises can be eliminated. At the same time, for the scenario of neural network inference on terminal devices, the integrated storage and computing chip itself can dynamically update the model without the need for retraining and deployment in the cloud.
[0005] Based on the above, how to implement neural network training on a storage and computing integrated chip is an urgent problem that needs to be solved. Summary of the Invention
[0006] The present application provides a method and device for training a neural network model based on a storage-computing integrated chip, which can implement neural network training on the storage-computing integrated chip and ensure the accuracy and stability of neural network model training.
[0007] The specific technical solutions are as follows:
[0008] In a first aspect, an embodiment of the present application provides a method for training a neural network model based on a storage-computing integrated chip. The method is applied to the storage-computing integrated chip, and the method includes:
[0009] Initializing weight parameters of an initial neural network model, obtaining an initial weight value of each network layer of the initial neural network model, and adjusting the conductance value of the storage and computing integrated chip according to the initial weight value of each network layer, wherein the weight value corresponding to the same weight parameter is positively correlated with the corresponding conductance value;
[0010] Inputting a training set into the initial neural network model, outputting a predicted value for each training sample, and determining a current loss value based on a difference between the predicted value and the true value of each training sample, wherein the training set includes a plurality of training samples and a true value corresponding to each training sample;
[0011] Calculating the error gradient of the current loss value with respect to the weight parameter of each network layer, and determining a weight adjustment value for each network layer according to the error gradient of each network layer, wherein the weight adjustment value represents the weight change to be adjusted;
[0012] For each network layer, quantize the weight adjustment value into a preset integer range based on the relationship between the initial weight value of the network layer and the weight value boundary, and obtain a target quantized value corresponding to the weight adjustment value, wherein different quantized values within the preset integer range represent different adjustment directions;
[0013] For the initial weight value of each network layer, call the weight update interface, adjust the initial weight value along the adjustment direction represented by the target quantized value corresponding to the initial weight value, obtain the adjusted weight value, and adjust the conductance value of the storage and computing integrated chip according to the adjusted weight value of each network layer to obtain an updated neural network model;
[0014] The training set is continued to be trained based on the updated neural network model until the current loss value meets the preset convergence condition or reaches the preset iteration number threshold, and the obtained neural network model is used as the target neural network model.
[0015] In one possible implementation, for each network layer, quantizing the weight adjustment value to a preset integer range based on the relationship between the initial weight value and the weight value boundary of the network layer, and obtaining a target quantized value corresponding to the weight adjustment value includes:
[0016] When the initial weight value of the current network layer reaches any weight value boundary, quantizing the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value, and adjusting the initial quantization value to a quantization value in the opposite direction to obtain the target quantization value, wherein the current network layer is the network layer of the weight adjustment value to be quantized;
[0017] When the initial weight value of the current network layer does not reach any weight value boundary, the weight adjustment value of the current network layer is quantized to the preset integer range to obtain an initial quantization value, and the initial quantization value is directly used as the target quantization value.
[0018] In one possible implementation, quantizing the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantized value includes:
[0019] When the weight adjustment value of the current network layer is greater than 0, quantizing the weight adjustment value of the current network layer to a first integer value as the initial quantization value, wherein the first integer value is a preset positive integer, and the first integer value indicates that the weight adjustment value is adjusted in a positive incremental direction;
[0020] When the weight adjustment value of the current network layer is equal to 0, 0 is used as the initial quantization value, and when the initial quantization value is 0, it indicates that the weight adjustment value is not adjusted;
[0021] When the weight adjustment value of the current network layer is less than 0, the weight adjustment value of the current network layer is quantized to a second integer value as the initial quantization value, wherein the second integer value is a preset negative integer, and the second integer value indicates that the weight adjustment value is adjusted in the direction of the reverse increment.
[0022] In one possible implementation, each training sample in the training set includes an input vector;
[0023] The training set is input into the initial neural network model, and the predicted value of each training sample is output, including:
[0024] Inputting the training set into the input layer of the initial neural network model, and performing a matrix multiplication operation on the input vector in the training set and a matrix consisting of multiple initial weight values of the input layer to obtain an output result of the input layer;
[0025] Inputting the output result of the input layer into the hidden layer of the initial neural network model, performing a nonlinear transformation on the output result of the input layer through a V-type relu activation function, performing a matrix multiplication operation on the output result after the nonlinear transformation and a matrix composed of multiple initial weight values of the hidden layer to obtain the output result of the hidden layer;
[0026] The output result of the hidden layer is input into the output layer of the initial neural network model, and the output result of the hidden layer is normalized to obtain the probability distribution of each category, and the category with the largest probability is selected as the prediction value of the initial neural network model for the input vector.
[0027] In a second aspect, an embodiment of the present application provides a device for training a neural network model based on a storage-computing integrated chip. The device is applied to the storage-computing integrated chip, and the device includes:
[0028] An initialization unit, used to initialize the weight parameters of the initial neural network model and obtain the initial weight value of each network layer of the initial neural network model;
[0029] A conductance adjustment unit, configured to adjust the conductance value of the storage-computing integrated chip according to the initial weight value of each network layer, wherein the weight value corresponding to the same weight parameter is positively correlated with the corresponding conductance value;
[0030] A prediction unit, configured to input a training set into the initial neural network model and output a predicted value for each training sample, wherein the training set includes a plurality of the training samples and a true value corresponding to each of the training samples;
[0031] a determination unit, configured to determine a current loss value based on a difference between a predicted value and a true value of each of the training samples;
[0032] a calculation unit, configured to calculate an error gradient of the current loss value with respect to a weight parameter of each network layer, and determine a weight adjustment value of each network layer according to the error gradient of each network layer, wherein the weight adjustment value represents an amount of weight change to be adjusted;
[0033] a quantization unit, configured to quantize, for each network layer, the weight adjustment value into a preset integer range based on a relationship between an initial weight value of the network layer and a weight value boundary, and obtain a target quantization value corresponding to the weight adjustment value, wherein different quantization values within the preset integer range represent different adjustment directions;
[0034] A weight adjustment unit, configured to call a weight update interface for the initial weight value of each network layer, adjust the initial weight value along an adjustment direction represented by the target quantization value corresponding to the initial weight value, and obtain an adjusted weight value;
[0035] The conductance adjustment unit is used to adjust the conductance value of the storage and computing integrated chip according to the adjusted weight value of each network layer to obtain an updated neural network model;
[0036] An iterative training unit is used to continue training the training set based on the updated neural network model until the current loss value meets a preset convergence condition or reaches a preset iteration number threshold, and the obtained neural network model is used as the target neural network model.
[0037] In a possible implementation, the quantization unit includes:
[0038] a quantization module, configured to, when the initial weight value of the current network layer reaches any weight value boundary, quantize the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value; and, when the initial weight value of the current network layer does not reach any weight value boundary, quantize the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value, wherein the current network layer is the network layer whose weight adjustment value is currently to be quantized;
[0039] A setting module is used to adjust the initial quantization value to a quantization value in the opposite direction when the initial weight value of the current network layer reaches any weight value boundary, and obtain the target quantization value; when the initial weight value of the current network layer does not reach any weight value boundary, directly use the initial quantization value as the target quantization value.
[0040] In a possible implementation, the quantization module is configured to:
[0041] When the weight adjustment value of the current network layer is greater than 0, quantizing the weight adjustment value of the current network layer to a first integer value as the initial quantization value, wherein the first integer value is a preset positive integer, and the first integer value indicates that the weight adjustment value is adjusted in a positive incremental direction;
[0042] When the weight adjustment value of the current network layer is equal to 0, 0 is used as the initial quantization value, and when the initial quantization value is 0, it indicates that the weight adjustment value is not adjusted;
[0043] When the weight adjustment value of the current network layer is less than 0, the weight adjustment value of the current network layer is quantized to a second integer value as the initial quantization value, wherein the second integer value is a preset negative integer, and the second integer value indicates that the weight adjustment value is adjusted in the direction of the reverse increment.
[0044] In one possible implementation, each training sample in the training set includes an input vector;
[0045] The prediction unit includes:
[0046] An input layer calculation module, configured to input the training set into the input layer of the initial neural network model, and perform a matrix multiplication operation on the input vector in the training set and a matrix consisting of a plurality of initial weight values of the input layer to obtain an output result of the input layer;
[0047] A hidden layer calculation module is used to input the output result of the input layer into the hidden layer of the initial neural network model, perform a nonlinear transformation on the output result of the input layer through a V-type relu activation function, and perform a matrix multiplication operation on the output result after the nonlinear transformation and a matrix composed of multiple initial weight values of the hidden layer to obtain the output result of the hidden layer;
[0048] The output layer calculation module is used to input the output results of the hidden layer into the output layer of the initial neural network model, and normalize the output results of the hidden layer to obtain the probability distribution of each category, and select the category with the largest probability as the prediction value of the initial neural network model for the input vector.
[0049] In a third aspect, an embodiment of the present application provides a storage and computing integrated chip, which is at least used to implement the method described in any possible implementation method of the first aspect.
[0050] In a fourth aspect, an embodiment of the present application provides an electronic device comprising at least one integrated storage and computing chip as described in the third aspect.
[0051] The method and device for training a neural network model based on a storage-computing integrated chip provided in the embodiment of the present application can train a neural network model on a storage-computing integrated chip. Specifically, the storage-computing integrated chip can initialize the weight parameters of the initial neural network model, obtain the initial weight value of each network layer of the initial neural network model, adjust the conductance value of the storage-computing integrated chip according to the initial weight value of each network layer, input the training set into the initial neural network model, output the predicted value of each training sample, and determine the current loss value based on the difference between the predicted value and the true value of each training sample, calculate the error gradient of the current loss value to the weight parameter of each network layer, and determine the error gradient of each network layer based on the error gradient of each network layer. After the weight adjustment value of the layer is obtained, the weight adjustment value can be quantized to a preset integer range for each network layer according to the relationship between the initial weight value of the network layer and the weight value boundary, and the target quantization value corresponding to the weight adjustment value can be obtained. Then, the weight update interface is called to adjust the initial weight value along the adjustment direction represented by the target quantization value corresponding to the initial weight value to obtain the adjusted weight value, and the conductance value of the storage and computing integrated chip is adjusted according to the adjusted weight value of each network layer to obtain the updated neural network model. Iterative training is performed through the above method until the current loss value meets the preset convergence condition or reaches the preset number of iterations. The final target neural network model can be obtained. It can be seen from this that in the model training process, similar to adjusting the weights of the neural network by gradient descent, the conductance value of the storage and computing integrated array will also be adjusted according to the error feedback. By applying an appropriate voltage (such as a pulse), the conductance of the storage and computing integrated chip can be changed toward the desired value, thereby optimizing the performance of the neural network. Moreover, by quantizing the weight adjustment value to a preset integer range that only represents the adjustment direction, it not only meets the integer characteristics of the storage and computing integrated chip, but also because the conductance value only needs to be updated according to the adjustment direction and does not require an accurate update value, it can significantly reduce the time for updating the weight link during subsequent on-chip training.
[0052] In addition, the embodiments of the present application may also achieve the following technical effects:
[0053] 1. When quantizing the weight adjustment value to a preset integer range, the embodiment of the present application does not directly quantize it, but first determines whether the initial weight value of each network layer reaches the weight value boundary. If the initial weight value of a network layer reaches any weight value boundary, the weight adjustment value of the network layer will be quantized to the preset integer range first to obtain the initial quantization value, and then the initial quantization value will be adjusted in the opposite direction to obtain the final target quantization value, realizing the weight constraint method of extreme value rebound, avoiding the problem of nonlinear and uncontrollable weight data, and thereby reducing the risk of chip damage.
[0054] 2. When training the weights of the neural network, during the forward propagation process, when calculating the output of each unit in the hidden layer, the use of a new neuron activation function, namely the V-type relu function, can ensure that the weights will not shift in the negative direction as a whole after multiple updates, making full use of the representation range of the storage and computing integrated chip. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] To more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are merely some embodiments of the present application. Those skilled in the art can derive other drawings based on these drawings without inventive effort.
[0056] Figure 1 A flowchart of a method for training a neural network model based on a storage and computing integrated chip provided in an embodiment of the present application;
[0057] Figure 2 A flowchart of another method for training a neural network model based on a storage and computing integrated chip provided in an embodiment of the present application;
[0058] Figure 3 An example diagram of the internal network layer structure of a neural network model provided in an embodiment of the present application;
[0059] Figure 4 A schematic diagram of a curve of a V-type relu activation function provided in an embodiment of the present application;
[0060] Figure 5 A block diagram of the composition of a device for training a neural network model based on a storage and computing integrated chip provided in an embodiment of the present application. DETAILED DESCRIPTION
[0061] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0062] It should be noted that, in the absence of conflict, the embodiments in this application and the features in the embodiments can be combined with each other. The terms "including" and "having" in the embodiments of this application and the accompanying drawings, as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices.
[0063] The embodiments of the present application can be applied to scenarios involving neural network models such as image recognition, text recognition, and speech recognition. For example, a face recognition model can be used to recognize faces in images, a text recognition model can be used to recognize text content in text, and a speech recognition model can be used to recognize the content in speech. The neural network model trained in the storage and computing integrated chip of the embodiments of the present application can be a neural network model for any scenario, and the embodiments of the present application do not limit this.
[0064] The following combination Figure 1 and Figure 2 The method of training neural network models based on integrated storage and computing chips is elaborated in detail:
[0065] S110: Initialize the weight parameters of the initial neural network model, obtain the initial weight value of each network layer of the initial neural network model, and adjust the conductance value of the storage and computing integrated chip according to the initial weight value of each network layer.
[0066] Among them, the weight value corresponding to the same weight parameter is positively correlated with the corresponding conductance value.
[0067] In the initial stage of neural network model training, the weight parameters can be randomly initialized to obtain the initial weight value of each network layer, and then the conductance value can be adjusted according to the positive correlation between the weight parameters and the conductance value of the storage and computing integrated chip.
[0068] In a neural network, weights typically represent the strength of the connections between neurons. The integrated storage and computing chip uses conductance to store and represent this "connection strength." Specifically, different conductance states (e.g., high or low conductance) of the integrated storage and computing chip can represent different weight values in the neural network:
[0069] A high conductance represents a stronger connection, similar to a larger weight;
[0070] A low conductance represents a weaker connection, similar to a smaller weight.
[0071] During the training process, the conductance of the storage and computing chip will be adjusted as the input signal changes, thereby updating the weights.
[0072] S120: Input the training set into the initial neural network model, output the predicted value of each training sample, and determine the current loss value based on the difference between the predicted value and the true value of each training sample.
[0073] The training set includes multiple training samples and the true value corresponding to each training sample. In the embodiment of the present application, each training sample in the training set includes an input vector. The input vector can be a vector generated based on raw data such as sample images, sample text, or sample speech.
[0074] like Figure 2 As shown, the specific implementation process of inputting the training set into the initial neural network model and outputting the predicted value of each training sample includes: inputting the training set into the input layer of the initial neural network model, and performing matrix multiplication operation on the input vector in the training set and the matrix composed of multiple initial weight values of the input layer to obtain the output result of the input layer; inputting the output result of the input layer into the hidden layer of the initial neural network model, and performing nonlinear transformation on the output result of the input layer through the V-type relu activation function, and performing matrix multiplication operation on the output result after the nonlinear transformation and the matrix composed of multiple initial weight values of the hidden layer to obtain the output result of the hidden layer; inputting the output result of the hidden layer into the output layer of the initial neural network model, and normalizing the output result of the hidden layer to obtain the probability distribution of each category, and selecting the category with the largest probability as the predicted value of the initial neural network model for the input vector.
[0075] Among them, Figure 3 As shown in the figure, the neural network model includes an input layer, a hidden layer, and an output layer, and the hidden layer can include at least one layer. In this figure, x represents the input data, w represents the weight parameter, z represents the result of the weight matrix calculation of each layer, f() represents the activation function, and y is the final output result.
[0076] like Figure 4 As shown in the figure, when training the weights of a neural network, in the forward propagation process, a new neuron activation function, namely the V-type relu function, is used to calculate the output of each unit in the hidden layer. The details are as follows:
[0077] The activation function for hidden layer neurons uses a variant of the ReLU. Unlike ReLU, the slope of the negative half-axis is -1, forming a V-shaped function symmetrical along the Y axis, with the formula y = |x|. This activation function ensures that the weights do not shift in the negative direction overall after multiple updates, fully utilizing the storage and computing chip's range.
[0078] After obtaining the predicted value of each training sample, the difference between the predicted value and the true value of each training sample can be calculated, and the mean square error of all differences can be used as the current loss value. Cross entropy can also be used as the current loss value, or other algorithms can be used. The embodiment of the present application does not limit the method for calculating the loss value.
[0079] S130: Calculate the error gradient of the current loss value with respect to the weight parameters of each network layer, and determine the weight adjustment value of each network layer according to the error gradient of each network layer.
[0080] The weight adjustment value represents the weight change to be adjusted.
[0081] After obtaining the current loss value, the backpropagation method (such as the chain rule) can be used to calculate the error gradient of the current loss value to the weight parameters of each network layer, and the optimization algorithm (such as SGD (Stochastic Gradient Descent) momentum, Adam (Adaptive Moment Estimation), etc.) can be used to determine the weight adjustment value of each network layer according to the error gradient of each network layer.
[0082] S140: For each network layer, according to the relationship between the initial weight value of the network layer and the weight value boundary, quantize the weight adjustment value to a preset integer range to obtain a target quantization value corresponding to the weight adjustment value.
[0083] Different quantization values within the preset integer range represent different adjustment directions, including a positive incremental direction, a negative incremental direction, and a 0 direction (ie, no adjustment, the value remains unchanged).
[0084] In a storage-computing chip, data is of type int, typically in the range [-8, 7]. When adjusting weight parameters during neural network training, these parameters can reach the extreme values of -8 and 7. A large number of these extreme values can damage the chip. Furthermore, values outside the allowable range of the storage-computing chip can cause nonlinear and uncontrollable weight data. A neural network with numerous extreme values is not conducive to training. This differs from the wide dynamic range of floating-point numbers. For training such integer weights, bounded weight constraints are required.
[0085] This weight constraint method can be called extreme value rebound, that is, when the weight being adjusted is already an extreme value when the weight is updated, the update will force the extreme value parameter to be adjusted in the opposite direction. Therefore, when the initial weight value of the current network layer reaches any weight value boundary, the weight adjustment value of the current network layer is quantized to a preset integer range to obtain the initial quantization value, and after adjusting the initial quantization value to a quantization value in the opposite direction, the target quantization value is obtained, wherein the current network layer is the network layer of the current weight adjustment value to be quantized. For example, when the weight value of a certain position is already -8, when the weight is updated again, the adjustment direction is set to 1 when calling the weight update interface. When the weight parameter is 7, -1 is passed in.
[0086] When the initial weight value of the current network layer does not reach any weight value boundary, the weight adjustment value of the current network layer is quantized to a preset integer range to obtain an initial quantization value, and the initial quantization value is directly used as the target quantization value.
[0087] The specific implementation of “quantizing the weight adjustment value of the current network layer to a preset integer range to obtain an initial quantization value” may include:
[0088] (1) When the weight adjustment value of the current network layer is greater than 0, the weight adjustment value of the current network layer is quantized to a first integer value as an initial quantization value.
[0089] The first integer value is a preset positive integer, and the first integer value indicates that the weight adjustment value is adjusted in the direction of a positive increment. The first integer value can be 1, 2, or the like.
[0090] (2) When the weight adjustment value of the current network layer is equal to 0, 0 is used as the initial quantization value, and when the initial quantization value is 0, it means that the weight adjustment value is not adjusted.
[0091] (3) When the weight adjustment value of the current network layer is less than 0, the weight adjustment value of the current network layer is quantized to a second integer value as an initial quantization value.
[0092] The second integer value is a preset negative integer, and the second integer value indicates that the weight adjustment value is adjusted in the direction of the reverse increment. The second integer value can be -1, -2, etc.
[0093] S150: For the initial weight value of each network layer, call the weight update interface, adjust the initial weight value along the adjustment direction represented by the target quantization value corresponding to the initial weight value, obtain the adjusted weight value, and adjust the conductance value of the storage and computing integrated chip according to the adjusted weight value of each network layer to obtain an updated neural network model.
[0094] The target quantitative value only indicates the adjustment direction, and the specific adjustment amount can be random.
[0095] For example, assume that the 2x2 weight matrix on the memristor array needs to be adjusted, and the initial weight values of the memristors are as follows:
[0096] [-8,5]
[0097] [-3,7]
[0098] The weight adjustment value of each network layer is determined based on the error gradient of each network layer:
[0099] [-0.03,0.0]
[0100] [0.01,0.05]
[0101] The initial quantization value obtained after the weight adjustment value is quantized to a preset integer range (including -1, 0, 1) is:
[0102] [-1,0]
[0103] [1,1]
[0104] Since there are boundary values in the initial weight values, the extreme value rebound method is used to process the initial quantization value to obtain the target quantization value, including:
[0105] [1,0]
[0106] [1,-1]
[0107] Pass the target quantized value processed by the extreme rebound constraint to the weight update interface for actual weight adjustment.
[0108] -1 decreases the weight, 1 increases the weight, and 0 remains unchanged. The operation is as follows (+1, -1 indicates the adjustment direction):
[0109] [-8+1,5+0]
[0110] [-3+1,7-1]
[0111] Due to the noise characteristics of the memristor itself, the +1 and -1 update values do not represent a change of 1 unit in value, but rather random changes in value, but in the same direction. Therefore, the actual value obtained may be as follows:
[0112] [-4,5]
[0113] [-1,5].
[0114] The weight parameter storage precision supported by the integrated storage and computing chip is int4, meaning that each storage cell can have 16 resistance states (or conductance states), which can only represent an integer in the int4 range (-8 to 7), with a linear mapping relationship between the two. The weights of the memristors are updated through block programming, but only the direction of the update operation (increase or decrease the weight) is given, without specifying the specific change value. The conductance of an area is simultaneously increased (set) and decreased (reset) to complete the programming of the integrated storage and computing chip and achieve the update of the memristor weights. The block programming operation process is implemented through software control. The software increases and decreases (sets and resets) the conductance value of the entire area of the integrated storage and computing chip. The update only needs to be made according to the direction of the change, without requiring a precise update value. This can significantly reduce the time required to update the weights during subsequent on-chip training.
[0115] During training, similar to how neural network weights are adjusted through gradient descent, the conductance of the memory-computing chip is adjusted based on error feedback. By applying an appropriate voltage (e.g., a pulse), the conductance of the memory-computing chip can be adjusted toward the desired value, thereby optimizing the performance of the neural network.
[0116] It should be added that the present embodiment focuses only on the direction of weight adjustment, rather than the specific amount of data to be adjusted, for the following reasons:
[0117] 1. The optimization goal is the local minimum:
[0118] The goal of a neural network is to find a point that minimizes the loss function. In multidimensional space, this point is usually not unique, but rather a local or global minimum. The direction of the gradient is of particular interest, as it indicates the direction of the fastest increase in the loss function. Weights should be adjusted in the opposite direction of the gradient to minimize the loss.
[0119] 2. Working principle of gradient descent method:
[0120] The update rule of gradient descent is based on the gradient information of the weight with respect to the loss function. Refer to the following formula and explanation:
[0121]
[0122] Among them, ω old is the weight value before adjustment, ω new is the adjusted weight value, η is the learning rate, is the problem gradient of the current weight. The direction of the update is determined. The specific value of the weight will be adjusted according to the learning rate, but the most important thing is the direction of the gradient. As long as the direction is correct, the weight will be adjusted in the direction of minimizing the loss.
[0123] 3. Scale insensitivity:
[0124] Minimizing the loss function is inherently less dependent on the exact numerical values of the weights, but rather on the direction in which the weights are adjusted. If the learning rate is appropriate, a slight adjustment that is too large or too small will not significantly affect the final result. The important thing is to update in the right direction.
[0125] 4. Dynamic nature of the training process:
[0126] During training, weight values change constantly. The weight update process focuses on gradual adjustments, making the model more accurate after each update, without focusing too much on the absolute value of each update. Excessive focus on specific values can lead to inefficient model training or overfitting.
[0127] In general, weight updates during neural network training focus on the direction of adjustment—that is, adjusting the model parameters in the direction of the loss function's decrease—rather than the specific values of the update. The goal of optimization is to gradually approach the minimum value of the loss function, and the update direction is the most important information in this process.
[0128] S160: Continue training the training set based on the updated neural network model until the current loss value meets the preset convergence condition or reaches the preset iteration number threshold, and use the obtained neural network model as the target neural network model.
[0129] The preset convergence condition includes, but is not limited to: the current loss value is less than or equal to a preset loss threshold. The preset loss threshold and the preset iteration number threshold can both be empirical values.
[0130] The method for training a neural network model based on a storage-computing integrated chip provided in an embodiment of the present application can train a neural network model on a storage-computing integrated chip. Specifically, the storage-computing integrated chip can initialize the weight parameters of the initial neural network model, obtain the initial weight value of each network layer of the initial neural network model, adjust the conductance value of the storage-computing integrated chip according to the initial weight value of each network layer, and input the training set into the initial neural network model, output the predicted value of each training sample, and determine the current loss value based on the difference between the predicted value and the true value of each training sample, calculate the error gradient of the current loss value to the weight parameter of each network layer, and determine the error gradient of each network layer based on the error gradient of each network layer. After the weight adjustment value is obtained, the weight adjustment value can be quantized to a preset integer range for each network layer according to the relationship between the initial weight value and the weight value boundary of the network layer, and the target quantization value corresponding to the weight adjustment value can be obtained. The weight update interface is then called to adjust the initial weight value along the adjustment direction represented by the target quantization value corresponding to the initial weight value to obtain the adjusted weight value, and the conductance value of the storage and computing chip is adjusted according to the adjusted weight value of each network layer to obtain the updated neural network model. Iterative training is performed through the above method until the current loss value meets the preset convergence condition or reaches the preset iteration number threshold, and the final target neural network model required can be obtained. It can be seen from this that in the model training process, similar to adjusting the weights of the neural network by gradient descent, the conductance value of the storage and computing array will also be adjusted according to the error feedback. By applying an appropriate voltage (such as a pulse), the conductance of the storage and computing chip can be changed toward the desired value, thereby optimizing the performance of the neural network. Moreover, by quantizing the weight adjustment value to a preset integer range that only represents the adjustment direction, not only does it meet the integer characteristics of the storage and computing integrated chip, but also because the conductance value only needs to be updated according to the adjustment direction and does not require an accurate update value, it can significantly reduce the time for updating the weight link during subsequent on-chip training.
[0131] In addition, when quantizing the weight adjustment value to a preset integer range, the embodiment of the present application does not directly quantize it, but first determines whether the initial weight value of each network layer reaches the weight value boundary. If the initial weight value of a network layer reaches any weight value boundary, the weight adjustment value of the network layer will be quantized to a preset integer range first to obtain the initial quantization value, and then the initial quantization value will be adjusted in the opposite direction to obtain the final target quantization value, thereby realizing the weight constraint method of extreme value rebound, avoiding the problem of nonlinear uncontrollable weight data, and thus reducing the risk of chip damage. When performing weight training for neural network training, in the process of forward propagation, when calculating the output part of each layer unit in the hidden layer, by adopting a new neuron activation function, namely the V-type relu function, it can be ensured that the weight will not be offset in the negative direction as a whole after multiple updates, and the representation range of the storage and computing integrated chip is fully utilized.
[0132] Based on the above method embodiment, another embodiment of the present application provides a device for training a neural network model based on a storage and computing integrated chip, and the device is applied to the storage and computing integrated chip, such as Figure 5 As shown, the device includes:
[0133] Initialization unit 210, used to initialize the weight parameters of the initial neural network model and obtain the initial weight value of each network layer of the initial neural network model;
[0134] The conductance adjustment unit 220 is configured to adjust the conductance value of the storage-computing integrated chip according to the initial weight value of each network layer, wherein the weight value corresponding to the same weight parameter is positively correlated with the corresponding conductance value;
[0135] A prediction unit 230 is configured to input a training set into the initial neural network model and output a predicted value for each training sample, wherein the training set includes a plurality of training samples and a true value corresponding to each training sample;
[0136] a determination unit 240, configured to determine a current loss value based on a difference between a predicted value and a true value of each of the training samples;
[0137] a calculation unit 250, configured to calculate an error gradient of the current loss value with respect to a weight parameter of each network layer, and determine a weight adjustment value for each network layer based on the error gradient of each network layer, wherein the weight adjustment value represents an amount of weight change to be adjusted;
[0138] a quantization unit 260 configured to quantize the weight adjustment value into a preset integer range for each network layer based on the relationship between the initial weight value and the weight value boundary of the network layer, and obtain a target quantization value corresponding to the weight adjustment value, wherein different quantization values within the preset integer range represent different adjustment directions;
[0139] The weight adjustment unit 270 is configured to call a weight update interface for the initial weight value of each network layer, adjust the initial weight value along the adjustment direction represented by the target quantization value corresponding to the initial weight value, and obtain an adjusted weight value;
[0140] The conductance adjustment unit 220 is used to adjust the conductance value of the storage and computing chip according to the adjusted weight value of each network layer to obtain an updated neural network model;
[0141] The iterative training unit 280 is used to continue training the training set based on the updated neural network model until the current loss value meets the preset convergence condition or reaches the preset iteration number threshold, and the obtained neural network model is used as the target neural network model.
[0142] In a possible implementation, the quantization unit 260 includes:
[0143] a quantization module, configured to, when the initial weight value of the current network layer reaches any weight value boundary, quantize the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value; and, when the initial weight value of the current network layer does not reach any weight value boundary, quantize the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value, wherein the current network layer is the network layer whose weight adjustment value is currently to be quantized;
[0144] A setting module is used to adjust the initial quantization value to a quantization value in the opposite direction when the initial weight value of the current network layer reaches any weight value boundary, and obtain the target quantization value; when the initial weight value of the current network layer does not reach any weight value boundary, directly use the initial quantization value as the target quantization value.
[0145] In a possible implementation, the quantization module is configured to:
[0146] When the weight adjustment value of the current network layer is greater than 0, quantizing the weight adjustment value of the current network layer to a first integer value as the initial quantization value, wherein the first integer value is a preset positive integer, and the first integer value indicates that the weight adjustment value is adjusted in a positive incremental direction;
[0147] When the weight adjustment value of the current network layer is equal to 0, 0 is used as the initial quantization value, and when the initial quantization value is 0, it indicates that the weight adjustment value is not adjusted;
[0148] When the weight adjustment value of the current network layer is less than 0, the weight adjustment value of the current network layer is quantized to a second integer value as the initial quantization value, wherein the second integer value is a preset negative integer, and the second integer value indicates that the weight adjustment value is adjusted in the direction of the reverse increment.
[0149] In one possible implementation, each training sample in the training set includes an input vector;
[0150] The prediction unit includes:
[0151] An input layer calculation module, configured to input the training set into the input layer of the initial neural network model, and perform a matrix multiplication operation on the input vector in the training set and a matrix consisting of a plurality of initial weight values of the input layer to obtain an output result of the input layer;
[0152] A hidden layer calculation module is used to input the output result of the input layer into the hidden layer of the initial neural network model, perform a nonlinear transformation on the output result of the input layer through a V-type relu activation function, and perform a matrix multiplication operation on the output result after the nonlinear transformation and a matrix composed of multiple initial weight values of the hidden layer to obtain the output result of the hidden layer;
[0153] The output layer calculation module is used to input the output results of the hidden layer into the output layer of the initial neural network model, and normalize the output results of the hidden layer to obtain the probability distribution of each category, and select the category with the largest probability as the prediction value of the initial neural network model for the input vector.
[0154] The device for training a neural network model based on a storage-computing integrated chip provided in an embodiment of the present application can train a neural network model on a storage-computing integrated chip. Specifically, the storage-computing integrated chip can initialize the weight parameters of the initial neural network model, obtain the initial weight value of each network layer of the initial neural network model, adjust the conductance value of the storage-computing integrated chip according to the initial weight value of each network layer, and input the training set into the initial neural network model, output the predicted value of each training sample, and determine the current loss value based on the difference between the predicted value and the true value of each training sample, calculate the error gradient of the current loss value to the weight parameter of each network layer, and determine the error gradient of each network layer based on the error gradient of each network layer. After the weight adjustment value is obtained, the weight adjustment value can be quantized to a preset integer range for each network layer according to the relationship between the initial weight value and the weight value boundary of the network layer, and the target quantization value corresponding to the weight adjustment value can be obtained. The weight update interface is then called to adjust the initial weight value along the adjustment direction represented by the target quantization value corresponding to the initial weight value to obtain the adjusted weight value, and the conductance value of the storage and computing chip is adjusted according to the adjusted weight value of each network layer to obtain the updated neural network model. Iterative training is performed through the above method until the current loss value meets the preset convergence condition or reaches the preset iteration number threshold, and the final target neural network model required can be obtained. It can be seen from this that in the model training process, similar to adjusting the weights of the neural network by gradient descent, the conductance value of the storage and computing array will also be adjusted according to the error feedback. By applying an appropriate voltage (such as a pulse), the conductance of the storage and computing chip can be changed toward the desired value, thereby optimizing the performance of the neural network. Moreover, by quantizing the weight adjustment value to a preset integer range that only represents the adjustment direction, not only does it meet the integer characteristics of the storage and computing integrated chip, but also because the conductance value only needs to be updated according to the adjustment direction and does not require an accurate update value, it can significantly reduce the time for updating the weight link during subsequent on-chip training.
[0155] In addition, when quantizing the weight adjustment value to a preset integer range, the embodiment of the present application does not directly quantize it, but first determines whether the initial weight value of each network layer reaches the weight value boundary. If the initial weight value of a network layer reaches any weight value boundary, the weight adjustment value of the network layer will be quantized to a preset integer range first to obtain the initial quantization value, and then the initial quantization value will be adjusted in the opposite direction to obtain the final target quantization value, thereby realizing the weight constraint method of extreme value rebound, avoiding the problem of nonlinear uncontrollable weight data, and thus reducing the risk of chip damage. When performing weight training for neural network training, in the process of forward propagation, when calculating the output part of each layer unit in the hidden layer, by adopting a new neuron activation function, namely the V-type relu function, it can be ensured that the weight will not be offset in the negative direction as a whole after multiple updates, and the representation range of the storage and computing integrated chip is fully utilized.
[0156] Based on the above method embodiments, another embodiment of the present application provides a storage and computing integrated chip, which is at least used to implement the method described in any one of the embodiments.
[0157] Based on the above method embodiment, another embodiment of the present application provides an electronic device, which includes at least one storage and computing integrated chip as described above.
[0158] The above-mentioned device embodiment corresponds to the method embodiment and has the same technical effects as the method embodiment. For specific descriptions, please refer to the method embodiment. The device embodiment is obtained based on the method embodiment. For specific descriptions, please refer to the method embodiment section and will not be repeated here. It should be understood by those skilled in the art that the accompanying drawings are only schematic diagrams of one embodiment, and the modules or processes in the accompanying drawings are not necessarily required to implement this application.
[0159] Those skilled in the art will appreciate that the modules in the apparatuses of the embodiments may be distributed in the apparatuses of the embodiments as described in the embodiments, or may be located in one or more apparatuses different from the embodiments with corresponding changes. The modules in the above embodiments may be combined into one module or further divided into multiple sub-modules.
[0160] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for training a neural network model based on a storage and computing integrated chip, characterized in that: The method is applied to a storage-computing integrated chip, and the method includes: Initializing weight parameters of an initial neural network model, obtaining an initial weight value of each network layer of the initial neural network model, and adjusting the conductance value of the storage and computing integrated chip according to the initial weight value of each network layer, wherein the weight value corresponding to the same weight parameter is positively correlated with the corresponding conductance value; Inputting a training set into the initial neural network model, outputting a predicted value for each training sample, and determining a current loss value based on a difference between the predicted value and the true value of each training sample, wherein the training set includes a plurality of training samples and a true value corresponding to each training sample; Calculating the error gradient of the current loss value with respect to the weight parameter of each network layer, and determining a weight adjustment value for each network layer according to the error gradient of each network layer, wherein the weight adjustment value represents the weight change to be adjusted; For each network layer, quantize the weight adjustment value into a preset integer range based on the relationship between the initial weight value of the network layer and the weight value boundary, and obtain a target quantized value corresponding to the weight adjustment value, wherein different quantized values within the preset integer range represent different adjustment directions; For the initial weight value of each network layer, call the weight update interface, adjust the initial weight value along the adjustment direction represented by the target quantized value corresponding to the initial weight value, obtain the adjusted weight value, and adjust the conductance value of the storage and computing integrated chip according to the adjusted weight value of each network layer to obtain an updated neural network model; Continuing to train the training set based on the updated neural network model until the current loss value satisfies a preset convergence condition or reaches a preset iteration number threshold, and using the obtained neural network model as the target neural network model; For each network layer, according to the relationship between the initial weight value and the weight value boundary of the network layer, the weight adjustment value is quantized to a preset integer range to obtain a target quantized value corresponding to the weight adjustment value, including: When the initial weight value of the current network layer reaches any weight value boundary, quantizing the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value, and adjusting the initial quantization value to a quantization value in the opposite direction to obtain the target quantization value, wherein the current network layer is the network layer of the weight adjustment value to be quantized; When the initial weight value of the current network layer does not reach any weight value boundary, the weight adjustment value of the current network layer is quantized to the preset integer range to obtain an initial quantization value, and the initial quantization value is directly used as the target quantization value.
2. The method according to claim 1, characterized in that Quantizing the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value includes: When the weight adjustment value of the current network layer is greater than 0, quantizing the weight adjustment value of the current network layer to a first integer value as the initial quantization value, wherein the first integer value is a preset positive integer, and the first integer value indicates that the weight adjustment value is adjusted in a positive incremental direction; When the weight adjustment value of the current network layer is equal to 0, 0 is used as the initial quantization value, and when the initial quantization value is 0, it indicates that the weight adjustment value is not adjusted; When the weight adjustment value of the current network layer is less than 0, the weight adjustment value of the current network layer is quantized to a second integer value as the initial quantization value, wherein the second integer value is a preset negative integer, and the second integer value indicates that the weight adjustment value is adjusted in the direction of the reverse increment.
3. The method according to any one of claims 1 to 2, characterized in that Each training sample in the training set includes an input vector; The training set is input into the initial neural network model, and the predicted value of each training sample is output, including: Inputting the training set into the input layer of the initial neural network model, and performing a matrix multiplication operation on the input vector in the training set and a matrix consisting of multiple initial weight values of the input layer to obtain an output result of the input layer; Inputting the output result of the input layer into the hidden layer of the initial neural network model, performing a nonlinear transformation on the output result of the input layer through a V-type relu activation function, performing a matrix multiplication operation on the output result after the nonlinear transformation and a matrix composed of multiple initial weight values of the hidden layer to obtain the output result of the hidden layer; The output result of the hidden layer is input into the output layer of the initial neural network model, and the output result of the hidden layer is normalized to obtain the probability distribution of each category, and the category with the largest probability is selected as the prediction value of the initial neural network model for the input vector.
4. A device for training a neural network model based on a storage and computing integrated chip, characterized in that: The device is applied to a storage-computing integrated chip, and the device includes: An initialization unit, used to initialize the weight parameters of the initial neural network model and obtain the initial weight value of each network layer of the initial neural network model; a conductance adjustment unit, configured to adjust the conductance value of the storage-computing integrated chip according to the initial weight value of each network layer, wherein the weight value corresponding to the same weight parameter is positively correlated with the corresponding conductance value; A prediction unit, configured to input a training set into the initial neural network model and output a predicted value for each training sample, wherein the training set includes a plurality of the training samples and a true value corresponding to each of the training samples; a determination unit, configured to determine a current loss value based on a difference between a predicted value and a true value of each of the training samples; a calculation unit, configured to calculate an error gradient of the current loss value with respect to a weight parameter of each network layer, and determine a weight adjustment value of each network layer according to the error gradient of each network layer, wherein the weight adjustment value represents an amount of weight change to be adjusted; a quantization unit, configured to quantize, for each network layer, the weight adjustment value into a preset integer range based on a relationship between an initial weight value of the network layer and a weight value boundary, and obtain a target quantization value corresponding to the weight adjustment value, wherein different quantization values within the preset integer range represent different adjustment directions; A weight adjustment unit, configured to call a weight update interface for the initial weight value of each network layer, adjust the initial weight value along an adjustment direction represented by the target quantization value corresponding to the initial weight value, and obtain an adjusted weight value; The conductance adjustment unit is used to adjust the conductance value of the storage and computing integrated chip according to the adjusted weight value of each network layer to obtain an updated neural network model; an iterative training unit, configured to continue training the training set based on the updated neural network model until the current loss value satisfies a preset convergence condition or reaches a preset iteration number threshold, and use the obtained neural network model as a target neural network model; The quantization unit includes: a quantization module, configured to, when the initial weight value of the current network layer reaches any weight value boundary, quantize the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value; and, when the initial weight value of the current network layer does not reach any weight value boundary, quantize the weight adjustment value of the current network layer into the preset integer range to obtain an initial quantization value, wherein the current network layer is the network layer whose weight adjustment value is currently to be quantized; A setting module is used to adjust the initial quantization value to a quantization value in the opposite direction when the initial weight value of the current network layer reaches any weight value boundary, and obtain the target quantization value; when the initial weight value of the current network layer does not reach any weight value boundary, directly use the initial quantization value as the target quantization value.
5. The device according to claim 4, characterized in that The quantization module is used to: When the weight adjustment value of the current network layer is greater than 0, quantizing the weight adjustment value of the current network layer to a first integer value as the initial quantization value, wherein the first integer value is a preset positive integer, and the first integer value indicates that the weight adjustment value is adjusted in a positive incremental direction; When the weight adjustment value of the current network layer is equal to 0, 0 is used as the initial quantization value, and when the initial quantization value is 0, it indicates that the weight adjustment value is not adjusted; When the weight adjustment value of the current network layer is less than 0, the weight adjustment value of the current network layer is quantized to a second integer value as the initial quantization value, wherein the second integer value is a preset negative integer, and the second integer value indicates that the weight adjustment value is adjusted in the direction of the reverse increment.
6. The device according to any one of claims 4-5, characterized in that Each training sample in the training set includes an input vector; The prediction unit includes: An input layer calculation module, configured to input the training set into the input layer of the initial neural network model, and perform a matrix multiplication operation on the input vector in the training set and a matrix consisting of a plurality of initial weight values of the input layer to obtain an output result of the input layer; A hidden layer calculation module is used to input the output result of the input layer into the hidden layer of the initial neural network model, perform a nonlinear transformation on the output result of the input layer through a V-type relu activation function, and perform a matrix multiplication operation on the output result after the nonlinear transformation and a matrix composed of multiple initial weight values of the hidden layer to obtain the output result of the hidden layer; The output layer calculation module is used to input the output results of the hidden layer into the output layer of the initial neural network model, and normalize the output results of the hidden layer to obtain the probability distribution of each category, and select the category with the largest probability as the prediction value of the initial neural network model for the input vector.
7. A storage and computing integrated chip, characterized in that: The integrated storage and computing chip is at least used to implement the method as described in any one of claims 1-3.
8. An electronic device, characterized in that: The electronic device includes at least one storage and computing integrated chip as described in claim 7.
Citation Information
Patent Citations
Memristor-based neural network training method and memristor-based neural network training device
CN110796241A
Neural network quantification method, target detection method and device
CN115018070A