Federated learning personalization method based on contrastive learning
By adopting contrast learning technology in federated learning, the client performs personalized correction training, which solves the problem of insufficient adaptability of the global model on the heterogeneous client of data distribution, and achieves better model adaptability and generalization capabilities.
Patent Information
- Application Number
- CN202210956833.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-10
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2042-08-10
AI Technical Summary
Federated learning When dealing with clients with heterogeneous data distribution, the global model may not be able to effectively adapt to all clients' tasks, resulting in insufficient adaptability of the model on clients with less contribution.
Using a federated learning personalized method based on comparison learning, the client trains independent models locally, and extracts representations through the comparative learning network, and personalized correction training is carried out in combination with the global model and local model representations, and calculates the model consistency loss to update the local model. .
This method can correct the global model to adapt to the data distribution of the client, improve the adaptability and generalization ability of the model on all clients, and the personalized correction process will not affect the convergence of the global model.
Smart Images

Figure BDA0003791690210000021 
Figure BDA0003791690210000031 
Figure BDA0003791690210000033
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of personalization of federated learning models, and in particular relates to a federated learning personalization method based on contrastive learning. Background Art
[0002] Federated learning was born out of the data silo problem, and its goal is to collaboratively train data that is generated by many remote devices or local clients and cannot be shared due to privacy issues. Federated learning enables multiple parties to jointly learn a machine learning model without exchanging their local data. In each round of federated learning training, the updated local models of each party are transmitted to the server, which further aggregates the local models to update the global model. The original data is not exchanged during the learning process. Federated learning has become an important field of machine learning and has attracted a lot of research interest. In addition, it has been applied in many fields such as medical imaging, smart furniture, etc.
[0003] Since federated learning focuses on learning all client data to obtain a high-quality global model, it cannot capture the personal information of all clients. For clients with high data quality and greater contribution, the global model can adapt well to the client's tasks, but for clients with less contribution, the global model may not be well adaptable. When each client updates its local model, its local goal may be far from the global goal. Therefore, federated learning faces the problem of heterogeneous data distribution in real deployment, and the trained global model may not be suitable for working on all clients participating in the training.
[0004] A key challenge of federated learning is to deal with the heterogeneity of local data distribution across all parties. The global model trained by federated learning often ignores the personal information of low-contribution clients, resulting in low generalization ability of the global model. To address this challenge, a simple and effective method is to perform personalization on the device or model. For the global model obtained by broadcasting, the client performs corresponding personalized training to ensure that the final model can adapt to the task. Summary of the invention
[0005] The purpose of the present invention is to provide a federated learning personalization method based on contrastive learning to address the deficiencies of the prior art. The present invention can ensure that the global model can be modified according to the data distribution of the client.
[0006] The object of the present invention is achieved through the following technical solution: a federated learning personalization method based on contrastive learning, comprising the following steps:
[0007] (1) Train an independent model locally:
[0008] (1.1) The local client trains an independent model based on the data it holds. The independent model only contains the data information of a single client and is adapted to the task of the client.
[0009] (1.2) Build a contrastive learning network and use it to extract representations from independent models;
[0010] (2) Clients participate in federated learning training:
[0011] (2.1) The client starts normal federated learning training and gets local updates based on the global model published by the server and local data;
[0012] (2.2) After the training is completed, each client uploads the locally updated local model to the server;
[0013] (2.3) The server aggregates to obtain a new global model and broadcasts it globally. After receiving the new global model, the client extracts the global representation from it.
[0014] (3) The client performs personalized correction training:
[0015] (3.1) After the client receives the latest global model, it starts personalized correction training and obtains three representations during the training phase: the independent model representation, the global model representation, and the local model representation being updated;
[0016] (3.2) Using the three representations obtained in step (3.1), the model consistency loss is calculated and updated together with the training loss to the local model;
[0017] (3.3) Repeat steps (3.1) to (3.2) to perform iterative correction training and finally obtain a personalized local model.
[0018] Further, step (1.1) comprises:
[0019] There are N clients, denoted as P1,...,P N , client P i Have a local dataset D i , for local single training, the training objectives of the independent model are as follows:
[0020]
[0021] in, P i experience loss; Represents client P i The independent model weights of i A training data in , y represents the label corresponding to x; li Represents client P i Local loss function; E represents expectation.
[0022] Further, step (1.2) comprises:
[0023] The independent model weight is use Represents the network before the output layer of the independent model; the trained independent model weights are put into the contrastive learning network to obtain the representation of the independent model
[0024] Further, step (2.1) comprises:
[0025] For the local client, the training objectives of the federated learning local model are as follows:
[0026]
[0027] in, P i The local experience loss L in the tth round i,t ;w i Represents client P i The local model weight of i A training data in , y represents the label corresponding to x; l i,t Represents client P i The local loss function of the tth round; E represents the expectation.
[0028] Further, step (2.3) comprises:
[0029] The server receives the client's model update and uses the FedAvg aggregation algorithm to form a new global model; FedAvg calculates the average of the client's local model updates as the global model update, where each client is weighted according to the number of its training examples; using D = ∪ i∈[N] D i represents the dataset of all federated training, and the training objective of the t-th round global model is expressed as:
[0030]
[0031] Among them, L i,t Indicates P i Define the experience loss of round t; L g,t represents the loss of the global model in round t; w g is the weight of the global model; || means modulus;
[0032] After the aggregation is completed, a new global model is obtained After that, the server will Broadcast and send to each client; the client calculates the representation of the global model based on the latest global model
[0033] Further, step (3.1) comprises:
[0034] The loss of personalized correction training consists of two parts. The first part is the loss function The second part is the calculation of the model contrast loss function, which is defined as For each input x and local model Extracting representations from independent models Extracting representations from the global model and the representation extracted from the local model being trained Then the model contrast loss function is defined as:
[0035]
[0036] Furthermore, in step (3.1):
[0037] The server decides whether to perform personalized correction training for the corresponding client based on whether it has received the client's personalized application. When the server receives the client's personalized application, it determines that the client needs personalized correction training, and then the client starts personalized correction training; if the client's personalized application is not received, it jumps to step (2.1) for the next round of federated learning training.
[0038] Further, step (3.2) comprises:
[0039] The goals of the updated local model are to:
[0040]
[0041] Among them, μ controls the personalized hyperparameter of the model's contrast loss weight, which is set by the client; w g represents the weight of the global model, w i represents the weight of the local model, represents the weight of the independent model, and x represents D i A training data in , y represents the label corresponding to x.
[0042] The beneficial effects of the present invention are as follows:
[0043] (1) The correction training of the present invention is independent of the normal federated training, and the personalization process will not affect the global model, that is, it will not affect the convergence process of the global model;
[0044] (2) The present invention can efficiently map features through comparative learning and computational representation at the model level;
[0045] (3) The present invention can control the personalization degree of the model through consistency loss and can perform fine-grained customization. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 Schematic diagram of the federated learning personalization method based on contrastive learning of the method of the present invention.
[0047] Figure 2 The figure is a specific flow chart of the federated learning personalization method based on contrastive learning of the method of the present invention. DETAILED DESCRIPTION
[0048] The specific implementation modes of the present invention are further described in detail below in conjunction with the accompanying drawings.
[0049] The present invention achieves personalization by weighing the global model trained on the entire data set with the local model trained on the local subset. Based on this view, the present invention provides a federated learning personalization method based on contrastive learning, which corrects local updates through the consistency loss of the representation learned by the current local model and the representation learned by the global model, thereby achieving personalization of federated learning. Specifically, the method will simultaneously calculate the representation of the global model, the representation of the model obtained by local data training, and the representation of the local model trained by the current model, and then standardize the distance between the three representations through personalized parameters, that is, to achieve contrastive learning at the model level, so as to correct the global model to adapt to tasks on different clients.
[0050] like Figure 1 As shown, the present invention specifically comprises the following steps:
[0051] (1) Train an independent model locally.
[0052] Each client in federated learning has different training data, which is stored locally and cannot be transmitted. Before starting federated learning training, the present invention requires each client to use local data to train an independent model as one of the subsequent personalized representations. Due to the heterogeneity of data between clients, there may be a situation where the client lacks data and cannot train a good independent model. However, this does not affect the subsequent personalized customization, because the goal of personalized customization is to adapt the global model to a specific task, and the independent model plays a guiding role.
[0053] Therefore, step (1) includes the following sub-steps:
[0054] (1.1) The local client trains an independent model based on the data it holds. The weight of the independent model is represented by wind ,The independent model only contains the data information of a single client and is adapted to the task of that client.
[0055] Assume that there are N clients in federated learning, denoted as P1,...,P N , client P i Have a local dataset D i , for local single training, the training objectives of the independent model are as follows:
[0056]
[0057] in, P i experience loss. Represents client P i The independent model weights of i A training data in , y represents the label corresponding to x; l i Represents client P i Local conventional loss function; E represents expectation.
[0058] (1.2) Build a contrastive learning network and use it to extract representations from independent models.
[0059] Similar to the typical contrastive learning framework SimCLR, this contrastive learning network has three components: base encoder, neural network projection head and output layer. The base encoder is used to extract the representation vector from the input, and the neural network projection head is used to map the representation vector to a space with a fixed dimension. Finally, the output layer will be used to generate the prediction value for each class. Similar to the above, assuming that the independent model weights are use Represents the entire network of the independent model, with Represents the network before the output layer of the independent model. By putting the trained independent model weights into the contrastive learning network, the representation of the independent model can be obtained. The input x represents a training data.
[0060] (2) The client participates in federated learning training.
[0061] After the independent model is trained locally and the representation is obtained, the formal federated training process will begin. In order to ensure that the global model can converge, the present invention separates the training of the global model from the personalized model correction training, and maintains the two tasks with each other. That is, before the client performs personalized training, it is necessary to send a report to the server. After receiving the personalized application, the server marks the client to ensure that the client does not participate in the global model aggregation. Similarly, the client will perform correction training only after the end of this round of federated learning training, so as to ensure that the client's personalization will not affect the global model operation. Therefore, in step (2), only the normal federated learning training process is involved.
[0062] Therefore, step (2) includes the following sub-steps:
[0063] (2.1) The client starts normal federated learning training and gets local updates based on the global model published by the server and local data.
[0064] The server initializes the global model and broadcasts it to each client. The client receives the global model and updates the local model using local data and stochastic gradient descent for one or more iterations.
[0065] For the local client, the training objectives of the federated learning local model are as follows:
[0066]
[0067] in, P i The local experience loss L in the tth round i,t .w i Represents client P i The local model weight of i A training data in , y represents the label corresponding to x; l i,t Represents client P i The local conventional loss function for the tth round; E represents the expectation. After the local training is completed, the client uploads the local model update to the server.
[0068] (2.2) After training is completed, each client sends its local model and uploads the local update to the server, ensuring that the server can receive the local update without personalization.
[0069] (2.3) The server aggregates and obtains a new global model and broadcasts it globally. After receiving the new global model, the client extracts the global representation from it.
[0070] The server receives the client's model update and uses the FedAvg aggregation algorithm to form a new global model. FedAvg calculates the average of the client's local model updates as the global model update, where each client is weighted according to the number of its training examples. Using D = ∪ i∈[N] D i Represents the dataset of all federated training, and the training objective of the t-th round global model can be expressed as:
[0071]
[0072] Among them, L i,t Indicates P i Define the experience loss of round t; L g,t represents the loss of the global model; w g is the weight of the global model; || means modulus.
[0073] After the aggregation is completed, a new global model is obtained After that, the server will Broadcast and send to each client. The client can calculate the representation of the global model based on the latest global model. Where x represents a training data.
[0074] (3) The client performs personalized correction training.
[0075] After obtaining the latest global model, the client will perform personalized correction training on the local model. The goal of personalized correction training is to correct the distance between the local model representation and the global model representation and the independent model representation. For example, if the client wants the local model to adapt to the local task, the goal of its correction training is to reduce the distance between the representation learned by the local model and the representation learned by the global model, and increase the distance between the representation learned by the local model and the representation learned by the independent model.
[0076] Therefore, if Figure 2 As shown, step (3) includes the following sub-steps:
[0077] (3.1) The client receives the latest global model and sends a personalized training application to the server. The server decides whether to perform personalized correction training for the corresponding client based on whether it has received the personalized application from the client. When the server receives the personalized application from the client, it determines that the client needs personalized correction training, and then the client starts personalized correction training. If the personalized application from the client is not received, jump to step (2.1) for the next round of federated learning training. Among them, three representations are obtained in the personalized correction training stage: independent model representation, global model representation, and local model representation being updated.
[0078] The loss of the modified training consists of two parts. The first part is the conventional loss function The second part is the calculation of the model contrast loss function, which is defined as For each input x and local model Representations can be extracted from independent models Extracting representations from the global model and the representation extracted from the local model being trained Then the model comparison loss function can be defined as:
[0079]
[0080] (3.2) The model consistency loss is calculated through three representations and updated together with the traditional training loss. The goal is to minimize the following formula:
[0081]
[0082] Among them, μ controls the personalized hyperparameter of the model contrast loss weight, controls the degree of personalization of the local model, and is set by the client. g represents the weight of the global model, w i represents the weight of the local model, represents the weight of the independent model, and x represents D i A training data in , y represents the label corresponding to x.
[0083] (3.3) Repeat steps (3.1) to (3.2) and perform the revised training through multiple iterations until the overall loss update value of the revised training is less than 0.0001 or the training is terminated when the preset number of times is reached, and finally a personalized federated learning local model is obtained.
[0084] It should be noted that the correction training in the present invention is separate from the federated learning training, and the update of the global model is the same as the traditional federated learning method, so it will not interfere with the normal federated learning training. For the local model, whether or not to perform correction training does not actually affect the update of the global model, but only affects the personalization of the local model.
[0085] According to an embodiment of the present invention, in an experiment on the CIFAR-10 ten-class dataset, the test accuracy of the model modified by the present invention is improved by an average of 3.1% (±0.4%) compared with the federated average learning algorithm, where μ is set to 5.
[0086] The goal of federated learning is to learn the features of all data involved in the training. However, due to the existence of data heterogeneity, some relatively hidden data features on the client are often ignored, resulting in differences in the performance of the global model on each client. In order to solve this problem, the present invention provides a personalized method for federated learning based on contrastive learning. Through contrastive learning technology, a correction training step is added after normal local training. By calculating the representation of independent models, global models, and local models being updated, the local model is corrected to ensure that it can adapt to different tasks of the client and meet the requirements of personalized customization of federated learning.
[0087] The contents described in the embodiments of this specification are merely an enumeration of the implementation forms of the inventive concept. The protection scope of the present invention should not be regarded as limited to the specific forms described in the embodiments. The protection scope of the present invention also extends to equivalent technical means that can be conceived by those skilled in the art based on the inventive concept.
Claims
1. A federated learning personalization method based on contrastive learning, characterized in that: The following steps are involved: (1) Train an independent model locally: (1.1) The local client trains an independent model based on the data it holds. The independent model only contains the data information of a single client and is adapted to the task of the client. (1.2) Build a contrastive learning network and use it to extract representations from independent models; (2) Clients participate in federated learning training: (2.1) The client starts normal federated learning training and gets local updates based on the global model published by the server and local data; (2.2) After the training is completed, each client uploads the locally updated local model to the server; (2.3) The server aggregates to obtain a new global model and broadcasts it globally. After receiving the new global model, the client extracts the global representation from it. (3) The client performs personalized correction training: (3.1) After the client receives the latest global model, it starts personalized correction training and obtains three representations during the training phase: the independent model representation, the global model representation, and the local model representation being updated; The loss of personalized correction training consists of two parts. The first part is the loss function The second part is the calculation of the model contrast loss function, which is defined as For each input x and local model Extracting representations from independent models Extracting representations from the global model and the representation extracted from the local model being trained Then the model contrast loss function is defined as: The server determines whether to perform personalized correction training on the corresponding client according to whether it has received the personalized application from the client. When the server receives the personalized application from the client, it determines that the client needs to perform personalized correction training, and then the client starts personalized correction training; If no personalized application is received from the client, jump to step (2.1) for the next round of federated learning training; (3.2) Using the three representations obtained in step (3.1), the model consistency loss is calculated and updated together with the training loss to the local model; (3.3) Repeat steps (3.1) to (3.2) to perform iterative correction training and finally obtain a personalized local model.
2. The federated learning personalization method based on contrastive learning as claimed in claim 1, characterized in that: Step (1.1) includes: There are N clients, denoted as P1,...,P N , client P i Have a local dataset D i , for local single training, the training objectives of the independent model are as follows: in, P i Experience loss; wind i Represents client P i The independent model weights of i A training data in , y represents the label corresponding to x; Represents client P i The local loss function; Ε represents the expectation.
3. The federated learning personalization method based on contrastive learning as claimed in claim 1, characterized in that: Step (1.2) includes: The independent model weight is use Represents the network before the output layer of the independent model; the trained independent model weights are put into the contrastive learning network to obtain the representation of the independent model 4. The federated learning personalization method based on contrastive learning as claimed in claim 1, characterized in that: Step (2.1) includes: For the local client, the training objectives of the federated learning local model are as follows: in, P i The local experience loss L in the tth round i,t ;w i Represents client P i The local model weight of i A training data in , y represents the label corresponding to x; Represents client P i The local loss function of the tth round; Ε represents the expectation.
5. The federated learning personalization method based on contrastive learning as claimed in claim 1, characterized in that: Step (2.3) includes: The server receives the client's model update and uses the FedAvg aggregation algorithm to form a new global model; FedAvg calculates the average of the client's local model updates as the global model update, where each client is weighted according to the number of its training examples; using D = ∪ i∈[N] D i represents the dataset of all federated training, and the training objective of the t-th round global model is expressed as: Among them, L i,t Indicates P i Define the experience loss of round t; L g,t represents the loss of the global model in round t; w g is the weight of the global model; || means modulus; After the aggregation is completed, a new global model is obtained After that, the server will Broadcast and send to each client; the client calculates the representation of the global model based on the latest global model 6. The federated learning personalization method based on contrastive learning as claimed in claim 1, characterized in that: Step (3.2) includes: The goal of the updated local model is: Among them, μ controls the personalized hyperparameter of the model's contrast loss weight, which is set by the client; w g represents the weight of the global model, w i represents the weight of the local model, represents the weight of the independent model, and x represents D i A training data in , y represents the label corresponding to x.
Citation Information
Patent Citations
Network training method and device, electronic equipment and storage medium
CN113344131A
Federal learning system and method and client device
CN113762524A