Neural network training method and optimizer for updating neural network parameters
By combining first-order momentum and second-order momentum information, using the derivative and curvature information of the loss function to update the neural network parameters, and releasing the memory of the derivative information, the existing optimizer solves the problem of large memory and calculation loads in ultra-large-scale neural network training. problem, improving training speed and efficiency.
Patent Information
- Application Number
- PCT/CN2024/081693
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-14
- Filing Date
- 2024-03-14
- Publication Date
- 2024-09-19
AI Technical Summary
Existing optimizers require a large amount of memory and calculation when training very large-scale neural networks, and are difficult to effectively utilize the curvature information of the loss function, resulting in slow training speed and high memory overhead.
By combining first-order momentum information and second-order momentum information, the optimizer uses the derivative and curvature information of the loss function to update parameters in each time step, and releases the memory of the derivative information after obtaining the first-order momentum information, reducing memory consumption.
It significantly improves the training speed of neural networks and reduces memory overhead, making it suitable for very large-scale neural network models in the field of deep learning.
Smart Images

Figure CN2024081693_19092024_PF_FP_ABST
Abstract
Description
Method for training neural network and optimizer for updating neural network parameters
[0001] This application claims priority to Chinese Patent Application No. 202310246645.2 filed on March 14, 2023. The contents of the above-mentioned Chinese patent application disclosure are hereby incorporated by reference in their entirety as a part of this application. Technical Field
[0002] The present disclosure relates to the field of artificial intelligence services, and more specifically to a method for training a neural network, an optimizer for updating neural network parameters, an electronic device, and a computer-readable storage medium. Background Art
[0003] Deep learning is a key branch of artificial intelligence. It uses multi-layer neural network models to model and predict complex data. As deep learning applications continue to expand, efficiently training deep neural network models has become a hot research topic within the field.
[0004] Currently, industry and academia have proposed various optimizers to update the parameters of neural networks to achieve neural network training. During training, various optimizers adjust the model parameters in the neural network by calculating the gradient of the loss function, so that the loss function can converge to the extreme value more quickly, thereby shortening the time required for neural network training.
[0005] These optimizers can be applied across a variety of fields. For example, in computer vision, optimizers can be used for tasks such as image classification, image object detection, and image generation. In natural language processing, optimizers can be used for tasks such as language modeling, text translation, text generation, and speech recognition. In recommendation systems, optimizers can be used for tasks such as product and ad recommendations. Furthermore, this optimizer can be applied to artificial intelligence and scientific computing, such as solving and simulating partial differential equations (PDEs) that describe physical phenomena. In reinforcement learning, it can be used for tasks such as playing chess and implementing chat models that follow human instructions and values.
[0006] However, for very large neural networks, using optimizers during training requires a lot of memory and computation. Therefore, further improvements are needed to the technology of using optimizers to train neural networks.
[0007] Summary of the Invention
[0008] Embodiments of the present disclosure provide a method for training a neural network, an optimizer for updating neural network parameters, an electronic device, and a computer-readable storage medium.
[0009] An embodiment of the present disclosure provides a method for training a neural network, comprising: iteratively training the neural network using a loss function in multiple time steps, wherein, for each time step in the multiple time steps, first-order momentum information corresponding to the time step is determined based on values of parameters of the neural network at the time step, the first-order momentum information being fused with derivative information of the loss function at the time step; second-order momentum information corresponding to the time step is determined based on the first-order momentum information corresponding to the time step, the second-order momentum information being fused with curvature information of the loss function at the time step; and updating the parameters of the neural network based on the first-order momentum information and the second-order momentum information to obtain parameters of the neural network for the next time step.
[0010] An embodiment of the present disclosure provides an optimizer for updating parameters of a neural network, wherein the optimizer is used to update the neural network using a loss function in each time step of multiple time steps, and the optimizer includes: a first-order momentum information calculation circuit, configured to: determine the first-order momentum information corresponding to the time step based on the value of the parameter of the neural network at the time step, wherein the first-order momentum information is integrated with the derivative information of the loss function at the time step; a second-order momentum information calculation circuit, configured to: determine the second-order momentum information corresponding to the time step based on the first-order momentum information corresponding to the time step, wherein the second-order momentum information is integrated with the curvature information of the loss function at the time step; and a parameter updating circuit, configured to: update the parameters of the neural network based on the first-order momentum information and the second-order momentum information to obtain the parameters of the neural network for the next time step.
[0011] An embodiment of the present disclosure provides an electronic device, including: a processor; and a memory, wherein a computer executable program is stored in the memory, and when the computer executable program is executed by the processor, the above method is performed.
[0012] An embodiment of the present disclosure provides a device, including: a processor; a memory, wherein the memory stores computer instructions, and the computer instructions implement the above method when executed by the processor.
[0013] An embodiment of the present disclosure provides a computer-readable storage medium having computer instructions stored thereon. When the computer instructions are executed by a processor, the above method is implemented.
[0014] According to another aspect of the present disclosure, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable medium and executes the computer instructions, causing the computer device to perform the methods provided in the various aspects or various optional implementations of the various aspects described above.
[0015] The various embodiments of the present disclosure combine the advantages of first-order momentum information and second-order momentum information, fully utilize the derivative information and curvature information of the loss function at each time step in the process of training the neural network, and release the memory used to store the derivative information after obtaining the first-order momentum information, which can improve the training speed of the neural network while reducing memory overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required for describing the embodiments. The drawings described below are only exemplary embodiments of the present disclosure.
[0017] FIG1 shows a schematic diagram of an application scenario according to an embodiment of the present disclosure.
[0018] FIG2 is a flowchart illustrating a method for training a neural network according to an embodiment of the present disclosure.
[0019] FIG3 is a diagram illustrating an example loss function according to an embodiment of the present disclosure.
[0020] FIG4 is a schematic diagram illustrating an optimizer for updating neural network parameters according to an embodiment of the present disclosure.
[0021] FIG5 is a diagram illustrating the effect of implementing the method according to an embodiment of the present disclosure.
[0022] FIG6 shows a schematic diagram of an electronic device according to an embodiment of the present disclosure.
[0023] FIG7 shows an architectural diagram of a computing device according to an embodiment of the present disclosure.
[0024] FIG8 shows a schematic diagram of a computer-readable storage medium according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solutions and advantages of the present disclosure more apparent, the following will describe in detail exemplary embodiments of the present disclosure with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments of the present disclosure, and it should be understood that the present disclosure is not limited to the exemplary embodiments described herein.
[0026] In this specification and the accompanying drawings, substantially the same or similar steps and elements are denoted by the same or similar reference numerals, and repeated descriptions of these steps and elements will be omitted. At the same time, in the description of the present disclosure, the terms "first", "second", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance or ranking.
[0027] To facilitate description of the present disclosure, concepts related to the present disclosure are introduced below.
[0028] Optionally, the various models involved in the embodiments of the present disclosure may be artificial intelligence models, in particular artificial intelligence-based neural network models. Typically, artificial intelligence-based neural network models are implemented as acyclic graphs in which neurons are arranged in different layers. Typically, a neural network model includes an input layer and an output layer, which are separated by at least one hidden layer. The hidden layer transforms the input received by the input layer into a representation useful for generating an output in the output layer. The network nodes (i.e., neurons) are fully connected to the nodes in the adjacent layers via edges, and there are no edges between the nodes in each layer. The data received at the nodes of the input layer of the neural network are propagated to the nodes of the output layer via any one of the hidden layer, activation layer, pooling layer, convolutional layer, etc. The input and output of the neural network model can take various forms, and the present disclosure is not limited thereto.
[0029] Various optimizers have been proposed in industry and academia for training neural networks. During training, these optimizers adjust the model parameters in the neural network by calculating the gradient of the loss function, so that the loss function converges to an extreme value more quickly, thereby shortening the time required for neural network training.
[0030] For example, the Stochastic Gradient Descent (SGD) optimizer has been proposed in industry and academia. This gradient-based optimizer updates model parameters by calculating the gradient of the loss function with respect to the parameters. The SGD optimizer uses the same learning rate for each parameter update, which often requires manual tuning to achieve model convergence. Because the SGD optimizer only utilizes first-order momentum information, it converges slowly and can become stuck near local minima when dealing with non-convex optimization problems with high curvature.
[0031] For example, the Adaptive Moment Estimation (Adam) optimizer has been proposed by industry and academia. It is a gradient-based optimizer that combines momentum gradient descent with an adaptive learning rate. The Adam optimizer utilizes both first-order and second-order momentum information to improve the convergence rate of the loss function. However, the second-order momentum information it uses does not include information about the curvature of the loss function. This results in slow convergence in some tasks and may not converge to the optimal point.
[0032] Currently, a traditional second-order optimizer that uses first-order momentum information and second-order momentum information has been proposed, which requires memory that is about six times the amount of parameters of the neural network. Such a traditional second-order optimizer may not be applicable to neural network models with extremely large parameter amounts. The number of parameters of these neural network models can reach tens of billions, hundreds of billions, or even trillions. When training these neural network models, traditional second-order optimizers often need to perform complex calculations based on the massive parameters of the neural network model in order to update the parameters in the neural network model. In particular, for traditional second-order optimizers, since they need to consume a large amount of computing resources to obtain second-order momentum information (and / or loss function curvature information), and cannot release memory resources in time during the calculation of second-order momentum information (and / or loss function curvature information), they are difficult to apply in the field of deep learning.
[0033] To this end, the present disclosure provides an improved optimizer, which can not only quickly obtain first-order momentum information and second-order momentum information containing loss function curvature information with less computational effort, but also release part of the memory in time after obtaining the first-order momentum information, thereby improving the training speed of the neural network while reducing memory overhead.
[0034] Various embodiments of the present disclosure are described in detail through the following drawings.
[0035] First, an application scenario of the method and corresponding apparatus according to an embodiment of the present disclosure will be described with reference to Figure 1. Figure 1 shows a schematic diagram of an application scenario 100 according to an embodiment of the present disclosure, in which a server 110 and multiple terminals 120 are schematically shown.
[0036] The apparatus for training a neural network in the embodiments of the present disclosure can be specifically integrated into various electronic devices, for example, any electronic device in the server 110 and multiple terminals 120 in FIG1 . For example, the apparatus for training a neural network can be integrated into the terminal 120. The terminal 120 can be a mobile phone, a tablet computer, a laptop computer, a desktop computer, a personal computer (PC), a smart speaker or a smart watch, etc., but is not limited thereto. For another example, the apparatus for training a neural network can also be integrated into the server 110. The server 110 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The terminal and the server can be directly or indirectly connected via wired or wireless communication, and the present disclosure does not limit this.
[0037] It is understood that the device for inferring various possible complex neural network models using the method for training a neural network model according to the embodiments of the present disclosure can be a terminal, a server, or a system consisting of a terminal and a server. Of course, the present disclosure is not limited to this.
[0038] During the training of the neural network model, the terminal and / or server may train the neural network based on the training sample set stored in the terminal and / or server. It is worth noting that the neural network model herein may be a neural network model that can be applied to various scenarios, particularly neural network models used in computer vision, natural language processing, and recommendation systems.
[0039] The present disclosure provides a method for training a neural network, comprising: iteratively training the neural network using a loss function in multiple time steps, wherein, for each time step in the multiple time steps, first-order momentum information corresponding to the time step is determined based on the values of parameters of the neural network at the current time step, the first-order momentum information being fused with derivative information of the loss function at the time step; second-order momentum information corresponding to the time step is determined based on the first-order momentum information corresponding to the time step, the second-order momentum information being fused with curvature information of the loss function at the time step; and updating the parameters of the neural network at the next time step based on the first-order momentum information and the second-order momentum information.
[0040] Various embodiments of the present disclosure combine the advantages of first-order momentum information and second-order momentum information. During neural network training, second-order momentum information, integrated with the curvature of the loss function, is directly obtained from the first-order momentum information. This allows for convenient and full utilization of the derivative and curvature information of the loss function at each time step, significantly improving the training speed of the neural network. Some embodiments of the present disclosure also free up memory used to store derivative information after obtaining the first-order momentum information, thereby increasing the training speed of the neural network while reducing memory overhead.
[0041] The following is a more detailed description of all or part of the embodiments according to the present disclosure in conjunction with FIG. 2 to FIG. 8 .
[0042] Figure 2 is a flow chart illustrating a method 20 for training a neural network according to an embodiment of the present disclosure. Figure 3 is a diagram illustrating an example loss function according to an embodiment of the present disclosure.
[0043] The method 20 for training a neural network according to an embodiment of the present disclosure can be applied to any electronic device. It is understood that the electronic device can be a variety of hardware devices, such as a personal digital assistant (PDA), an audio / video device, a mobile phone, an MP3 player, a personal computer, a laptop computer, a server, and the like. For example, the electronic device can be the server and user terminal shown in FIG1 . Below, the present disclosure is described using a server as an example, but those skilled in the art should understand that the present disclosure is not limited thereto.
[0044] Before training a neural network, it is necessary to initialize the various parameters in the neural network so that the neural network is ready for training. The initialization process includes, but is not limited to, setting initial values for the weights and biases of the neurons in the neural network. In some embodiments of the present disclosure, random initialization can be used to set random initial values for the various parameters in the neural network model, or various parameters in the neural network model can be set to preset values (e.g., 0 or 1), etc. The present disclosure is not limited to this.
[0045] After the initialization of the neural network is completed, multiple time steps may be optionally used to train the neural network. For example, a time step refers to a discrete time point in the process of training the neural network, and each time step corresponds to an update of the parameters of the neural network. In order to better update the parameters of the neural network to a state that enables the loss function of the neural network to converge at each time step, the optimizer according to the embodiment of the present disclosure can be used to solve the amount by which the various parameters of the neural network need to change in that time step. The loss function is a function of the predicted value of the target label by the neural network and the true value of the target label, which includes but is not limited to: mean square error function, cross entropy function, etc. The optimizer according to the embodiment of the present disclosure can extract the direction information and magnitude information of the changes that the various parameters of the neural network need to make from the information of the loss function and the parameters of the neural network at that time step. This information includes but is not limited to the first-order momentum information, second-order momentum information, derivative information and curvature information described in detail below. Of course, the present disclosure is not limited to this.
[0046] For example, method 20 according to an embodiment of the present disclosure includes iteratively training the neural network using a loss function over multiple time steps. After the multiple time steps, the value of the loss function converges. Optionally, in each of the multiple time steps, operations S201 to S204 are sequentially performed, where operation S202 is optional.
[0047] First, in operation S201, based on the values of the parameters of the neural network at the time step, the first-order momentum information corresponding to the time step is determined, and the first-order momentum information is integrated with the derivative information of the loss function at the time step.
[0048] For example, the first-order momentum information according to the embodiment of the present disclosure can also be called the first-order moment information, which indicates the direction information of the gradient of the loss function estimated by the optimizer according to the embodiment of the present disclosure at the time step. Specifically, the first-order momentum information can be integrated with the derivative information of the loss function at the time step. The derivative information includes but is not limited to the value of the partial derivative of the loss function at each trainable parameter in the neural network at the time step. For example, assuming that the loss function is L and a trainable parameter in the neural network is w, then the derivative information corresponding to the parameter is
[0049] In addition, the first-order momentum information can also be fused with other information. For example, considering that there is a certain dependency between each time step during the training process, the first-order momentum information of a certain time step can also be fused with the value of the first-order momentum information of the previous time step, or the value of the second-order momentum information, etc. Optionally, the parameters, first-order momentum information, and second-order momentum information of the neural network at a certain time step all contain the information of the previous time step and can be recursively applied to the initial time step. After each time the parameters of the neural network are updated for a time step, the parameters, first-order momentum information, and second-order momentum information of the neural network at the current step will be stored as constants in the memory for subsequent calls, and the calculation graph used to calculate the parameters, first-order momentum information, and second-order momentum information of the neural network at the current step will be cleared to save storage overhead.
[0050] For example, in operation S201, the first-order momentum information corresponding to the neural network at the previous time step and the values of the parameters of the neural network at the time step may be further obtained; and the first-order momentum information corresponding to the time step may be determined based on the derivative information of the loss function at the current time step and the value of the first-order momentum information corresponding to the neural network at the previous time step. Of course, the present disclosure is not limited to this.
[0051] Optionally, determining the first-order momentum information corresponding to the current time step based on the derivative information of the loss function at the current time step and the first-order momentum information corresponding to the neural network at the previous time step includes: obtaining a preconfigured first-order moment coefficient, and based on the first-order moment coefficient, calculating the weighted sum of the values of the derivative information of the loss function at the current time step and the first-order momentum information corresponding to the neural network at the previous time step, and determining the weighted sum as the first-order momentum information corresponding to the time step.
[0052] Taking FIG3 as an example, it is assumed that the loss function according to the embodiment of the present disclosure is in the form of y=4.0x 2 ,y=x 2 , and y = 0.1x 2 Any one of the following, where x is the difference between the sample label and the output value of the neural network, and y is the value of the loss function. In other words, x may be a function with the parameters of the neural network, the sample data, and the label corresponding to the sample data as independent variables. When x is not equal to 0, the first-order momentum information can indicate the direction of gradient descent. As shown in Figure 3, y = 4.0x 2 The corresponding downward direction is y=0.1x 2 The corresponding gradient descent direction is more jittery, so when y=4.0x 2 When used as a loss function, the update amount of the neural network parameters should be less than y = 0.1x 2 As the case of loss function, of course, the present disclosure is not limited to this.
[0053] Next, in some embodiments according to the present disclosure, optionally, in operation S202 , the memory used to store the derivative information of the loss function at the time step is released.
[0054] At this point, the memory of the device used to train the neural network may store all state information of the neural network at that time step, including but not limited to the weights and biases corresponding to the various parameters of the neural network model after being updated in the previous time step, the first-order momentum information corresponding to the previous time step, and derivative information. Furthermore, the memory may also include the second-order momentum information corresponding to the previous time step. This information consumes a significant amount of storage resources. However, after operation S201, the first-order momentum information already incorporates the derivative information of the loss function at that time step. The optimizer according to an embodiment of the present disclosure will then use the first-order momentum information instead of the derivative information, thereby safely freeing up the memory used to store the derivative information of the loss function at that time step. However, as mentioned above, since the derivative information may include the values of the partial derivatives of all trainable parameters in the neural network at that time step, it consumes a significant amount of memory resources. By freeing up the memory used to store the derivative information of the loss function at that time step, the optimizer according to an embodiment of the present disclosure reduces the overhead required by the optimizer according to an embodiment of the present disclosure.
[0055] Next, in operation S203 , based on the first-order momentum information corresponding to the time step, the second-order momentum information corresponding to the time step is determined, where the second-order momentum information is integrated with the curvature information of the loss function at the time step.
[0056] For example, the second-order momentum information according to the embodiment of the present disclosure can also be called second-order moment information, which indicates the step amplitude information of the gradient of the loss function estimated by the optimizer according to the embodiment of the present disclosure at the time step. Specifically, the second-order momentum information can be integrated with the curvature information of the loss function at the time step. The curvature information includes but is not limited to the value of the second-order partial derivative of the loss function at each trainable parameter in the neural network at the time step. For example, assuming that the loss function is L, and the two trainable parameters in the neural network are w1 and w2, then the derivative information corresponding to the parameter w1 is and In addition, the second-order momentum information can also be fused with other information. For example, considering the certain dependencies between time steps during training, the second-order momentum information of a certain time step can also be fused with the second-order momentum information of the previous time step, and so on.
[0057] For example, in operation S203, a random vector may be further generated, wherein the value of the elements in the random vector has a 50% probability of being positive one and a 50% probability of being negative one, and the number of elements in the random vector is consistent with the number of parameters of the neural network; based on the random vector, the values of the parameters of the neural network at the time step, and the first-order momentum information corresponding to the time step, a derivative operation is used to determine the second-order momentum information corresponding to the time step. The derivative operation can extract the curvature information of the loss function at the time step from the first-order momentum information at a faster computation speed, which exceeds the computation speed of traditional second-order optimizers.
[0058] Optionally, the use of a derivative operation to determine the second-order momentum information corresponding to the time step includes: multiplying the random vector by the first-order momentum information to obtain a vector of elements on the diagonal of a Hessian matrix; performing a nonlinear transformation on the vector of elements on the diagonal of the Hessian matrix corresponding to the time step to obtain a vector of elements on the diagonal of the Hessian matrix after the nonlinear transformation; obtaining pre-configured first-order moment coefficients and second-order moment coefficients, and based on the first-order moment coefficients and second-order moment coefficients, calculating a weighted sum of the vector of elements on the diagonal of the Hessian matrix after the nonlinear transformation and the second-order momentum information corresponding to the neural network at the previous time step, and determining the weighted sum as the second-order momentum information corresponding to the time step. The diagonal elements of the Hessian matrix contain curvature information of the loss function with respect to the neural network parameters. Multiplying the random vector by the first-order momentum information can quickly and easily solve for the vector of elements on the diagonal of the Hessian matrix without explicitly solving for the value of each element in the Hessian matrix. Of course, the present disclosure is not limited thereto.
[0059] Continuing with FIG3 as an example, it is assumed that the loss function according to the embodiment of the present disclosure is in the form of y=4.0x 2 ,y=x 2 , and y = 0.1x 2 Any one of , where x is the difference between the sample label and the output value of the neural network, and y is the value of the loss function. When x is equal to 0, the first-order momentum information of the three loss functions is the same, and because the second-order momentum information can indicate the change information of the gradient (for example, the step size of the gradient), it contains more information. For example, it can indicate y = 4.0x 2 The corresponding bending degree is greater than y=0.1x 2 Of course, the present disclosure is not limited thereto.
[0060] In operation S204 , the parameters of the neural network are updated based on the first-order momentum information and the second-order momentum information to obtain the parameters of the neural network for the next time step.
[0061] As mentioned above, the first-order momentum information provides the direction information of the gradient of the loss function at that time step, and the second-order momentum information provides the step size information of the gradient of the loss function at that time step. From this information, the update amount of each parameter of the neural network at that time step can be derived. In some embodiments of the present disclosure, this update amount can be regarded as a nonlinear conversion of the first-order momentum information and the second-order momentum information. Ultimately, the parameters of the neural network will be updated according to this update amount to better adapt to the sample data in the next time step and improve the accuracy of the output data.
[0062] Specifically, the update direction of each parameter of the neural network at that time step can be derived from the first-order momentum information, and the amplitude correction of the step size of each parameter of the neural network at that time step can be derived from the second-order momentum information. In some embodiments of the present disclosure, the update amount can be regarded as a function of the first-order momentum information and the second-order momentum information. For example, in the function, the first-order momentum information is used as the numerator of the function to represent the update direction, and the second-order momentum information is used as the denominator to represent the amplitude correction of the update step size.
[0063] For another example, in some embodiments of the present disclosure, in operation S204, a de-bias operation is further included for the first-order momentum information and the second-order momentum information. As described above, both the first-order momentum information and the second-order momentum information may be data estimated by the optimizer, and the estimated values may be inaccurate, so these estimated values need to be corrected. For example, it is possible to determine a correction factor based on the step size, the first-order momentum information and / or the second-order momentum information of the previous time step, the form of the loss function, etc., to correct the first-order momentum information and the second-order momentum information of the current time step, and based on the corrected first-order momentum information and the second-order momentum information, determine the update amount of each parameter of the neural network at the time step, thereby determining the parameters of the neural network for the next time step. Of course, the present disclosure is not limited to this.
[0064] For example, in operation S204, preconfigured first-order moment coefficients and second-order moment coefficients may be further obtained, and based on the first-order moment coefficients and the second-order moment coefficients, the first-order momentum information and the second-order momentum information may be debiased to obtain debiased first-order momentum information and second-order momentum information. Based on the debiased first-order momentum information and second-order momentum information, the parameters of the neural network may be updated to obtain parameters of the neural network for the next time step. Of course, the present disclosure is not limited to this.
[0065] Optionally, updating the parameters of the neural network based on the first-order momentum information and the second-order momentum information includes: performing a nonlinear transformation on the first-order momentum information and the second-order momentum information to obtain an update amount for updating the parameters of the neural network; and superimposing the update amount with the value of the parameters of the neural network at the time step to update the parameters of the neural network.
[0066] Therefore, the method 20 for training a neural network according to an embodiment of the present disclosure combines the advantages of first-order momentum information and second-order momentum information, fully utilizes the derivative information and curvature information of the loss function at each time step in the process of training the neural network, and releases the memory used to store the derivative information after obtaining the first-order momentum information, which can improve the training speed of the neural network while reducing the memory overhead.
[0067] Figure 4 is a schematic diagram illustrating an optimizer 400 for updating neural network parameters according to an embodiment of the present disclosure. Figure 5 is a diagram illustrating the effect of implementing a method according to an embodiment of the present disclosure.
[0068] Optimizer 400 can be applied in multiple fields. For example, in the field of computer vision, optimizer 400 can be used for tasks such as image classification, image object detection, and image generation. In the field of natural language processing, optimizer 400 can be used for tasks such as language modeling, text translation, text generation, and speech recognition. In the field of recommendation systems, optimizer 400 can be used for tasks such as product recommendation and advertising recommendation. In addition, optimizer 400 can also be applied in the field of artificial intelligence scientific computing, such as solving and simulating partial differential equations (PDEs) that describe physical phenomena. In the field of reinforcement learning, optimizer 400 can be used for tasks such as playing chess and chat models that follow human instructions and values.
[0069] The optimizer 400 described with reference to FIG4 is used to update the neural network using a loss function at each of a plurality of time steps. The optimizer 400 includes a first-order momentum information calculation circuit, a memory release circuit, a second-order momentum information calculation circuit, and a parameter update circuit. The optimizer 400 can be configured to execute the method 20 described in detail above. The optimizer 400 may also be referred to herein as an apparatus for training a neural network. In addition, the optimizer 400 may also include more or fewer circuits, and the present disclosure is not limited thereto.
[0070] Assume that the neural network consists of N parameters, which are represented by w=(w1,w2,…,w N ) T The loss function for this neural network is represented by L(w). Before training the neural network, it may be necessary to initialize the neural network, that is, assign the value of w0 to w. w0 is also called the initial network parameter.
[0071] Further assume that the learning rate during the training of the neural network is η t , and the learning rate may vary according to the learning rate strategy. In practice, the optimizer 400 also requires the first-order moment coefficient β1 and the second-order moment coefficient β2 for subsequent calculations.
[0072] At the first time step, the optimizer 400 sets the first-order momentum information m0 and the second-order momentum information v0 corresponding to the previous time step to zero, that is, m0 = 0, v0 = 0. At any other time step t, the optimizer 400 can obtain the first-order momentum information m corresponding to the previous time step (t-1) t-1 and second-order momentum information v t-1 Wherein, t is an integer greater than 1. Of course, the present disclosure is not limited thereto.
[0073] The following uses time step t as an example to illustrate various operations in method 20 performed by the optimizer 400. Those skilled in the art should understand that the present disclosure is not limited to this sequence.
[0074] First, at time step t, the first-order momentum information calculation circuit in the optimizer 400 is configured to perform operation S201: based on the values of the parameters of the neural network at the time step, determine the first-order momentum information corresponding to the time step, wherein the first-order momentum information is integrated with the derivative information of the loss function at the time step. Specifically, the first-order momentum information calculation circuit can perform the operations of: obtaining the first-order momentum information corresponding to the neural network at the previous time step and the values of the parameters of the neural network at the time step; and determining the first-order momentum information corresponding to the time step based on the derivative information of the loss function at the current time step and the first-order momentum information corresponding to the neural network at the previous time step. Optionally, determining the first-order momentum information corresponding to the current time step based on the derivative information of the loss function at the current time step and the first-order momentum information corresponding to the neural network at the previous time step includes: obtaining a preconfigured first-order moment coefficient, and based on the first-order moment coefficient, calculating a weighted sum of the derivative information of the loss function at the current time step and the first-order momentum information corresponding to the neural network at the previous time step, and determining the weighted sum as the first-order momentum information corresponding to the time step. Of course, the present disclosure is not limited to this.
[0075] For example, assuming that the derivative information of the loss function at time step t is g, it can be calculated according to formula (1). In formula (1), N is the number of parameters of the neural network.
[0076] Then, the first-order momentum information calculation circuit calculates the first-order momentum information m corresponding to the previous time step (t-1) according to formula (2). t-1and the first-order momentum information m of the derivative information g t , thus realizing the use of g to update the first-order momentum information. t =β1m t-1 +(1-β1)g (2)
[0077] Then, optionally, the memory release circuit in the optimizer 400 is configured to perform operation S202: releasing the memory used to store the derivative information of the loss function at the time step. Since the storage of the derivative information g is removed, memory consumption is reduced.
[0078] Next, the second-order momentum information calculation circuit in the optimizer 400 can be configured to perform operation S203: based on the first-order momentum information corresponding to the time step, determine the second-order momentum information corresponding to the time step, wherein the second-order momentum information is integrated with the curvature information of the loss function at the time step. The second-order momentum information calculation circuit can be configured to generate a random vector, wherein the element values in the random vector have a 50% probability of being positive one and a 50% probability of being negative one, and the number of elements in the random vector is consistent with the number of parameters of the neural network; and based on the random vector, the values of the parameters of the neural network at the time step, and the first-order momentum information corresponding to the time step, determine the second-order momentum information corresponding to the time step using a derivative operation, wherein the second-order momentum information is integrated with the curvature information of the loss function at the time step. The method of using the derivation operation to determine the second-order momentum information corresponding to the time step includes: multiplying the random vector by the first-order momentum information to obtain a vector consisting of elements on the diagonal of the Hessian matrix; performing a nonlinear transformation on the vector consisting of elements on the diagonal of the Hessian matrix corresponding to the time step to obtain a vector consisting of elements on the diagonal of the Hessian matrix after the nonlinear transformation; obtaining pre-configured first-order moment coefficients and second-order moment coefficients, and based on the first-order moment coefficients and the second-order moment coefficients, calculating the weighted sum of the vector consisting of elements on the diagonal of the Hessian matrix after the nonlinear transformation and the second-order momentum information corresponding to the neural network at the previous time step, and determining the weighted sum as the second-order momentum information corresponding to the time step.
[0079] Specifically, the second-order momentum information calculation circuit can automatically generate a random vector z, the dimension of which is consistent with w, and the value of its elements is either +1 or -1, and the probability of +1 and -1 is 50%. Then the second-order momentum information calculation circuit uses automatic differentiation based on formula (3) and the random vector z to calculate the first-order momentum information m t Derivative is performed to obtain the curvature information of the loss function at the time step. As shown in formula (4), for the random vector z and the first-order momentum information m t Taking the derivative of the product of According to The vector consisting of the elements on the diagonal of the Hessian matrix can be solved
[0080] Among them, i is the index of the sample data, and H is the Hessian matrix (size N 2 ), that is (1-β1)Hz i The approximate estimate of is only N. According to formula (3), without explicitly solving the value of the Hessian matrix H, we can directly obtain The amount of computation and memory is reduced.
[0081] and in, for The expected value of diag{H} represents the set of diagonal elements in H, which can be further expressed as That is, is the approximate value of (1-β1)diag{H}. Based on the following formula (5), diag{H} can be determined approximate.
[0082] where diag{H} is of size N and its inverse is simply element-wise division diag{H} -1 = 1 / diag{H}. Compared to the traditional second-order optimizer, which requires N 2 The second-order momentum information can be calculated only when the size of H is large enough. The optimizer 400 greatly reduces the amount of calculation. More specifically, according to formula (3) and formula (4), the solution obtained at this time is The curvature information is already included, and the entire solution process only involves the first-order momentum information m t The derivative information g is not involved. Therefore, releasing the memory used to store the derivative information g of the loss function at the time step in the aforementioned step does not affect the subsequent process of obtaining the second-order momentum information including curvature information. Therefore, the optimizer 400 can also significantly reduce memory requirements.
[0083] In the known In the case of , we can use formula (6) based on the second-order momentum information v corresponding to the previous time step (t-1) t-1 and the second-order moment coefficient β2 determine the second-order momentum information v corresponding to the time step t t . Among them, formula (6) is obtained by This approximates the square of the vector consisting of the diagonal elements of the Hessian matrix.
[0084] From formula (6), we can see that the second-order momentum information v t is the vector consisting of the elements on the diagonal of the Hessian matrix after the nonlinear transformation and the value v of the second-order momentum information corresponding to the neural network at the previous time step t-1 The weighted sum of .
[0085] Then, the parameter updating circuit in the optimizer 400 is configured to perform operation S204: updating the parameters of the neural network based on the first-order momentum information and the second-order momentum information to obtain the parameters of the neural network for the next time step.
[0086] Optionally, the parameter updating circuit is configured to obtain preconfigured first-order moment coefficients and second-order moment coefficients; based on the first-order moment coefficients and the second-order moment coefficients, perform a debiasing operation on the first-order momentum information and the second-order momentum information to obtain debiased first-order momentum information and second-order momentum information; and based on the debiased first-order momentum information and second-order momentum information, update the parameters of the neural network to obtain the parameters of the neural network for the next time step. Optionally, updating the parameters of the neural network based on the first-order momentum information and the second-order momentum information includes: performing a nonlinear transformation on the first-order momentum information and the second-order momentum information to obtain an update amount for updating the parameters of the neural network; and superimposing the update amount with the value of the parameters of the neural network at the time step to update the parameters of the neural network.
[0087] Optionally, the parameter updating circuit can first use formula (7) and formula (8) to update the first-order momentum information m t and second-order momentum information v t Perform debiasing operation to obtain the debiased first-order momentum information m t and second-order momentum information v t .
[0088] Then the parameter update circuit will use formula (9) to update the parameters of the neural network from w to t-1 Update to w t .
[0089] Among them, ε is a very small floating point number used to ensure that m does not occur t In the case of division by zero, η t is the learning rate. The update amount for updating the parameters of the neural network in formula (9) is The nonlinear transformation of the first-order momentum information and the second-order momentum information is realized.
[0090] In each of the above operations, whether it is the first-order momentum information calculation circuit, the memory release circuit, the second-order momentum information calculation circuit or the parameter update circuit, it needs to use at most 5 times the memory of the neural network parameter N. For example, when calculating the second-order momentum information, the second-order momentum information calculation circuit needs to store at most 5 vectors w at the same time. t-1 ,m t ,v t-1 ,z i ,h i , which takes up 5N of memory. Compared with the traditional implementation method that requires at least 6N of memory, the optimizer disclosed in this disclosure can reduce the memory overhead by 1 / 6.
[0091] As shown in FIG5 , in actual experiments, the optimizer 400 is used to train the transformer-based translation neural network model. Whether in the training process or in the verification process, its loss function can converge in about 8,000 time steps. While having similar convergence effect and training time as the traditional implementation method, it reduces the maximum memory usage.
[0092] It can be seen that the various optimizers 400 disclosed in the present invention combine the advantages of first-order momentum information and second-order momentum information, fully utilize the derivative information and curvature information of the loss function at each time step in the process of training the neural network, and release the memory used to store the derivative information after obtaining the first-order momentum information, which can improve the training speed of the neural network while reducing the memory overhead.
[0093] According to another aspect of the present disclosure, an electronic device is provided for implementing the method 20 according to an embodiment of the present disclosure or carrying the optimizer 400 according to an embodiment of the present disclosure. FIG6 shows a schematic diagram of an electronic device 2000 according to an embodiment of the present disclosure.
[0094] As shown in Figure 6, the electronic device 2000 may include one or more processors 2010 and one or more memories 2020. The memory 2020 stores computer-readable code, which, when executed by the one or more processors 2010, may execute the method described above.
[0095] The processor in the embodiments of the present disclosure may be an integrated circuit chip having signal processing capabilities. The processor may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. The methods, operations, and logic block diagrams disclosed in the embodiments of the present disclosure may be implemented or executed. The general-purpose processor may be a microprocessor or any conventional processor, and may be an X86 architecture or an ARM architecture.
[0096] In general, various example embodiments of the present disclosure may be implemented in hardware or dedicated circuitry, software, firmware, logic, or any combination thereof. Certain aspects may be implemented in hardware, while other aspects may be implemented in firmware or software that may be executed by a controller, microprocessor, or other computing device. When various aspects of the disclosed embodiments are illustrated or described as block diagrams, flow charts, or using some other graphical representation, it will be understood that the blocks, devices, systems, techniques, or methods described herein may be implemented, as non-limiting examples, in hardware, software, firmware, dedicated circuitry or logic, general-purpose hardware or a controller or other computing device, or some combination thereof.
[0097] For example, the method or apparatus according to an embodiment of the present disclosure may also be implemented with the aid of the architecture of the computing device 3000 shown in FIG7 . As shown in FIG7 , the computing device 3000 may include a bus 3010, one or more CPUs 3020, a read-only memory (ROM) 3030, a random access memory (RAM) 3040, a communication port 3050 connected to a network, an input / output component 3060, a hard disk 3070, and the like. The storage device in the computing device 3000, such as the ROM 3030 or the hard disk 3070, may store various data or files used for processing and / or communication of the method provided by the present disclosure, as well as program instructions executed by the CPU. The computing device 3000 may also include a user interface 3080. Of course, the architecture shown in FIG7 is merely exemplary. When implementing different devices, one or more components in the computing device shown in FIG7 may be omitted according to actual needs.
[0098] According to another aspect of the present disclosure, a computer-readable storage medium is further provided. FIG8 shows a schematic diagram of a storage medium 4000 according to the present disclosure.
[0099] As shown in Figure 8, the computer storage medium 4020 stores computer-readable instructions 4010. When the computer-readable instructions 4010 are executed by the processor, the method according to the embodiment of the present disclosure described with reference to the above figures can be executed. The computer-readable storage medium in the embodiment of the present disclosure can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. The non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct memory bus random access memory (DR RAM). It should be noted that memory of the methods described herein is intended to include, but is not limited to, these and any other suitable types of memory. It should be noted that memory of the methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0100] The present disclosure also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform a method according to the present disclosure.
[0101] It should be noted that the flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architectures, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the boxes can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified functions or operations, or can be implemented using a combination of dedicated hardware and computer instructions.
[0102] In general, various example embodiments of the present disclosure may be implemented in hardware or dedicated circuitry, software, firmware, logic, or any combination thereof. Certain aspects may be implemented in hardware, while other aspects may be implemented in firmware or software that may be executed by a controller, microprocessor, or other computing device. When various aspects of the disclosed embodiments are illustrated or described as block diagrams, flow charts, or using some other graphical representation, it will be understood that the blocks, devices, systems, techniques, or methods described herein may be implemented, as non-limiting examples, in hardware, software, firmware, dedicated circuitry or logic, general-purpose hardware or a controller or other computing device, or some combination thereof.
[0103] The exemplary embodiments of the present disclosure described in detail above are merely illustrative and not restrictive. Those skilled in the art will appreciate that various modifications and combinations may be made to these embodiments or their features without departing from the principles and spirit of the present disclosure, and such modifications should fall within the scope of the present disclosure.
Claims
1. A method for training a neural network, comprising: The neural network is iteratively trained using a loss function in a plurality of time steps, wherein for each time step in the plurality of time steps, Based on the values of the parameters of the neural network at the time step, determining the first-order momentum information corresponding to the time step, wherein the first-order momentum information is integrated with the derivative information of the loss function at the time step; Determining second-order momentum information corresponding to the time step based on first-order momentum information corresponding to the time step, wherein the second-order momentum information is integrated with curvature information of the loss function at the time step; and Based on the first-order momentum information and the second-order momentum information, the parameters of the neural network are updated to obtain the parameters of the neural network for the next time step.
2. The method of claim 1, wherein: After determining the first-order momentum information corresponding to the time step, releasing the memory used to store the derivative information of the loss function at the time step.
3. The method according to any one of claims 1 to 2, wherein: The loss function is a function of the predicted value of the target label by the neural network and the true value of the target label.
4. The method according to any one of claims 1 to 3, wherein: The determining, based on the value of the parameter of the neural network at the time step, the first-order momentum information corresponding to the time step comprises: Obtaining first-order momentum information corresponding to the neural network at a previous time step and values of parameters of the neural network at the time step; and Based on the derivative information of the loss function at the time step and the value of the first-order momentum information corresponding to the neural network at the previous time step, the first-order momentum information corresponding to the time step is determined.
5. The method of claim 4, wherein: Determining the first-order momentum information corresponding to the current time step based on the derivative information of the loss function at the current time step and the first-order momentum information corresponding to the neural network at the previous time step includes: Obtain a preconfigured first-order moment coefficient, and based on the first-order moment coefficient, calculate the weighted sum of the derivative information of the loss function at the current time step and the value of the first-order momentum information corresponding to the neural network at the previous time step, and determine the weighted sum as the first-order momentum information corresponding to the time step.
6. The method according to any one of claims 1 to 5, wherein: The determining, based on the first-order momentum information corresponding to the time step, the second-order momentum information corresponding to the time step comprises: Generate a random vector, wherein the value of an element in the random vector has a 50% probability of being positive one and a 50% probability of being negative one, and the number of elements in the random vector is consistent with the number of parameters of the neural network; and Based on the random vector, the values of the parameters of the neural network at the time step, and the first-order momentum information corresponding to the time step, a derivation operation is used to determine the second-order momentum information corresponding to the time step, where the second-order momentum information is integrated with the curvature information of the loss function at the time step.
7. The method of claim 6, wherein: Determining the second-order momentum information corresponding to the time step by using a derivation operation includes: Multiplying the first-order momentum information by the random vector to obtain a vector consisting of elements on the diagonal of a Hessian matrix; Performing a nonlinear transformation on the vector composed of the elements on the diagonal of the Hessian matrix corresponding to the time step to obtain a vector composed of the elements on the diagonal of the Hessian matrix after the nonlinear transformation; Obtain preconfigured first-order moment coefficients and second-order moment coefficients, and based on the first-order moment coefficients and the second-order moment coefficients, calculate the weighted sum of the vector composed of the elements on the diagonal of the Hessian matrix after the nonlinear transformation and the value of the second-order momentum information corresponding to the neural network at the previous time step, and determine the weighted sum as the second-order momentum information corresponding to the time step.
8. The method according to any one of claims 1 to 7, wherein: The updating of the parameters of the neural network based on the first-order momentum information and the second-order momentum information includes: Get the preconfigured first-order moment coefficients and second-order moment coefficients; Based on the first-order moment coefficient and the second-order moment coefficient, a debiasing operation is performed on the first-order momentum information and the second-order momentum information to obtain debiased first-order momentum information and second-order momentum information, Based on the debiased first-order momentum information and second-order momentum information, the parameters of the neural network are updated to obtain the parameters of the neural network for the next time step.
9. The method according to any one of claims 1 to 8, wherein: The updating of the parameters of the neural network based on the first-order momentum information and the second-order momentum information includes: performing a nonlinear transformation on the first-order momentum information and the second-order momentum information to obtain an update amount for updating parameters of the neural network; and The update amount is superimposed on the value of the parameter of the neural network at the time step to update the parameter of the neural network.
10. An optimizer for updating neural network parameters, wherein the optimizer is used to update the neural network using a loss function in each time step of a plurality of time steps, the optimizer comprising: A first-order momentum information calculation circuit is configured to: determine the first-order momentum information corresponding to the time step based on the value of the parameter of the neural network at the time step, wherein the first-order momentum information is integrated with the derivative information of the loss function at the time step; A second-order momentum information calculation circuit is configured to: determine the second-order momentum information corresponding to the time step based on the first-order momentum information corresponding to the time step, wherein the second-order momentum information is integrated with the curvature information of the loss function at the time step; as well as The parameter updating circuit is configured to update the parameters of the neural network based on the first-order momentum information and the second-order momentum information to obtain the parameters of the neural network for the next time step.
11. The optimizer of claim 10, further comprising: The memory release circuit is configured to release the memory used to store the derivative information of the loss function at the time step after determining the first-order momentum information corresponding to the time step.
12. An electronic device comprising: processor; as well as A memory, wherein a computer executable program is stored in the memory, and when the computer executable program is executed by the processor, the method according to any one of claims 1 to 9 is executed.
13. A computer-readable storage medium having computer instructions stored thereon, wherein the computer instructions, when executed by a processor, implement the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Method and apparatus for neural network quantization
CN107967515A
Waste plastic image segmentation method based on dense connection
CN112541916A
Data processing method and device, storage medium and computer equipment
CN112990958A
Hardware-oriented Adam algorithm second-order moment estimation optimization method and system
CN115099397A
Method for training neural network and optimizer for updating parameters of neural network
CN116258196A
Cited By
Broadband signal DOA estimation method based on deep convolutional neural network
CN120103251A
Training method and system, parameter updating method, electronic equipment and storage medium
CN122334383A
