Federated learning method, device and electronic device based on differential privacy
By using the differential privacy method in federated learning to process and sample gradient vectors, the problem of privacy protection and low efficiency in the data integration process is solved, and efficient data integration and privacy protection are achieved.
Patent Information
- Application Number
- CN202210636831.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-06
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-12-06
AI Technical Summary
It is difficult for existing technology to efficiently integrate data scattered across various platforms to train machine learning models, mainly due to data privacy protection and security issues.
Using a federated learning method based on differential privacy, through the cooperation of servers and terminal devices, multiple iterative processes are performed, including selecting gradient vectors from local training data, performing multi-level quantization processing and random sampling, generating target gradient vectors, and Upload to the server to meet the conditions of differential privacy.
It improves the communication efficiency of the federated learning process and improves the overall efficiency while ensuring the protection of data privacy.
Smart Images

Figure CN115081640B_ABST
Abstract
Description
[0001] This application is a divisional application of the invention patent application with application number 2020114095801 filed on December 6, 2020, and entitled “Federated learning method, device and electronic device based on differential privacy”. Technical Field
[0002] One or more embodiments of this specification relate to the field of privacy protection technology, and in particular, to a federated learning method, device, and electronic device based on differential privacy. Background Art
[0003] The data required for machine learning often involves multiple fields. For example, in the merchant classification analysis scenario based on machine learning, the electronic payment platform has the merchant's transaction flow data, the e-commerce platform stores the merchant's sales data, and the banking institution has the merchant's loan data. Data often exists in the form of isolated islands. Due to industry competition, data security, user privacy and other issues, data integration faces great resistance. How to more efficiently integrate the data scattered on various platforms to train machine learning models is of particular significance. Summary of the invention
[0004] In order to solve one of the above technical problems, one or more embodiments of this specification provide a federated learning method, device and electronic device based on differential privacy.
[0005] According to a first aspect, a federated learning method based on differential privacy is provided, wherein the federated learning is performed by a server and a plurality of terminal devices, the method is applied to any terminal device, and the method comprises a plurality of iterations, wherein each iteration comprises:
[0006] Select training data from the local training set and obtain the current local parameters sent by the server;
[0007] Determine a first gradient vector to be processed based on the training data and the current local parameter, wherein the Euclidean norm of the first gradient vector is less than or equal to a preset norm U;
[0008] Performing multi-level quantization processing on the first gradient vector to obtain a second gradient vector;
[0009] In the vector space of the second gradient vector, a first vector set and a second vector set are generated based on the second gradient vector, so that the number of common vector components between any vector in the first vector set and the second gradient vector is greater than a preset number κ, and the number of common vector components between any vector in the second vector set and the second gradient vector is less than or equal to the preset number κ;
[0010] A third gradient vector is randomly sampled from the first vector set or the second vector set; wherein the probabilities of sampling from the first vector set and from the second vector set are preset probabilities p and 1-p respectively; wherein the preset probability p is greater than or equal to 0.5; and the preset number κ and the preset probability p are set so that the sampling satisfies differential privacy;
[0011] The third gradient vector is normalized to obtain a target gradient vector, and the target gradient vector is uploaded to the server.
[0012] Optionally, performing multi-level quantization processing on the first gradient vector to obtain a second gradient vector includes:
[0013] Divide the interval from -U to U into multiple sub-intervals evenly;
[0014] Determine target subintervals to which the values of the components of the first gradient vector correspond in the plurality of subintervals;
[0015] Based on a preset probability, randomly selecting any one of the two endpoints of each target sub-interval as a correction value of each component;
[0016] The second gradient vector is obtained based on the correction values of the respective components.
[0017] Optionally, the determining a first gradient vector to be processed based on the training data and the current local parameter includes:
[0018] Based on the training data and the current local parameters, a current local gradient vector is determined, wherein the Euclidean norm of the current local gradient vector is normalized to be less than or equal to the preset norm U;
[0019] Randomly selecting a preset number x of target components from the components of the current local gradient vector;
[0020] Determine the current gradient residual vector of this iteration;
[0021] Obtaining a target residual component of the current gradient residual vector in the direction of the target component;
[0022] The first gradient vector is determined based on the target component and the target residual component.
[0023] Optionally, in the first iteration, the current gradient residual vector is 0; in non-first iteration, the current gradient residual vector is the product of a first vector part, a preset first correction factor, and the sum of a second vector part; the first vector part is the component part of the local gradient vector in the last iteration except the target component in the last iteration; the second vector part is the component part of the gradient residual vector in the last iteration except the target residual component in the last iteration.
[0024] Optionally, determining the first gradient vector based on the target component and the target residual component includes:
[0025] Determine a target rotation matrix, wherein the target rotation matrix is an orthogonal matrix;
[0026] The product of the target component and a preset second correction factor and the sum of the target residual component are calculated, and the target rotation matrix is multiplied by the calculated result to obtain the first gradient vector.
[0027] Optionally, determining the target rotation matrix includes:
[0028] Generate a target diagonal matrix; the diagonal elements of the target diagonal matrix are 0.5;
[0029] Get the target Walsh-Hadamard matrix;
[0030] The target Walsh-Hadamard matrix is multiplied by the target diagonal matrix and divided by the preset number x.
[0031] According to a second aspect, a federated learning device based on differential privacy is provided, wherein the federated learning is performed by a server and a plurality of terminal devices, the device is applied to any terminal device, the device performs a plurality of iterations, and the device comprises:
[0032] The acquisition module is used to select training data from the local training set and obtain the current local parameters sent by the server;
[0033] A determination module, configured to determine a first gradient vector to be processed based on the training data and the current local parameter, wherein the Euclidean norm of the first gradient vector is less than or equal to a preset norm U;
[0034] A processing module, configured to perform multi-level quantization processing on the first gradient vector to obtain a second gradient vector;
[0035] a generating module, configured to generate a first vector set and a second vector set based on the second gradient vector in the vector space of the second gradient vector, so that the number of the same vector components between any vector in the first vector set and the second gradient vector is greater than a preset number κ, and the number of the same vector components between any vector in the second vector set and the second gradient vector is less than or equal to the preset number κ;
[0036] A sampling module, configured to randomly sample a third gradient vector from the first vector set or the second vector set; wherein the probabilities of sampling from the first vector set and from the second vector set are preset probabilities p and 1-p respectively; wherein the preset probability p is greater than or equal to 0.5; and the preset number κ and the preset probability p are set so that the sampling satisfies differential privacy;
[0037] An output module is used to normalize the third gradient vector to obtain a target gradient vector, and upload the target gradient vector to the server.
[0038] Optionally, the processing module includes:
[0039] A sub-division module is used to evenly divide the interval range from -U to U into multiple sub-intervals;
[0040] A mapping submodule, used to determine the target subintervals to which the values of the components of the first gradient vector correspond in the plurality of subintervals;
[0041] A selection submodule, used for randomly selecting any one of the two endpoints of each target subinterval as a correction value of each component based on a preset probability;
[0042] The acquisition submodule is used to acquire the second gradient vector based on the correction values of each component.
[0043] Optionally, the determining module includes:
[0044] A calculation submodule, configured to determine a current local gradient vector based on the training data and the current local parameter, wherein the Euclidean norm of the current local gradient vector is normalized to be less than or equal to the preset norm U;
[0045] A component selection submodule, used for randomly selecting a preset number x of target components from the components of the current local gradient vector;
[0046] The residual determination submodule is used to determine the current gradient residual vector of this iteration;
[0047] A component acquisition submodule, used to acquire a target residual component of the current gradient residual vector in the direction of the target component;
[0048] A determination submodule is used to determine the first gradient vector based on the target component and the target residual component.
[0049] Optionally, in the first iteration, the current gradient residual vector is 0; in non-first iteration, the current gradient residual vector is the product of a first vector part, a preset first correction factor, and the sum of a second vector part; the first vector part is the component part of the local gradient vector in the last iteration except the target component in the last iteration; the second vector part is the component part of the gradient residual vector in the last iteration except the target residual component in the last iteration.
[0050] Optionally, the determining submodule is configured to:
[0051] Determine a target rotation matrix, wherein the target rotation matrix is an orthogonal matrix;
[0052] The product of the target component and a preset second correction factor and the sum of the target residual component are calculated, and the target rotation matrix is multiplied by the calculated result to obtain the first gradient vector.
[0053] Optionally, the determination submodule determines the target rotation matrix in the following manner:
[0054] Generate a target diagonal matrix; the diagonal elements of the target diagonal matrix are 0.5;
[0055] Get the target Walsh-Hadamard matrix;
[0056] The target Walsh-Hadamard matrix is multiplied by the target diagonal matrix and divided by the preset number x.
[0057] According to a third aspect, a computer-readable storage medium is provided, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of the above-mentioned first aspects is implemented.
[0058] According to a fourth aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method described in any one of the first aspects is implemented.
[0059] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0060] The embodiments of the present specification provide a federated learning method and device based on differential privacy, which selects training data from a local training set and obtains the current local parameters sent by a server. Based on the training data and the current local parameters, a first gradient vector to be processed is determined, and the Euclidean norm of the first gradient vector is less than or equal to a preset norm. The first gradient vector is subjected to multi-level quantization processing to obtain a second gradient vector. In the vector space of the second gradient vector, a first vector set and a second vector set are generated based on the second gradient vector, and sampling that satisfies differential privacy is performed to randomly sample a third gradient vector from the first vector set or the second vector set. The third gradient vector is normalized to obtain a target gradient vector, and the target gradient vector is uploaded to the server. Since the present embodiment uses multi-level quantization processing for the gradient vector and uses a method that satisfies differential privacy for sampling, the target gradient vector is finally obtained, which improves the communication efficiency in the federated learning process, thereby improving the efficiency of federated learning.
[0061] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0063] Figure 1 is a schematic diagram of a scenario of federated learning based on differential privacy according to an exemplary embodiment of this specification;
[0064] Figure 2 is a flowchart of a federated learning method based on differential privacy according to an exemplary embodiment of this specification;
[0065] Figure 3 is a flowchart of another federated learning method based on differential privacy according to an exemplary embodiment of this specification;
[0066] Figure 4 is a flowchart of another federated learning method based on differential privacy according to an exemplary embodiment of this specification;
[0067] Figure 5 is a block diagram of another federated learning device based on differential privacy according to an exemplary embodiment of this specification;
[0068] Figure 6It is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0069] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.
[0070] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit the present application. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0071] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0072] like Figure 1 Shown is a schematic diagram of a federated learning scenario based on differential privacy according to an exemplary embodiment.
[0073] exist Figure 1 In the illustrated scenario, any terminal device can obtain the current local parameters from the server and randomly select some training data from the local training set stored locally. Then, based on the current local parameters and the training data, a first gradient vector is obtained, and the first gradient vector is subjected to multi-level quantization processing to obtain a second gradient vector.
[0074] Next, a first vector set and a second vector set are generated according to the second gradient vector, so that the number of the same vector components of any vector in the first vector set and the second gradient vector is greater than the preset number κ. And the number of the same vector components of any vector in the second vector set and the second gradient vector is less than or equal to κ. Then a third gradient vector is randomly sampled from the first vector set or the second vector set. Among them, the probabilities of sampling from the first vector set and from the second vector set are preset probabilities p and 1-p, respectively. And, the settings of κ and p make the sampling satisfy differential privacy.
[0075] Finally, the third gradient vector is normalized to obtain the target gradient vector, and the target gradient vector is uploaded to the server.
[0076] The server may collect the target gradient vectors uploaded by the terminal devices, and integrate the target gradient vectors to obtain the local parameters corresponding to the terminal devices, and return the local parameters corresponding to the terminal devices.
[0077] The solution provided in this specification will be described in detail below in conjunction with specific embodiments.
[0078] like Figure 2 As shown, Figure 2 The flowchart of a federated learning method based on differential privacy is shown according to an exemplary embodiment. The federated learning can be performed by a server and multiple terminal devices, and the method can be applied to any terminal device. It can be understood by those skilled in the art that the terminal device can include but is not limited to a mobile terminal device such as a smart phone, a smart wearable device, a tablet computer, a laptop portable computer, and a desktop computer. The method may include multiple iterations, wherein each iteration may include the following steps:
[0079] In step 201, training data is selected from a local training set, and current local parameters sent by a server are obtained.
[0080] In step 202, a first gradient vector to be processed is determined based on training data and current local parameters.
[0081] In this embodiment, the terminal device may randomly select training data from the local training set and obtain the current local parameters of this iteration sent by the server. Then, based on the training data and the current local parameters, the first gradient vector to be processed may be determined, wherein the Euclidean norm of the first gradient vector is less than or equal to the preset norm U. U may be an upper bound of a norm obtained based on experience, or an upper bound of a norm calculated using a preset algorithm. It can be understood that this embodiment does not limit the specific value of the preset norm U.
[0082] Specifically, based on the training data and the current local parameters, the current local gradient vector is determined, and the norm of the current local gradient vector is calculated. If the calculated norm is greater than U, the current local gradient vector is divided by U. If the calculated norm is less than or equal to U, the current local gradient vector is not processed. Thus, the Euclidean norm of the current local gradient vector is normalized to be less than or equal to U.
[0083] In one implementation, the current local gradient vector whose Euclidean norm is normalized to be less than or equal to U may be used as the first gradient vector to be processed. In another implementation, the current local gradient vector whose Euclidean norm is normalized to be less than or equal to U may be further processed to obtain the first gradient vector to be processed. It is understood that this embodiment is not limited in this respect.
[0084] In step 203, multi-level quantization processing is performed on the first gradient vector to obtain a second gradient vector.
[0085] In this embodiment, the first gradient vector can be subjected to multi-level quantization processing to obtain the second gradient vector. Specifically, first, the interval range from -U to U (U is the above-mentioned preset norm) can be evenly divided into K-1 sub-intervals (K is an integer greater than 2) to obtain K endpoints. n represents the nth endpoint, then these K endpoints can be expressed as B1<B2<……B K-1 <B K , and B1=-U,B K =U. Among them, B n =-U+2(n-1)U / (k-1).
[0086] Next, the target subintervals corresponding to the values of the components of the first gradient vector in the multiple subintervals can be determined. For example, if the value of the i-th component of the first gradient vector is m, the subinterval corresponding to the i-th component can be found in the above K-1 subintervals [B n-1 , B n ], so that B n-1 <m<B n .
[0087] Finally, based on the preset probability, any one of the two endpoints of each target sub-interval is randomly used as the correction value of each component, and the second gradient vector is obtained based on the correction value of each component. For example, the value of the i-th component of the first gradient vector is m, and the sub-interval corresponding to the i-th component is [B n-1 , B n ], you can randomly select B n-1 or B n As the correction value of the i-th component. Among them, select B n-1The probability of is the preset value q, select B n The probability of is 1-q. Where q = (n-1)(mB n After determining the correction value of each component of the first gradient vector, the second gradient vector is constructed using the correction value of each component (the value of each component of the second gradient vector is the correction value of each component of the first gradient vector).
[0088] In step 204, in the vector space of the second gradient vector, a first vector set and a second vector set are generated based on the second gradient vector.
[0089] In this embodiment, a first vector set and a second vector set may be generated in the vector space of the second gradient vector based on the second gradient vector, so that the number of the same vector components between any vector in the first vector set and the second gradient vector is greater than a preset number κ, and the number of the same vector components between any vector in the second vector set and the second gradient vector is less than or equal to κ.
[0090] For example, the second gradient vector is κ=4, we can construct the vector visible, and the second gradient vector Have the same vector components and The number of identical vector components is 5, which is greater than κ, so, Can be used as an element in the first vector set. Construct vector visible, and the second gradient vector Have the same vector components and The number of identical vector components is 3, which is less than κ, so, Can be used as an element in the second vector set.
[0091] In step 205, a third gradient vector is randomly sampled from the first vector set or the second vector set.
[0092] In this embodiment, the third gradient vector can be randomly sampled from the first vector set or the second vector set, wherein the probability of sampling from the first vector set is a preset probability p, the probability of sampling from the second vector set is 1-p, p is greater than or equal to 0.5, and the settings of κ and p make the above sampling satisfy differential privacy.
[0093] For example, κ and p can be any values that satisfy the following formula:
[0094]
[0095]
[0096] Where d is the dimension of the second gradient vector, τ is the smallest integer greater than (d+κ+1) / 2, ∈ is the preset privacy budget, is a combination constant, and K is the number of endpoints mentioned in step 203.
[0097] In step 206, the third gradient vector is normalized to obtain a target gradient vector, and the target gradient vector is uploaded to the server.
[0098] In this embodiment, the third gradient vector may be normalized to obtain a target gradient vector, and the target gradient vector is uploaded to the server.
[0099] The above-mentioned embodiment of the present specification provides a federated learning method based on differential privacy, by selecting training data from a local training set and obtaining the current local parameters sent by the server, determining the first gradient vector to be processed based on the training data and the current local parameters, the Euclidean norm of the first gradient vector is less than or equal to the preset norm, performing multi-level quantization processing on the first gradient vector to obtain a second gradient vector, generating a first vector set and a second vector set based on the second gradient vector in the vector space of the second gradient vector, performing sampling that satisfies differential privacy, and randomly sampling a third gradient vector from the first vector set or the second vector set. The third gradient vector is normalized to obtain a target gradient vector, and the target gradient vector is uploaded to the server. Since the present embodiment uses multi-level quantization processing on the gradient vector and uses a method that satisfies differential privacy for sampling, the target gradient vector is finally obtained, which improves the communication efficiency in the federated learning process, thereby improving the efficiency of federated learning.
[0100] like Figure 3 As shown, Figure 3 According to a flowchart of another federated learning method based on differential privacy shown in an exemplary embodiment, the embodiment describes a process of determining a first gradient vector to be processed. The method can be applied to a terminal device and includes the following steps:
[0101] In step 301, a current local gradient vector is determined based on training data and current local parameters, and the Euclidean norm of the current local gradient vector is normalized to be less than or equal to a preset norm U.
[0102] In this embodiment, based on the training data and the current local parameters, the current local gradient vector is determined, and the norm of the current local gradient vector is calculated. If the calculated norm is greater than U, the current local gradient vector is divided by U. If the calculated norm is less than or equal to U, the current local gradient vector is not processed. Thus, the Euclidean norm of the current local gradient vector is normalized to be less than or equal to U.
[0103] In step 302, x target components are randomly selected from the components of the current local gradient vector.
[0104] In this embodiment, a preset number x of target components may be randomly selected from the components of the current local gradient vector. For example, the current local gradient vector is x is 3, which can be randomly selected 3 components are used as target components.
[0105] In step 303, the current gradient residual vector of this iteration is determined.
[0106] In this embodiment, the current gradient residual vector of this iteration can be determined. Specifically, in the first iteration, the current gradient residual vector is 0.
[0107] When it is not the first iteration, the current gradient residual vector is the product of the first vector part and the preset first correction factor and the sum of the second vector part. The first vector part is the local gradient vector in the last iteration minus the component part of the target component in the last iteration. The second vector part is the gradient residual vector in the last iteration minus the component part of the target residual component in the last iteration. For example, the current gradient residual vector can be expressed as: R t =αV t—1 +R t—1 , where α is the first correction factor, V t—1 is the first vector part, R t—1 is the second vector part.
[0108] The first vector part is the local gradient vector in the last iteration minus the target component in the last iteration. For example, the local gradient vector in the last iteration is expressed as: Selected in the last iteration As the target component, the first vector part is
[0109] The second vector part is the component part of the gradient residual vector in the last iteration minus the target residual component in the last iteration. For example, the gradient residual vector in the last iteration is expressed as: Selected in the last iteration As the target residual component, the second vector part is
[0110] In step 304, a target residual component of the current gradient residual vector in the direction of the target component is obtained.
[0111] In this embodiment, the target residual component of the current gradient residual vector in the direction of the target component can be obtained. For example, the current gradient residual vector is expressed as: The target component of this iteration is The target residual component of the current gradient residual vector in the direction of the target component can be expressed as
[0112] In step 305, a first gradient vector is determined based on the target component and the target residual component.
[0113] In this embodiment, the first gradient vector may be determined based on the target component and the target residual component. For example, the result of adding the target component and the target residual component may be used as the first gradient vector.
[0114] The above-mentioned embodiment of the present specification provides a federated learning method based on differential privacy, by determining the current local gradient vector based on training data and current local parameters, randomly selecting a preset number of target components from the components of the current local gradient vector, determining the current gradient residual vector of this iteration, obtaining the target residual component of the current gradient residual vector in the direction of the target component, and determining the first gradient vector based on the target component and the target residual component. Since the present embodiment adopts a gradient sampling method to randomly select multiple target components from the components of the current local gradient vector to further determine the target residual component and determine the first gradient vector, the strength of privacy protection is further improved.
[0115] like Figure 4 As shown, Figure 4 According to a flowchart of another federated learning method based on differential privacy shown in an exemplary embodiment, the embodiment describes in detail the process of determining the first gradient vector. The method can be applied to a terminal device and includes the following steps:
[0116] In step 401, a target rotation matrix is determined, and the target rotation matrix is an orthogonal matrix.
[0117] In this embodiment, an orthogonal matrix can be generated as a target rotation matrix. Specifically, based on the dimension of the current local gradient vector, a diagonal matrix with a diagonal element of 0.5 that can be multiplied with the current local gradient vector can be generated as the target diagonal matrix. And according to the order of the target diagonal matrix, a Walsh-Hadamard matrix is obtained as the target Walsh-Hadamard matrix. Then, the target Walsh-Hadamard matrix is multiplied by the target diagonal matrix and divided by the number of target components x, thereby obtaining the target rotation matrix.
[0118] In step 402, the sum of the product of the target component and the preset second correction factor and the target residual component is calculated, and the calculated result is multiplied by the target rotation matrix to obtain a first gradient vector.
[0119] In this embodiment, the product of the target component and the preset second correction factor and the sum of the target residual component can be calculated, and the target rotation matrix is multiplied by the calculated result to obtain the first gradient vector. For example, the first gradient vector can be expressed as: H = S (βX + Y), where β is the second correction factor, X is the target component, Y is the target residual component, and S is the target rotation matrix.
[0120] The above embodiments of the present specification provide a federated learning method based on differential privacy, by determining a target rotation matrix, which is an orthogonal matrix, calculating the sum of the product of the target component and the preset second correction factor and the target residual component, and multiplying the target rotation matrix by the calculated result to obtain a first gradient vector. Since the present embodiment uses a rotation matrix to rotate the target component and the target residual component, the error generated in the federated learning process can be reduced, thereby improving the accuracy of the federated learning.
[0121] It should be noted that although the operations of the methods of the embodiments of this specification are described in a specific order in the above embodiments, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. On the contrary, the steps depicted in the flowchart can change the order of execution. Additionally or alternatively, some steps can be omitted, multiple steps can be combined into one step for execution, and / or one step can be decomposed into multiple steps for execution.
[0122] Corresponding to the aforementioned embodiment of the federated learning method based on differential privacy, this specification also provides an embodiment of a federated learning device based on differential privacy.
[0123] like Figure 5 As shown, Figure 5 This is a block diagram of a federated learning device based on differential privacy shown in this specification according to an exemplary embodiment. The federated learning is performed through a server and multiple terminal devices. The device is applied to any terminal device. The device performs multiple iterations and may include: an acquisition module 501, a determination module 502, a processing module 503, a generation module 504, a sampling module 505 and an output module 506.
[0124] The acquisition module 501 is used to select training data from a local training set and acquire current local parameters sent by the server.
[0125] The determination module 502 is used to determine a first gradient vector to be processed based on the training data and the current local parameters, wherein the Euclidean norm of the first gradient vector is less than or equal to a preset norm U.
[0126] The processing module 503 is used to perform multi-level quantization processing on the first gradient vector to obtain a second gradient vector.
[0127] A generating module 504 is used to generate a first vector set and a second vector set based on the second gradient vector in the vector space of the second gradient vector, so that the number of the same vector components between any vector in the first vector set and the second gradient vector is greater than a preset number κ, and the number of the same vector components between any vector in the second vector set and the second gradient vector is less than or equal to κ.
[0128] The sampling module 505 is used to randomly sample a third gradient vector from the first vector set or the second vector set, wherein the probabilities of sampling from the first vector set and from the second vector set are preset probabilities p and 1-p, respectively, wherein the preset probability p is greater than or equal to 0.5, and the settings of κ and p make the sampling satisfy differential privacy.
[0129] The output module 506 is used to normalize the third gradient vector to obtain a target gradient vector, and upload the target gradient vector to the server.
[0130] In some other optional implementations, the processing module 503 may include: a division submodule, a mapping submodule, a selection submodule and an acquisition submodule (not shown in the figure).
[0131] The division submodule is used to divide the interval range from -U to U into multiple sub-intervals on average.
[0132] The mapping submodule is used to determine the target subintervals to which the values of the components of the first gradient vector correspond in the plurality of subintervals.
[0133] The selection submodule is used to randomly select any one of the two endpoints of each target subinterval as the correction value of each component based on a preset probability.
[0134] The acquisition submodule is used to acquire a second gradient vector based on the correction value of each component.
[0135] In some other optional implementations, the determination module 502 may include: a calculation submodule, a component selection submodule, a residual determination submodule, a component acquisition submodule and a determination submodule (not shown in the figure).
[0136] The calculation submodule is used to determine the current local gradient vector based on the training data and the current local parameters, and the Euclidean norm of the current local gradient vector is normalized to be less than or equal to the preset norm U.
[0137] The component selection submodule is used to randomly select a preset number x of target components from the components of the current local gradient vector.
[0138] The residual determination submodule is used to determine the current gradient residual vector of this iteration.
[0139] The component acquisition submodule is used to obtain the target residual component of the current gradient residual vector in the direction of the target component.
[0140] The determination submodule is used to determine a first gradient vector based on a target component and a target residual component.
[0141] In some other optional implementations, in the first iteration, the current gradient residual vector is 0. In non-first iteration, the current gradient residual vector is the product of the first vector part and the preset first correction factor and the sum of the second vector part. The first vector part is the component part of the local gradient vector in the last iteration except the target component in the last iteration, and the second vector part is the component part of the gradient residual vector in the last iteration except the target residual component in the last iteration.
[0142] In some other optional embodiments, the determination submodule is configured to: determine a target rotation matrix, which is an orthogonal matrix, calculate the sum of the product of the target component and the preset second correction factor and the target residual component, and multiply the target rotation matrix by the result of the above calculation to obtain a first gradient vector.
[0143] In other optional implementations, the determination submodule determines the target rotation matrix by generating a target diagonal matrix whose diagonal elements are 0.5, obtaining a target Walsh-Hadamard matrix, multiplying the target Walsh-Hadamard matrix by the target diagonal matrix, and dividing by x.
[0144] It should be understood that the above device can be pre-set in the terminal device, or loaded into the terminal device by downloading, etc. The corresponding modules in the above device can cooperate with the modules in the terminal device to implement a federated learning scheme based on differential privacy.
[0145] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of one or more embodiments of the present specification. A person of ordinary skill in the art can understand and implement them without creative work.
[0146] One or more embodiments of the present specification also provide a computer-readable storage medium, which stores a computer program, which can be used to execute the above Figures 2 to 4Any embodiment provides a federated learning method based on differential privacy.
[0147] Corresponding to the above-mentioned federated learning method based on differential privacy, one or more embodiments of this specification also propose Figure 6 The schematic structural diagram of an electronic device according to an exemplary embodiment of this specification is shown in FIG. Figure 6 At the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and of course may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a federated learning device based on differential privacy at the logical level. Of course, in addition to software implementations, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0148] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0149] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0150] Those of ordinary skill in the art should also be further aware that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those of ordinary skill in the art can use different methods to implement the described functions for each specific application, but this implementation should not be considered to be beyond the scope of the present application. Among them, the software module can be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the technical field.
[0151] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A federated learning method based on differential privacy, wherein the federated learning is performed by a server and a plurality of terminal devices, the method is applied to any terminal device, and the method includes multiple iterations, wherein: Each iteration consists of: Determine a first gradient vector to be processed based on training data selected from a local training set and current local parameters obtained from the server; Performing multi-level quantization processing on the first gradient vector to obtain a second gradient vector; In the vector space of the second gradient vector, generating a first vector set and a second vector set based on the second gradient vector; Perform sampling that satisfies differential privacy to randomly sample a third gradient vector from the first vector set or the second vector set; Normalizing the third gradient vector to obtain a target gradient vector, and uploading the target gradient vector to the server; The number of common vector components between any vector in the first vector set and the second gradient vector is greater than a preset number κ, and the number of common vector components between any vector in the second vector set and the second gradient vector is less than or equal to the preset number κ.
2. The method according to claim 1, wherein: The probabilities of sampling from the first vector set and from the second vector set are preset probabilities p and 1-p respectively; wherein the preset probability p is greater than or equal to 0.5; and the setting of the preset number κ and the preset probability p enables the sampling to satisfy differential privacy.
3. The method according to claim 1, wherein: The Euclidean norm of the first gradient vector is less than or equal to a preset norm U; and the multi-level quantization processing is performed on the first gradient vector to obtain a second gradient vector, including: Divide the interval from -U to U into multiple sub-intervals evenly; Determine target subintervals to which the values of the components of the first gradient vector correspond in the plurality of subintervals; Randomly select any one of the two endpoints of each target sub-interval as the correction value of each component; The second gradient vector is obtained based on the correction values of the respective components.
4. The method according to claim 1, wherein: The determining of a first gradient vector to be processed based on the training data selected from the local training set and the current local parameters obtained from the server includes: Determining a current local gradient vector based on the training data and the current local parameters; Randomly selecting a preset number x of target components from the components of the current local gradient vector; Determine the current gradient residual vector of this iteration; Obtaining a target residual component of the current gradient residual vector in the direction of the target component; The first gradient vector is determined based on the target component and the target residual component.
5. The method according to claim 4, wherein: In the first iteration, the current gradient residual vector is 0; in the non-first iteration, the current gradient residual vector is the product of the first vector part, the preset first correction factor, and the sum of the second vector part; the first vector part is the component part of the local gradient vector in the last iteration except the target component in the last iteration; the second vector part is the component part of the gradient residual vector in the last iteration except the target residual component in the last iteration.
6. The method according to claim 4, wherein: The determining the first gradient vector based on the target component and the target residual component includes: Determine a target rotation matrix, wherein the target rotation matrix is an orthogonal matrix; The product of the target component and a preset second correction factor and the sum of the target residual component are calculated, and the target rotation matrix is multiplied by the calculated result to obtain the first gradient vector.
7. The method according to claim 6, wherein: Determining the target rotation matrix includes: Generate a target diagonal matrix; the diagonal elements of the target diagonal matrix are 0.5; Get the target Walsh-Hadamard matrix; The target Walsh-Hadamard matrix is multiplied by the target diagonal matrix and divided by the preset number x.
8. A federated learning device based on differential privacy, wherein the federated learning is performed by a server and a plurality of terminal devices, the device is applied to any terminal device, the device performs a plurality of iterations, and the device comprises: A determination module, configured to determine a first gradient vector to be processed based on training data selected from a local training set and current local parameters obtained from the server; A processing module, configured to perform multi-level quantization processing on the first gradient vector to obtain a second gradient vector; A generating module, configured to generate a first vector set and a second vector set based on the second gradient vector in a vector space of the second gradient vector; A sampling module, configured to perform sampling that satisfies differential privacy, so as to randomly sample a third gradient vector from the first vector set or the second vector set; an output module, configured to normalize the third gradient vector to obtain a target gradient vector, and upload the target gradient vector to the server; The number of common vector components between any vector in the first vector set and the second gradient vector is greater than a preset number κ, and the number of common vector components between any vector in the second vector set and the second gradient vector is less than or equal to the preset number κ.
9. The device according to claim 8, wherein: The probabilities of sampling from the first vector set and from the second vector set are preset probabilities p and 1-p respectively; wherein the preset probability p is greater than or equal to 0.5; and the setting of the preset number κ and the preset probability p enables the sampling to satisfy differential privacy.
10. The device according to claim 8, wherein: The Euclidean norm of the first gradient vector is less than or equal to a preset norm U; the processing module includes: A sub-division module is used to evenly divide the interval range from -U to U into multiple sub-intervals; A mapping submodule, used to determine the target subintervals to which the values of the components of the first gradient vector correspond in the plurality of subintervals; A selection submodule, used for randomly selecting any one of the two endpoints of each target subinterval as a correction value of each component; The acquisition submodule is used to acquire the second gradient vector based on the correction values of each component.
11. The device according to claim 8, wherein: The determination module comprises: A calculation submodule, used for determining a current local gradient vector based on the training data and the current local parameters; A component selection submodule, used for randomly selecting a preset number x of target components from the components of the current local gradient vector; The residual determination submodule is used to determine the current gradient residual vector of this iteration; A component acquisition submodule, used to acquire a target residual component of the current gradient residual vector in the direction of the target component; A determination submodule is used to determine the first gradient vector based on the target component and the target residual component.
12. The device according to claim 11, wherein In the first iteration, the current gradient residual vector is 0; in the non-first iteration, the current gradient residual vector is the product of the first vector part, the preset first correction factor, and the sum of the second vector part; the first vector part is the component part of the local gradient vector in the last iteration except the target component in the last iteration; the second vector part is the component part of the gradient residual vector in the last iteration except the target residual component in the last iteration.
13. The device according to claim 11, wherein: The determining submodule is configured to: Determine a target rotation matrix, wherein the target rotation matrix is an orthogonal matrix; The product of the target component and a preset second correction factor and the sum of the target residual component are calculated, and the target rotation matrix is multiplied by the calculated result to obtain the first gradient vector.
14. The device according to claim 13, wherein: The determination submodule determines the target rotation matrix in the following manner: Generate a target diagonal matrix; the diagonal elements of the target diagonal matrix are 0.5; Get the target Walsh-Hadamard matrix; The target Walsh-Hadamard matrix is multiplied by the target diagonal matrix and divided by the preset number x.
15. A computer-readable storage medium storing a computer program, wherein the computer program implements the method according to any one of claims 1 to 7 when executed by a processor.
16. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.
Citation Information
Patent Citations
Model training method based on federated learning
CN111046433A
Federated learning method and device based on differential privacy and storage medium
CN111091199A
