Federal learning method and device, electronic equipment and storage medium
By using the HDBSCAN algorithm to cluster client models in federated learning, the problem of exception client data processing in multi-center federated learning is solved, which improves the robustness and efficiency of the model and reduces misclassification.
Patent Information
- Application Number
- CN202410918990.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-29
AI Technical Summary
The existing multi-center federated learning method cannot effectively remove abnormal client data when processing non-independent and homogeneously distributed user data, and the DBSCAN algorithm depends on the selection of key parameters, resulting in insufficient model training and high misclassification rate.
By establishing a global parameter model in federated learning and using HDBSCAN algorithm to cluster client models, automatically cluster according to category stability, remove unclustered clients, continuously maintain global model parameters, and correct errors in iteration process Classification.
It improves the robustness and model performance of federated learning, reduces misclassification, and enhances the stability and efficiency of the system.
Smart Images

Figure CN119047541A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of federated learning technology, and in particular to a federated learning method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of network communication technology, personal information can be easily collected, transmitted and used by various intelligent terminal devices. If the platform is not well supervised, personal privacy information can be easily leaked. At the enterprise level, once certain business secrets are leaked, it will cause huge human and financial losses to the enterprise. Traditional machine learning needs to collect all information to the central server first, and the client's private data can be easily leaked. Federated learning, as a distributed machine learning model, does not require data to leave the local client, thereby protecting the privacy of the data.
[0003] In federated learning, since data comes from a variety of terminal devices, data heterogeneity will naturally arise, that is, the data is non-independent and identically distributed (non-IID). In earlier federated learning methods, all user data was brought into the same global model for training. After the training was completed, all users also used the same model for prediction. This approach treats non-IID data as independent and identically distributed data, ignoring the differences between user data, which will result in poor performance of the final trained global model.
[0004] Many scholars adopt the method of establishing multiple global models to conduct federated learning on non-IID user data. This method can be called multi-center federated learning. None of the existing multi-center federated learning methods can remove some abnormal client data. When the number of clients in federated learning is large, it is easy to have some abnormal devices. The existing methods use the DBSCAN (Density-Based Spatial Clustering of Applications with Noise) algorithm to cluster user model parameters, which can eliminate these abnormal clients. However, in the DBSCAN algorithm, the selection of the core object neighborhood parameters is crucial, but in the actual operation process, it is often unknown how to select the appropriate neighborhood parameters. In addition, the DBSCAN algorithm only classifies the clients in the first round of iterations. Due to reasons such as misaligned parameters and insufficient model training, some clients are more likely to be classified into the wrong category. Summary of the invention
[0005] In view of the above problems, embodiments of the present invention are proposed to provide a federated learning method, device, electronic device, and storage medium that overcome the above problems or at least partially solve the above problems.
[0006] In a first aspect, an embodiment of the present invention discloses a federated learning method, which is applied to a server in federated learning. The method includes:
[0007] Establishing a global parameter model and setting an initial value of the global parameter model;
[0008] Sending the initial value to each client in the federated learning; so that each client uses local data and the initial value for training, obtains each first local model parameter, and sends each first local model parameter to the server;
[0009] Obtaining first local model parameters;
[0010] If the clustering conditions for each first local model parameter are met, multiple category model parameters and global model parameters are obtained based on the training of each first local model parameter;
[0011] If the current number of iterations does not reach the iteration number threshold, each category model parameter, global model parameter and training instruction are sent to the corresponding client, so that each client adopts the corresponding category model parameter or global model parameter for training to obtain the trained local model parameters, and the trained local model parameters are sent to the server as the first local model parameters.
[0012] Optionally, the training based on each first local model parameter to obtain multiple category model parameters and global model parameters includes:
[0013] Clustering each first local model parameter to obtain multiple categories and non-clustered clients;
[0014] Aggregating the first local model parameters in each category to obtain multiple category model parameters corresponding to each category;
[0015] Aggregate multiple category model parameters to obtain global model parameters.
[0016] Optionally, clustering the first local model parameters to obtain multiple categories and non-clustered clients includes:
[0017] The hierarchical density-based spatial clustering with noise HDBSCAN is used to cluster the parameters of each first local model and generate a mutual reachability graph;
[0018] Generate a minimum spanning tree using the mutually reachable graph;
[0019] Using the minimum spanning tree to generate multiple clustering levels;
[0020] An optimal clustering level is determined from multiple clustering levels, and clustering results corresponding to the optimal clustering level are used as multiple categories, and the remaining clients are used as non-clustered clients.
[0021] Optionally, sending each category model parameter, the global model parameter and the training instruction to the corresponding client so that each client adopts the corresponding category model parameter or the global model parameter for training to obtain the trained local model parameter, and sending the trained local model parameter as each first local model parameter to the server includes:
[0022] Generate a training instruction, a first loss function identifier and a second loss function identifier; the first loss function identifier is used to indicate that the first loss function is used for training, and the second loss function identifier is used to indicate that the second loss function is used for training;
[0023] Each category model parameter, the training instruction and the first loss function identifier are sent to the client corresponding to each category, so that the client corresponding to each category responds to the training instruction, adopts the corresponding category model parameter and the first loss function to generate each second loss function, adopts the corresponding category model parameter and the corresponding second loss function for training to obtain each second local model parameter, and sends each second local model parameter to the server as each first local model parameter, and sends the global model parameter and the training instruction to the unclustered client, so that the unclustered client responds to the training instruction, adopts the global model parameter and the first loss function for training to obtain the third local model parameter, and sends the third local model parameter to the server as the first local model parameter.
[0024] Optionally, it also includes:
[0025] If the clustering condition for each first local model parameter is not satisfied, each first local model is trained independently.
[0026] Optionally, it also includes:
[0027] If the current number of iterations reaches the iteration number threshold, a stop training instruction is generated;
[0028] Each category model parameter and the stop training instruction are sent to the client corresponding to each category, so that the client corresponding to each category responds to the stop training instruction and uses the corresponding category model parameters as the final model parameters; and the global model parameters and the stop training instruction are sent to the unclustered client, so that the unclustered client responds to the stop training instruction and uses the global model parameters as the final model parameters.
[0029] Optionally, the clustering condition is detected by:
[0030] Detect whether the current clustering number reaches the clustering number threshold, and whether a new client joins the current iteration;
[0031] If the current clustering times reaches the clustering times threshold, and a new client joins the current iteration, the clustering condition is met; otherwise, the clustering condition is not met.
[0032] In a second aspect, an embodiment of the present invention discloses a federated learning device, the device comprising:
[0033] A generation module, used for establishing a global parameter model and setting an initial value of the global parameter model;
[0034] A sending module, used to send the initial value to each client in the federated learning; so that each client uses local data and the initial value for training, obtains each first local model parameter, and sends each first local model parameter to the server;
[0035] An acquisition module, used for acquiring each first local model parameter;
[0036] A first training module, configured to obtain a plurality of category model parameters and a global model parameter based on the training of each first local model parameter if a clustering condition for each first local model parameter is met;
[0037] The sending module is also used to send each category model parameter, global model parameter and training instruction to the corresponding client if the current number of iterations does not reach the iteration number threshold, so that each client adopts the corresponding category model parameter or global model parameter for training to obtain the trained local model parameters, and send the trained local model parameters as each first local model parameter to the server.
[0038] In a third aspect, the present invention further discloses an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the steps of the above-mentioned federated learning method when executed by the processor.
[0039] In a fourth aspect, the present invention further discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned federated learning method are implemented.
[0040] The embodiments of the present invention include the following advantages:
[0041] The server in the federated learning establishes a global parameter model and sets the initial value of the global parameter model, and then sends the initial value to each client in the federated learning; so that each client uses local data and the initial value for training to obtain each first local model parameter, and sends each first local model parameter to the server; obtains each first local model parameter; if the clustering conditions for each first local model parameter are met, multiple category model parameters and global model parameters are obtained based on the training of each first local model parameter; if the current number of iterations does not reach the iteration number threshold, each category model parameter, global model parameter and training instruction are sent to the corresponding client, so that each client uses the corresponding category model parameter or global model parameter for training to obtain the trained local model parameter, and sends the trained local model parameter as each first local model parameter to the server. In this way, after each client uses the initial value for the first round of training to obtain its corresponding local model parameters, the server can cluster the local model parameters. Since the HDBSCAN algorithm no longer relies on the selection of neighborhood parameters, it can automatically cluster according to the stability of the category, and can remove problematic model parameters (i.e., unclustered clients) while clustering, thereby obtaining multiple category model parameters and global model parameters. Different clients use the corresponding category model parameters or global model parameters for the next round of training to obtain their corresponding new local model parameters. The server uses each new local model parameter for the next round of clustering, and in this way, the corresponding model parameters of each client can be obtained. By performing clustering at each iteration, the server continuously maintains a global model parameter as the initial value for the next round of training for clients that fail clustering, so that even if the client is misclassified in the current iteration, it can be corrected in the subsequent clustering process, thereby improving the robustness of federated learning. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 is a flowchart of a federated learning method provided by an embodiment of the present invention;
[0043] Figure 2 is a flowchart of another federated learning method provided by an embodiment of the present invention;
[0044] Figure 3 is a structural block diagram of an electronic device provided by an embodiment of the present invention;
[0045] Figure 4 It is a structural block diagram of a computer-readable storage medium provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0047] like Figure 1 , shows a flowchart of the steps of a federated learning method provided by an embodiment of the present invention, which is applied to a server in multi-center federated learning, wherein the multi-center federated learning device may include: a server as a federated learning coordinator and a group of clients that need to jointly train a neural network model; the method may include the following steps:
[0048] Step 101: Establish a global parameter model and set the initial value of the global parameter model.
[0049] When joint training of each client is required, the server can establish a global parameter model and set the initial value of the global parameter model, denoted as Among them, the server can establish a global parameter model based on instructions for establishing a global parameter model, or establish a global parameter model when preset conditions are met, such as establishing a global parameter model when a certain time is reached, or trigger the establishment of a global parameter model by other means. In actual applications, the triggering method for establishing a global parameter model can be set according to actual needs, and the embodiments of the present invention are not limited to this.
[0050] Step 102: Send the initial value to each client in the federated learning; so that each client uses local data and the initial value for training, obtains each first local model parameter, and sends each first local model parameter to the server.
[0051] After the initial value is set, it can be sent to each client. Since the data in each client (for easy distinction, denoted as "local data") is different, each client can use its own local data and initial value for training after obtaining the initial value, so as to obtain the local model parameters corresponding to each client (denoted as "first local model parameters"), and then each client sends its own first local model parameters to the server, so that the server can use each first local model parameter for training.
[0052] It should be noted that the model in each client may be the same as the model in the server, that is, the parameters of the model in the server and each client may be the same, but the specific values of the parameters may be different.
[0053] Furthermore, when the client is performing local training, different clients have different corresponding loss functions. For the i-th client, the corresponding loss function is in, For local data, the goal of the training process is to minimize During training, the stochastic gradient descent method can be used to perform T local Rounds of iterations, each round of training uses the following formula:
[0054]
[0055] Among them, B i In each round of training, from local data A mini-batch of data randomly selected from local is the step size of model training.
[0056] Of course, in addition to the stochastic gradient descent method, other algorithms may also be used for training. In practical applications, they may be set according to actual needs, and the embodiments of the present invention do not limit this.
[0057] Step 103: Acquire various first local model parameters.
[0058] After each client obtains its corresponding first local model parameter through training, the server can obtain each first local model parameter from each client.
[0059] Step 104: If the clustering conditions for each first local model parameter are met, multiple category model parameters and global model parameters are obtained through training based on each first local model parameter.
[0060] After the server obtains each first local model parameter, if the server detects that the clustering conditions for clustering each first local model parameter are met, then each first local model parameter can be clustered to obtain category model parameters corresponding to each of the multiple categories, and the global model parameters can be obtained based on the multiple category model parameters.
[0061] In one embodiment, the training of obtaining multiple category model parameters and global model parameters based on each first local model parameter includes:
[0062] Clustering each first local model parameter to obtain multiple categories and non-clustered clients;
[0063] Aggregating the first local model parameters in each category to obtain multiple category model parameters corresponding to each category;
[0064] Aggregate multiple category model parameters to obtain global model parameters.
[0065] Specifically, when performing the current round of iteration, the server clusters each first local model parameter to obtain multiple categories C KEach category includes at least one client. If there are still clients that fail to be clustered, the clients that fail to be clustered are regarded as non-clustered clients. The non-clustered clients can be abnormal clients or newly added clients.
[0066] For example, there are a total of clients 1 to 10. After clustering the first local model parameters of all clients, the first local model parameters corresponding to clients 1, 2, and 3 belong to category 1, the first local model parameters corresponding to clients 4, 5, and 6 belong to category 2, the first local model parameters corresponding to clients 7 and 8 belong to category 3, and the first local model parameters corresponding to clients 9 and 10 belong to their respective corresponding unclustered clients.
[0067] For any category C K , the corresponding index set is Ind K For example, continuing with the above example, the index set corresponding to C1 is Ind1, and Ind1 includes indexes "client 1, client 2, client 3". Of course, the specific form of the index can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0068] It should be noted that after the clustering in the current round of iteration is completed, there may be one or more non-clustered clients, which may be scattered, and it is not necessary to classify all non-clustered clients as a category. Of course, for ease of management, all non-clustered clients may also be classified as a category. In actual applications, whether all non-clustered clients need to be classified as a category can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0069] Furthermore, when the unclustered clients are not considered as a category, an index set Ind K+1 , used to record all non-clustered clients, for example, continuing the example, Ind K+1 Includes indexes "client 9, client 10".
[0070] Furthermore, after clustering is completed in the current iteration, if a client is determined to be an unclustered client, it may be classified into a certain category or remain an unclustered client after multiple subsequent iterations. Therefore, clustering all clients in each iteration solves the problem of misclassification caused by clustering only once.
[0071] After obtaining multiple categories and unclustered clients, for any category, all first local model parameters contained therein are aggregated to obtain category model parameters corresponding to the category, and so on to obtain category model parameters corresponding to all categories.
[0072] Then all category model parameters are aggregated to obtain the global model parameters.
[0073] When aggregating all first local model parameters, the following formula may be used:
[0074]
[0075] Where |Ind k | represents the set Ind k The number of . Will send to Ind k Each client in .
[0076] Then use the following formula for aggregation to get the global model parameters:
[0077]
[0078] Will send to Ind K+1 Each client in .
[0079] In one embodiment, clustering the first local model parameters to obtain multiple categories and non-clustered clients includes:
[0080] The hierarchical density-based spatial clustering with noise HDBSCAN is used to cluster the parameters of each first local model and generate a mutual reachability graph;
[0081] Generate a minimum spanning tree using the mutually reachable graph;
[0082] Using the minimum spanning tree to generate multiple clustering levels;
[0083] An optimal clustering level is determined from multiple clustering levels, and clustering results corresponding to the optimal clustering level are used as multiple categories, and the remaining clients are used as non-clustered clients.
[0084] Specifically, when clustering the first local model parameters, the server can use the HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) algorithm to generate a mutual reachable graph, and then use the mutual reachable graph to generate a minimum spanning tree, and use the minimum spanning tree to generate multiple clustering levels, and then determine the optimal clustering level from the multiple clustering levels. The clustering results corresponding to the optimal clustering level can be used as multiple categories after clustering, and the remaining clients that have not been clustered are non-clustered clients.
[0085] For example, assuming that the number of clients participating in the current round of training is 10, that is, all the first local model parameters obtained by the server Perform HDBSCAN clustering on each data point in W as data X, calculate the core distance and mutual reachability distance of each data point, and obtain the mutual reachability graph Then adopt Generate a minimum spanning tree MST and use MST to generate three clustering levels:
[0086] Cluster level 1: category 1 (client 1, client 2), category 2 (client 3, client 4), category 3 (client 5, client 6), category 4 (client 7, client 8), client 9, client 10;
[0087] Cluster level 2: category 1 (client 1, client 2, client 3), category 2 (client 4, client 5, client 6), category 3 (client 7, client 8), client 9, client 10;
[0088] Cluster level 3: category 1 (client 1, client 2), category 2 (client 3, client 4, client 5, client 6), category 3 (client 7, client 8), client 9, client 10.
[0089] After solving, it is determined that clustering level 2 is the optimal clustering level. Then it can be determined that 3 categories are obtained after clustering, and client 9 and client 10 are non-clustered clients.
[0090] Since the HDBSCAN algorithm no longer relies on the selection of neighborhood parameters, it can automatically perform clustering according to the stability of the categories and remove problematic model parameters (ie, non-clustered clients) while clustering.
[0091] For ease of understanding, the basic process of the HDBSCAN algorithm is described below. Lowercase letters (such as x) represent scalars. represents a vector, and capital letters (such as X) represent matrices or data sets. represents a data set containing n data points, Indicate point and The distance between.
[0092] Definition 1: (Core Distance) Object About m pts Core distance yes With its mth pts The nearest point (including ) distance.
[0093] Definition 2: (mutual reachability) points and About m pts The mutual reachability distance is defined as
[0094] Definition 3: (Mutually reachable graph) It is a complete graph (i.e. any two vertices are connected), its vertices are each point in X, and the weight of the edge between each two vertices is the mutual reachable distance between the two points.
[0095] The main idea of HDBSCAN is to first generate a minimum spanning tree based on the mutually reachable graph of data points. At this time, all points are connected together and they are considered to belong to the same class (set class labels). Then the largest edge is deleted and the tree is divided into two parts. At this time, it can be divided into the following cases:
[0096] a. There are many points on both sides. In this case, the tree is divided into two subtrees, and the data points of each subtree belong to different categories (new labels are set for the two categories).
[0097] b. There are more data points on one side, and fewer on the other side. The side with more data points is used as a subtree, and its points belong to one category (inheriting the label corresponding to the tree before deleting the side), and the other side is classified as noise points.
[0098] c. The number of points on both sides is small, and the points on both sides are classified as noise points. Here we set the number of points less than m clSize The data points are set as noise points.
[0099] Next, the same operation is performed on each subtree until all categories disappear (that is, all points are classified as noise points). Next, the optimal division level is selected from the above division levels.
[0100] To judge the optimal level, we need to establish the following concepts. First, we use the mutual reachability distance d mreach The inverse of λ = 1 / d mreach To measure the level of the category (this level represents the density of the category to a certain extent, and the larger the value, the greater the density of the category). k , and its stability is defined as:
[0101]
[0102] where λ min (C k ) is C k The minimum level of existence, For point No longer in Category Ck when the level.
[0103] HDBSCAN first extracts the clustering hierarchy as a dendrogram. The main steps are as follows:
[0104] 1) Calculate the relationship between each point in X and m pts core distance.
[0105] 2) Calculate the mutual reachability distance between any two points to form a mutual reachability graph
[0106] 3) Generated using Prime algorithm The minimum spanning tree MST.
[0107] 4) Extracting a hierarchical clustering structure from the MST (in the embodiment of the present invention, forming a dendrogram of categories) is divided into the following steps:
[0108] a) Set the root node category label of the category dendrogram to C1, which corresponds to the current MST.
[0109] b) Find the edge with the largest length (length d) from all sub-MSTs del ), assuming that its corresponding category is C k , remove this edge from the sub-MST. Suppose the number of vertices of the two new subtrees after the removal is m l and m r , which can be divided into the following situations:
[0110] I) If m l ≥m clSize ,m r <m clSize or m l <m clSize ,m r ≥m clSize .by
[0111] m l ≥m clSize ,m r <m clsize For example, for m l <m clSize ,m r ≥m clSize If necessary, just swap the two sides.
[0112] Remove m from this sub-MST r These vertices corresponding to one side. l The tree formed on the corresponding side still corresponds to the class label C k , set this m r points no longer belong to category C kThe level is Then go to step b.
[0113] II) If m l ≥m clsize and m r ≥m clsize Then the two sides of the disconnection form subtrees (sub-MSTs) respectively, and two child nodes are added to the node corresponding to the current category in the category tree diagram, and they correspond to the two sub-MSTs, and they are labeled, assuming that they are C l ,C r For C l , and record the index set of its points as Set the level at which categories are generated For C r , similarly, the index set of the record points is Set the level at which categories are generated
[0114] Next, determine whether the current category label is C1. If it is C1, go directly to step b; if it is not C1, set this m l +m r points no longer belong to category C k The level is Then use the formula
[0115]
[0116] Calculation Category C k Then go to step b.
[0117] III) If m l <m clSize and m r <m clSize Remove this m from this sub-MST l +m r point, set this m l +m r points no longer belong to category C k The level is Then use the formula
[0118]
[0119] Calculation Category C k Then go to step b.
[0120] Then continue step b for each sub-MST until all points are set as noise points.
[0121] After step 4, a dendrogram of categories is formed. Except for C1, each category can be calculated to get a stability value, and each category has two subcategories (or no subcategories). Then these stability values can be used to cluster the data points. The goal is to find the most stable clustering method. The specific steps are as follows:
[0122] 5) Initialize the category label δ2 = ... = δ K =1, where K is the total number of categories generated in step 4.
[0123] Set the overall stability of the category
[0124] 6) Starting from the deepest layer, compare the category stability S(C i ) and its two subcategories The sum of . There are two cases:
[0125] a) If Set the overall stability of the current category to And set δ i =0.
[0126] b) If Set the overall stability of the current category to And for C i All categories in the subtree are set to δ (·) =0.
[0127] 7) Take out those category labels δ k =1 Category C k and the index set of corresponding points The clustering results can be obtained, and the remaining points are outliers.
[0128] In one embodiment, the clustering condition is detected by:
[0129] Detect whether the current clustering number reaches the clustering number threshold, and whether a new client joins the current iteration;
[0130] If the current clustering times reaches the clustering times threshold, and a new client joins the current iteration, the clustering condition is met; otherwise, the clustering condition is not met.
[0131] Specifically, when determining whether the clustering condition is met, the server can detect whether the number of clustering times reaches the clustering times threshold after the clustering of the current iteration is completed, and whether there are new clients joining the current iteration. If the number of clustering times reaches the clustering times threshold, and there are new clients joining the current iteration, then it can be determined that the clustering condition is met, so that clustering is performed for each first local model parameter. If the number of clustering times does not reach the clustering times threshold, or there are no new clients joining the current iteration, then it can be determined that the clustering condition is not met.
[0132] Since clustering requires a large amount of computation and takes a long time to calculate, if clustering is performed in each iteration, it will cause a large training burden on the server. Moreover, after a certain number of iterations, the clustering of the model parameters will basically stabilize. Therefore, if no new clients join, clustering can be stopped after a certain number of clusterings, thereby reducing the training burden on the server and speeding up the training. However, since adding new clients during multiple rounds of iterations may cause the new clients to be determined as non-clustered clients, clustering can continue when a new client is detected to ensure that the new client will not be misclassified.
[0133] Step 105: If the current number of iterations does not reach the iteration number threshold, each category model parameter, global model parameter and training instruction are sent to the corresponding client, so that each client adopts the corresponding category model parameter or global model parameter for training to obtain the trained local model parameters, and the trained local model parameters are sent to the server as each first local model parameter.
[0134] After the current round of iterations is completed, the server can detect whether the number of current iterations reaches the iteration number threshold. If not, each category model parameter, global model parameter and training instruction can be sent to the corresponding client. After obtaining the corresponding model parameters and training instructions, each client uses the corresponding model parameters for training to obtain the trained local model parameters. Then, each client sends its trained local model parameters as the first local model parameters to the server. After obtaining each new first local model parameter, the server can use each first local model parameter for the next round of iterations. Among them, a client can obtain one of the category model parameters and the global model parameters at a time, and cannot obtain them at the same time.
[0135] In one embodiment, sending each category model parameter, the global model parameter and the training instruction to the corresponding client so that each client adopts the corresponding category model parameter or the global model parameter for training to obtain the trained local model parameter, and sending the trained local model parameter as each first local model parameter to the server includes:
[0136] Generate a training instruction, a first loss function identifier and a second loss function identifier; the first loss function identifier is used to indicate that the first loss function is used for training, and the second loss function identifier is used to indicate that the second loss function is used for training;
[0137] Each category model parameter, the training instruction and the first loss function identifier are sent to the client corresponding to each category, so that the client corresponding to each category responds to the training instruction, adopts the corresponding category model parameter and the first loss function to generate each second loss function, adopts the corresponding category model parameter and the corresponding second loss function for training to obtain each second local model parameter, and sends each second local model parameter to the server as each first local model parameter, and sends the global model parameter and the training instruction to the unclustered client, so that the unclustered client responds to the training instruction, adopts the global model parameter and the first loss function for training to obtain the third local model parameter, and sends the third local model parameter to the server as the first local model parameter.
[0138] Specifically, if the current number of iterations does not reach the iteration number threshold, then a training instruction can be generated, the training instruction is used to indicate that the client needs to perform training, and a first loss function identifier and a second loss function identifier are generated. The first loss function identifier is used to instruct the client to use the first loss function for training, and the second loss function identifier is used to instruct the client to use the second loss function for training.
[0139] For any category, the server can send the category model parameters, training instructions and first loss function identifier corresponding to the category to each client corresponding to the category. For any client, after obtaining the category model parameters, training instructions and first loss function identifier, in response to the training instruction, the category model parameters and the first loss function are used to generate the second loss function, and then the category model parameters and the second loss function are used for training to obtain the second local model parameters. By analogy, the second local model parameters of all clients under all categories can be obtained, and each client can send its corresponding second local model parameters to the server.
[0140] Among them, the first loss function can be the one mentioned above When generating the second loss function, a proximal term can be added to the first loss function That is to say, the second loss function corresponding to different clients is also different. If the i-th client is classified into the k-th category, then its training goal is to minimize the following function:
[0141]
[0142] in is the category model parameter of the category to which the i-th client belongs received from the server (see above for details), and the hyperparameter λ controls and Correspondingly, the local model of the client is updated as follows:
[0143]
[0144] For each unclustered client, the server can send the global model parameters, training instructions and the first loss function identifier to each client. For any unclustered client, after obtaining the global model parameters, training instructions and the first loss function identifier, it responds to the training instructions and uses the global model parameters and the first loss function for training to obtain the third local model parameters, and then each client sends its corresponding third local model parameters to the server.
[0145] The purpose of setting the global model is to:
[0146] 1. Some clients may join the federated learning process in the middle due to a fault. They can use the global model as the initial value for the next round of training.
[0147] 2. Due to the misalignment of model parameters or insufficient training, some clients may be mistakenly classified as non-clustered clients. They cannot be discarded directly, so that they can use the global model for the next cycle.
[0148] 3. An individual client may have a temporary failure and send problematic model parameters. After a period of time, it returns to normal, allowing it to still use the global model for the next cycle.
[0149] In this way, even if the client is misclassified in the current iteration, it can be corrected in the subsequent clustering process. In addition, for the local training of the client within the category, a proximal term is added to its loss function based on the corresponding category model parameters, thereby accelerating the convergence of the model and enhancing the robustness of the clustering model.
[0150] In an embodiment of the present invention, a server in federated learning establishes a global parameter model, sets an initial value of the global parameter model, and then sends the initial value to each client in the federated learning; so that each client uses local data and the initial value for training to obtain each first local model parameter, and sends each first local model parameter to the server; obtains each first local model parameter; if the clustering conditions for each first local model parameter are met, multiple category model parameters and global model parameters are obtained based on the training of each first local model parameter; if the current number of iterations does not reach the iteration number threshold, each category model parameter, global model parameter and training instruction are sent to the corresponding client, so that each client uses the corresponding category model parameter or global model parameter for training to obtain the trained local model parameter, and sends the trained local model parameter as each first local model parameter to the server. In this way, after each client uses the initial value for the first round of training to obtain its corresponding local model parameters, the server can cluster the local model parameters. Since the HDBSCAN algorithm no longer relies on the selection of neighborhood parameters, it can automatically cluster according to the stability of the category, and can remove problematic model parameters (i.e., unclustered clients) while clustering, thereby obtaining multiple category model parameters and global model parameters. Different clients use the corresponding category model parameters or global model parameters for the next round of training to obtain their corresponding new local model parameters. The server uses each new local model parameter for the next round of clustering, and in this way, the corresponding model parameters of each client can be obtained. By performing clustering at each iteration, the server continuously maintains a global model parameter as the initial value for the next round of training for clients that fail clustering, so that even if the client is misclassified in the current iteration, it can be corrected in the subsequent clustering process, thereby improving the robustness of federated learning.
[0151] like Figure 2 , shows a flowchart of another method for federated learning provided by an embodiment of the present invention, which is applied to a server in federated learning. The method may include the following steps:
[0152] Step 201: Establish a global parameter model and set the initial value of the global parameter model.
[0153] Step 202: Send the initial value to each client in the federated learning; so that each client uses local data and the initial value for training, obtains each first local model parameter, and sends each first local model parameter to the server.
[0154] Step 203: Acquire various first local model parameters.
[0155] Step 204: If the clustering conditions for each first local model parameter are met, multiple category model parameters and global model parameters are obtained through training based on each first local model parameter.
[0156] Step 205: If the current number of iterations does not reach the iteration number threshold, each category model parameter, global model parameter and training instruction are sent to the corresponding client, so that each client uses the corresponding category model parameter or global model parameter for training to obtain the trained local model parameters, and the trained local model parameters are sent to the server as each first local model parameter.
[0157] Among them, steps 201 to 205 are substantially the same as steps 101 to 105, and will not be described here to avoid repetition.
[0158] Step 206: If the clustering condition for each first local model parameter is not satisfied, each first local model is trained independently.
[0159] Since clustering requires a large amount of computation and takes a long time to calculate, if clustering is performed in each iteration, it will cause a large training burden on the server. Moreover, after a certain number of iterations, the clustering of the model parameters will basically stabilize. Therefore, when the clustering conditions are not met, each first local model can be trained independently, such as using Trimmed-Mean, Mult-Krum and other algorithms for training, thereby reducing the training burden on the server and speeding up the training. Of course, the specific algorithm used for training can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0160] Step 207: If the current number of iterations reaches the iteration number threshold, a stop training instruction is generated.
[0161] After the current round of iterations is completed, the server can detect whether the number of current iterations reaches the iteration number threshold. If it has reached it, the iteration can be ended. At this time, a stop training instruction can be generated, which is used to instruct the client to stop training.
[0162] Step 208: Send each category model parameter and the stop training instruction to the client corresponding to each category, so that the client corresponding to each category responds to the stop training instruction and uses the corresponding category model parameters as the final model parameters; and send the global model parameters and the stop training instruction to the unclustered client, so that the unclustered client responds to the stop training instruction and uses the global model parameters as the final model parameters.
[0163] Specifically, after generating a stop training instruction, the server can send the stop training instruction and the category model parameters corresponding to the category to any client in any category. After receiving the stop training instruction, the client will no longer perform training. At the same time, the category model parameters will be predicted as the final model parameters of the client.
[0164] Similarly, each non-clustered client will not continue training after receiving the stop training instruction. At the same time, the global model parameters will be used as the final model parameters for prediction.
[0165] In the embodiment of the present invention, when the clustering condition is not met, the server can independently train each first local model, thereby reducing the training burden of the server and speeding up the training. Further, when it is detected that the current number of iterations reaches the iteration threshold, the iteration can be stopped so that each client can obtain its own corresponding and final model parameters, further reducing the training burden of the server and speeding up the training.
[0166] The present invention also provides a federated learning device, comprising:
[0167] A generation module, used for establishing a global parameter model and setting an initial value of the global parameter model;
[0168] A sending module, used to send the initial value to each client in the federated learning; so that each client uses local data and the initial value for training, obtains each first local model parameter, and sends each first local model parameter to the server;
[0169] An acquisition module, used for acquiring each first local model parameter;
[0170] A first training module, configured to obtain a plurality of category model parameters and a global model parameter based on the training of each first local model parameter if a clustering condition for each first local model parameter is met;
[0171] The sending module is also used to send each category model parameter, global model parameter and training instruction to the corresponding client if the current number of iterations does not reach the iteration number threshold, so that each client adopts the corresponding category model parameter or global model parameter for training to obtain the trained local model parameters, and send the trained local model parameters as each first local model parameter to the server.
[0172] Optionally, the first training module includes:
[0173] A clustering submodule, used for clustering each first local model parameter to obtain multiple categories and non-clustered clients;
[0174] an aggregation submodule, configured to aggregate the first local model parameters in each category to obtain a plurality of category model parameters corresponding to each category; and
[0175] Aggregate multiple category model parameters to obtain global model parameters.
[0176] Optionally, the clustering submodule is specifically used to:
[0177] The hierarchical density-based spatial clustering with noise HDBSCAN is used to cluster the parameters of each first local model and generate a mutual reachability graph;
[0178] Generate a minimum spanning tree using the mutually reachable graph;
[0179] Using the minimum spanning tree to generate multiple clustering levels;
[0180] An optimal clustering level is determined from multiple clustering levels, and clustering results corresponding to the optimal clustering level are used as multiple categories, and the remaining clients are used as non-clustered clients.
[0181] Optionally, the sending module is specifically used to:
[0182] Generate a training instruction, a first loss function identifier and a second loss function identifier; the first loss function identifier is used to indicate that the first loss function is used for training, and the second loss function identifier is used to indicate that the second loss function is used for training;
[0183] Each category model parameter, the training instruction and the first loss function identifier are sent to the client corresponding to each category, so that the client corresponding to each category responds to the training instruction, adopts the corresponding category model parameter and the first loss function to generate each second loss function, adopts the corresponding category model parameter and the corresponding second loss function for training to obtain each second local model parameter, and sends each second local model parameter to the server as each first local model parameter, and sends the global model parameter and the training instruction to the unclustered client, so that the unclustered client responds to the training instruction, adopts the global model parameter and the first loss function for training to obtain the third local model parameter, and sends the third local model parameter to the server as the first local model parameter.
[0184] Optionally, it also includes:
[0185] The second training module is used to independently train each first local model if the clustering condition for each first local model parameter is not met.
[0186] Optionally, the generating module is further configured to: generate a stop training instruction if the current number of iterations reaches the iteration number threshold;
[0187] The sending module is further used to send each category model parameter and the stop training instruction to the client corresponding to each category, so that the client corresponding to each category responds to the stop training instruction and uses the corresponding category model parameters as the final model parameters, and to send the global model parameters and the stop training instruction to the unclustered client, so that the unclustered client responds to the stop training instruction and uses the global model parameters as the final model parameters.
[0188] Optionally, a detection module is also included, specifically used for:
[0189] Detect whether the current clustering number reaches the clustering number threshold, and whether a new client joins the current iteration;
[0190] If the current clustering times reaches the clustering times threshold, and a new client joins the current iteration, the clustering condition is met; otherwise, the clustering condition is not met.
[0191] like Figure 3 , showing a structural block diagram of an electronic device 30 provided in an embodiment of the present invention, including:
[0192] A processor 301, a memory 302, and a computer program 3021 stored in the memory 302 and capable of running on the processor 301. When the computer program 3021 is executed by the processor 301, each process of the above-mentioned federated learning method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0193] like Figure 4 , shows a structural block diagram of a computer-readable storage medium 40 provided in an embodiment of the present invention. A computer program 401 is stored on the computer-readable storage medium 40. When the computer program 401 is executed by the processor, the various processes of the above-mentioned federated learning method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0194] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0195] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0196] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0197] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0198] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0199] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0200] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0201] The above is a detailed introduction to a federated learning method, device, electronic device and storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A federated learning method, characterized in that: Applied to a server in federated learning, the method comprises: Establishing a global parameter model and setting an initial value of the global parameter model; Sending the initial value to each client in the federated learning; so that each client uses local data and the initial value for training, obtains each first local model parameter, and sends each first local model parameter to the server; Obtaining first local model parameters; If the clustering conditions for each first local model parameter are met, multiple category model parameters and global model parameters are obtained based on the training of each first local model parameter; If the current number of iterations does not reach the iteration number threshold, each category model parameter, global model parameter and training instruction are sent to the corresponding client, so that each client adopts the corresponding category model parameter or global model parameter for training to obtain the trained local model parameters, and the trained local model parameters are sent to the server as the first local model parameters.
2. The federated learning method according to claim 1, characterized in that: The training of obtaining multiple category model parameters and global model parameters based on each first local model parameter includes: Clustering each first local model parameter to obtain multiple categories and non-clustered clients; Aggregating the first local model parameters in each category to obtain multiple category model parameters corresponding to each category; Aggregate multiple category model parameters to obtain global model parameters.
3. The federated learning method according to claim 2, characterized in that: The clustering of the first local model parameters to obtain multiple categories and non-clustered clients includes: The hierarchical density-based spatial clustering with noise HDBSCAN is used to cluster the parameters of each first local model and generate a mutual reachability graph; Generate a minimum spanning tree using the mutually reachable graph; Using the minimum spanning tree to generate multiple clustering levels; An optimal clustering level is determined from multiple clustering levels, and clustering results corresponding to the optimal clustering level are used as multiple categories, and the remaining clients are used as non-clustered clients.
4. The federated learning method according to claim 1, characterized in that: The sending of each category model parameter, the global model parameter and the training instruction to the corresponding client so that each client adopts the corresponding category model parameter or the global model parameter for training to obtain the trained local model parameter, and sending the trained local model parameter as each first local model parameter to the server includes: Generate a training instruction, a first loss function identifier and a second loss function identifier; the first loss function identifier is used to indicate that the first loss function is used for training, and the second loss function identifier is used to indicate that the second loss function is used for training; Each category model parameter, the training instruction and the first loss function identifier are sent to the client corresponding to each category, so that the client corresponding to each category responds to the training instruction, adopts the corresponding category model parameter and the first loss function to generate each second loss function, adopts the corresponding category model parameter and the corresponding second loss function for training to obtain each second local model parameter, and sends each second local model parameter to the server as each first local model parameter, and sends the global model parameter and the training instruction to the unclustered client, so that the unclustered client responds to the training instruction, adopts the global model parameter and the first loss function for training to obtain the third local model parameter, and sends the third local model parameter to the server as the first local model parameter.
5. The federated learning method according to claim 1, characterized in that: Also includes: If the clustering condition for each first local model parameter is not satisfied, each first local model is trained independently.
6. The federated learning method according to claim 1, characterized in that: Also includes: If the current number of iterations reaches the iteration number threshold, a stop training instruction is generated; Each category model parameter and the stop training instruction are sent to the client corresponding to each category, so that the client corresponding to each category responds to the stop training instruction and uses the corresponding category model parameters as the final model parameters; and the global model parameters and the stop training instruction are sent to the unclustered client, so that the unclustered client responds to the stop training instruction and uses the global model parameters as the final model parameters.
7. The federated learning method according to claim 1, characterized in that: The clustering condition is detected by: Detect whether the current clustering number reaches the clustering number threshold, and whether a new client joins the current iteration; If the current clustering times reaches the clustering times threshold, and a new client joins the current iteration, the clustering condition is met; Otherwise, the clustering condition is not met.
8. A federated learning device, characterized in that: The device comprises: A generation module, used for establishing a global parameter model and setting an initial value of the global parameter model; A sending module, used to send the initial value to each client in the federated learning; so that each client uses local data and the initial value for training, obtains each first local model parameter, and sends each first local model parameter to the server; An acquisition module, used for acquiring each first local model parameter; A first training module, configured to obtain a plurality of category model parameters and a global model parameter based on the training of each first local model parameter if a clustering condition for each first local model parameter is met; The sending module is also used to send each category model parameter, global model parameter and training instruction to the corresponding client if the current number of iterations does not reach the iteration number threshold, so that each client adopts the corresponding category model parameter or global model parameter for training to obtain the trained local model parameters, and send the trained local model parameters as each first local model parameter to the server.
9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the federated learning method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the federated learning method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Self-adaptive hierarchical distributed learning method and system for industrial production line data isomerism
CN121543033A
