Model Training Method and Device Based on Federated Machine Learning
Through the encrypted transmission and homomorphic encryption processing of client gradients in federated machine learning, the problem of easy leakage of gradient information is solved, and safe and efficient model training is achieved, which is suitable for multi-client environments.
Patent Information
- Application Number
- CN202211369556.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-03
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2042-11-03
AI Technical Summary
In federated machine learning, the gradient information of the client is easily recovered by the attacker, resulting in private data leakage and poor security.
The client encrypts the gradient and sends it, uses homomorphic encryption to encrypt the submask when secret sharing, and forwards it through the cloud server or third-party server as intermediate. The mask difference is calculated to ensure the encryption effect, and uses homomorphic encryption key pairs to perform secure transmission.
Improves the security of model training, prevents the leakage of gradient original text, protects client privacy, and is suitable for scenarios where a large number of clients participate.
Smart Images

Figure CN115883053B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to computer technologies, and in particular, to a model training method and apparatus based on federated machine learning. Background Art
[0002] Federated machine learning is a distributed machine learning framework with privacy protection effects, which can effectively help multiple clients perform data usage and machine learning modeling while meeting the requirements of privacy protection, data security, and government regulations. As a distributed machine learning paradigm, federated machine learning can effectively solve the data silo problem, enabling each client to jointly model without sharing its local data, achieving intelligent collaboration and jointly training a globally optimal model.
[0003] When training a model based on federated machine learning, in each round of training, the central cloud server distributes the global model to each client. Each client uses its private local data to train the gradient of the model parameters, and then transmits the gradient obtained in this round of training to the cloud server. After the cloud server collects the gradients from all parties, it calculates the average gradient and uses this average gradient to update the global model on the cloud server side. In the next round of training, the updated global model is distributed to each client.
[0004] It can be seen that in the training of the global model based on federated machine learning, each client needs to send the gradient it has trained to the cloud server. However, in many attack scenarios, the gradient information sent by the client to the cloud server can be used to recover the original private data stored locally by the client, resulting in the leakage of private data, the inability to protect the privacy of users, and poor security. Summary of the Invention
[0005] One or more embodiments of this specification describe a model training method and apparatus based on federated machine learning, which can improve the security of model training.
[0006] According to a first aspect, there is provided a model training method based on federated machine learning. At least two clients and at least one cloud server participate in the model training based on federated machine learning. This method is applied to any first client among the at least two clients, and includes:
[0007] In each round of training, the first client receives the global model distributed by the cloud server;
[0008] The first client uses its local private data to train the gradient of the global model;
[0009] The first client encrypts the gradient obtained in this round of training, and then sends the encrypted gradient to the cloud server;
[0010] The first client performs the next round of training until the global model converges.
[0011] Wherein, the method further includes: the first client obtains a mask corresponding to the first client; wherein, the sum of all the masks corresponding to all the clients participating in the model training is less than a predetermined value;
[0012] The first client encrypts the gradient obtained in this round of training, including:
[0013] The first client adds the gradient obtained in this round of training to the mask corresponding to the first client to obtain the encrypted gradient.
[0014] Wherein, the sum of all the masks corresponding to all the clients is 0.
[0015] Wherein, the first client obtaining the mask corresponding to the first client includes:
[0016] The first client obtains each sub-mask s(u, v generated by the first client and corresponding to each of the other clients among all the clients j );
[0017] The first client obtains each sub-mask s(v, u generated by each of the other clients and corresponding to the first client j , u); wherein, j is a variable, taking values from 1 to N; N is the number of all clients participating in the model training minus 1; u represents the first client, and v j represents the jth client among all the clients participating in the model training except the first client;
[0018] For each variable j, the first client respectively calculates the difference between s(u, v j ) and s(v j , u), and obtains p(u, v according to the difference j );
[0019] The first client calculates And takes the calculated result as the mask corresponding to the first client.
[0020] Wherein, the obtaining p(u, v according to the difference j ) includes:
[0021] Taking the difference directly as the p(u, v j );
[0022] Or,
[0023] Calculating the remainder of the difference mod r, and taking the calculated remainder result as the p(u, v j); where mod is the modulo operation and r is a preset value greater than 1.
[0024] Wherein, the r is a prime number not less than 200 bits.
[0025] The method further includes: the first client generates a homomorphic encryption key pair corresponding to the first client; the first client sends the public key in the homomorphic encryption key pair corresponding to the first client to the forwarding server; and the first client receives the public keys corresponding to each of the other clients among all the clients sent by the forwarding server;
[0026] Correspondingly, after the first client obtains each sub-mask s(u, v corresponding to each of the other clients generated by the first client j ), it further includes: for each of the other clients, the first client uses the public key corresponding to the jth client to encrypt the sub-mask s(u, v j ) corresponding to the jth client, and then sends the encrypted s(u, v j ) to the forwarding server;
[0027] Correspondingly, the first client obtains each sub-mask s(v generated by each of the other clients and corresponding to the first client j , u), including:
[0028] The first client receives each encrypted sub-mask s(v generated by each of the other clients and corresponding to the first client j , u) sent by the forwarding server;
[0029] The first client uses the private key in the homomorphic encryption key pair corresponding to the first client to decrypt each encrypted sub-mask s(v j , u) to obtain each sub-mask s(v j , u).
[0030] Wherein, the forwarding server includes: the cloud server, or a third-party server independent of the cloud server.
[0031] According to a second aspect, a model training method based on federated machine learning is provided. At least two clients and at least one cloud server participate in the model training based on federated machine learning. The method is applied to the cloud server and includes:
[0032] In each round of training, the cloud server distributes the latest obtained global model to each client participating in the model training based on federated machine learning;
[0033] The cloud server receives the encrypted gradients of the global model sent by each client;
[0034] The cloud server adds up the gradients of each encrypted global model received to obtain the aggregated gradient.
[0035] The cloud server updates the global model using the aggregated gradient.
[0036] The cloud server performs the next round of training until the global model converges.
[0037] According to a third aspect, there is provided a model training apparatus based on federated machine learning. At least two clients and at least one cloud server participate in the model training based on federated machine learning. This apparatus is applied to any one of the at least two clients, i.e., the first client. The apparatus includes:
[0038] A global model acquisition module, configured to receive the global model sent by the cloud server in each round of training.
[0039] A gradient acquisition module, configured to train the gradient of the global model using local private data in each round of training.
[0040] An encryption module, configured to encrypt the gradient obtained in this round of training and then send the encrypted gradient to the cloud server in each round of training.
[0041] Each module performs the next round of training until the global model converges.
[0042] According to a fourth aspect, there is provided a model training apparatus based on federated machine learning. At least two clients and at least one cloud server participate in the model training based on federated machine learning. This apparatus is applied to the cloud server. The apparatus includes:
[0043] A global model distribution module, configured to distribute the latest obtained global model to each client participating in the model training based on federated machine learning in each round of training.
[0044] A gradient receiving module, configured to receive the encrypted gradients of the global model sent by each client in each round of training.
[0045] A gradient aggregation module, configured to add up the encrypted gradients of the global model received to obtain the aggregated gradient in each round of training.
[0046] A global model update module, configured to update the global model using the aggregated gradient in each round of training.
[0047] Each module performs the next round of training until the global model converges.
[0048] According to a fifth aspect, there is provided a computing device including a memory and a processor. An executable code is stored in the memory. When the processor executes the executable code, the method described in any embodiment of this specification is implemented.
[0049] The methods and devices provided in the embodiments of this specification can achieve the following beneficial effects alone or in combination:
[0050] 1. After obtaining the gradient, the client does not directly send the gradient information to the cloud server. Instead, it first encrypts the gradient and sends the encrypted information to the cloud server. In this way, what the cloud server obtains from each client is the encrypted gradient rather than the original gradient. That is to say, the cloud server can only obtain the aggregated gradient and cannot obtain the gradient of each client. Therefore, the security is improved. For example, an attacker cannot steal the original gradient from the transmission link between the client and the cloud server or from the cloud server, and thus cannot recover the private data in the terminal device where the client is located through means such as a generative adversarial network (GAN). The client can keep the privacy in its own hands, thus greatly improving the security.
[0051] 2. The homomorphic encryption means is used to encrypt the sub-mask during secret sharing. That is to say, each client does not send the original sub-mask to the forwarding server, but sends the sub-mask encrypted by the public key in the homomorphic encryption key pair, thereby further improving the security.
[0052] 3. Compared with the sub-mask acquisition method in which the sub-masks are exchanged pairwise between clients, in the embodiments of this specification, the homomorphic encryption means is used to encrypt the sub-masks during secret sharing, which can be achieved by relying on the central cloud server or a third-party server as an intermediate third party to convey, avoiding the problem of sub-mask leakage caused by pairwise exchange of sub-masks between clients, thereby further improving the security.
[0053] 4. When calculating the difference between two sub-masks, the remainder is taken using the difference, and the mask corresponding to the client is obtained using the result of taking the remainder, so as to ensure that the numerical range of the calculated mask does not exceed the maximum value that the protocol can carry, thereby increasing the application scope of the embodiments of this specification. For example, when the number of clients participating in the model training based on federated machine learning is huge, the model training in the embodiments of this specification can also be realized. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] To more clearly illustrate the technical solutions in the embodiments of this specification or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are some embodiments of this specification. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on these drawings.
[0055] Figure 1 It is a schematic structural diagram of a system applied in an embodiment of this specification.
[0056] Figure 2 It is a flowchart of a model training method based on federated machine learning executed by a client in an embodiment of this specification.
[0057] Figure 3 It is a flowchart of a method for a first client to obtain a mask corresponding to the first client in an embodiment of this specification.
[0058] Figure 4 It is a flowchart of a model training method based on federated machine learning executed by a cloud server in an embodiment of this specification.
[0059] Figure 5 It is a flowchart of a model training method based on federated machine learning implemented by the cooperation of a client and a cloud server in an embodiment of this specification.
[0060] Figure 6 It is a schematic structural diagram of a model training device based on federated machine learning applied to a client in an embodiment of this specification.
[0061] Figure 7 It is a schematic structural diagram of a model training device based on federated machine learning applied to a client in an embodiment of this specification.
[0062] Figure 8 It is a schematic structural diagram of a model training device based on federated machine learning applied to a cloud server in an embodiment of this specification. Detailed implementation manners
[0063] As described above, each client needs to send the gradients trained by itself to the cloud server. In many attack scenarios, an attacker can use the gradient information sent by the client to the cloud server to recover the original private data in the terminal device where the client is located. For example, the private data can be recovered by means of a generative adversarial network (GAN) or other methods. Again, the central cloud server receives the gradient information of each individual client. Generally speaking, the central cloud server is reliable. However, when there is an accidental data loss behavior in the central cloud server or it colludes with other clients, the private data of the client will be leaked. The client cannot keep its privacy in its own hands.
[0064] The solution provided in this specification will be described below with reference to the accompanying drawings.
[0065] For the convenience of understanding this specification, the system architecture applied in this specification will be described first. As Figure 1 shown, the system architecture mainly includes M clients participating in federated machine learning and a cloud server. M is a positive integer greater than 1. Among them, each client and the cloud server interact through a network, and the network can include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.
[0066] The M clients are respectively located in M terminal devices. Each client can be located in any terminal device that performs modeling through federated machine learning, such as a banking device, a payment terminal device, a mobile terminal, etc., and the cloud server can be located in the cloud.
[0067] The method of the embodiment of this specification involves the processing of the client and the processing of the cloud server. They will be described separately below.
[0068] First, the model training method executed in the client will be described.
[0069] Figure 2 is a flowchart of the model training method based on federated machine learning executed by the client in an embodiment of this specification. The execution subject of this method is each client participating in federated machine learning. It can be understood that this method can also be executed by any device, equipment, platform, or device cluster with computing and processing capabilities. Refer to Figure 2 and this method includes:
[0070] Step 201: In each round of training, the first client receives the global model sent by the cloud server.
[0071] Step 203: The first client trains the gradient of the global model using local private data.
[0072] Step 205: The first client encrypts the gradients obtained from this round of training, and then sends the encrypted gradients to the cloud server.
[0073] Step 207: The first client performs the next round of training until the global model converges.
[0074] According to the above Figure 2 As can be seen from the above process, in the method provided in the embodiments of this specification, after obtaining the gradients, the client does not directly send the gradient information to the cloud server. Instead, it first encrypts the gradients and sends the encrypted information to the cloud server. In this way, what the cloud server obtains from each client is the encrypted gradients rather than the original gradient text. Therefore, the security is improved. For example, an attacker cannot steal the original gradient text from the transmission link between the client and the cloud server or from the cloud server, and thus cannot recover the private data in the terminal device where the client is located through means such as a generative adversarial network (GAN). The client can keep the privacy in its own hands, thus greatly improving the security.
[0075] The method in the embodiments of this specification can be applied to various business scenarios for model training based on federated machine learning, such as the "Ant Forest" product of Alipay, code scanning image risk control, etc.
[0076] Next, each step in Figure 2 will be described separately with specific embodiments.
[0077] First, for step 201: In each round of training, the first client receives the global model sent by the cloud server.
[0078] For ease of description and to better distinguish the currently processed client from other clients, the Figure 2 client that executes the model training method is denoted as the first client. It can be understood that in the embodiments of this specification, the first client is each client participating in model training based on federated machine learning. That is to say, each client participating in model training based on federated machine learning needs to execute the model training method described in combination with Figure 2 this specification.
[0079] Next, for step 203: The first client uses the local private data to train the gradients of the global model.
[0080] Next, for step 205: The first client encrypts the gradients obtained from this round of training, and then sends the encrypted gradients to the cloud server.
[0081] In the method of the embodiments of this specification, the following two requirements need to be met:
[0082] 1. Security.
[0083] To meet this security requirement, the client cannot directly send the original text of the gradients it has trained to the cloud server, but instead sends the ciphertext of the gradients.
[0084] 2. Availability.
[0085] For model training, the cloud server needs to obtain the aggregation result of the gradients of each client. This aggregation result must be equal to or close to the aggregation result of the original texts of the gradients, so as to better perform model training. That is to say, although the cloud server cannot directly obtain the original text of each gradient, the obtained gradient aggregation result must be equal to or close to the aggregation result of the original texts of the gradients. Therefore, the encryption processes of all clients participating in the model training need to ensure that the sum of all the passwords attached to each gradient can or is close to canceling each other out. To illustrate this idea with a simple example, for example, if we need to obtain the result Y, one calculation method is Y = X1 + X2, and another calculation method is: Y = (X1 + S) + (X2 - S). To meet this requirement 2, the method in the embodiments of this specification precisely utilizes the latter calculation idea.
[0086] At this time, in an embodiment of this specification, before step 205, the method further includes: Step A: The first client obtains the mask corresponding to the first client.
[0087] It should be noted that, among them, the sum of all the masks corresponding to all the clients participating in the model training is less than a predetermined value. Further, the sum of all the masks corresponding to all these clients is 0. Because the sum of all these masks is less than the predetermined value or even can be 0, it can be ensured that the subsequent process of encrypting the gradients with the masks has little or even no impact on the magnitude of the sum of the gradients of each client. In this way, the implementation process of this step 205 includes: The first client adds the gradients obtained in this round of training to the mask corresponding to the first client to obtain the encrypted gradients.
[0088] Each client has its own corresponding mask. For example, if there are 100 clients participating in the model training method based on federated machine learning, then each client will obtain its own corresponding mask. To further improve security, the masks corresponding to different clients are different.
[0089] In an embodiment of this specification, referring to Figure 3 , one implementation process for the first client in step A above to obtain the mask corresponding to the first client includes:
[0090] Step 301: The first client obtains each sub - mask s(u, v generated by the first client and corresponding to each of the other clients among all the clients j)。
[0091] For example, if there are 100 client devices participating in the model training method based on federated machine learning, then the first client device generates 99 sub-masks s(u, v) corresponding to the other 99 client devices respectively j ). For example, s(u, v1) represents the sub-mask generated by the first client device corresponding to client device 1 among the other 99 client devices; similarly, s(u, v2) represents the sub-mask generated by the first client device corresponding to client device 2 among the other 99 client devices; and so on, s(u, v 99 ) represents the sub-mask generated by the first client device corresponding to client device 99.
[0092] Step 303: The first client device obtains the sub-masks s(v j , u) generated by each of the other client devices corresponding to the first client device; where j is a variable with a value ranging from 1 to N; N is the number of all client devices participating in the model training minus 1; u represents the first client device, and v j represents the j-th client device among all client devices participating in the model training except the first client device.
[0093] All client devices participating in the model training method based on federated machine learning will perform the processing in step 301. Therefore, each of the other client devices will also generate a sub-mask corresponding to the first client device. In this step 303, the first client device needs to obtain all the sub-masks s(v j , u) generated by each of the other client devices corresponding to the first client device.
[0094] For example, if there are 100 client devices participating in the model training method based on federated machine learning, then the first client device needs to obtain 99 sub-masks s(v j , u) respectively generated by the other 99 client devices corresponding to the first client device. Among them, s(v1, u) represents the sub-mask generated by client device 1 among the other 99 client devices corresponding to the first client device; s(v2, u) represents the sub-mask generated by client device 2 among the other 99 client devices corresponding to the first client device; and so on, s(v 99 , u) represents the sub-mask generated by client device 99 among the other 99 client devices corresponding to the first client device.
[0095] For example, if there are 100 client devices participating in the model training method based on federated machine learning, then after completing this step 303, the first client device obtains 99 sub-masks it generates corresponding to the other 99 client devices, and 99 sub-masks generated by the other 99 client devices corresponding to this first client device, for a total of 198 sub-masks.
[0096] In order for each client participating in model training to obtain the sub-masks corresponding to each other client generated by each other client, after step 301, the first client needs to send all the sub-masks it generates to the cloud server or a third-party server. After the cloud server or the third-party server receives them, they are forwarded to the corresponding client. However, if the cloud server or the third-party server obtains the original text of the sub-masks, then it may also cause problems in obtaining the original text of the gradients based on the sub-masks subsequently. Therefore, in order to further enhance security, in an embodiment of this specification, the sub-masks can be encrypted, and what is sent to the cloud server or the third-party server are all the encrypted sub-masks. In this way, the cloud server or the third-party server can neither obtain the original text of the gradients of each client nor obtain the original text of the sub-masks generated by each client, greatly improving security.
[0097] To achieve the effect that the cloud server or the third-party server cannot obtain the original text of the sub-masks, the method further includes: the first client generates a homomorphic encryption key pair corresponding to the first client; wherein, the homomorphic encryption key pair corresponding to the first client is a homomorphic encryption key pair dedicated to the first client, rather than a homomorphic encryption key pair shared by each client. Therefore, the homomorphic encryption key pairs corresponding to different clients are different; the first client sends the public key in the homomorphic encryption key pair corresponding to the first client to the forwarding server; and the first client receives the public keys corresponding to each other client among all the clients sent by the forwarding server;
[0098] Correspondingly, after step 301, it further includes: for each other client, the first client uses the public key corresponding to the jth client to encrypt the sub-mask s(u, v j ) corresponding to the jth client, and then sends the encrypted s(u, v j ) to the forwarding server, so that the forwarding server sends the encrypted s(u, v j ) to the corresponding jth client;
[0099] Correspondingly, the process of step 303 includes:
[0100] The first client receives the encrypted sub-masks s(v j , u) generated by each other client and corresponding to the first client sent by the forwarding server;
[0101] The first client uses the private key in the homomorphic encryption key pair corresponding to the first client to decrypt the encrypted sub-masks s(v j , u), and obtains the sub-masks s(v j , u).
[0102] Among them, the above forwarding server includes: a cloud server, or a third-party server independent of the cloud server.
[0103] Step 305: For each variable j, the first client calculates the difference between s(u, v j ) and s(v j , u) respectively, and obtains p(u, v j ) according to the difference.
[0104] For example, if there are 100 clients participating in the model training method based on federated machine learning, that is, j = 99, then in this step 305, 99 differences need to be calculated. That is, for client 1 among the other 99 clients, the difference between s(u, v1) and s(v1, u) needs to be calculated; for client 2 among the other 99 clients, the difference between s(u, v2) and s(v2, u) needs to be calculated; and so on, until for client 99 among the other 99 clients, the difference between s(u, v 99 ) and s(v 99 , u) needs to be calculated.
[0105] It should be noted that when calculating the difference between s(u, v1) and s(v1, u), either one can be used as the minuend or the subtrahend, as long as the same method is used when all clients calculate all the differences. For example, all use the s(u, v j ) generated by themselves as the subtrahend, and all use the s(v j , u) generated by the jth client as the minuend.
[0106] In an embodiment of this specification, the implementation process of this step 305 adopts Method 1, including: directly using the calculated difference as p(u, v j ).
[0107] Alternatively, in another embodiment of this specification, the implementation process of this step 305 adopts Method 2, including: taking the remainder of the calculated difference modulo r, and then using the remainder result as p(u, v j ); where mod is the modulo operation, and r is a preset value greater than 1.
[0108] In actual business implementation, the number of clients participating in model training may be very large. For example, there are 20,000 clients. Then, according to the processing in step 305, each client needs to calculate 19,999 differences. Then, in step 307, the 19,999 differences need to be added together. The value of the result obtained after addition will be very large and is very likely to exceed the maximum value that the protocol can carry. Subsequently, the cloud server needs to add the 20,000 masks obtained by the 20,000 clients. Each mask is the sum of the above 19,999 differences. Therefore, even if the value of the mask in a single client does not exceed the maximum value that the protocol can carry, the value that the subsequent cloud server needs to calculate may still exceed the maximum value that the protocol can carry. Therefore, in order to further avoid the problem of out-of-bounds numerical range caused by a huge number of clients participating in model training, in the embodiment of this specification, in step 305, when each difference is calculated, the difference can be taken modulo r. In this way, all differences are equivalently reduced by r times as a whole, so as to ensure that the value is within the range that the protocol can carry. Among them, r can be taken as a relatively large value as much as possible, so as to limit all differences to the greatest extent. For example, r is a prime number not less than 200 digits.
[0109] It can be understood that the modulo operation will not affect the mask sum being less than a predetermined value or the mask sum being equal to 0. Whether the difference is taken modulo or not, that is, whether method one or method two is adopted, the effect of making the mask sums of all clients less than a predetermined value or equal to 0 subsequently is the same.
[0110] Step 307: The first client calculates Take the calculated result as the mask corresponding to the first client.
[0111] For example, there are 100 clients participating in the model training method based on federated machine learning, that is, j = 99. Then, according to the processing in step 307, the first client needs to calculate the sum of 99 p(u, v j ) and take the sum value as the mask corresponding to the first client.
[0112] According to the above Figure 3 shown process, it can be seen that because the mask corresponding to the first client is obtained based on the sum of all p(u, v j ), and each p(u, v j ) is obtained based on the difference between s(u, v j ) and s(v j , u). In this way, if the masks p(u, v j) ) of all clients are added together, the mask values will cancel each other out positively and negatively, thereby eliminating the impact of encrypting the gradient using the mask.
[0113] As described above, in step 205, the first client adds the gradient obtained in this round of training to the mask corresponding to the first client to obtain the encrypted gradient. For example, in this round of training, the gradient obtained by the first client is x(u), and the mask corresponding to the first client is ∑ v p(u,v). Then, in step 205, the first client calculates y(u) = x(u) + ∑ v p(u,v), and sends y(u) to the cloud server.
[0114] Next, step 207 is executed: the first client performs the next round of training until the global model converges.
[0115] Next, the processing of the cloud server in the model training based on federated machine learning is described.
[0116] Figure 4 is a flowchart of the model training method based on federated machine learning executed by the cloud server in an embodiment of this specification. At least two clients and at least one cloud server participate in the model training based on federated machine learning, and the execution subject of this method is the cloud server participating in federated machine learning. It can be understood that this method can also be executed by any device, equipment, platform, or device cluster with computing and processing capabilities. Refer to Figure 4 , this method includes:
[0117] Step 401: In each round of training, the cloud server distributes the latest obtained global model to each client participating in the model training based on federated machine learning.
[0118] Step 403: The cloud server receives the encrypted gradients of the global model sent by each client.
[0119] Step 405: The cloud server adds the received encrypted gradients of the global model to obtain the aggregated gradient.
[0120] Step 407: The cloud server updates the global model using the aggregated gradient.
[0121] Step 409: The cloud server performs the next round of training until the global model converges.
[0122] The description of the processing performed by the cloud server can also be further referred to in combination with Figure 2 , Figure 3 , Figure 5 The description of the embodiments of this specification.
[0123] Next, in combination with the processing of the client and the cloud server, the model training method based on federated machine learning in an embodiment of this specification is described. Figure 5This is a flowchart of a model training method based on federated machine learning implemented by a client and a cloud server in an embodiment of this specification. Refer to Figure 5 , the method includes:
[0124] Step 501: Each client generates a dedicated homomorphic encryption key pair corresponding to this client.
[0125] Step 503: Each client sends the public key in the homomorphic encryption key pair corresponding to this client to the cloud server.
[0126] Step 505: After receiving the public keys sent by each client, the cloud server broadcasts them to each client, so that each client obtains the public keys corresponding to all clients participating in model training.
[0127] Step 507: The first client generates each sub-mask s(u, v for each of the other clients among all clients j ).
[0128] In the following steps, for the convenience of description, the processing performed by the first client is used as an example for illustration. The processing performed by the first client is the processing performed by each client participating in model training.
[0129] Step 509: For the other N clients, the first client uses the public key corresponding to the jth client to encrypt the s(u, v corresponding to the jth client j ), to obtain the encrypted sub-mask corresponding to the jth client; where j is a variable, taking values from 1 to N, and N is the number of all clients participating in model training minus 1, and then sends all N encrypted sub-masks s(u, v j ) to the cloud server.
[0130] Step 511: The cloud server sends the encrypted sub-masks corresponding to the ith client sent by all clients to the ith client; where i is a variable, taking values from 1 to M; and M is the number of all clients participating in model training.
[0131] Step 513: The first client receives the encrypted sub-masks corresponding to itself, and uses the private key in the dedicated homomorphic encryption key pair corresponding to the first client to decrypt each encrypted sub-mask, to obtain the decrypted N s(v j , u).
[0132] Step 515: For each variable j, the first client calculates p(u, v j ) = [s(u, v j ) - s(v j , u)] mod r, to obtain N p(u, vj )。
[0133] Step 517: The first client calculates Take the calculated result as the mask corresponding to the first client.
[0134] The processes of the above steps 501 to 519 can be executed once when each client starts. In subsequent rounds of training, directly use the N masks p(u, v j ), that is, the masks used by the first client in each round of training are the same. Or, the processes of the above steps 501 to 517 can also be executed once in each round of training, so that the masks used by the first client in each round of training are different, further improving security.
[0135] Step 519: In each round of training, the first client receives the global model sent by the cloud server.
[0136] Step 521: The first client uses the local private data to train the gradient of the global model, denoted as x(u).
[0137] Step 523: The first client calculates the encrypted gradient Then send y(u) to the cloud server.
[0138] Step 525: The cloud server obtains the M y(u) sent by all clients i , and calculates the aggregated gradient in this round of polling where i is a variable and M is the number of all clients participating in model training.
[0139]
[0140] Step 527: The cloud server updates the global model using the aggregated gradient T obtained in this round of training for all clients to use in the next round of training until the global model converges.
[0141] Thus, the global model is obtained.
[0142] This embodiment of the specification also proposes a service prediction method, which includes: using the trained global model for service prediction, such as risk user identification, etc.
[0143] This embodiment of the specification also proposes a model training device based on federated machine learning. At least two clients and at least one cloud server participate in the model training based on federated machine learning. This device is applied to any one of the at least two clients, the first client, see Figure 6 , this device includes:
[0144] The global model acquisition module 601 is configured to receive the global model sent by the cloud server in each round of training.
[0145] The gradient acquisition module 602 is configured to train the gradient of the global model using local private data in each round of training.
[0146] The encryption module 603 is configured to encrypt the gradient obtained in this round of training and then send the encrypted gradient to the cloud server in each round of training.
[0147] Each module performs the next round of training until the global model converges.
[0148] In the embodiment of the device in this specification, refer to Figure 7 , and further includes: a mask acquisition module 701;
[0149] The mask acquisition module 701 is configured to obtain the mask corresponding to the first client where the device is located; wherein, the sum of all masks corresponding to all clients participating in the model training is less than a predetermined value.
[0150] When performing encryption, the encryption module 603 is configured to execute: adding the gradient obtained in this round of training to the mask corresponding to the first client to obtain the encrypted gradient.
[0151] In Figure 6 、 7 In the embodiment of the device in this specification shown, the sum of all masks corresponding to all clients is 0.
[0152] In Figure 7 In the embodiment of the device in this specification shown, the mask acquisition module 701 is configured to execute:
[0153] Obtain each sub-mask s(u, v j ) generated by the first client where it is located and corresponding to each of the other clients among all the clients;
[0154] Obtain each sub-mask s(v j , u) generated by each of the other clients and corresponding to the first client; wherein, j is a variable, taking values from 1 to N; N is the number of all clients participating in the model training minus 1; u represents the first client, and v j represents the jth client among all clients participating in the model training except the first client;
[0155] For each variable j, calculate the difference between s(u, v j ) and s(v j , u), and obtain p(u, v j ) according to the difference.
[0156] Calculate Use the calculated result as the mask corresponding to the first client.
[0157] In Figure 7 In the embodiment of the device of the present specification shown, the mask acquisition module 701 is configured to perform: directly use the difference as the p(u, v j ); or, calculate the difference mod r, and use the calculated remainder result as the p(u, v j ); where, mod is the remainder operation, and r is a preset value greater than 1.
[0158] In Figure 7 In the embodiment of the device of the present specification shown, where the r is a prime number not less than 200 bits.
[0159] In Figure 7 In the embodiment of the device of the present specification shown, the mask acquisition module 701 is further configured to perform: generate a homomorphic encryption key pair corresponding to the first client; send the public key in the homomorphic encryption key pair corresponding to the first client to the forwarding server; and receive the public keys corresponding to each of the other clients among all the clients sent by the forwarding server;
[0160] Correspondingly, the mask acquisition module 701 is configured to perform:
[0161] After obtaining each sub-mask s(u, v j ) generated by the first client and corresponding to each of the other clients among all the clients, for each of the other clients, use the public key corresponding to the jth client to encrypt the sub-mask s(u, v j ) corresponding to the jth client, and then send the encrypted s(u, v j ) to the forwarding server;
[0162] Receive the encrypted sub-masks s(vj, u) generated by each of the other clients and corresponding to the first client sent by the forwarding server;
[0163] Use the private key in the homomorphic encryption key pair corresponding to the first client to decrypt each encrypted sub-mask s(vj, u) to obtain each sub-mask s(vj, u).
[0164] Wherein, the forwarding server includes: the cloud server, or a third-party server independent of the cloud server.
[0165] In one embodiment of this specification, a model training device based on federated machine learning is proposed. At least two client devices and at least one cloud server participate in the model training based on federated machine learning. This device is applied to the cloud server. Refer to Figure 8 , this device includes:
[0166] A global model distribution module 801, configured to distribute the latest obtained global model to each client device participating in the model training based on federated machine learning in each round of training;
[0167] A gradient receiving module 802, configured to receive the encrypted gradients of the global model sent by each client device in each round of training;
[0168] A gradient aggregation module 803, configured to add up the received encrypted gradients of the global model in each round of training to obtain the aggregated gradient;
[0169] A global model update module 804, configured to update the global model using the aggregated gradient in each round of training;
[0170] Each module performs the next round of training until the global model converges.
[0171] One embodiment of this specification provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed on a computer, the computer is made to execute the method in any one of the embodiments in the specification.
[0172] One embodiment of this specification provides a computing device, including a memory and a processor. An executable code is stored in the memory. When the processor executes the executable code, the method in any one of the embodiments in the specification is implemented.
[0173] It can be understood that the structure schematically shown in the embodiments of this specification does not constitute a specific limitation on the device in the embodiments of this specification. In other embodiments of the specification, the above device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or have different component arrangements. The components shown in the figure can be implemented in hardware, software, or a combination of software and hardware.
[0174] Regarding the information interaction, execution process, etc. among the various modules within the above device and system, since they are based on the same concept as the method embodiments of this specification, the specific content can be referred to the description in the method embodiments of this specification and will not be elaborated here.
[0175] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other, and the key point of each embodiment is to illustrate the differences from other embodiments. In particular, for the device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and reference can be made to the relevant parts of the method embodiments for the relevant content.
[0176] Those skilled in the art should be able to realize that in one or more of the above examples, the functions described in the present invention can be implemented by hardware, software, add-ons, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0177] The specific embodiments described above further elaborate on the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only the specific embodiments of the present invention and is not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solution of the present invention should be included in the protection scope of the present invention.
Claims
1. A model training method based on federated machine learning, where at least two clients and at least one cloud server participate in the model training based on federated machine learning. This method is applied to any one of the at least two clients, namely the first client, and includes: In each round of training, the first client receives the global model sent by the cloud server; The first client uses the local private data to train the gradient of the global model; The first client encrypts the gradient obtained in this round of training, and then sends the encrypted gradient to the cloud server; The first client performs the next round of training until the global model converges; Wherein, this method further includes: the first client obtains a mask corresponding to the first client; and the sum of all masks corresponding to all clients participating in the model training is 0; The first client encrypts the gradient obtained in this round of training, including: The first client adds the gradient obtained in this round of training to the mask corresponding to the first client to obtain the encrypted gradient; Wherein, the first client obtains the mask corresponding to the first client, including: The first client obtains respective sub-masks s(u, v) generated by the first client and corresponding to each of the other clients among all the clients j ); The first client obtains each sub-mask s(v j , u) generated by each of the other clients, corresponding to the first client; where j is a variable with a value ranging from 1 to N; N is the number of all clients participating in the model training minus 1; u represents the first client, and v j represents the j-th client among all clients participating in the model training except the first client; For each variable j, the first client separately calculates the difference between s(u, v j ) and s(v j , u), and obtains p(u, v j ) based on this difference; First client calculation Use the calculated result as the mask corresponding to the first client.
2. The method according to claim 1, wherein Said obtaining p(u, v) according to the difference value j ) includes: Use this difference directly as the p(u, v j ); Or, Calculate the difference modulo r, and use the resulting modulo calculation as the p(u, v j ); where mod is the modulo operation and r is a preset value greater than 1.
3. The method according to claim 2, wherein The r is a prime number not less than 200 bits.
4. According to the method described in claim 1, wherein, This method further includes: the first client generates a homomorphic encryption key pair corresponding to the first client; the first client sends the public key in the homomorphic encryption key pair corresponding to the first client to the forwarding server; and the first client receives the public keys corresponding to each of the other clients among all clients sent by the forwarding server; Accordingly, after the first client obtains each sub-mask s(u, v corresponding to each of the other clients among all the clients and generated by the first client j ), it further includes: for each of the other clients, the first client uses the public key corresponding to the j-th client to encrypt the sub-mask s(u, v j ) corresponding to the j-th client, and then sends the encrypted s(u, v j ) to the forwarding server; Accordingly, the first client obtains each sub-mask s(v j , u) corresponding to the first client and generated by each of the other clients, including: The first client receives each of the encrypted sub-masks s(v j , u) generated by other clients and corresponding to the first client sent by the forwarding server; The first client uses the private key in the corresponding homomorphic encryption key pair of the first client to decrypt each encrypted sub-mask s(v j , u), and obtains each sub-mask s(v j , u).
5. The method according to claim 4, wherein The forwarding server includes: the cloud server, or a third-party server independent of the cloud server.
6. A model training method based on federated machine learning, where at least two clients and at least one cloud server participate in the model training based on federated machine learning. This method is applied to the cloud server and includes: In each round of training, the cloud server sends the latest obtained global model to each client participating in the model training based on federated machine learning; The cloud server receives the encrypted gradients of the global model sent by each client; wherein, the encrypted gradients of the global model sent by each client are obtained by using any one of the methods described in claims 1 to 5; The cloud server adds the received encrypted gradients of the global model to obtain an aggregated gradient; The cloud server updates the global model by using the aggregated gradient; The cloud server performs the next round of training until the global model converges.
7. A model training device based on federated machine learning, where at least two clients and at least one cloud server participate in the model training based on federated machine learning. This device is applied to any one of the at least two clients, namely the first client, and the device includes: A global model acquisition module configured to receive the global model sent by the cloud server in each round of training; A gradient acquisition module configured to use the local private data to train the gradient of the global model in each round of training; An encryption module configured to encrypt the gradient obtained in this round of training in each round of training, and then send the encrypted gradient to the cloud server; Further comprising: a mask acquisition module; the mask acquisition module is configured to obtain a mask corresponding to the first client where the device is located; wherein, the sum of all masks corresponding to all clients participating in model training is 0; When performing encryption, the encryption module is configured to execute: adding the gradient obtained in this round of training to the mask corresponding to the first client to obtain the encrypted gradient; Wherein, the mask acquisition module is configured to execute: Obtain each sub-mask s(u, v) corresponding to each of the other clients among all the clients, which is generated by the first client where it is located j ) Obtain each sub-mask s(v j , u) generated by each of the other clients, corresponding to the first client; where j is a variable with values ranging from 1 to N; N is the number of all clients participating in the model training minus 1; u represents the first client, and v j represents the j-th client among all clients participating in the model training except the first client; For each variable j, calculate the difference between s(u, v j ) and s(v j , u) respectively, and obtain p(u, v j ) based on this difference; Calculation Use the calculated result as the mask corresponding to the first client; Each module performs the next round of training until the global model converges.
8. A model training device based on federated machine learning, at least two clients and at least one cloud server participate in the model training based on federated machine learning, the device is applied to the cloud server, and the device includes: A global model distribution module, configured to distribute the latest obtained global model to each client participating in the model training based on federated machine learning in each round of training; A gradient receiving module, configured to receive the encrypted gradient of the global model sent by each client in each round of training; wherein, the encrypted gradient of the global model sent by each client is obtained and sent by the device described in claim 7; A gradient aggregation module, configured to add the received encrypted gradients of the global model in each round of training to obtain an aggregated gradient; A global model update module, configured to update the global model using the aggregated gradient in each round of training; Each module performs the next round of training until the global model converges.
9. A computing device, including a memory and a processor, an executable code is stored in the memory, and when the processor executes the executable code, the method described in any one of claims 1-6 is implemented.
Citation Information
Patent Citations
Data regression method based on longitudinal federated learning and electronic device
CN114186263A