Federated model training method and device, storage medium, and electronic device
By exchanging only the model parameters during the training process of the federated model and optimizing the model parameters using the quasi-Newtonian matrix, the problem of low training efficiency of federated model in the existing technology is solved, and more efficient and stable model training is achieved.
Patent Information
- Application Number
- CN202210365333.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2042-04-07
AI Technical Summary
The training efficiency of existing federated models is low, mainly due to the high communication load on the server and client.
By exchanging only model parameters between the server and terminal device, instead of the model itself, and optimizing model parameters in combination with the quasi-Newtonian matrix, the communication load and computational complexity are reduced.
This improves the training efficiency of the federated model, avoids the problem of instability in training results caused by instability in model parameters, and improves the accuracy of the model.
Smart Images

Figure CN114707660B_ABST
Abstract
Description
Background Art
[0002] Federated learning can complete the training of machine learning models based on decentralized storage data while protecting user privacy.
[0003] In the existing federated model training tasks, the client needs to send the local model to the server; then the server aggregates the model based on the models received from all the clients, and finally sends the aggregated model to the client; the above process is repeated until the model converges or the maximum number of iterations is reached.
[0004] However, due to the large amount of data in the federated model itself, there is a high communication load between the server and the client, resulting in low training efficiency of the federated model.
[0005] Therefore, it is necessary to provide a new training method and device for the federated model.
[0006] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0007] The purpose of the present disclosure is to provide a training method for a federated model, a training device for a federated model, a computer-readable storage medium, and an electronic device, thereby at least to a certain extent overcoming the problem of low model training efficiency caused by the limitations and defects of related technologies.
[0008] According to one aspect of the present disclosure, a method for training a federated model is provided, which is configured on a server side. The method for training a federated model includes:
[0009] Initializing a federated model to be trained set on the server side, obtaining first model parameters, and sending the first model parameters to the terminal device;
[0010] Receiving second original model parameters sent by a terminal device, which are obtained by iteratively training a federated model to be trained set at a terminal device end using the first model parameters, and calculating a first quasi-Newton matrix according to the second original model parameters;
[0011] Based on the first quasi-Newton matrix, first model parameters included in the federated model to be trained set on the server are optimized to obtain third model parameters;
[0012] The third model parameters are sent to the terminal device, so that the terminal device updates the second original model parameters included in the federated model to be trained set on the terminal device according to the third model parameters to obtain a trained federated model.
[0013] In an exemplary embodiment of the present disclosure, calculating a first quasi-Newton matrix according to the second primitive model parameters includes:
[0014] Aggregating the second original model parameters to obtain second target model parameters, and constructing a current global gradient according to the second original model parameters and the second target model parameters;
[0015] Constructing a first intermediate variable according to the current global gradient and a global gradient of a previous round corresponding to the current global gradient;
[0016] A second intermediate variable is constructed according to the second original model parameter and the original model parameter of the previous round corresponding to the second original model parameter, and the first quasi-Newton matrix is calculated according to the first intermediate variable and the second intermediate variable.
[0017] In an exemplary embodiment of the present disclosure, constructing a current global gradient according to the second original model parameters and the second target model parameters includes:
[0018] Calculating a first difference between a second original model parameter and a second target model parameter corresponding to each of the terminal devices to obtain a first loss function corresponding to each of the terminal devices;
[0019] Calculate the current local gradient of the terminal device according to the first loss function and a first learning rate of the federated model to be trained set at the terminal device;
[0020] The current global gradient is calculated according to the weight value of each terminal device and the current local gradient corresponding to each terminal device.
[0021] In an exemplary embodiment of the present disclosure, the first model parameters included in the federated model to be trained set on the server are optimized based on the first quasi-Newton matrix to obtain third model parameters, including:
[0022] Calculating a first ratio between a second learning rate of the federated model to be trained set on the server side and a first learning rate of the federated model to be trained set on the terminal device side;
[0023] The third model parameter is calculated based on the first ratio, the first difference between the second original model parameter and the second target model parameter, and the first quasi-Newton matrix.
[0024] In an exemplary embodiment of the present disclosure, the federated model to be trained includes one or more of a logistic regression model, a decision tree model, a convolutional neural network model, and a recurrent neural network model.
[0025] According to one aspect of the present disclosure, a method for training a federated model is provided, which is configured on a terminal device, and the method for training the federated model includes:
[0026] Receiving a first model parameter sent by the server; wherein the first model parameter is obtained by the server initializing a federated model to be trained set on the server;
[0027] Iteratively training a federated model to be trained set on a terminal device using the first model parameters to obtain second original model parameters, and sending the second original model parameters to a server, so that the server calculates a first quasi-Newton matrix according to the second original model parameters;
[0028] Receive third model parameters sent by the server end, which are obtained by optimizing the first model parameters included in the federated model to be trained set on the server end using the first quasi-Newton matrix, and use the third model parameters to update the second original model parameters to obtain a trained federated model.
[0029] In an exemplary embodiment of the present disclosure, the first model parameters are used to iteratively train the federated model to be trained set on the terminal device to obtain the second original model parameters, including:
[0030] Using the first model parameter, updating a first current parameter included in a federated model to be trained set on a terminal device, and inputting local data included in the terminal device into the federated model to be trained after the parameter update, to obtain a first data prediction result;
[0031] Constructing a second loss function according to the first data prediction result and the first annotation result of the local data;
[0032] The federated model to be trained after the parameter update is iteratively trained based on the second loss function to obtain the second original model parameters.
[0033] According to one aspect of the present disclosure, a training device for a federated model is provided, which is configured on a server side, and the training device for the federated model includes:
[0034] A first initialization module, used to initialize the federated model to be trained set on the server side, obtain first model parameters, and send the first model parameters to the terminal device;
[0035] A first quasi-Newton matrix calculation module is used to receive second original model parameters sent by a terminal device, which are obtained by iteratively training a federated model to be trained set at a terminal device end using the first model parameters, and calculate a first quasi-Newton matrix according to the second original model parameters;
[0036] a third model parameter calculation module, configured to optimize the first model parameters included in the federated model to be trained and set on the server side based on the first quasi-Newton matrix to obtain third model parameters;
[0037] The model training module is used to send the third model parameters to the terminal device so that the terminal device updates the second original model parameters included in the federal model to be trained set on the terminal device according to the third model parameters to obtain a trained federal model.
[0038] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the training method of the federated model described in any one of the above is implemented.
[0039] According to one aspect of the present disclosure, there is provided an electronic device, including:
[0040] Processor; and
[0041] A memory, configured to store executable instructions of the processor;
[0042] Wherein, the processor is configured to execute any one of the above-mentioned federated model training methods by executing the executable instructions.
[0043] The present disclosure provides a method for training a federated model. On the one hand, during the training of the federated model, the server and the terminal device only need to exchange model parameters without transferring the model itself, thereby avoiding the problem of low training efficiency of the federated model due to high communication load between the server and the client in the prior art, thereby improving the training efficiency of the federated model. On the other hand, during the calculation of the first model parameter, the first quasi-Newton matrix is calculated based on the second original model parameter; and then the first model parameter included in the federated model to be trained set on the server is optimized based on the first quasi-Newton matrix. The result is not calculated directly based on the second original model parameter, thereby avoiding the problem that the third model parameter is unstable due to different customer data of each client, thereby improving the accuracy of the third model parameter, thereby improving the accuracy of the trained federated model.
[0044] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0046] Figure 1 A flowchart of a method for training a federated model configured on a server side according to an exemplary embodiment of the present disclosure is schematically shown.
[0047] Figure 2 A block diagram of a federated model training system according to an example embodiment of the present disclosure is schematically shown.
[0048] Figure 3 A flowchart of a method for calculating a first quasi-Newton matrix according to the second primitive model parameters according to an exemplary embodiment of the present disclosure is schematically shown.
[0049] Figure 4 A flowchart of a method for training a federated model configured on a terminal device according to an example embodiment of the present disclosure is schematically shown.
[0050] Figure 5 A flowchart of a training method for a federated model based on interaction between a server and a terminal device according to an exemplary embodiment of the present disclosure is schematically shown.
[0051] Figure 6 A scenario example diagram schematically illustrates a method for training a federated model based on interaction between a server and a terminal device according to an example embodiment of the present disclosure.
[0052] Figure 7 A block diagram of a training device for a federated model configured on a server side according to an exemplary embodiment of the present disclosure is schematically shown.
[0053] Figure 8 A block diagram schematically shows a training apparatus for a federated model configured on a terminal device according to an exemplary embodiment of the present disclosure.
[0054] Fig. 9 An electronic device for implementing the training method of the above-mentioned federated model according to an exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0055] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0056] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0057] In the current research and practice of federated learning, it can be implemented in the following ways: the federated average algorithm, and a series of methods improved on the basis of the federated average algorithm, which mainly solve the heterogeneity of data sources in real scenarios and reduce the communication load between the client and the server. In this series of methods, there is usually a server and multiple clients; the server can be used to provide computing power and network communication services, and the server can establish a network connection with all clients, which requires high system stability; the client provides raw data, part of the computing power and network communication services, and the client usually only communicates with the server. In the specific process of training the federated model, all clients update the model locally based on the initialized global model and local data, and then send the local model to the server; the server aggregates the model based on all the received models, and then sends the aggregated model to the client - repeating the process until the model converges or reaches the maximum number of iterations. However, due to the large amount of data in the federated model itself, there is still a problem of communication load.
[0058] In addition, in the process of training the federated model, it is necessary to separately build the global model and the local model, optimize the loss function of the local model, and optimize the aggregation method of the global model to train the federated model; for example, the federated average algorithm simply averages all local models without considering the tendency of each local model; in FedNL, the federated modeling method optimized by the Newton method requires the calculation of the second-order derivative of the loss function on the client, as well as frequent communication with the server, which places higher requirements on the client's computing power and network communication capabilities.
[0059] Based on this, this exemplary embodiment first provides a method for training a federated model, which can be run on a server, server cluster, or cloud server, etc. Of course, those skilled in the art can also run the method disclosed in this disclosure on other platforms as required, and this exemplary embodiment does not specifically limit this. Figure 1 As shown, the training method of the federated model may include the following steps:
[0060] Step S110: Initialize the federated model to be trained set on the server side, obtain first model parameters, and send the first model parameters to the terminal device;
[0061] Step S120. Receive second original model parameters sent by the terminal device, which are obtained by iteratively training the federated model to be trained set at the terminal device using the first model parameters, and calculate a first quasi-Newton matrix according to the second original model parameters;
[0062] Step S130. Optimize the first model parameters included in the federated model to be trained set on the server side based on the first quasi-Newton matrix to obtain third model parameters;
[0063] Step S140. Send the third model parameters to the terminal device, so that the terminal device updates the second original model parameters included in the federated model to be trained set on the terminal device according to the third model parameters to obtain a trained federated model.
[0064] In the above-mentioned federal model training method, on the one hand, since during the training process of the federal model, the server side and the terminal device side only need to exchange model parameters, and there is no need to transfer the model itself, thereby avoiding the problem of low training efficiency of the federal model due to the high communication load between the server and the client in the prior art, and improving the training efficiency of the federal model; on the other hand, since in the process of calculating the first model parameters, the first quasi-Newton matrix is calculated based on the second original model parameters; and then based on the first quasi-Newton matrix, the first model parameters included in the federal model to be trained set on the server side are optimized, and the obtained result is not directly calculated based on the second original model parameters, thereby avoiding the problem that the client data of each client is different, which makes the third model parameters unstable and leads to the instability of the trained federal model, thereby improving the accuracy of the third model parameters, and thus improving the accuracy of the trained federal model.
[0065] Hereinafter, the training method of the federated model of the exemplary embodiment of the present disclosure will be explained and illustrated in detail with reference to the accompanying drawings.
[0066] First, the training system of the federated model of the exemplary embodiment of the present disclosure is explained and illustrated. Figure 2 As shown, the training system of the federal model may include a terminal device 210 and a server 220, and the terminal device may be connected to the server through a wired or wireless network. In addition, the terminal device may include multiple devices, such as a first terminal device, a second terminal device, ..., an Nth terminal device, etc. In the actual application process, the number of corresponding terminal devices can be set as needed, and this example does not impose any special restrictions on this. Among them, the terminal device is used to train the federal model to be trained set locally according to the model parameters sent by the server and the local data set to obtain the corresponding model parameters; the server is used to calculate the quasi-Newton matrix according to the model parameters sent by the terminal device, and calculate the updated model parameters based on the quasi-Newton matrix, so that the terminal device can train the federal model to be trained set locally according to the updated model parameters, and then obtain the trained federal model. It should be noted here that, in the traditional method, the updated model parameters are calculated by the Hessian Matrix (also known as the Hessian Matrix, the Hessian Matrix, the Hessian Matrix, etc.); however, compared with the quasi-Newton matrix, the calculation difficulty and complexity of the Hessian Matrix are higher, which will bring huge computing pressure to the server; therefore, the example embodiment of the present disclosure uses the quasi-Newton matrix to replace the Hessian matrix, thereby reducing the computational amount of the server while ensuring accuracy, thereby achieving the purpose of improving the training efficiency of the federated model.
[0067] Secondly, in a training method of a federated model provided in an exemplary embodiment of the present disclosure:
[0068] In step S110, the federated model to be trained set on the server side is initialized to obtain first model parameters, and the first model parameters are sent to the terminal device.
[0069] Specifically, when it is necessary to jointly optimize a certain federal model to be trained, the federal model to be trained set on the server side can be initialized to obtain the initialization model parameters included in the federal model to be trained, that is, the first model parameter X0, and then the first model parameter is sent to each terminal device; wherein each terminal device is also provided with a federal model to be trained, and the federal model to be trained set on the server side and the federal model to be trained set on the terminal device side have the same model depth; and the federal model to be trained can include a logistic regression (LR) model, a decision tree (Decision Tree) model, a convolutional neural network (CNN) model, a recurrent neural network (RNN) model, etc., and of course, it can also include other types of network models, and this example does not impose any special restrictions on this.
[0070] In step S120, second original model parameters obtained by iteratively training the federated model to be trained set at the terminal device end using the first model parameters are received from the terminal device, and a first quasi-Newton matrix is calculated based on the second original model parameters.
[0071] In this example embodiment, first, the second original model parameters are obtained by iteratively connecting the federated model to be trained set on the terminal device side using the first model parameters sent by the terminal device. Specifically, the second original model parameters are obtained in the following manner: after the terminal device receives the first model parameters sent by the server side, the parameters of the federated model to be trained set locally can be updated based on the first model parameters and the local data set to obtain the above second original model parameters.
[0072] Secondly, after receiving the second original model parameters, the first quasi-Newton matrix can be calculated according to the second original model parameters. Figure 3 As shown, the specific calculation method of the first quasi-Newton matrix may include the following steps:
[0073] Step S310, aggregating the second original model parameters to obtain second target model parameters, and constructing a current global gradient according to the second original model parameters and the second target model parameters.
[0074] In this example embodiment, first, the second original model parameters are aggregated to obtain second target model parameters; specifically, in the process of aggregating the second original model parameters, average aggregation can be used for aggregation, or weighted aggregation can be used for aggregation, and this example does not impose any special restrictions on this; wherein, when weighted aggregation is used for aggregation, the second target model parameters can be calculated based on the weight of the federal model to be trained set on each terminal device and the second original model parameters sent by the terminal device; wherein, the weight of the federal model to be trained on the terminal device can be determined based on the weight of the local data set of the terminal device in the total data set required for the entire federal model to be trained, and of course other methods can also be used for determination, and this example does not impose any special restrictions on this.
[0075] Secondly, after obtaining the second target model parameters, the current global gradient can be constructed according to the second original model parameters and the second target model parameters. Specifically, the current global gradient can be obtained in the following manner: first, the first difference between the second original model parameters and the second target model parameters corresponding to each of the terminal devices is calculated to obtain the first loss function corresponding to each of the terminal devices; secondly, the current local gradient of the terminal device is calculated according to the first loss function and the first learning rate of the federated model to be trained set at the terminal device; finally, the current global gradient is calculated according to the weight value of each of the terminal devices and the current local gradient corresponding to each of the terminal devices.
[0076] Specifically, the second original model parameters corresponding to each terminal device can be obtained by Indicates that the first loss function corresponding to each terminal device may be, for example: Among them, k is the second target model parameter, and the current local gradient of each terminal device is: in, is the first learning rate of the federated model to be trained set on each terminal device. The first learning rate can be the same or different. This example does not impose any special restrictions on this. Furthermore, the current global gradient It can be expressed as the following formula (1):
[0077]
[0078] Among them, w iis the weight value of each terminal device, which can be the same or different, and N represents the number of terminal devices. It should be noted that when the first learning rates and weight values are the same, the above formula (1) can also be written as the following formula (2):
[0079]
[0080] It should be noted here that the example embodiment of the present disclosure calculates the current global gradient through the learning rate and the first loss function, rather than using the first-order derivative or the second-order derivative to calculate the global gradient. This can greatly reduce the amount of calculation of the global gradient, thereby reducing the computing burden of the server, and thereby improving the training efficiency of the federated model to be trained.
[0081] Step S320: construct a first intermediate variable according to the current global gradient and the global gradient of the previous round corresponding to the current global gradient.
[0082] Specifically, order: The first intermediate variable obtained can be expressed as follows:
[0083] y k-1 =g(X k )-g(X k-1 ); Formula (3)
[0084] Among them, y k-1 is the first intermediate variable, g(X k ) in which g stands for gradient (slope or inclination). f in the formula represents the gradient vector; g(X k ) is the current global gradient, g(X k-1 ) is the global gradient of the previous round corresponding to the current global gradient, k represents the kth round, and k-1 represents the round before the kth round.
[0085] Step S330, constructing a second intermediate variable according to the second original model parameter and the original model parameter of the previous round corresponding to the second original model parameter, and calculating the first quasi-Newton matrix according to the first intermediate variable and the second intermediate variable.
[0086] Specifically, the second intermediate variable can be expressed as follows:
[0087] S k-1 =X k -X k-1 ; Formula (4)
[0088] Among them, S k-1 is the second intermediate variable, X kis the second original model parameter, that is, the original model parameter of the current round, X k-1 It is the original model parameter of the previous round. It should be noted here that, since there may be multiple terminal devices, in the process of calculating the second intermediate variable, the original model parameters of the current round of each terminal device and the original model parameters of the previous round can be respectively subjected to difference calculation, and finally the obtained difference calculations are added together to obtain the above-mentioned second intermediate variable.
[0089] Furthermore, after obtaining the second intermediate variable, the first quasi-Newton matrix can be calculated according to the first intermediate variable and the second intermediate variable. The first quasi-Newton matrix can be specifically shown in the following formula (5):
[0090]
[0091] Among them, B k is the first quasi-Newton matrix of the kth round, B k-1 is the first quasi-Newton matrix of the k-1th round.
[0092] In step S130, first model parameters included in the federated model to be trained set on the server side are optimized based on the first quasi-Newton matrix to obtain third model parameters.
[0093] In this example embodiment, first, a first ratio between a second learning rate of the federated model to be trained set on the server side and a first learning rate of the federated model to be trained set on the terminal device side is calculated; secondly, based on the first ratio, a first difference between the second original model parameters and the second target model parameters, and a first quasi-Newton matrix, the third model parameters are calculated.
[0094] Specifically, the specific calculation formula of the third model parameter can be shown as the following formula (6):
[0095]
[0096] Among them, X k+1 are the third model parameters, and the parameters of the k+1th round corresponding to the kth round, I is the unit matrix, η k The second learning rate, α k,τ is the first learning rate, and τ represents the frequency of local updates, that is, the frequency of updates at each terminal device.
[0097] In step S140, the third model parameters are sent to the terminal device, so that the terminal device updates the second original model parameters included in the federated model to be trained set on the terminal device according to the third model parameters to obtain a trained federated model.
[0098] Specifically, after obtaining the third model parameter, the third model parameter can be sent to each terminal device, so that each terminal device can update the second original model parameter included in the model to be trained set at the terminal device end according to the third model parameter, thereby obtaining a trained federated model. It should be noted here that before obtaining the trained federated model, it is also necessary to determine whether the federated model has converged or whether the maximum number of iterations has been reached; if any of the conditions is met, the training is stopped; if none of the conditions is met, steps S120-S140 are repeated until any of the above conditions is met.
[0099] The following explains why the first quasi-Newton matrix can be used instead of the Hessian matrix. Specifically, first, construct the objective function at the current X k The quadratic model of:
[0100]
[0101] From formula (7), we can get:
[0102] Secondly, in the k+1th round, we can use the model obtained by each client The weighted average is used to obtain the global model: The global gradient can then be approximated:
[0103]
[0104] The Substituting into the calculation, we get:
[0105] Furthermore, according to the BFGS method, we can get: k ≈B k ;
[0106] So we have:
[0107] Based on this, it can be known that the Hessian matrix can be replaced by the first quasi-Newton matrix. At the same time, since the Hessian matrix is the second-order derivative of the loss function, it can be specifically expressed as follows:
[0108]
[0109] in, That is, the Hessian matrix, which is too difficult to calculate, greatly aggravates the computing burden of the server, and also requires a lot of time to calculate; by using the first quasi-Newton matrix instead of the Hessian matrix, since there is no need to calculate the second-order derivative, the calculation amount of the server can be greatly reduced, and the calculation time can be saved, which can further improve the training efficiency of the model; at the same time, since the first quasi-Newton matrix can be equivalent to the Hessian matrix, the accuracy of the third model parameters obtained in the end can be ensured while reducing the calculation amount, thereby ensuring the accuracy of the federated model to be trained.
[0110] This exemplary embodiment also provides a training method for a federated model configured on a terminal device. Figure 4 As shown, the training method of the federated model may include the following steps:
[0111] Step S410, receiving a first model parameter sent by the server; wherein the first model parameter is obtained by the server initializing a federated model to be trained set on the server.
[0112] Specifically, a first model parameter X0 sent by the server can be received, where the first model parameter X0 is obtained by the server by initializing the federated model to be trained set locally; wherein the federated model to be trained set on each terminal device has the same model depth as the federated model to be trained set on the server.
[0113] Step S420, using the first model parameters to iteratively train the federated model to be trained set on the terminal device end, obtain second original model parameters, and send the second original model parameters to the server end, so that the server end calculates the first quasi-Newton matrix according to the second original model parameters.
[0114] In this example embodiment, first, the first model parameters are used to iteratively train the federated model to be trained on the terminal device to obtain the second original model parameters. Specifically, this can be achieved in the following manner: first, the first current parameters included in the federated model to be trained on the terminal device are updated using the first model parameters, and the local data included in the terminal device is input into the federated model to be trained after the parameter update to obtain the first data prediction result; secondly, a second loss function is constructed according to the first data prediction result and the first annotation result of the local data; further, the federated model to be trained after the parameter update is iteratively trained based on the second loss function to obtain the second original model parameters. Among them, the second loss function can be determined according to the model category described in the federated model to be trained, and this example does not impose any special restrictions on this.
[0115] Step S430, receiving the third model parameters sent by the server end, which are obtained by optimizing the first model parameters included in the federated model to be trained set on the server end using the first quasi-Newton matrix, and using the third model parameters to update the second original model parameters to obtain a trained federated model.
[0116] exist Figure 4 In the training method of the federated model shown, on the one hand, during the training process of the federated model, the server and the terminal device only need to exchange model parameters without transferring the model itself, thereby avoiding the problem of low training efficiency of the federated model due to high communication load between the server and the client in the prior art, thereby improving the training efficiency of the federated model; on the other hand, during the calculation of the first model parameters, the first quasi-Newton matrix is calculated based on the second original model parameters; and then the first model parameters included in the federated model to be trained set on the server are optimized based on the first quasi-Newton matrix, and the obtained result is not calculated directly based on the second original model parameters, thereby avoiding the problem that the client data of each client is different, which makes the third model parameters unstable and leads to instability of the trained federated model, thereby improving the accuracy of the third model parameters, and thus improving the accuracy of the trained federated model.
[0117] The following, combined Figure 5 as well as Figure 6 The training method of the federated model involved in the exemplary embodiment of the present disclosure is further explained and illustrated. Figure 5 As shown, the training method of the federated model may include the following steps:
[0118] Step S501, the server initializes the federated model (601) to be trained to obtain a first model parameter;
[0119] Step S502, the server sends the first model parameter to each client;
[0120] Step S503, the terminal device trains the federated model (602) to be trained locally according to the first model parameters and the locally set data set using a gradient descent method to obtain second original model parameters;
[0121] Step S504, the terminal device sends the second original model parameters to the server;
[0122] Step S505, the server calculates a first quasi-Newton matrix according to the second original model parameters, and calculates a third model parameter according to the first quasi-Newton matrix;
[0123] Step S506, the server sends the third model parameter to the terminal device;
[0124] Step S507: The terminal device updates the second original model parameters according to the third model parameters to obtain a trained federated model.
[0125] Below, taking the federated model as an example of a user classification model, the specific application process of the trained federated model is explained and illustrated. Specifically, first, the first user feature of the user to be identified can be obtained; wherein, the first user feature can be the user portrait feature of the historical user and the relevant behavioral features of the historical user; specifically, the user portrait feature is some features abstracted from the user's demographic characteristics, web browsing content, consumption content, social activities and other information, including but not limited to: gender, age, education, price sensitivity, geographic location, occupation, family structure; related behavioral characteristics include but are not limited to: browsing, adding to shopping carts, clicking, purchasing and other behaviors (may be sequences or statistical times) under the target brand or category (such as brand: Apple, category: mobile phone), etc. Then, the first user feature can be input into the trained federated model to obtain the predicted score of the historical user. ; Among them, the trained federal model can be a logistic regression model, a deep neural network learning model (CNN or RNN) or a supervised machine learning model, etc.; secondly, after obtaining the prediction score, the user can be classified according to the prediction score.
[0126] The following explains and illustrates the specific application process of the federated model in the medical scenario. Specifically, first, the user portrait features and medical data features of the patient to be classified can be obtained; wherein, the user portrait features may include the patient's attribute information (for example, name, gender, age, occupation, travel trajectory, etc.), and the medical data features may include the patient's electronic medical record information, medication information, imaging information, etc.; then, the user portrait features and medical data features can be input into the trained federated model to obtain the prediction results of the patient to be classified, and then the prediction results can be used to determine whether the patient to be classified is a confirmed patient, or which type of patient he belongs to, etc. It should be noted here that the above-mentioned trained federated model can also be used in various scenarios such as image recognition, feature extraction, and natural language processing, and this example does not impose any special restrictions on this.
[0127] The exemplary embodiment of the present disclosure also provides a training device for a federated model, which is configured on a server side. Figure 7 As shown, the training device of the federated model may include a first initialization module 710, a first quasi-Newton matrix calculation module 720, a third model parameter calculation module 730 and a model training module 740. Among them:
[0128] A first initialization module 710 may be used to initialize a federated model to be trained that is set on a server side, obtain first model parameters, and send the first model parameters to a terminal device;
[0129] The first quasi-Newton matrix calculation module 720 may be used to receive second original model parameters sent by the terminal device, obtained by iteratively training the federated model to be trained set at the terminal device using the first model parameters, and calculate the first quasi-Newton matrix according to the second original model parameters;
[0130] A third model parameter calculation module 730 may be used to optimize the first model parameters included in the federated model to be trained set on the server side based on the first quasi-Newton matrix to obtain third model parameters;
[0131] The model training module 740 can be used to send the third model parameters to the terminal device, so that the terminal device updates the second original model parameters included in the federal model to be trained set on the terminal device side according to the third model parameters to obtain a trained federal model.
[0132] In an exemplary embodiment of the present disclosure, calculating a first quasi-Newton matrix according to the second primitive model parameters includes:
[0133] Aggregating the second original model parameters to obtain second target model parameters, and constructing a current global gradient according to the second original model parameters and the second target model parameters;
[0134] Constructing a first intermediate variable according to the current global gradient and a global gradient of a previous round corresponding to the current global gradient;
[0135] A second intermediate variable is constructed according to the second original model parameter and the original model parameter of the previous round corresponding to the second original model parameter, and the first quasi-Newton matrix is calculated according to the first intermediate variable and the second intermediate variable.
[0136] In an exemplary embodiment of the present disclosure, constructing a current global gradient according to the second original model parameters and the second target model parameters includes:
[0137] Calculating a first difference between a second original model parameter and a second target model parameter corresponding to each of the terminal devices to obtain a first loss function corresponding to each of the terminal devices;
[0138] Calculate the current local gradient of the terminal device according to the first loss function and a first learning rate of the federated model to be trained set at the terminal device;
[0139] The current global gradient is calculated according to the weight value of each terminal device and the current local gradient corresponding to each terminal device.
[0140] In an exemplary embodiment of the present disclosure, the first model parameters included in the federated model to be trained set on the server are optimized based on the first quasi-Newton matrix to obtain third model parameters, including:
[0141] Calculating a first ratio between a second learning rate of the federated model to be trained set on the server side and a first learning rate of the federated model to be trained set on the terminal device side;
[0142] The third model parameter is calculated based on the first ratio, the first difference between the second original model parameter and the second target model parameter, and the first quasi-Newton matrix.
[0143] In an exemplary embodiment of the present disclosure, the federated model to be trained includes one or more of a logistic regression model, a decision tree model, a convolutional neural network model, and a recurrent neural network model.
[0144] The exemplary embodiment of the present disclosure also provides another training device for a federated model, which is configured on a terminal device. Figure 8 As shown, the training device of the federated model may include a first model parameter receiving module 810, a second original model parameter calculating module 820, and a second original model parameter updating module 830. Among them:
[0145] The first model parameter receiving module 810 may be used to receive the first model parameter sent by the server; wherein the first model parameter is obtained by the server initializing the federated model to be trained set on the server;
[0146] The second original model parameter calculation module 820 can be used to iteratively train the federated model to be trained set on the terminal device side using the first model parameters to obtain second original model parameters, and send the second original model parameters to the server side, so that the server side calculates the first quasi-Newton matrix according to the second original model parameters;
[0147] The second original model parameter updating module 830 can be used to receive the third model parameters sent by the server end, which are obtained by optimizing the first model parameters included in the federated model to be trained set on the server end using the first quasi-Newton matrix, and use the third model parameters to update the second original model parameters to obtain a trained federated model.
[0148] In an exemplary embodiment of the present disclosure, the first model parameters are used to iteratively train the federated model to be trained set on the terminal device to obtain the second original model parameters, including:
[0149] Using the first model parameter, updating a first current parameter included in a federated model to be trained set on a terminal device, and inputting local data included in the terminal device into the federated model to be trained after the parameter update, to obtain a first data prediction result;
[0150] Constructing a second loss function according to the first data prediction result and the first annotation result of the local data;
[0151] The federated model to be trained after the parameter update is iteratively trained based on the second loss function to obtain the second original model parameters.
[0152] The specific details of each module in the above-mentioned federal model training device have been described in detail in the corresponding federal model training method, so they will not be repeated here.
[0153] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0154] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0155] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0156] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware implementation, complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0157] Refer to the following Fig. 9The electronic device 900 according to this embodiment of the present disclosure is described. Fig. 9 The electronic device 900 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0158] like Fig. 9 As shown, the electronic device 900 is in the form of a general computing device. The components of the electronic device 900 may include, but are not limited to: the at least one processing unit 910, the at least one storage unit 920, a bus 930 connecting different system components (including the storage unit 920 and the processing unit 910), and a display unit 940.
[0159] The storage unit stores a program code, which can be executed by the processing unit 910, so that the processing unit 910 performs the steps according to various exemplary embodiments of the present disclosure described in the above “Exemplary Method” section of this specification. For example, the processing unit 910 can perform the following steps: Figure 1 Step S110 shown in: initialize the federated model to be trained set on the server side, obtain first model parameters, and send the first model parameters to the terminal device; step S120: receive the second original model parameters sent by the terminal device after iteratively training the federated model to be trained set on the terminal device side using the first model parameters, and calculate the first quasi-Newton matrix according to the second original model parameters; step S130: optimize the first model parameters included in the federated model to be trained set on the server side based on the first quasi-Newton matrix to obtain third model parameters; step S140: send the third model parameters to the terminal device, so that the terminal device updates the second original model parameters included in the federated model to be trained set on the terminal device side according to the third model parameters to obtain a trained federal model.
[0160] For another example, the processing unit 910 may execute the following Figure 4The step S410 shown in the figure is: receiving the first model parameters sent by the server; wherein the first model parameters are obtained by the server initializing the federated model to be trained set on the server; step S420: using the first model parameters to iteratively train the federated model to be trained set on the terminal device to obtain second original model parameters, and sending the second original model parameters to the server, so that the server calculates the first quasi-Newton matrix according to the second original model parameters; step S430: receiving the third model parameters sent by the server, which are obtained by optimizing the first model parameters included in the federated model to be trained set on the server using the first quasi-Newton matrix, and using the third model parameters to update the second original model parameters to obtain a trained federated model.
[0161] The storage unit 920 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 9201 and / or a cache storage unit 9202 , and may further include a read-only storage unit (ROM) 9203 .
[0162] The storage unit 920 may also include a program / utility 9204 having a set (at least one) of program modules 9205, such program modules 9205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0163] Bus 930 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0164] The electronic device 900 may also communicate with one or more external devices 1000 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 900, and / or communicate with any device that enables the electronic device 900 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 950. Furthermore, the electronic device 900 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 960. As shown, the network adapter 960 communicates with other modules of the electronic device 900 via a bus 930. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 900, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0165] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0166] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present disclosure may also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary implementations of the present disclosure described in the above "Exemplary Method" section of the present specification.
[0167] According to the program product for implementing the above method in the embodiment of the present disclosure, it can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0168] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0169] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0170] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0171] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0172] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0173] Other embodiments of the present disclosure will be readily apparent to those skilled in the art after considering the specification and practicing the inventions invented herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not invented by the present disclosure. The specification and examples are to be considered merely exemplary, and the true scope and spirit of the present disclosure are indicated by the claims.
Claims
1. A method for training a federated model, characterized in that: Configured on the server side, the training method of the federated model includes: Initializing a federated model to be trained set on the server side, obtaining first model parameters, and sending the first model parameters to the terminal device; The receiving terminal device sends a second original model parameter obtained by iteratively training the federated model to be trained set at the terminal device end using the first model parameter, and calculates the first quasi-Newton matrix according to the second original model parameter, including: aggregating the second original model parameter to obtain the second target model parameter, and calculating the first difference between the second original model parameter and the second target model parameter corresponding to each of the terminal devices to obtain the first loss function corresponding to each of the terminal devices; calculating the current local gradient of the terminal device according to the first loss function and the first learning rate of the federated model to be trained set at the terminal device end; calculating the current global gradient according to the weight value of each of the terminal devices and the current local gradient corresponding to each of the terminal devices; constructing a first intermediate variable according to the current global gradient and the global gradient of the previous round corresponding to the current global gradient; constructing a second intermediate variable according to the second original model parameter and the original model parameter of the previous round corresponding to the second original model parameter, and calculating the first quasi-Newton matrix according to the first intermediate variable and the second intermediate variable; Based on the first quasi-Newton matrix, first model parameters included in the federated model to be trained set on the server are optimized to obtain third model parameters; The third model parameters are sent to the terminal device, so that the terminal device updates the second original model parameters included in the federated model to be trained set on the terminal device according to the third model parameters to obtain a trained federated model.
2. The method for training a federated model according to claim 1, characterized in that: The first model parameters included in the federated model to be trained set on the server are optimized based on the first quasi-Newton matrix to obtain third model parameters, including: Calculating a first ratio between a second learning rate of the federated model to be trained set on the server side and a first learning rate of the federated model to be trained set on the terminal device side; The third model parameter is calculated based on the first ratio, the first difference between the second original model parameter and the second target model parameter, and the first quasi-Newton matrix.
3. The method for training a federated model according to claim 1 or 2, characterized in that: The federal model to be trained includes one or more of a logistic regression model, a decision tree model, a convolutional neural network model, and a recurrent neural network model.
4. A method for training a federated model, characterized in that: Configured on the terminal device side, the training method of the federated model includes: Receiving a first model parameter sent by the server; wherein the first model parameter is obtained by the server initializing a federated model to be trained set on the server; Iteratively train the federated model to be trained set at the terminal device end using the first model parameters to obtain second original model parameters, and send the second original model parameters to the server end, so that the server end calculates a first quasi-Newton matrix according to the second original model parameters; wherein the first quasi-Newton matrix is obtained in the following manner: aggregating the second original model parameters to obtain second target model parameters, and calculating the first difference between the second original model parameters and the second target model parameters corresponding to each of the terminal devices to obtain a first loss function corresponding to each of the terminal devices; calculating the current local gradient of the terminal device according to the first loss function and the first learning rate of the federated model to be trained set at the terminal device end; calculating the current global gradient according to the weight value of each of the terminal devices and the current local gradient corresponding to each of the terminal devices; constructing a first intermediate variable according to the current global gradient and the global gradient of the previous round corresponding to the current global gradient; constructing a second intermediate variable according to the second original model parameters and the original model parameters of the previous round corresponding to the second original model parameters, and calculating the first quasi-Newton matrix according to the first intermediate variable and the second intermediate variable; Receive third model parameters sent by the server end, which are obtained by optimizing the first model parameters included in the federated model to be trained set on the server end using the first quasi-Newton matrix, and use the third model parameters to update the second original model parameters to obtain a trained federated model.
5. The method for training a federated model according to claim 4, characterized in that: Iteratively training the federated model to be trained set on the terminal device using the first model parameters to obtain second original model parameters, including: Using the first model parameter, updating a first current parameter included in a federated model to be trained set on a terminal device, and inputting local data included in the terminal device into the federated model to be trained after the parameter update, to obtain a first data prediction result; Constructing a second loss function according to the first data prediction result and the first annotation result of the local data; The federated model to be trained after the parameter update is iteratively trained based on the second loss function to obtain the second original model parameters.
6. A training device for a federated model, characterized in that: Configured on the server side, the training device of the federated model includes: A first initialization module, used to initialize the federated model to be trained set on the server side, obtain first model parameters, and send the first model parameters to the terminal device; The first quasi-Newton matrix calculation module is used to receive the second original model parameters sent by the terminal device, which are obtained by iteratively training the federated model to be trained set at the terminal device end using the first model parameters, and calculate the first quasi-Newton matrix according to the second original model parameters, including: aggregating the second original model parameters to obtain the second target model parameters, and calculating the first difference between the second original model parameters and the second target model parameters corresponding to each of the terminal devices to obtain the first loss function corresponding to each of the terminal devices; calculating the current local gradient of the terminal device according to the first loss function and the first learning rate of the federated model to be trained set at the terminal device end; calculating the current global gradient according to the weight value of each of the terminal devices and the current local gradient corresponding to each of the terminal devices; constructing a first intermediate variable according to the current global gradient and the global gradient of the previous round corresponding to the current global gradient; constructing a second intermediate variable according to the second original model parameters and the original model parameters of the previous round corresponding to the second original model parameters, and calculating the first quasi-Newton matrix according to the first intermediate variable and the second intermediate variable; a third model parameter calculation module, configured to optimize the first model parameters included in the federated model to be trained and set on the server side based on the first quasi-Newton matrix to obtain third model parameters; The model training module is used to send the third model parameters to the terminal device so that the terminal device updates the second original model parameters included in the federal model to be trained set on the terminal device according to the third model parameters to obtain a trained federal model.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the training method of the federated model described in any one of claims 1 to 5 is implemented.
8. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; Wherein, the processor is configured to execute the training method of the federated model described in any one of claims 1-5 by executing the executable instructions.
Citation Information
Patent Citations
Federal learning-based model training method and device, and federal learning system
CN112862011A
Federal model training method and device, electronic equipment and storage medium
CN113011602A