A personalized federated learning method and system based on adaptive clustering hierarchy
By employing a personalized federated learning method based on adaptive clustering hierarchy, and utilizing a fusion algorithm of customer clustering and adaptive hierarchy, the performance imbalance between the global and local models caused by data heterogeneity in federated learning is resolved, resulting in better model adaptability and generalization performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-16
- Publication Date
- 2026-04-10
AI Technical Summary
Existing federated learning methods struggle to train a single model applicable to all clients when faced with statistical heterogeneity in data, leading to an imbalance in the performance of global and local models. Furthermore, cluster-based personalized methods lack flexibility, impacting the generalization performance of the global model.
We employ a personalized federated learning approach with adaptive clustering hierarchy. By combining customer clustering and adaptive hierarchical fusion algorithms, we utilize customer performance feedback for clustering and model training, flexibly formulate personalized strategies, and combine the advantages of global and local models to improve personalized performance.
Without compromising global generalization ability, it significantly improves the personalized performance of local customer models, solves the performance imbalance problem caused by data statistical heterogeneity, and achieves better model adaptability and generalization ability.
Smart Images

Figure CN115840900B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of distributed machine learning, and particularly relates to a personalized federated learning method and system based on adaptive clustering layering. BACKGROUND
[0002] With the advent of the cloud era and the popularity of edge devices (such as smart phones and smart wearable devices), data is being generated at all times and in all places, and even in an explosive manner. These rich data provide great opportunities for machine learning applications, such as in speech recognition and computer vision, where deep neural networks can effectively extract the required information with a large amount of training data. However, as society becomes increasingly concerned about data privacy, a large amount of data generated in edge devices or organizations (such as hospitals, companies, and courts) cannot be collected into a central server, which poses a great challenge to deep learning.
[0003] Federated learning is a deep learning framework in which clients can collaboratively train a shared global model to process their data under the coordination of a central server, while maintaining the privacy of the data and reducing systematic privacy risks and communication costs. Most existing training methods are variants of federated averaging, and traditional federated learning focuses on obtaining a high-quality and general-purpose global model by learning the local data of participating clients. However, in the presence of data statistical heterogeneity (such as non-independent and identically distributed and unbalanced data), federated learning has difficulty in training a single model that is suitable for all clients. Optimizing the global model alone can lead to poor performance of the local model, as the global model is not adapted to each client. This problem is further exacerbated as the differences between the local data of different clients become greater.
[0004] To alleviate the problem of data statistical heterogeneity causing federated learning performance to decline, personalized federated learning has become a solution. Personalized federated learning aims to train unique personalized models for different clients, which can combine the generalization characteristics of the global model and the distribution matching characteristics of the local model, but the challenge lies in how to strike a delicate balance between the specific knowledge of the local model and the shared knowledge of the global model. In recent years, in the exploration of personalized federated learning, many works have focused on two possible solutions: clustering-based personalization and layering-based personalization. The clustering-based personalization method groups clients with similar data distributions into clusters and trains a dedicated model for each cluster group. The layering-based personalization method personalizes certain layers of the local model, while other layers are derived from the global model.
[0005] Although both of these two solutions can improve the performance of federated learning through personalization, there are still problems that cannot be ignored. Current clustering-based personalization methods pay little attention to model sharing between groups, so they may affect the generalization performance of the global model. At the same time, existing layer-based personalization methods usually adopt a pre-defined hierarchical scheme, which lacks flexibility and adaptability. Therefore, they may eventually get a suboptimal solution, resulting in an imbalance between the performance of the global model and the local model.
[0006] The invention with application number 202210511356.6 provides a federated learning method and system, which includes: S1, sending an initial global model to all clients, and uploading an initial local model to the central service system by the client; S2, clustering the clients according to the initial local model uploaded by the client to obtain more than one client class; S3, performing multiple rounds of iterative training on the global model until the iteration stopping condition is reached, the tth round of iterative training: selecting at least one client from each client class to participate in training; judging whether there is a gradient conflict between the clients participating in the tth round of iterative training based on the tth round of local model returned by the client and the tth round of loss function value, and obtaining cumulative model difference according to the gradient conflict; updating the tth round of global model using the cumulative model difference. The reasons for model unfairness are divided into external contradictions and internal contradictions to eliminate them, improve the representativeness and fairness of the selected clients, reduce the number of training rounds and communication costs, and speed up convergence. However, this invention cannot solve the problems of imbalance between the performance of the global model and the local model, and poor generalization performance of the global model. SUMMARY
[0007] The technical problem solved by the present invention is to provide a personalized federated learning method and system based on adaptive clustering and hierarchical layering, which solves the problem of data statistical heterogeneity in federated learning and the imbalance between the performance of the global model and the local model in personalized federated learning. By integrating the client clustering method and the adaptive hierarchical fusion algorithm, the performance feedback of the clients is used for clustering grouping and adaptive hierarchical fusion, and personalized strategies are flexibly formulated for specific federated learning tasks, achieving the technical effect of greatly improving the individual performance of the client local model without compromising the global generalization ability.
[0008] Technical solution:
[0009] A personalized federated learning method based on adaptive clustering and hierarchical layering, the personalized federated learning method comprising the following steps:
[0010] S1, the client prepares the training data set and test data set of the prediction task, and the global parameter server randomly initializes the global model parameters;
[0011] S2, the global parameter server sends the global model parameters to the client, instructing the client to use the received global model parameters as the initial parameters of the local model, train the model in the current round using the local training dataset, evaluate the model's prediction performance using the test dataset after training, calculate the gradient, and upload the calculated gradient to the parameter server; the parameter server performs a weighted average of the gradients received from all clients, and adjusts the global model parameters using the calculated average gradient;
[0012] S3, Repeat step S2 until the training rounds reach the maximum number of communication rounds in the first stage, then proceed to step S4;
[0013] S4, the parameter server calculates the similarity between clients based on the gradients uploaded by all clients in the most recent round, clusters all clients according to the calculation results, selects a group server for each client group, and generates a personalized weight vector with hierarchical structure within each client group.
[0014] S5, the parameter server sends the latest global model parameters to all group servers, and the group servers iteratively execute personalized federated learning training within the group, and upload the latest group model parameters obtained to the parameter server; the parameter server then weights and averages the latest group model parameters received from all client groups to obtain a new global model;
[0015] S6. Repeat step S5 until the training rounds reach the maximum number of rounds or the model has converged, then end the process.
[0016] Further, in step S2, the global parameter server sends the global model parameters to the client, instructing the client to use the received global model parameters as the initial parameters of the local model, train the model using the local training dataset for the current round, and evaluate the model's prediction performance using the test dataset after training, calculate the gradient, and upload the calculated gradient to the parameter server. The process includes the following steps:
[0017] S21, the global parameter server will send model W g The parameters of the t-th round Distributed to K clients participating in federated learning training; t∈[1,T] pre ], where T pre The maximum number of communication rounds in the first phase, and the parameters for round 1. The model is obtained by randomly initializing it from the global parameter server;
[0018] S22, in each receiving model W g The parameters of the t-th round The following training steps are performed in parallel on the client:
[0019] S221, the client will use model W g The parameters of the t-th round As the initial model parameters, let them be denoted as This represents the initial model parameters of the k-th client-side local model in round t.
[0020] S222, based on initial model parameters The training dataset consists of N samples randomly drawn from the original data held by the customer. The client trains and optimizes the local model using stochastic gradient descent for E rounds of local iterations to obtain the optimized model parameters.
[0021] S223, the client uses the optimized model parameters. For the test dataset Perform predictive inference, evaluate the prediction performance, and calculate the gradient.
[0022] S224, The client will transfer gradient g k Send to the global parameter server.
[0023] Further, in step S222, the optimized model parameters are calculated using the following formula.
[0024]
[0025]
[0026] in, This represents the sampled training dataset. The number of samples, Here, x and y represent the loss value, respectively, the features and corresponding labels of a single sample in the dataset. Indicates the model output results The loss between the true value y and the actual value y, where η represents the learning rate. express for The gradient.
[0027] Further, in step S2, the parameter server performs a weighted average of the gradients received from all clients, and the process of adjusting the global model parameters using the calculated average gradient includes the following steps:
[0028] The global parameter server uses the client's training dataset. The number of samples n k Calculate the weight ratio γ of client k k =n k / ∑ k∈K nk ;
[0029] The FedAvg algorithm is used to weight and aggregate the gradients of all K clients participating in the federated learning training to obtain the model parameters for round t+1.
[0030]
[0031] Further, in step S4, the parameter server calculates the similarity between clients based on the gradients uploaded by all clients in the most recent round, and clusters all clients according to the calculation results. The process of selecting a group server for each client group includes the following steps:
[0032] S41, the parameter server according to the Tth pre Gradients {g} uploaded by all clients k} k∈K By calculating the cosine similarity S between every two client gradients C , obtain the similarity matrix ρ; where ρ i,j =S C (i,j), S C (i,j)=(g i ·g j ) / (||g i ||·|g j ||);
[0033] S42, based on the similarity matrix ρ, uses a top-down hierarchical clustering algorithm to cluster K clients into M client groups, denoted as...
[0034] S43 selects a group server for each client group to coordinate the training of clients within the group.
[0035] S44 instructs each client group's group server to copy a copy of model W from the global parameter server. g The Tth pre Wheel parameters As a client group server model W m parameters Where m∈{1,2,…,M}.
[0036] Furthermore, in step S4, the process of generating personalized weight vectors with intra-group stratification for each customer group includes the following steps:
[0037] Calculate the group average gradient based on the gradients of the clients within the group.
[0038]
[0039] average gradient Expanding by model parameter layer, it is represented as follows: Where l is the total number of model parameter layers;
[0040] For the average gradient The Euclidean distance is calculated layer by layer to obtain a 1×l-dimensional vector δ. m :
[0041]
[0042] Define a hyperparameter β to adjust the degree of personalization, and set δ m After normalization, multiplying by β yields the personalized model weights ψ for stratification within groups. m :
[0043] ψ m =β·δ m / max(δ m ).
[0044] Further, in step S5, the parameter server sends the latest global model parameters to all group servers, and the group servers iteratively execute personalized federated learning training within their groups. The process of uploading the latest group-specific model parameters to the parameter server includes the following steps:
[0045] S51, the global parameter server will send model W g The parameters of the t-th round Distribute to M client group servers; t∈(T) pre ,T total ), where T pre ,T total These are the maximum number of communication rounds in the first phase and the maximum number of communication rounds in the second phase, respectively.
[0046] S52 executes the following steps in parallel on each client group server:
[0047] S521, the group server receives the global model W from the parameter server. g The parameters of the t-th round
[0048] S522, the group server will use the global model W in the t-th round. g parameters With group model W m parameters Personalized model weights ψ using group-level stratification m Layer-by-layer weighted fusion will group the model W m The parameters are updated to The weighted fusion process first... and Decomposed into layers and Then, the parameters of each layer are fused together, using the following formula:
[0049]
[0050]
[0051] in express The parameters of the nth layer, express The parameters of the nth layer, n∈{1,2,…,l};
[0052] S523, the group server will group model W m parameters Distribute to clients within the group;
[0053] S53, in each receiver group model W m The parameters of the t-th round The following training steps are performed in parallel on the client:
[0054] S531, the client will group model W m The parameters of the t-th round As the initial model parameters, let them be denoted as This represents the initial model parameters of the k-th client-side local model in round t.
[0055] S532, based on initial model parameters The training dataset consists of N samples randomly drawn from the original data held by the customer. The client trains and optimizes the local model using stochastic gradient descent (SGD) for E rounds of local iterations to obtain the optimized model parameters.
[0056] S534, the client uses the optimized model parameters. For the test dataset Perform predictive inference, evaluate the prediction performance, and calculate the gradient.
[0057] S535, the client will transfer gradient g k Send to the corresponding group server;
[0058] S54, each group server trains the dataset based on the client training dataset within the group. The number of samples n k Calculate the weight ratio of client k within the group. The gradients of clients within the group are weighted and aggregated using the FedAvg algorithm to update the group server model W. m parameters The specific calculation formula is:
[0059]
[0060] S55, judge whether the iteration number reaches the maximum communication round of the second stage, if the condition is met, execute S56, otherwise continue to execute S523 to S54;
[0061] S56, send the group server model W m The updated parameters are denoted as The group server sends the parameters m of the group server model W to the global parameter server.
[0062] Further, in step S5, the process that the parameter server aggregates the latest group model parameters sent by all client groups to obtain a new global model includes the following steps:
[0063] The global parameter server uses the federated average algorithm FedAvg to aggregate the model parameters sent by all group servers to obtain the parameters g of the t+1 round of the model W The specific calculation formula is:
[0064]
[0065] The application also discloses a personalized federated learning system based on adaptive clustering and layering, which comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the personalized federated learning method based on adaptive clustering and layering as described above when executing the program.
[0066] Advantages:
[0067] First, the personalized federated learning method based on adaptive clustering and layering integrates a client clustering method, so that clients can be grouped according to the similarity of data distribution without obtaining real client data, and the clients can join the corresponding network learning system to train and infer the model.
[0068] Second, the personalized federated learning method based on adaptive clustering and layering integrates an adaptive layering fusion scheme, so that the clients can obtain the most suitable personalized model, and the application can maintain a global model with good generalization performance to facilitate new clients to join or use the corresponding personalized federated learning system.
[0069] Thirdly, the personalized federated learning method based on adaptive clustering layering of the present application solves the data statistical heterogeneity problem in federated learning and the performance imbalance problem between the global model and the local model in personalized federated learning, and achieves the technical effect of greatly improving the individualized performance of the customer local model without compromising the global generalization capability. BRIEF DESCRIPTION OF DRAWINGS
[0070] Figure 1 A personalized federated learning method based on adaptive clustering layering according to an embodiment of the present application is shown in the overall process schematic diagram.
[0071] Figure 2 A personalized federated learning method based on adaptive clustering layering according to an embodiment of the present application is shown in the group training process schematic diagram.
[0072] Figure 3 A personalized federated learning method based on adaptive clustering layering according to an embodiment of the present application is shown in the first stage principle schematic diagram.
[0073] Figure 4 A personalized federated learning method based on adaptive clustering layering according to an embodiment of the present application is shown in the second stage principle schematic diagram.
[0074] Figure 5 A personalized federated learning system based on adaptive clustering layering according to an embodiment of the present application is shown in the structure schematic diagram. DETAILED DESCRIPTION
[0075] The following examples enable those skilled in the art to more fully understand the present application, but in no way limit the present application.
[0076] The present embodiment discloses a personalized federated learning method based on adaptive clustering layering, which comprises the following steps:
[0077] S1, the client prepares the training data set and the test data set of the prediction task, and the global parameter server randomly initializes the global model parameters;
[0078] S2, the global parameter server distributes the global model parameters to the client, and the client uses the received global model parameters as the initial parameters of the local model, trains the model in the current round using the local training data set, and evaluates the prediction effect of the model using the test data set after the training is completed, and calculates the gradient, and uploads the calculated gradient to the parameter server; the parameter server performs weighted average processing on the gradients received from all clients, and adjusts the global model parameters using the calculated average gradient;
[0079] S3, repeat step S2 until the training round reaches the first stage maximum communication round, and go to step S4;
[0080] S4, the parameter server calculates the similarity between the clients according to the gradients uploaded by all the clients in the last round, clusters and groups all the clients according to the calculation results, selects a group server for each client group, and generates an intra-group hierarchical personalized weight vector for each client group;
[0081] S5, the parameter server sends the latest global model parameters to all the group servers, and the group servers iteratively perform intra-group personalized federated learning training to obtain the latest intra-group model parameters, which are uploaded to the parameter server; the parameter server aggregates the latest intra-group model parameters received from all the client groups by weighted averaging to obtain a new global model;
[0082] S6, repeat step S5 until the training round reaches the maximum round or the model has converged, and end the process.
[0083] In another aspect, the embodiment of the present application provides a personalized federated learning system based on adaptive clustering and hierarchical layering, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the aforementioned personalized federated learning method based on adaptive clustering and hierarchical layering when executing the program.
[0084] The embodiment provides a personalized federated learning method and system based on adaptive clustering and hierarchical layering, which solves the problem of data statistical heterogeneity in federated learning and the performance imbalance between global models and local models in personalized federated learning. By integrating a client clustering method and an adaptive hierarchical fusion algorithm, the performance feedback of clients is used for clustering and grouping and adaptive hierarchical fusion, and personalized strategies are flexibly formulated for specific federated learning tasks, achieving the technical effect of significantly improving the personalized performance of client local models without compromising the global generalization ability.
[0085] As shown in Figure 1 , the embodiment provides a personalized federated learning method based on adaptive clustering and hierarchical layering. Specifically, it is divided into two stages, including the following steps:
[0086] The first stage, the principle schematic diagram is as shown in Figure 3 :
[0087] S100: All clients prepare training data sets and test data sets for prediction tasks.
[0088] S110: The global parameter server randomly initializes the model W g of the 1st round of parameters
[0089] S200: The global parameter server uploads the model W gThe parameters of the t-th round Distributed to K clients participating in federated learning training; t∈[1,T] pre ], where T pre To specify the communication round.
[0090] S210: In each receiving model W g The parameters of the t-th round The following training steps are performed in parallel on the client:
[0091] The client will use model W g The parameters of the t-th round As the initial model parameters, let them be... This represents the initial model parameters of the k-th client-side local model in round t.
[0092] Based on initial model parameters The training dataset consists of N samples randomly drawn from the original data held by the customer. The client trains and optimizes the local model using Stochastic Gradient Descent (SGD) for E rounds of local iterations to obtain the optimized model parameters.
[0093] S220: The client uses the optimized model parameters. For the test dataset Perform predictive inference, evaluate the prediction performance, and calculate the gradient.
[0094] S230: The client will transfer gradient g k Send to the global parameter server.
[0095] S240: The global parameter server uses the client's training dataset. The number of samples n k Calculate the weight ratio γ of client k. k =n k / ∑ k∈K n k Then, the FedAvg algorithm is used to weighted aggregate the gradients of all K clients participating in the federated learning training, obtaining the model parameters for round t+1. The specific calculation formula is as follows:
[0096]
[0097] S250: Determine whether the number of iterations has reached the specified number of communication rounds. If the condition is met, execute S300; otherwise, continue executing S200 to S250.
[0098] S300: The parameter server is based on the Tth... pre Gradients {g} uploaded by all clients k} k∈K By calculating the cosine similarity S between every two client gradients C , obtain the similarity matrix ρ; where ρ i,j =S C (i,j),
[0099] S C (i,j)=(g i ·g j ) / (||g i ||·|g j ||) (2);
[0100] Based on the similarity matrix ρ, a top-down hierarchical clustering algorithm is used to cluster K clients into M client groups, denoted as ρ. A group server is selected for each client group to coordinate the training of clients within the group; each client group server copies the model W from the global parameter server. g The Tth pre Wheel parameters As a client group server model W m parameters Where m∈{1,2,…,M}.
[0101] Furthermore, within each client group, the group server performs the following calculations:
[0102] Calculate the group average gradient D based on the gradients of the clients within the group. m :
[0103]
[0104] average gradient Expanding by model parameter layer, it is represented as follows: Where l is the total number of model parameter layers;
[0105] For the average gradient The Euclidean distance is calculated layer by layer to obtain a 1×l-dimensional vector δ. m The calculation formula is as follows:
[0106]
[0107] Define a hyperparameter β to adjust the degree of personalization, and set δ m After normalization, multiplying by β yields the personalized model weights ψ for stratification within groups. m The specific calculation formula is as follows:
[0108] ψm =β·δ m / max(δ m (5).
[0109] The second stage, as shown in the schematic diagram... Figure 4 As shown:
[0110] S400: The global parameter server will send model W g The parameters of the t-th round Distribute to M client group servers; t∈(T) pre ,T total ), where T pre ,T total To specify the communication round.
[0111] S410: As Figure 2 As shown, the following steps are executed in parallel on each client group server:
[0112] S411: The group server receives the global model W from the parameter server. g The parameters of the t-th round
[0113] S412: The group server will use the global model W in round t. g parameters With group model W m parameters Personalized model weights ψ using group-level stratification m Layer-by-layer weighted fusion will group the model W m The parameters are updated to The weighted fusion process first... and Decomposed into layers and Then, the parameters of each layer are fused together, using the following formula:
[0114]
[0115]
[0116] in express The parameters of the nth layer, express The parameters of the nth layer, n∈{1,2,…,l}.
[0117] S413: The group server will group model W m parameters Distribute to clients within the group;
[0118] In each receiver group model W mThe parameters of the t-th round The following training steps are performed in parallel on the client:
[0119] S414: The client will group model W m The parameters of the t-th round As the initial model parameters, let them be denoted as This represents the initial model parameters for the k-th client-side local model in round t.
[0120] Based on initial model parameters The training dataset consists of N samples randomly drawn from the original data held by the customer. The client trains and optimizes the local model using stochastic gradient descent (SGD) for E rounds of local iterations to obtain the optimized model parameters.
[0121] S415: The client uses the optimized model parameters. For the test dataset Perform predictive inference, evaluate the prediction performance, and calculate the gradient.
[0122] S416: The client will transfer gradient g k Send it to the corresponding group server.
[0123] S417: Each group server trains the dataset based on the client training dataset within the group. The number of samples n k Calculate the weight ratio of client k within the group. Then, the FedAvg algorithm is used to weight and aggregate the gradients of clients within the group, and the group server model W is updated. m parameters The specific calculation formula is as follows:
[0124]
[0125] S418: Determine whether the number of iterations has reached the specified number of communication rounds. If the condition is met, execute S420; otherwise, continue executing S413 to S418.
[0126] S420: Group server model W m Updated parameters Recorded as Group servers will use the group server model W m parameters Send to the global parameter server.
[0127] S430: The global parameter server uses the FedAvg weighted aggregation algorithm to aggregate the model parameters sent by all group servers. Model W is obtainedg Parameters of round t+1 The specific calculation formula is as follows:
[0128]
[0129] S440: Determine if the model has converged or if the specified number of iterations has been reached. If a certain condition is met, training ends, and all clients use their respective group models on the client test dataset. Perform the test; otherwise, continue with steps S400 through S440.
[0130] In S210 and S414, the initial model parameters are described. and training dataset Train and optimize the local model on the client side to obtain the optimized initial model parameters. The specific calculation formula is as follows:
[0131]
[0132]
[0133] in, This represents the sampled training dataset. The number of samples, Here, x and y represent the loss value, respectively, the features and corresponding labels of a single sample in the dataset. Indicates the model output results The loss between the true value y and the actual value y, where η represents the learning rate. express for The gradient.
[0134] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:
[0135] By integrating a customer clustering method, this embodiment can group customers based on the similarity of their data distribution without obtaining their actual data. Customers can then join the system for model training and inference. Furthermore, by integrating an adaptive hierarchical fusion scheme, customers can obtain the most suitable personalized model through this embodiment. Simultaneously, this embodiment maintains a global model with good generalization performance to facilitate new customers joining or using the personalized federated learning system. This embodiment solves the problems of statistical heterogeneity in federated learning and the performance imbalance between the global and local models in personalized federated learning, achieving the technical effect of significantly improving the personalized performance of the customer's local model without compromising global generalization ability.
[0136] The following is for reference. Figure 5To describe the electronic device of the embodiments of the present application, based on the same inventive concept as the foregoing embodiment of the adaptive clustering hierarchical personalized federated learning method, the embodiments of the present application also provide an adaptive clustering hierarchical personalized federated learning system, comprising: a processor coupled with a memory, the memory being used to store programs, when the programs are executed by the processor, the system is caused to execute the method of any one of the first aspect.
[0137] The electronic device 300 includes a processor 302, a communication interface 303, and a memory 301. Optionally, the electronic device 300 can also include a bus architecture 304. The communication interface 303, the processor 302, and the memory 301 can be connected to each other through the bus architecture 304; the bus architecture 304 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus architecture 304 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 In the figure, only one thick line is used to represent the bus architecture 304, but it does not mean that there is only one bus or only one type of bus.
[0138] The processor 302 can be a CPU, a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of programs of the present application.
[0139] The communication interface 303 uses any transceiver-like device for communicating with other devices or communication networks, such as an Ethernet, a radio access network (RAN), a wireless local area network (WLAN), a wired access network, etc.
[0140] The memory 301 can be a ROM, or other type of static storage device that can store static information and instructions, a RAM, or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disk storage, an optical disk storage including a compact disc, a laser disc, an optical disc, a digital versatile disc, a Blu-ray disc, and the like, a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to this. The memory can exist independently and be connected to the processor through the bus architecture 304. The memory can also be integrated with the processor. The memory 301 is used to store computer execution instructions for executing the scheme of the present application, and is controlled by the processor 302 to execute. The processor 302 is used to execute the computer execution instructions stored in the memory 301, so as to realize the self-adaptive clustering hierarchical personalized federated learning method provided by the above-mentioned embodiments of the present application.
[0141] The above is only the preferred embodiment of the present application, and the protection scope of the present application is not limited to the above-mentioned embodiments. Any technical scheme falling within the idea of the present application shall fall within the protection scope of the present application. It should be noted that, for ordinary skilled in the art, some improvements and refinements without departing from the principle of the present application shall be considered as the protection scope of the present application.
Claims
1. A personalized federated learning method based on adaptive clustering hierarchical layering, characterized in that, The personalized federated learning method comprises the following steps: S1, the client prepares a training data set and a test data set of a prediction task, and a global parameter server randomly initializes global model parameters; S2, the global parameter server sends the global model parameters to the client, and the client uses the received global model parameters as the initial parameters of the local model, trains the model in the current round of training using the local training data set, and after the training is completed, evaluates the prediction effect of the model using the test data set, calculates the gradient, and uploads the calculated gradient to the parameter server; the parameter server performs weighted average processing on the gradients received from all clients, and adjusts the global model parameters using the calculated average gradient; S3, repeat step S2 until the training round reaches the first stage maximum communication round, and go to step S4; S4, the parameter server calculates the similarity between the clients according to the gradients uploaded by all clients in the last round, clusters and groups all clients according to the calculation result, selects a group server for each client group, and generates an intra-group layered personalized weight vector for each client group; S5, the parameter server sends the latest global model parameters to all group servers, and the group servers iteratively perform intra-group personalized federated learning training, and upload the latest intra-group model parameters obtained to the parameter server; the parameter server aggregates the latest intra-group model parameters sent by all client groups received to obtain a new global model; S6, repeat step S5 until the training round reaches the maximum round or the model has converged, and end the process.
2. The method of claim 1, wherein, In step S2, the global parameter server sends the global model parameters to the client, and the client uses the received global model parameters as the initial parameters of the local model, trains the model in the current round of training using the local training data set, and after the training is completed, evaluates the prediction effect of the model using the test data set, calculates the gradient, and uploads the calculated gradient to the parameter server. The process comprises the following steps: S21, the global parameter server sends the model W g of the t-th round of parameters to K clients participating in federated learning training; t ∈ [1, T pre ], where T pre is the maximum number of communication rounds in the first stage, and the first round of parameters is randomly initialized by the global parameter server S22, at each receiving model W g of the t-th round of parameters The following training steps are performed in parallel on the clients of the t-th round of parameters S221, the client updates the model W g the t-th round of parameters of the model as the initial model parameters, denoted as denotes the t-th round of initial model parameters of the k-th client local model; S222, based on the initial model parameters and a training dataset consisting of N samples randomly drawn from the original data held by the customer The client trains and optimizes the local model using stochastic gradient descent for E rounds of local iterations, resulting in optimized model parameters S223, the client uses the optimized model parameters on the test data set perform prediction inference, evaluate the prediction effect, and calculate the gradient S224, the client sends the gradient g k to the global parameter server.
3. The method of claim 2, wherein, In step S222, the optimized model parameters are calculated using the following formula wherein, denotes the number of samples of the sampled training dataset , is the loss value, x and y represent the feature and corresponding label of a single sample in the dataset, respectively, denotes the loss between the model output result and the true value y, and η denotes the learning rate, denotes the gradient of with respect to x.
4. The method of claim 2, wherein, In step S2, the parameter server performs weighted average processing on the gradients received from all clients, and adjusts the global model parameters using the calculated average gradient. The process comprises the following steps: The global parameter server calculates the weight proportion γ of the client k according to the sample number n in the client training data set k The weight proportion γ of the client k is calculated according to the sample number n in the client training data set k k / ∑ k∈K n k ; The federated average algorithm FedAvg is used to aggregate the gradients of K clients participating in the federated learning training by weighting, to obtain model parameters in the t+1 round 5. The method of claim 1, wherein, In step S4, the parameter server calculates the similarity between the clients according to the gradients uploaded by all clients in the last round, clusters and groups all clients according to the calculation result, and selects a group server for each client group. The process comprises the following steps: S41, the parameter server according to the T pre Gradient {g k} k∈K , by calculating the cosine similarity S C , obtain the similarity matrix ρ;Where ρ i,j =S C (i,j), S C (i,j) = (g i ·g j ) / (||g i ||·|g j ||); S42, based on the similarity matrix p, using a top-down hierarchical clustering algorithm, K clients are clustered into M client groups, denoted as S43, a group server is selected for each client group to coordinate the training of the clients in the group; S44, let each client group's group server copy a copy of the model W in the global parameter server g the T pre th round parameter as the parameter of the client group server model W m where m ∈ {1, 2, …, M}. 6. The method of claim 5, wherein, In step S4, the process of generating an intra-group layered personalized weight vector for each client group comprises the following steps: calculating an intra-group average gradient from the gradients of the clients in the group The average gradient Unfolding by model parameter layer, denoted as where is the total number of model parameter layers; On average gradient The Euclidean distance is computed layer by layer, resulting in a dimensional vector δ m : A hyper-parameter β is defined to adjust the degree of personalization. δ m The normalized δ is multiplied by β to obtain the stratified personalization model weight ψ m : ψ m = β · δ m / max(δ m ).
7. The adaptive clustering hierarchy-based personalized federated learning method according to claim 1, characterized in that, In step S5, the parameter server sends the latest global model parameters to all group servers, and the group servers iteratively perform intra-group personalized federated learning training, and upload the latest intra-group model parameters obtained to the parameter server. The process comprises the following steps: S51, the global parameter server sends the model W g of the tth round of parameters to the M client group servers; t ∈ (T pre , T total ), wherein T pre , T total are the maximum communication rounds of the first stage and the second stage, respectively. S52, the following steps are performed in parallel on each client group server: S521, the group server receives the global model W sent by the parameter server g the t-th round of parameters S522, the group server updates the parameters of the global model W g m m m wherein denotes parameters of the n-th layer in the denotes parameters of the n-th layer in the S523, the group server sends the group model W m parameters of the group model W to the clients in the group; S53, at each receiving group model W m of the t-th round of parameters The following training steps are performed in parallel on the clients of the group of clients: S531, the client updates the group model W m the t-th round parameters of the k-th client local model as the initial model parameters, denoted as represent the t-th round initial model parameters of the k-th client local model S532, based on the initial model parameters and a training data set consisting of N samples randomly drawn from the original data held by the customer The client trains and optimizes the local model, using stochastic gradient descent (SGD) for E local iterations, resulting in optimized model parameters S534, the client uses the optimized model parameters on the test data set perform prediction inference, evaluate the prediction effect, and calculate the gradient S535, the client sends the gradient g k to the corresponding group server; S54, each group server trains the dataset based on the client training dataset within the group. The number of samples n k Calculate the weight ratio of client k within the group. The gradients of clients within the group are weighted and aggregated using the FedAvg algorithm to update the group server model W. m parameters The specific calculation formula is as follows: S55, judge whether the iteration number reaches the maximum communication round of the second stage, if the condition is met, execute S56, otherwise continue to execute S523 to S54; S56, the group server model W m updated parameters denoted The group server sends the updated parameters of the group server model W m to the global parameter server. to the global parameter server.
8. The method of claim 7, wherein, In step S5, the parameter server aggregates the latest intra-group model parameters sent by all client groups to obtain a new global model, and the process includes the following steps: The global parameter server aggregates the model parameters sent by all group servers using the federated averaging algorithm FedAvg Obtain the model W g The parameters of the t+1 round The specific calculation formula is:
9. A personalized federated learning system based on adaptive clustering hierarchical, characterized in that, The personalized federated learning system comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the adaptive clustering-based hierarchical personalized federated learning method as claimed in any one of claims 1-8 when executing the program.
Citation Information
Patent Citations
A Federated Learning Method and System
CN114781545B
Hierarchical federated learning method and device based on asynchronous communication, terminal equipment and storage medium
CN112532451A
Grouping training method based on distributed machine learning, server and client
CN114118210A