Gradient updating method and related device

By storing the t-1th parameter trend in the first electronic device, calculating the t-th parameter trend and judging the expired gradient, the problem of the impact of expired gradients in the asynchronous parallel distributed algorithm is solved, the accuracy and convergence speed of model training are improved, and Saves storage space.

CN117151239BActive Publication Date: 2024-08-27HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310301453.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-17
Publication Date
2024-08-27
Estimated Expiration
2043-03-17

AI Technical Summary

Technical Problem

Asynchronous and parallel distributed algorithms may cause expired gradients in model training, affecting the accuracy and convergence speed of model training, and existing methods need to occupy a large storage space to reduce the impact of expired gradients.

Method used

Calculate the latest t-th parameter trend by storing the t-1th parameter trend in the first electronic device, and determine whether the gradient is an expired gradient based on the trend, thereby updating the expired gradient to avoid storing multiple parameters and save storage space.

Benefits of technology

It achieves fast and accurate judgment and update of expired gradients, improves the accuracy and convergence speed of model training, and saves storage space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117151239B
    Figure CN117151239B
Patent Text Reader

Abstract

The embodiment of the present application provides a gradient updating method and related devices. The method is applied to a communication system, the communication system includes a first electronic device and m second electronic devices, m is a positive integer, including: the first electronic device obtains n first gradients from any second electronic device among the m second electronic devices; for the first gradient of the i-th dimension in the n first gradients, the first electronic device determines whether the first gradient of the i-th dimension is an expired gradient based on the t-th parameter trend of the i-th dimension; wherein the t-th parameter trend of the i-th dimension is related to the t-1-th parameter trend of the i-th dimension and the parameter change amount of the i-th dimension, the parameter change amount of the i-th dimension is positively correlated with the first difference, and the first difference is the difference between the t-th parameter of the i-th dimension and the t-1-th parameter of the i-th dimension. In this way, the first electronic device does not need to store multiple copies of the parameters, which effectively saves the storage space of the first electronic device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of deep learning, and in particular to a gradient updating method and related devices. Background Art

[0002] As the business develops, the amount of training data that can be used to train the model is increasing. When the amount of training data is large, it may take a long time to train the model. In order to speed up the model training, in some implementations, the model training can be performed through asynchronous parallel distributed algorithms. Specifically, the asynchronous parallel distributed algorithm can calculate the gradient of the model in parallel through multiple computing modules (workers), and send the calculated gradient to the parameter server (parameter server, PS). The parameter server updates the parameters (weight, W) of the model based on the gradient, thereby completing the model training. However, the asynchronous parallel distributed algorithm may have the problem of staleness gradient, which affects the accuracy of the model training results and the convergence speed of the model training.

[0003] In some implementations, in order to reduce the impact of outdated gradients on model training accuracy and convergence speed, outdated gradients can be updated based on parameter trends to reduce the impact of outdated gradients on model accuracy, where the parameter trend is the trend of model parameter changes.

[0004] However, the above method requires a large storage space. Summary of the invention

[0005] The embodiment of the present application provides a gradient updating method and related devices, which are applied to the field of terminal technology. The method can calculate the latest t-th parameter trend based on the t-1th parameter trend stored in the first electronic device, and the first electronic device determines whether the gradient obtained by the first electronic device is an expired gradient based on the calculated t-1th parameter trend, and updates the expired gradient.

[0006] In the first aspect, an embodiment of the present application proposes a gradient updating method. The method is applied to a communication system, the communication system includes a first electronic device and m second electronic devices, m is a positive integer, including: the first electronic device obtains n first gradients from any second electronic device among the m second electronic devices; wherein n is a positive integer; for the first gradient of the i-th dimension in the n first gradients, the first electronic device determines whether the first gradient of the i-th dimension is an expired gradient based on the t-th parameter trend of the i-th dimension; wherein the t-th parameter trend of the i-th dimension is related to the t-1th parameter trend of the i-th dimension and the parameter change amount of the i-th dimension, the parameter change amount of the i-th dimension is positively correlated with the first difference, and the first difference is the difference between the t-1th parameter of the i-th dimension and the t-1th parameter of the i-th dimension; wherein i is a positive integer less than or equal to n, and t is a positive integer. In this way, the first electronic device stores the t-1th parameter trend of the i-th dimension There is no need to store multiple parameters, which effectively saves the storage space of the first electronic device.

[0007] In a possible implementation, the parameter change is the difference between the t-th parameter of the i-th dimension and the t-1-th parameter of the i-th dimension. In this way, the parameter trend can be calculated more accurately based on the parameter change.

[0008] In possible implementations, the trend of the tth parameter in the i-th dimension Satisfies the following formula: in, represents the trend of the tth parameter in the i-th dimension, represents the t-1th parameter trend of the i-th dimension, β represents the first scaling factor, represents the parameter change, lr represents the learning rate, represents the gradient of the i-th dimension after the t-1th update. In this way, the t-th parameter trend of the i-th dimension is calculated When the first electronic device stores the t-1th parameter trend of the i-th dimension There is no need to store multiple parameters, which effectively saves the storage space of the first electronic device.

[0009] In a possible implementation, the value range of the first scaling factor is [0.9, 1). In this way, the parameter trend can be calculated more accurately.

[0010] In a possible implementation, the first electronic device determines whether the first gradient of the i-th dimension is an expired gradient based on the t-th parameter trend of the i-th dimension, including: when the sign function value of the t-th parameter trend of the i-th dimension is not equal to the sign function value of the first gradient of the i-th dimension, the first electronic device determines that the first gradient of the i-th dimension is not an expired gradient; when the sign function value of the t-th parameter trend of the i-th dimension is equal to the sign function value of the first gradient of the i-th dimension, the first electronic device determines that the first gradient of the i-th dimension is an expired gradient. In this way, the first electronic device can determine whether the sign function value of the t-th parameter trend of the i-th dimension is equal to the sign function value of the first gradient of the i-th dimension by calling the sign function, and then quickly and accurately determine whether the first gradient of the i-th dimension is an expired gradient.

[0011] Possible implementations also include: the first electronic device calculates a second scaling factor, the second scaling factor is used to update the first gradient of the i-th dimension; the first electronic device updates the first gradient of the i-th dimension based on the second scaling factor to obtain the second gradient of the i-th dimension. In this way, the first gradient of the i-th dimension can be updated based on the second scaling factor, so that when the first electronic device updates the model parameters based on the first gradient of the i-th dimension, the updated parameters are more accurate, and the convergence speed during model training can also be faster.

[0012] In a possible implementation, the first electronic device calculates the second scaling factor, including: when the first gradient of the i-th dimension is not an expired gradient, the value of the second scaling factor is 1; when the first gradient of the i-th dimension is an expired gradient, the first electronic device obtains the first parameter trend and the second parameter trend from the t-th parameter trend of n dimensions, wherein the first parameter trend is the parameter trend with the largest absolute value among the t-th parameter trends of n dimensions, and the second parameter trend is the parameter trend with the smallest absolute value among the t-th parameter trends of n dimensions; the second scaling factor is negatively correlated with the difference ratio, the difference ratio is the ratio between the third difference and the second difference, the second difference is the difference between the absolute value of the first parameter trend and the absolute value of the second parameter trend, and the third difference is the difference between the absolute value of the t-th parameter trend of the i-th dimension and the absolute value of the second parameter trend. In this way, when processing expired gradients, a qualitative method is used, that is, judging whether the parameter trend of the i-th dimension is equal to the sign function value of the first gradient of the i-th dimension; and a quantitative method is used, that is, calculating the second scaling factor based on the parameter trend. The second scaling factors calculated for different parameter trends may be different, which can more accurately update the expired gradients and speed up the convergence of the model.

[0013] In a possible implementation, the second scaling factor satisfies the following formula: in, is the second scaling factor, is the ratio of the second difference to the first difference. In this way, a scaling factor related to the parameter trend can be obtained to speed up the convergence of the model.

[0014] In a possible implementation, after the first electronic device updates the first gradient of the i-th dimension based on the scaling factor and obtains the second gradient of the i-th dimension, the method further includes: the first electronic device obtains the t+1th parameter of the i-th dimension based on the tth parameter of the i-th dimension and the second gradient of the i-th dimension; the first electronic device transmits the t+1th parameter of the i-th dimension to m second electronic devices. In this way, in the process of continuous iterative update of parameters and gradients, a more accurate model can be trained through the first electronic device and the second electronic device.

[0015] In a second aspect, an embodiment of the present application provides a gradient updating device. The gradient updating device may be an electronic device, or a chip or chip system in an electronic device. The gradient updating device may include a processing unit and a communication unit, and may also include a storage unit, wherein the processing unit is used to implement any method related to processing performed by the electronic device in any possible implementation of the aspect or aspect. When the gradient updating device is an electronic device, the processing unit may be a processor. The communication unit is used to support the interaction of the gradient updating device with other devices. The gradient updating device may also include a storage unit, which may be a memory. The storage unit is used to store instructions, and the processing unit executes the instructions stored in the storage unit so that the electronic device implements the method performed by the electronic device described in any possible implementation of the aspect or aspect. When the gradient updating device is a chip or chip system in an electronic device, the processing unit may be a processor. The processing unit executes the instructions stored in the storage unit so that the electronic device implements the method performed by the electronic device described in any possible implementation of the aspect or aspect. The storage unit may be a storage unit (e.g., a register, a cache, etc.) in the chip, or a storage unit (e.g., a read-only memory, a random access memory, etc.) located outside the chip in the electronic device.

[0016] Exemplarily, a communication unit is used to obtain n first gradients from any second electronic device among m second electronic devices; wherein n is a positive integer; for the first gradient of the i-th dimension among the n first gradients, a processing unit is used to determine whether the first gradient of the i-th dimension is an expired gradient based on the t-th parameter trend of the i-th dimension; wherein the t-th parameter trend of the i-th dimension is related to the t-1-th parameter trend of the i-th dimension and the parameter change of the i-th dimension, the parameter change of the i-th dimension is positively correlated with the first difference, and the first difference is the difference between the t-th parameter of the i-th dimension and the t-1-th parameter of the i-th dimension; wherein i is a positive integer less than or equal to n, and t is a positive integer.

[0017] In a possible implementation, the parameter change amount is the difference between the t-th parameter of the i-th dimension and the t-1-th parameter of the i-th dimension.

[0018] In possible implementations, the trend of the tth parameter in the i-th dimension Satisfies the following formula: in, represents the trend of the tth parameter in the i-th dimension, represents the t-1th parameter trend of the i-th dimension, β represents the first scaling factor, represents the parameter change, lr represents the learning rate, Represents the gradient of the i-th dimension after the t-1th update.

[0019] In a possible implementation, the value range of the first scaling factor is [0.9, 1).

[0020] In a possible implementation, when the sign function value of the t-th parameter trend of the i-th dimension is not equal to the sign function value of the first gradient of the i-th dimension, the processing unit is specifically used to determine that the first gradient of the i-th dimension is not an expired gradient; when the sign function value of the t-th parameter trend of the i-th dimension is equal to the sign function value of the first gradient of the i-th dimension, the processing unit is specifically used to determine that the first gradient of the i-th dimension is an expired gradient.

[0021] In a possible implementation, the processing unit is further used to calculate a second scaling factor, and the second scaling factor is used to update the first gradient of the i-th dimension; the processing unit is further used to update the first gradient of the i-th dimension based on the second scaling factor to obtain the second gradient of the i-th dimension.

[0022] In a possible implementation, when the first gradient of the i-th dimension is not an expired gradient, the value of the second scaling factor is 1; when the first gradient of the i-th dimension is an expired gradient, the processing unit is further used to obtain the first parameter trend and the second parameter trend from the t-th parameter trend of n dimensions, wherein the first parameter trend is the parameter trend with the largest absolute value among the t-th parameter trends of n dimensions, and the second parameter trend is the parameter trend with the smallest absolute value among the t-th parameter trends of n dimensions; the second scaling factor is negatively correlated with the difference ratio, the difference ratio is the ratio between the third difference and the second difference, the second difference is the difference between the absolute value of the first parameter trend and the absolute value of the second parameter trend, and the third difference is the difference between the absolute value of the t-th parameter trend of the i-th dimension and the absolute value of the second parameter trend.

[0023] In a possible implementation, the second scaling factor satisfies the following formula: in, is the second scaling factor, is the ratio of the second difference to the first difference.

[0024] In a possible implementation, the processing unit is further used to obtain the t+1th parameter of the i-th dimension based on the t-th parameter of the i-th dimension and the second gradient of the i-th dimension; the processing unit is further used to transmit the t+1th parameter of the i-th dimension to m second electronic devices.

[0025] In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, the memory being used to store code instructions, and the processor being used to run the code instructions to execute the method described in the first aspect or any possible implementation of the first aspect.

[0026] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the method of the first aspect is implemented.

[0027] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed, the computer executes the method of the first aspect.

[0028] In a sixth aspect, an embodiment of the present application provides a chip, the chip including a processor, the processor being used to call a computer program in a memory to execute the method described in the first aspect.

[0029] It should be understood that the second to sixth aspects of the present application correspond to the technical solutions of the first aspect of the present application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1A Schematic diagram of the process of asynchronous parallel model training based on parameter trends in some implementations;

[0031] Figure 1B Schematic diagram of parameter matrices in some implementations;

[0032] Figure 2 A schematic diagram of a gradient updating method provided in an embodiment of the present application;

[0033] Figure 3 A schematic diagram of an expired gradient update method provided in an embodiment of the present application;

[0034] Figure 4 A schematic diagram of a method for calculating a second scaling factor provided in an embodiment of the present application;

[0035] Figure 5 A schematic diagram of the structure of a parameter updating device provided in an embodiment of the present application;

[0036] Figure 6 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;

[0037] Figure 7 A schematic diagram of the structure of a chip provided in an embodiment of the present application. DETAILED DESCRIPTION

[0038] In order to clearly describe the technical solutions of the embodiments of the present application, some technical terms and techniques involved in the embodiments of the present application are briefly introduced below.

[0039] 1. Loss function

[0040] In an embodiment of the present application, the loss function can be used to measure the difference between the model prediction value and the target value. The higher the output value of the loss function, the greater the difference, and the lower the output value of the loss function, the smaller the difference.

[0041] In order to make the output value of the loss function converge quickly to the minimum value, the gradient descent method can be used. The gradient descent method is introduced below.

[0042] 2. Stochastic gradient descent (SGD)

[0043] The gradient is a vector, and the loss function converges fastest in the opposite direction of its gradient (negative gradient). Therefore, in the process of training the model, the model parameters can be updated in the opposite direction of the gradient of the loss function to continuously reduce the output value of the loss function and make the model prediction value as close to the target value as possible. This process can be called "stochastic gradient descent method".

[0044] The stochastic gradient descent method can include synchronous stochastic gradient descent and asynchronous stochastic gradient descent, which are described below respectively.

[0045] Synchronous stochastic gradient descent (synchronous SGD) can also be called a synchronous parallel algorithm. In distributed training, the parameter server needs to receive the gradients of the model calculated by each computing module, and then use the average of these gradients to update the model parameters.

[0046] Asynchronous stochastic gradient descent (asynchronous SGD) can also be called an asynchronous parallel algorithm. The asynchronous parallel algorithm may mean that in distributed training, after the parameter server receives the gradient of the model calculated by a computing module, it can use the gradient to update the parameters of the model.

[0047] The stochastic gradient descent method used in the embodiment of the present application is asynchronous gradient descent, and asynchronous stochastic gradient descent may lead to the problem of expired gradients.

[0048] 3. Expired gradient

[0049] In an embodiment of the present application, an expired gradient may refer to that when the first computing module transmits the gradient of the calculated model to the parameter server and the parameter server updates the model parameters based on the acquired gradient, the model parameters have been updated based on the gradient transmitted by other computing modules except the first computing module. The gradient transmitted by the first computing module to the parameter server can be called an expired gradient.

[0050] 4. Data Sharding

[0051] In an embodiment of the present application, data sharding may refer to storing the data in a training data set in multiple computing modules respectively. Through data sharding, the amount of data in each computing module can be kept within a certain range, and more data can be stored and processed without the need for each computing module to increase its computing power.

[0052] Data sharding can be done in vertical and horizontal ways. Vertical sharding can be called vertical splitting, which can distribute the data in the training data set to multiple machines according to the business dimension of the data, for example, sharding the data in the training data set according to business dimensions such as business 1 and business 2; horizontal sharding can be called horizontal splitting, which can distribute the data in the training data set to multiple machines according to certain rules, for example, sharding the data in the training data set by row number, storing the data in rows 1-5 in the training data set in machine 1, and storing the data in rows 6-10 in the training data set in machine 2.

[0053] It is understandable that when data in the training data set is sharded, vertical sharding or horizontal sharding can be performed. The data in the training data set can also be sharded vertically and horizontally, for example, the data after vertical sharding can be sharded horizontally. In addition, in addition to vertical sharding and horizontal sharding, data sharding can also have other sharding methods, and the data sharding method used in the embodiment of the present application can be horizontal sharding.

[0054] 5. In order to facilitate the clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0055] In the embodiments of the present application, "at least one" refers to one or more, and "plurality" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.

[0056] It should be noted that the "at..." in the embodiment of the present application can be the instant when a certain situation occurs, or a period of time after a certain situation occurs, and the embodiment of the present application does not specifically limit this. In addition, the display interface provided in the embodiment of the present application is only an example, and the display interface can also include more or less content.

[0057] As the business develops, the amount of training data that can be used to train the model is increasing. Taking the game skin recommendation model as an example, the game skin recommendation model can be used to recommend game skins to users based on the user's game skin usage records, game skin ordering records, and game skin browsing records. The training data set used to train the model may include: a large number of user game skin usage records, game skin ordering records, and user game skin browsing records. For this large training data set, in order to make the game skin recommendation results more accurate, that is, to make the model's fitting ability stronger, the model's parameters are usually large.

[0058] For model training with large training data volume and many model parameters, in order to improve the model training speed, in some implementations, model training can be performed through a distributed asynchronous parallel model training method based on parameter trends.

[0059] For example, Figure 1A The process of asynchronous parallel model training based on parameter trends in some implementations.

[0060] like Figure 1A As shown, Figure 1A The parameter server and a computing module may be included, where a is a positive integer, wherein a computing module may correspond to Figure 1A Machine 1, machine 2, ..., and machine a, etc.

[0061] It should be noted that the parameter server can also be called a parameter storage module or a parameter storage node. The parameter server can be used to store the parameters of the model, update the parameters of the model according to the gradient sent by the computing module, and transmit the updated model parameters to the computing module; the computing module can also be called a computing node, and the computing module can be used to calculate the gradient of the model based on the stochastic gradient descent method.

[0062] The parameter server and the computing module may be actual hardware. For example, the parameter server and the computing module may correspond to multiple servers respectively. The parameter server and the computing module may also correspond to multiple central processing units (CPUs) and / or multiple graphics processing units (GPUs) in a server respectively. The parameter server and the computing module may also be software running in the server, which is not specifically limited in the embodiments of the present application.

[0063] In the process of asynchronous parallel model training based on parameter trends, the training data set can be divided into a data shards, namely data shard 1, data shard 2, ..., and data shard a, and a computing modules can respectively train the model copies based on the corresponding data shards. For example, computing module 1 can train the model copy based on data shard 1, computing module 2 can train the model copy based on data shard 2, and computing module a can train the model copy based on data shard a, wherein each computing module can obtain the model copy from the parameter server.

[0064] A computing module can calculate the gradient (gradient, g) of the model based on the model parameter (weight, W), and transmit the calculated gradient g to the parameter server. The parameter server can update the model parameter W based on the obtained gradient g, and transmit the updated model parameter W to the a computing module respectively. The a computing module can calculate the gradient g of the model based on the updated model parameter W. In this way, by continuously updating the model parameter W in the above manner, the model can be trained to make the predicted value of the model closer to the target value.

[0065] Specifically, the parameters of the model can be a matrix with m rows and n columns, where m and n are both positive integers. For ease of description, the present embodiment and subsequent embodiments distinguish the parameters in the above parameter matrix by dimension. For example, Figure 1B The parameter matrix shown is 2 rows and 2 columns, and the parameter W in the first row and first column is 11 It can be called the parameter of the first dimension, the parameter W of the first row and second column 12 It can be called the parameter of the second dimension, the parameter W in the second row and first column 21It can be called the parameter of the third dimension, the parameter W in the second row and second column 22 It can be called the parameter of the fourth dimension, and each parameter in the matrix can correspond to different dimensions. For ease of description, the present embodiment and subsequent embodiments are based on the parameter W of the i-th dimension. i Take for example to illustrate, i is a positive integer.

[0066] It is understandable that the parameter W updated for the tth time i Can be used Indicates that the parameter W updated for the tLth time i Can be used Indicates that based on and The change trend of the parameters from the tLth update to the tth update can be obtained, that is, the parameter trend The calculation process can be expressed by formula (1):

[0067]

[0068] Wherein, t and L are both positive integers, and L is less than or equal to t. It should be noted that the parameter trend reflects the change of the parameter over a period of time. In order to obtain a more accurate parameter trend, L can be a larger value, for example, the value range of L can be [50,200].

[0069] Calculate the parameter trend After that, the parameter server can determine the gradient through the sign function Direction and parameter trends Whether they are consistent, the judgment process can be expressed by formula (2):

[0070]

[0071] when and When the values ​​of are equal, and The value of is 1, or and When the values ​​of are all -1, the parameter server can determine the parameter trend With gradient have the same sign, that is, the gradient Direction and parameter trends Consistent.

[0072] From the stochastic gradient descent method, we know that the parameter server continuously updates the model parameters according to the opposite direction of the gradient, so that the predicted value of the model is constantly close to the actual value. The relationship between the parameters and the gradient can be expressed by formula (3).

[0073]

[0074] in, is the parameter updated for the t+1th time, is the parameter updated for the tth time, lr is the learning rate, and the learning rate is used to control the difference between the model parameters updated for the t+1th time and the tth time. The larger the learning rate, the larger the difference between the model parameters updated for the t+1th time and the tth time. On the contrary, the smaller the learning rate, the smaller the difference between the model parameters updated for the t+1th time and the tth time. The value of the learning rate can be pre-set in the parameter server based on experience or experimental results, and the embodiments of the present application do not impose specific restrictions on this.

[0075] Parameter Trend With gradient If the signs of are the same, it means that the parameter server is not following the gradient The parameters are updated in the opposite direction of , so the gradient is the expired gradient, to reduce the expired gradient The impact on model accuracy and model training convergence speed can be reduced The value of is reduced as shown in formula (4).

[0076]

[0077] in, is the updated gradient, α is the scaling factor, and the value range of α is between (0, 1). For example, α can be 0.5, 0.8, etc. The embodiment of the present application does not specifically limit the value of α.

[0078] when and When the values ​​of are not equal, The value of is 1, When the value of is -1, or The value of is -1, When the value is 1, the parameter server can determine the parameter trend With gradient have different signs, that is, the gradient Direction and parameter trends Inconsistent, the parameter server is based on the gradient The parameters updated in the opposite direction of Perform reduction processing.

[0079]

[0080] However, in the above model training process, in order to obtain the parameter change trend of parameter W between the tLth update and the tth update The parameter server needs to store L+1 parameters, that is It takes up a lot of storage space on the parameter server. For example, if L is 100, It is understandable that the parameters are continuously updated iteratively. If the parameter server does not store the parameters before the update, the parameters will be overwritten by the updated parameters. For example, is the parameter before updating, For the updated parameters, if the parameter server does not store will be Coverage, therefore, for the calculation of parameter trends To parameter trend Parameters need to be stored in advance To Parameters The parameter server needs to store 100 parameters, which takes up a lot of storage space, which may cause the parameter server to freeze and overheat.

[0081] In view of this, an embodiment of the present application provides a gradient updating method, which can calculate the latest tth parameter trend based on the t-1th parameter trend stored in the first electronic device. The first electronic device determines whether the gradient obtained by the first electronic device is an expired gradient based on the calculated tth parameter trend, and updates the expired gradient. When calculating the latest tth parameter trend, the first electronic device performs the calculation based on the stored t-1th parameter trend, without the need to store multiple parameters, effectively saving the storage space of the first electronic device.

[0082] The gradient updating method provided in the embodiment of the present application is applied to a communication system, which may include a first electronic device and m second electronic devices, where m is a positive integer. The first electronic device may be used to calculate a parameter, and the first electronic device may correspond to Figure 1A The parameter server in the second electronic device can be used to calculate the gradient, and the second electronic device can correspond to Figure 1A The calculation module in .

[0083] In a possible implementation, the first electronic device and the second electronic device can also be any form of terminal device that can be used to train the model. For example, some terminal devices are: mobile phones, tablet computers, PDAs, laptop computers, mobile Internet devices (mobile internet device, MID), etc. The embodiments of the present application are not limited to this.

[0084] The following is an exemplary description of the gradient updating method provided in the embodiment of the present application.

[0085] The first electronic device obtains n first gradients from any second electronic device among m second electronic devices, where n is a positive integer.

[0086] That is, any second electronic device may calculate one or more first gradients in one calculation, and the first electronic device may obtain the n first gradients calculated by any second electronic device among the m second electronic devices.

[0087] In the embodiment of the present application, for the convenience of description, the n first gradients updated by any second electronic device in a calculation process can be expressed by gradients of different dimensions. For example, the n first gradients updated for the tth time It can be called the first gradient of the first dimension, It can be called the first gradient of the second dimension, It can be called the first gradient of the third dimension, It can be called the first gradient of the nth dimension.

[0088] Since there may be outdated gradients in asynchronous parallel distributed algorithms, for the first gradient of the i-th dimension among the n first gradients, The first electronic device may be configured to: Determine the first gradient of the i-th dimension Whether it is an expired gradient. Among them, the tth parameter trend of the i-th dimension and the t-1th parameter trend of the i-th dimension And it is related to the parameter change in the i-th dimension, i is a positive integer less than or equal to n, and t is a positive integer.

[0089] The parameter change of the i-th dimension is positively correlated with the first difference, and the first difference is the t-th parameter of the i-th dimension and the t-1th parameter of the i-th dimension That is, the parameter change of the i-th dimension can be the t-th parameter of the i-th dimension and the t-1th parameter of the i-th dimension The difference can also be found in the tth parameter of the i-th dimension and the t-1th parameter of the i-th dimension Based on the difference between the two, add the adjustment parameter. For example, the parameter change of the i-th dimension = the t-th parameter of the i-th dimension and the t-1th parameter of the i-th dimension The difference between 0 and 1 is calculated by multiplying the values ​​of 0.9 and 1.1 by 1.1, wherein a is an adjustment parameter and the value range of a may be 0.9 or a value near 0.9, 1.1 or a value near 1.1, etc., and the embodiment of the present application does not make any specific limitation on this.

[0090] From the above embodiment, it can be seen that the first electronic device is based on the t-1th parameter trend of the i-th dimension And the parameter change of the i-th dimension can be calculated to get the t-th parameter trend of the i-th dimension The first electronic device stores the t-1th parameter trend of the i-th dimension There is no need to store multiple parameters, for example, there is no need to store L+1 parameters to In this way, the storage space of the first electronic device can be effectively saved.

[0091] In possible implementations, the trend of the tth parameter in the i-th dimension Satisfies the following formula:

[0092]

[0093] in, represents the trend of the tth parameter in the i-th dimension, represents the t-1th parameter trend of the i-th dimension, β represents the first scaling factor, represents the parameter change, lr represents the learning rate, represents the gradient of the i-th dimension after the t-1th update. The value of the gradient of the i-th dimension after the t-1th update may change, for example, the value of the gradient of the i-th dimension after the t-1th update may be less than the value of the gradient before the update, or may remain unchanged.

[0094] In this way, the trend of the tth parameter of the i-th dimension is calculated When the first electronic device stores the t-1th parameter trend of the i-th dimension There is no need to store multiple parameters, which effectively saves the storage space of the first electronic device.

[0095] The value range of the first scaling factor β can be (0,1). It can be understood that when the value of the first scaling factor β is small, the tth parameter trend of the i-th dimension is It depends largely on the parameter change of the i-th dimension, which is equivalent to a smaller value of L in some implementations; when the value of the first scaling factor β is large, the trend of the t-th parameter of the i-th dimension Depends largely on the trend of the t-1th parameter of the i-th dimension This is equivalent to a larger value of L in some implementations. Therefore, the value of the first scaling factor β can be set according to actual needs to achieve a more accurate calculation of the parameter trend.

[0096] In a possible implementation, the value range of the first scaling factor β may be [0.9, 1). It can be understood that the trend of the tth parameter of the i-th dimension and the t-1th parameter trend of the i-th dimension And the parameter change of the i-th dimension, when the value range of the first scaling factor β is [0.9,1), for example, when β is 0.9 or a value near 0.9, based on It changes with the change of the parameter in the i-th dimension.

[0097] In a possible implementation, the first electronic device determines whether the first gradient of the i-th dimension is an expired gradient based on the t-th parameter trend of the i-th dimension, including: when the sign function value of the t-th parameter trend of the i-th dimension is not equal to the sign function value of the first gradient of the i-th dimension, the first electronic device determines that the first gradient of the i-th dimension is not an expired gradient; when the sign function value of the t-th parameter trend of the i-th dimension is equal to the sign function value of the first gradient of the i-th dimension, the first electronic device determines that the first gradient of the i-th dimension is an expired gradient.

[0098] That is, the first electronic device can call the sign function to determine the first gradient of the i-th dimension Whether it is an expired gradient.

[0099] For example, when The value of is 1, When the value of is -1, or The value of is -1, When the value of is 1, the first electronic device can determine the sign function value of the tth parameter trend of the i-th dimension The sign function value of the first gradient of the i-th dimension The values ​​of are not equal, that is, the gradient Direction and parameter trends Inconsistent.

[0100] For example, and The value of is 1, or and When the values ​​of are all -1, the first electronic device can determine the sign function value of the tth parameter trend of the i-th dimension The sign function value of the first gradient of the i-th dimension The value of is equal, that is, the first gradient Direction and parameter trends Consistent.

[0101] based on Figure 1A As can be seen from the relevant description in , the first electronic device continuously updates the parameters of the model according to the reverse direction of the gradient. Direction and parameter trends When the first electronic device is inconsistent, the first gradient When updating the parameters of the model in the opposite direction of Not an expired gradient; when the first gradient Direction and parameter trends When the first electronic device is not consistent with the first gradient When updating the parameters of the model in the opposite direction of Expired gradient.

[0102] In this way, the first electronic device can call the sign function to determine whether the sign function value of the tth parameter trend of the i-th dimension is equal to the sign function value of the first gradient of the i-th dimension, and then quickly and accurately determine whether the first gradient of the i-th dimension is an expired gradient.

[0103] In a possible implementation, the first electronic device calculates a second scaling factor, and the first electronic device updates a first gradient of the i-th dimension based on the second scaling factor to obtain a second gradient of the i-th dimension.

[0104] In the embodiment of the present application, the second scaling factor is used to update the first gradient of the i-th dimension The second gradient of the i-th dimension is the gradient obtained after the first gradient of the i-th dimension is updated. The second gradient of the i-th dimension can be express.

[0105] The first electronic device may update the first gradient of the i-th dimension based on the second scaling factor by referring to the following formula:

[0106]

[0107] Wherein, α represents the second scaling factor.

[0108] In this way, the first gradient of the i-th dimension can be updated based on the second scaling factor, so that when the first electronic device updates the model parameters based on the first gradient of the i-th dimension, the updated parameters are more accurate and the convergence speed during model training can be faster.

[0109] It can be understood that when the first electronic device determines the first gradient of the i-th dimension The second gradient of the i-th dimension when it is not an expired gradient Can be equal to the first gradient g of the i-th dimension i , the second scaling factor can be 1. In a possible implementation, the second scaling factor can also be a letter, a symbol, a word, etc. When the second scaling factor is a letter, a symbol, a word, etc., it indicates the second gradient of the i-th dimension Can be equal to the first gradient of the i-th dimension For example, when the second scaling factor is the word true, the second gradient Can be equal to the first gradient of the i-th dimension

[0110] When the first electronic device determines the first gradient of the i-th dimension When the gradient is expired, the first electronic device uses the first gradient Update the model parameters. The updated parameters may be inaccurate and affect the convergence speed of model training. To reduce the first gradient The impact on model training can reduce the first gradient That is, the first electronic device can use the second scaling factor to convert the first gradient Update to the second gradient Second gradient The value is less than the first gradient In a possible implementation, the second scaling factor may be a preset value, and the value range of the second scaling factor may be (0, 1).

[0111] In another possible implementation, the corresponding second scaling factor can be calculated based on the parameter trend. This is because for a large parameter trend value When the gradient Direction and parameter trends When consistent, to reduce the gradient The impact on parameter accuracy can be For parameter trend values ​​with small When the gradient Direction and parameter trends When the gradient is consistent, A smaller reduction is made, so that the trend of the parameter Calculate the second scaling factor

[0112] Specifically, when the first gradient of the i-th dimension is an expired gradient, the first electronic device obtains the first parameter trend and the second parameter trend from the t-th parameter trend of the n-dimensions, wherein the first parameter trend is the parameter trend with the largest absolute value among the t-th parameter trends of the n-dimensions, and the second parameter trend is the parameter trend with the smallest absolute value among the t-th parameter trends of the n-dimensions.

[0113] The second scaling factor is negatively correlated with the difference ratio, the difference ratio is the ratio between the third difference and the second difference, the second difference is the difference between the absolute value of the first parameter trend and the absolute value of the second parameter trend, and the third difference is the difference between the absolute value of the t-th parameter trend of the i-th dimension and the absolute value of the second parameter trend. The second scaling factor is negatively correlated with the difference ratio, which may mean that the second scaling factor decreases as the difference ratio increases, or the second scaling factor increases as the difference ratio decreases.

[0114] The above process can be expressed by the following formula:

[0115]

[0116]

[0117]

[0118]

[0119] in, is the first parameter trend, is the second parameter trend, trend t is the tth parameter trend of n dimensions, interval is the second difference, is the third difference, is the ratio of the third difference to the second difference.

[0120] In a possible implementation, the second scaling factor satisfies the following formula:

[0121]

[0122] in, is the second scaling factor, is the ratio of the second difference to the first difference.

[0123] The second scaling factor is calculated based on the parameter trend, and the gradient is updated by the second scaling factor. In this way, when processing expired gradients, both a qualitative method is used, that is, judging whether the parameter trend of the i-th dimension is equal to the sign function value of the first gradient of the i-th dimension; and a quantitative method is used, that is, the second scaling factor is calculated based on the parameter trend. The second scaling factors calculated for different parameter trends may be different, which can more accurately update the expired gradient and accelerate the convergence of the model.

[0124] In a possible implementation, the first electronic device updates the first gradient of the i-th dimension based on the second scaling factor to obtain the second gradient of the i-th dimension. Then, the first electronic device obtains the t+1th parameter of the i-th dimension based on the tth parameter of the i-th dimension and the second gradient of the i-th dimension. The t+1th parameter can be shown as follows.

[0125]

[0126] in, is the t+1th parameter of the ith dimension.

[0127] Get the t+1th parameter of the i-th dimension After that, the first electronic device can The data are transmitted to m second electronic devices respectively.

[0128] That is to say, the first electronic device can update the parameters of the model and transmit the updated parameters to the second electronic device. The electronic device updates the gradient based on the acquired parameters. In this way, in the process of continuous iterative update of parameters and gradients, a more accurate model can be trained through the first electronic device and the second electronic device.

[0129] It can be understood that the model trained based on the gradient update method provided in the embodiment of the present application can be applicable to any of the following target scenarios, which may include: speech recognition, image recognition, language translation, intelligent customer service, recommendation system, etc. The embodiment of the present application does not specifically limit the scenario in which the gradient update method is used.

[0130] Taking the target scenario as a speech recognition scenario, after the speech recognition model is trained based on the gradient update method provided in the embodiment of the present application, the trained speech recognition model can be applied to the speech recognition scenario. Among them, the speech recognition model can be used to convert the voice information sent / received by the user into text information, and the training data set when training the speech recognition model can include: a large amount of user voice information from different countries and regions. For example, a chat application (application, App) has a speech recognition function. When the user uses the speech-to-text function, the chat App can convert the voice information uploaded by the user into text information based on the trained speech recognition model.

[0131] Taking the target scenario as an example of a game skin recommendation scenario in a recommendation system, after training the game skin recommendation model based on the gradient update method provided in the embodiment of the present application, the trained game skin recommendation model can be applied to the game skin recommendation scenario. Among them, the game skin recommendation model can be used to recommend game skins that game users may be interested in. The training data set for training the game skin recommendation model may include: a large number of user game skin usage records, game skin ordering records, and user game skin browsing records. For example, a game App has a game skin recommendation function. When a user uses the game App, the game App can recommend game skins to the user based on the user's game skin usage records, game skin ordering records, and user game skin browsing records.

[0132] Below, according to Figure 2 , taking the first electronic device as a parameter server and the second electronic device as a computing module as an example, the gradient updating method provided in an embodiment of the present application is described.

[0133] like Figure 2 As shown, Figure 2The parameter server and a computing modules may be included, where m is a positive integer, wherein a computing module may correspond to Figure 2 Machine 1, machine 2, ..., and machine m, etc.

[0134] S201: Initialize model parameters.

[0135] Before training the model, it is necessary to initialize the model parameters and assign initial values ​​to the parameters. The initial values ​​of the parameters can be values ​​set based on experience or experimental results, and the embodiments of the present application do not impose specific restrictions on this.

[0136] In addition, the parameter trend also needs to be assigned an initial value. In a possible implementation, the initial value of the parameter trend is trend 0 Can be assigned a value of 0.

[0137] It should be noted that, corresponding to the matrix of parameters with m rows and n columns, the gradient g is also a matrix with m rows and n columns, and the parameter trend trend is also a matrix with m rows and n columns. Below, we take the i-th dimension g in the gradient matrix as i and the trend of the i-th dimension in the parameter trend matrix i Take this as an example to explain.

[0138] S202, such as Figure 3 As shown, the parameter server determines the gradient through the sign function Direction and parameter trends Whether they are consistent, the judgment process can be expressed by formula (14):

[0139]

[0140] in, is the parameter trend of the tth update, which can correspond to the tth parameter trend of the i-th dimension above. is the gradient updated for the tth time, which may correspond to the first gradient of the i-th dimension mentioned above.

[0141] when and When the values ​​of are equal, and The value of is 1, or and When the values ​​of are all -1, the parameter server can determine the parameter trend With gradient have the same sign, that is, the gradient Direction and parameter trends Consistent.

[0142] when and When the values ​​of are not equal, The value of is 1, When the value of is -1, or The value of is -1, When the value is 1, the parameter server can determine the parameter trend With gradient have different signs, that is, the gradient Direction and parameter trends Inconsistent.

[0143] S203, such as Figure 3 As shown, when and When the values ​​of are equal, the parameter server Calculate the scaling factor Scaling Factor It may correspond to the second scaling factor mentioned above.

[0144] based on Figure 1A From the relevant description in , we can see that when the gradient Direction and parameter trends When consistent, the gradient For expired gradients, the parameter server is based on the gradient The updated parameters may be inaccurate and slow down the convergence of the training model. The impact on parameter accuracy and speeding up the convergence of model training can be given to the gradient Multiply by the scaling factor To reduce the gradient The value of .

[0145] Calculation method: Figure 4 And shown in formula (15).

[0146]

[0147] in, The parameter trend The normalization factor of The calculation method can refer to Figure 4 And equations (16) to (19).

[0148] As shown in formula (16), the parameter server obtains the maximum parameter trend of the m*n dimensions updated for the tth time through the max function As shown in formula (17), the parameter server obtains the minimum parameter trend of the m*n dimensions updated for the tth time through the min function get and After that, as shown in formula (18), the parameter server calculates and According to formula (19), the normalization factor of the parameter trend can be obtained: Normalization factor is a value greater than 0 and less than 1.

[0149]

[0150]

[0151]

[0152]

[0153] S204, when and When the values ​​of are not equal, the second scaling factor Assign a value of 1.

[0154] like Figure 3 As shown, when and When the values ​​of are not equal, that is, the parameter server does not follow the gradient The parameters updated in the opposite direction Therefore, there is no need to reduce the gradient Scaling Factor Can be assigned a value of 1.

[0155] S205, parameter server based on scaling factor Calculate the updated gradient

[0156] The parameter server can calculate the updated gradient through the generate_update function, and the calculation method is as shown in formula (20).

[0157]

[0158] in, For gradient Based on the second scaling factor The updated gradient may correspond to the second gradient mentioned above.

[0159] S206, parameter server based on the updated gradient Update model parameters.

[0160] The parameter server calculates the updated gradient After that, we can use the updated gradient and the parameters updated for the tth time Calculate the parameters for the t+1th update The calculation process is shown in formula (21).

[0161]

[0162] Among them, lr is the learning rate. The relevant description of lr can refer to Figure 1A The relevant description in will not be repeated here.

[0163] In addition, the parameter server calculates the parameters for the t+1th update After that, the parameter server transmits the updated parameters to a computing modules respectively. The calculation module is based on the obtained parameters Computing Gradients And the calculated gradient Transmitted to the parameter server.

[0164] S207: The parameter server updates the parameter trend and stores the updated

[0165] Parameter trend of parameter server based on the tth update The parameter trend is updated by the change in the parameter, where the change in the parameter is the parameter and parameters The difference between The update method of can be shown as formula (22).

[0166]

[0167] in, is the parameter trend updated for the t+1th time, β may correspond to the first scaling factor mentioned above, β may be a constant preset based on experience or experimental results, and the value range of β is (0,1). In the embodiment of the present application, β may take a value of 0.9 or near 0.9.

[0168] The parameter server saves the updated And continue to execute step S202 to step S207 until the difference between the predicted value of the model and the target value is less than or equal to the preset difference.

[0169] In the embodiment of the present application, the parameter server is based on the parameter trend updated for the tth time The parameter trend of the t+1th update can be calculated, and the parameter server only needs to save the parameter trend of the tth update There is no need to save L+1 copies of parameters, which can save storage space on the parameter server. In addition, based on parameter trends Calculate the scaling factor The gradient g can be more accurately i Reduce and accelerate the convergence of the model.

[0170] Combined with the above Figures 2 to 4 , the method provided in the embodiment of the present application is described, and the device for executing the above method provided in the embodiment of the present application is described below. Figure 5 As shown, Figure 5 A structural schematic diagram of a parameter updating device provided in an embodiment of the present application. The parameter updating device may be the first electronic device in the embodiment of the present application, or may be a chip or chip system in the first electronic device.

[0171] like Figure 5 As shown, the parameter updating device 500 can be used in a circuit, a hardware component or a chip, and the parameter updating device includes a processing unit 501. The processing unit 501 is used to support the steps executed by the parameter updating device, for example, the processing unit can be used to process steps S201 to S207.

[0172] In a possible implementation, the parameter updating device may further include: a storage unit 503. The storage unit 503 may include one or more memories, and the memory may be a device in one or more devices or circuits for storing programs or data.

[0173] The storage unit 503 may exist independently and be connected to the processing unit 501 via a communication bus. The storage unit 503 may also be integrated with the processing unit 501.

[0174] Taking the parameter updating device as an example, which can be a chip or chip system of the first electronic device in the embodiment of the present application, the storage unit 503 can store computer execution instructions of the method of the first electronic device, so that the processing unit 501 executes the method of the first electronic device in the above embodiment. The storage unit 503 can be a register, a cache, or a random access memory (RAM), etc. The storage unit 503 can be integrated with the processing unit 501. The storage unit 503 can be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, and the storage unit 503 can be independent of the processing unit 501.

[0175] In a possible implementation, the parameter updating device may further include: a communication unit 502. The communication unit 502 is used to support the parameter updating device to interact with other devices. Exemplarily, when the parameter updating device is a first electronic device, the communication unit 502 may be a communication interface or an interface circuit. When the parameter updating device is a chip or a chip system in the first electronic device, the communication unit 502 may be a communication interface. For example, the communication interface may be an input / output interface, a pin or a circuit, etc.

[0176] The device of this embodiment can be used to execute the steps executed in the above method embodiment. Its implementation principle and technical effects are similar and will not be described in detail here.

[0177] Figure 6 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, the electronic device includes a processor 601, a communication line 604 and at least one communication interface ( Figure 6 The communication interface 603 is used as an example for explanation).

[0178] The processor 601 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.

[0179] Communications link 604 may include circuitry to transmit information between the above-described components.

[0180] The communication interface 603 uses any transceiver or other device for communicating with other devices or communication networks, such as Ethernet, wireless local area networks (WLAN), etc.

[0181] Possibly, the electronic device may further include a memory 602 .

[0182] The memory 602 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including a compressed optical disc, a laser disc, an optical disc, a digital versatile disc, a Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a communication line 604. The memory may also be integrated with the processor.

[0183] The memory 602 is used to store computer-executable instructions for executing the solution of the present application, and the execution is controlled by the processor 601. The processor 601 is used to execute the computer-executable instructions stored in the memory 602, thereby implementing the method provided by the embodiment of the present application.

[0184] Possibly, the computer-executable instructions in the embodiments of the present application may also be referred to as application code, and the embodiments of the present application do not specifically limit this.

[0185] In a specific implementation, as an embodiment, the processor 601 may include one or more CPUs, such as Figure 6 CPU0 and CPU1 in.

[0186] In a specific implementation, as an embodiment, the electronic device may include multiple processors, such as Figure 6 601 and processor 605 in the embodiment of the present invention. Each of these processors may be a single-CPU processor or a multi-CPU processor. The processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).

[0187] For example, Figure 7 A schematic diagram of the structure of a chip provided in an embodiment of the present application. The chip 700 includes one or more (including two) processors 720 and a communication interface 730 .

[0188] In some embodiments, the memory 740 stores the following elements: executable modules or data structures, or a subset thereof, or an extended set thereof.

[0189] In the embodiment of the present application, the memory 740 may include a read-only memory and a random access memory, and provide instructions and data to the processor 720. A portion of the memory 740 may also include a non-volatile random access memory (NVRAM).

[0190] In the embodiment of the present application, the memory 740, the communication interface 730 and the processor 720 are coupled together through the bus system 710. The bus system 710 may include a power bus, a control bus and a status signal bus in addition to a data bus. Figure 7 Various buses are labeled as bus system 710 .

[0191] The method described in the above embodiment of the present application can be applied to the processor 720, or implemented by the processor 720. The processor 720 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware or software instructions in the processor 720. The above processor 720 can be a general-purpose processor (for example, a microprocessor or a conventional processor), a digital signal processor (digital signal processing, DSP), an application specific integrated circuit (application specific integrated circuit, ASIC), a field-programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gates, transistor logic devices or discrete hardware components. The processor 720 can implement or execute the disclosed methods, steps and logic block diagrams in the embodiments of the present application.

[0192] The steps of the method disclosed in the embodiment of the present application can be directly embodied as being executed by a hardware decoding processor, or being executed by a combination of hardware and software modules in the decoding processor. Among them, the software module can be located in a mature storage medium in the field such as a random access memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable read only memory (EEPROM). The storage medium is located in the memory 740, and the processor 720 reads the information in the memory 740 and completes the steps of the above method in combination with its hardware.

[0193] In the above embodiments, the instructions stored in the memory for execution by the processor may be implemented in the form of a computer program product, wherein the computer program product may be pre-written in the memory, or may be downloaded and installed in the memory in the form of software.

[0194] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. For example, the available medium can include a magnetic medium (e.g., a floppy disk, a hard disk or a tape), an optical medium (e.g., a digital versatile disc (digital versatile disc, DVD)), or a semiconductor medium (e.g., a solid state drive (solid state disk, SSD)), etc.

[0195] The embodiments of the present application also provide a computer-readable storage medium. The methods described in the above embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. Computer-readable media may include computer storage media and communication media, and may also include any medium that can transfer a computer program from one place to another. The storage medium may be any target medium that can be accessed by a computer.

[0196] As a possible design, the computer readable medium may include a compact disc read-only memory (CD-ROM), RAM, ROM, EEPROM or other optical disc storage; the computer readable medium may include a magnetic disk storage or other magnetic disk storage device. Moreover, any connection line may also be appropriately referred to as a computer readable medium. For example, if the software is transmitted from a website, server or other remote source using a coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology (such as infrared, radio and microwave), the coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology such as infrared, radio and microwave are included in the definition of medium. Disk and disc as used herein include compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, where disks usually reproduce data magnetically, while optical discs reproduce data optically using lasers.

[0197] The above combinations should also be included in the scope of computer-readable media. The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

[0198] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

Claims

1. A gradient updating method, characterized in that: Applied to a communication system, the communication system includes a first electronic device and m second electronic devices, where m is a positive integer, including: The first electronic device obtains n first gradients from any second electronic device among the m second electronic devices; wherein n is a positive integer; For the first gradient of the i-th dimension among the n first gradients, the first electronic device determines whether the first gradient of the i-th dimension is an expired gradient based on the t-th parameter trend of the i-th dimension; wherein the first gradient of the i-th dimension is used to update the model parameters, the model parameters are a parameter matrix of m rows and n columns, each parameter of the parameter matrix corresponds to a different dimension, and the order of the dimensions is arranged in sequence according to the parameters corresponding to each row in the matrix, the t-th parameter trend of the i-th dimension is related to the t-1-th parameter trend of the i-th dimension and the parameter change of the i-th dimension, the parameter change of the i-th dimension is positively correlated with the first difference, the first difference is the difference between the t-th parameter of the i-th dimension and the t-1-th parameter of the i-th dimension, for any parameter in the parameter matrix a parameter, each of which has a corresponding t-th parameter trend of the i-th dimension, the t-th parameter trend of the i-th dimension is a change trend of the parameter corresponding to the i-th dimension from the tLth update to the t-th update, and the t-th parameter trend of the i-th dimension is determined according to the parameter updated for the tth time and the parameter updated for the tLth time. When the first computing module transmits the calculated gradient of the model to the parameter server, and the parameter server updates the model parameters based on the acquired gradient, the model parameters have been updated based on the gradient transmitted by other computing modules except the first computing module, then the gradient transmitted by the first computing module to the parameter server is called an expired gradient; wherein, i is a positive integer less than or equal to n, t and L are both positive integers, and L is less than or equal to t; The method further comprises: The first electronic device calculates a second scaling factor, where the second scaling factor is used to update the first gradient of the i-th dimension, wherein when the first gradient of the i-th dimension is an expired gradient, the second scaling factor is determined according to a t-th parameter trend of n dimensions; The first electronic device updates the first gradient of the i-th dimension based on the second scaling factor to obtain the second gradient of the i-th dimension.

2. The method according to claim 1, characterized in that The parameter change is the difference between the tth parameter of the i-th dimension and the t-1th parameter of the i-th dimension.

3. The method according to claim 2, characterized in that The tth parameter trend of the i-th dimension Satisfies the following formula: in, represents the trend of the tth parameter of the i-th dimension, represents the t-1th parameter trend of the i-th dimension, β represents the first scaling factor, represents the parameter change, lr represents the learning rate, Represents the gradient of the i-th dimension after the t-1th update.

4. The method according to claim 3, characterized in that The value range of the first scaling factor is [0.9, 1).

5. The method according to any one of claims 1 to 4, characterized in that: The first electronic device determines whether the first gradient of the i-th dimension is an expired gradient based on the t-th parameter trend of the i-th dimension, including: When the sign function value of the t-th parameter trend of the i-th dimension is not equal to the sign function value of the first gradient of the i-th dimension, the first electronic device determines that the first gradient of the i-th dimension is not an expired gradient; When the sign function value of the t-th parameter trend in the i-th dimension is equal to the sign function value of the first gradient in the i-th dimension, the first electronic device determines that the first gradient in the i-th dimension is an expired gradient.

6. The method according to claim 1, characterized in that The first electronic device calculates a second scaling factor, including: When the first gradient of the i-th dimension is not an expired gradient, the value of the second scaling factor is 1; When the first gradient of the i-th dimension is an expired gradient, the first electronic device obtains a first parameter trend and a second parameter trend from a t-th parameter trend of n dimensions, wherein the first parameter trend is a parameter trend with a maximum absolute value among the t-th parameter trends of the n dimensions, and the second parameter trend is a parameter trend with a minimum absolute value among the t-th parameter trends of the n dimensions; The second scaling factor is negatively correlated with the difference ratio, the difference ratio is the ratio between the third difference and the second difference, the second difference is the difference between the absolute value of the first parameter trend and the absolute value of the second parameter trend, and the third difference is the difference between the absolute value of the tth parameter trend of the i-th dimension and the absolute value of the second parameter trend.

7. The method according to claim 6, characterized in that The second scaling factor satisfies the following formula: in, is the second scaling factor, is the ratio of the second difference to the first difference.

8. The method according to claim 7, characterized in that After the first electronic device updates the first gradient of the i-th dimension based on the scaling factor to obtain the second gradient of the i-th dimension, the method further includes: The first electronic device obtains a t+1th parameter of the i-th dimension based on the t-th parameter of the i-th dimension and the second gradient of the i-th dimension; The first electronic device transmits the t+1th parameter of the i-th dimension to the m second electronic devices.

9. An electronic device, characterized in that: include: Processor and memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the electronic device performs the method according to any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

11. A computer program product, characterized in that The method comprises a computer program, which, when being executed, enables a computer to execute the method according to any one of claims 1 to 8.