Training method and device of global model and electronic equipment
By introducing feature extractors and discriminators from generative adversarial networks into federated learning, the problem of global model applicability caused by the heterogeneity of distributed device data is solved, achieving faster convergence speed and higher learning performance.
Patent Information
- Application Number
- CN202310118884.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-31
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2043-01-31
AI Technical Summary
In federated learning, the heterogeneity of data across distributed devices causes local model parameters to deviate from global model parameters, resulting in poor applicability of global model parameters across different devices and inconsistent training effects. Existing technologies cannot effectively solve this problem.
In servers and distributed devices, a generative adversarial network is formed by setting up a feature extractor, a discriminator, and a classifier. The feature extractor and classifier, along with the discriminator and classifier, are trained through multiple rounds of iterative training until the global model meets the convergence condition.
This improves the convergence speed of the global model, reduces the communication overhead of additional data between the server and various distributed devices, and enhances the performance of federated learning.
Smart Images

Figure CN116361642B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of global model technology, and in particular to a training method, apparatus and electronic device for a global model. Background Technology
[0002] With the development of the Industrial Internet of Things (IIoT), various devices are generating massive amounts of data. Machine learning can effectively utilize this data through data collection and model training to guide industrial practices. In traditional centralized machine learning, a central node needs to collect data for model training, which not only incurs huge communication overhead but also exposes data privacy. Therefore, federated learning has been proposed to achieve distributed machine learning without sharing data. In federated learning, each distributed device does not transmit local data but only transmits pre-trained local model parameters to the server. The server determines the global model parameters by receiving the local model parameters from each distributed device and then feeds the global model parameters back to each distributed device for the next round of training.
[0003] However, the data in each distributed device is not independent and identically distributed; for example, data from different enterprises exhibits heterogeneity. This data heterogeneity causes local model parameters to deviate from global model parameters to some extent, making the global model parameters fed back to each distributed device unapplicable and hindering training. Furthermore, the data heterogeneity across distributed devices results in poor generalization ability, high weight dispersion in the models across different distributed devices, and a sharp decline in the performance of federated learning. Summary of the Invention
[0004] In view of this, the purpose of this application is to propose a training method, apparatus and electronic device for a global model to overcome all or part of the shortcomings of the prior art.
[0005] To achieve the above objectives, this application provides a method for training a global model, applied to a federated learning system. The federated learning system includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each of the distributed devices. Both the global model and each local model are equipped with a feature extractor, a discriminator, and a classifier. The feature extractor and the discriminator form a generative adversarial network. The method includes: initializing the parameters of the global model using the server; and performing multiple rounds of iterative training on the parameter-initialized global model using the server and the multiple distributed devices until the global model meets the convergence condition, thereby obtaining a trained global model.
[0006] Optionally, the step of performing multiple rounds of iterative training on the global model initialized with the parameters using the server and the multiple distributed devices includes: performing the following operations for each iteration in the multiple rounds of iterative training: sending the current global model parameters of the global model to each distributed device using the server; training the feature extractor and classifier of the corresponding local model using each distributed device based on the current global model parameters and the local dataset of each distributed device to obtain first feature extractor parameters and classifier parameters; training the discriminator of the corresponding local model using each distributed device based on the current global model parameters, the local dataset, and the first feature extractor parameters to obtain discriminator parameters; training the feature extractor of the corresponding local model using each distributed device based on the local dataset, the first feature extractor parameters, and the discriminator parameters to obtain second feature extractor parameters; sending the classifier parameters, discriminator parameters, and second feature extractor parameters associated with each distributed device to the server; and updating the current global model parameters using the server based on multiple classifier parameters, multiple discriminator parameters, and multiple second feature extractor parameters.
[0007] Optionally, the current global model parameters include the current feature extractor parameters, and the local dataset includes multiple sets of data, each set including samples and their corresponding labels; based on the current global model parameters and the local dataset of each distributed device, the feature extractor of its corresponding local model is trained using each distributed device to obtain the first feature extractor parameters, including: training the feature extractor using each distributed device through the following first loss function: Among them, w 1t Here, w1 represents the parameters of the first feature extractor during the t-th training round, and w1 represents the parameters of the current feature extractor. For learning rate, The gradient calculated for the k1-th group of data in the local dataset randomly selected in round t. For the k1th group of samples randomly selected in the t-th round, Let t be the label corresponding to the k1th group of samples randomly selected in the tth round, where t is the number of training rounds.
[0008] Optionally, the current global model parameters include the current classifier parameters, and the local dataset includes multiple sets of data, each set including samples and their corresponding labels; based on the current global model parameters and the local dataset of each distributed device, the classifier of its corresponding local model is trained using each distributed device to obtain the classifier parameters, including: training the classifier using each distributed device through the following second loss function: Among them, w 2t Let w1 be the classifier parameters trained in the t-th round, and w2 be the current classifier parameters. For learning rate, The gradient calculated for the k2th group of data in the local dataset randomly selected in round t. For the k2th group of samples randomly selected in the t-th round, Let t be the label corresponding to the k2th sample group randomly selected in the tth round, where t is the training round number.
[0009] Optionally, the current global model parameters include current discriminator parameters, and the local dataset includes multiple sets of data, each set including samples and their corresponding labels; the step of training the discriminator of its corresponding local model using each distributed device based on the current global model parameters, the local dataset, and the first feature extractor parameters to obtain discriminator parameters includes: using each distributed device to label the label corresponding to the sample as the true label corresponding to the sample, wherein the true label corresponding to the sample is used to characterize the label that correctly classifies the sample; and using each distributed device to train the discriminator using the following third loss function: Where, θ t Let θ be the discriminator parameters trained in the t-th round, and θ be the current discriminator parameters. For learning rate, The gradient w is calculated for the k3th group of data in the local dataset randomly selected in round t. 1t The parameters of the first feature extractor during the t-th round of training are... For the k3th group of samples randomly selected in the t-th round, Let t be the true label corresponding to the k3th sample randomly selected in the t-th round, where t is the number of training rounds.
[0010] Optionally, the step of training the feature extractor of the corresponding local model using each distributed device based on the local dataset, the first feature extractor parameters, and the discriminator parameters to obtain the second feature extractor parameters includes: using each distributed device to label the label corresponding to the sample as a false label corresponding to the sample, wherein the false label corresponding to the sample is used to characterize the label that misclassifies the sample; and using each distributed device to train the feature extractor through the following fourth loss function: Among them, w 3t Let w be the parameter of the second feature extractor during the t-th round of training. 1t The parameters of the first feature extractor in the t-th round of training are... For learning rate, The gradient θ is calculated for the k4th set of data in the local dataset randomly selected in round t. t Let be the discriminator parameters trained in the t-th round. For the k4th sample group randomly selected in the t-th round, The false label is the k4th sample randomly selected in the t-th round, where t is the number of training rounds.
[0011] Optionally, updating the current global model parameters using the server based on multiple classifier parameters, multiple discriminator parameters, and multiple second feature extractor parameters includes: calculating a first average value of multiple classifier parameters, a second average value of multiple discriminator parameters, and a third average value of multiple second feature extractor parameters using the server; and updating the current global model parameters using the server based on the first average value, the second average value, and the third average value.
[0012] Optionally, the global model satisfies the convergence condition, including: in response to determining that the current global model parameters are equal to the global model parameters obtained in the previous iteration training, determining that the global model satisfies the convergence condition.
[0013] Based on the same inventive concept, this application also provides a training device for a global model applied to a federated learning system. The federated learning system includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each of the distributed devices. The global model and each local model are equipped with a feature extractor, a discriminator, and a classifier. The feature extractor and the discriminator form a generative adversarial network. The device includes: an initialization module configured to initialize the parameters of the global model using the server; and an iterative training module configured to perform multiple rounds of iterative training on the parameter-initialized global model using the server and the multiple distributed devices until the global model meets the convergence condition, thereby obtaining a trained global model.
[0014] Based on the same inventive concept, this application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein the processor implements the method described above when executing the computer program.
[0015] As can be seen from the above, the global model training method, apparatus, and electronic device provided in this application are applied to a federated learning system. The federated learning system includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each distributed device. Both the global model and each local model are equipped with a feature extractor, a discriminator, and a classifier. The feature extractor and the discriminator form a generative adversarial network, which reduces the heterogeneity of data from different distributed devices after training with their corresponding feature extractors. The global model is initialized with parameters using the server. Multiple rounds of iterative training are performed on the parameter-initialized global model using the server and the multiple distributed devices until the global model meets the convergence condition, resulting in a trained global model. This improves the convergence speed of the global model, does not generate additional data, avoids the communication overhead of additional data between the server and the distributed devices, and enhances the performance of federated learning. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in this application or related technologies, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart illustrating the training method of the global model in an embodiment of this application;
[0018] Figure 2 This is a schematic diagram of the structure of a training device for a global model according to an embodiment of this application;
[0019] Figure 3 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of this application. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with specific embodiments and the accompanying drawings.
[0021] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this application should have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms "first," "second," and similar terms used in the embodiments of this application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are only used to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0022] As described in the background section, the data among the distributed devices is not independent and identically distributed, exhibiting heterogeneity. This heterogeneity causes local model parameters to deviate from global model parameters to some extent, raising questions about the applicability of the global model parameters. For example, when the global model parameters are fed back to each distributed device, the training performance on each device may be unsatisfactory; or the training performance may be good on some distributed devices and poor on others, leading to training unfairness. This results in a sharp decline in the performance of federated learning.
[0023] In view of this, embodiments of this application propose a method for training a global model, referring to... Figure 1 This method is applied to a federated learning system, which includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each distributed device. Both the global model and each local model are equipped with a feature extractor, a discriminator, and a classifier. The feature extractor and the discriminator form a generative adversarial network. The method includes the following steps:
[0024] Step 101: Initialize the parameters of the global model using the server.
[0025] In this step, the server in federated learning trains the model by sending global model parameters to each distributed device and then receiving local model parameters from each distributed device. Before this process, the global model parameters need to be initialized to preset values, which are set based on experience and are beneficial to improving the convergence speed of the global model.
[0026] Step 102: Use the server and the multiple distributed devices to perform multiple rounds of iterative training on the global model initialized with the parameters until the global model meets the convergence condition, and obtain the trained global model.
[0027] In this step, the feature extractor reduces the dimensionality of the data and recombines its features. Reducing the dimensionality, i.e., decreasing data irrelevant to training the feature extractor, improves the model's training speed; recombinating the features and organizing existing data characteristics accelerates the model's convergence. The feature extractor and discriminator form a generative adversarial network (GAN). As the model trains, the feature extractor and discriminator engage in a dynamic adversarial process. Samples corresponding to fake labels train the feature extractor to confuse the discriminator. The discriminator, by identifying the deception, adjusts its parameters accordingly. Samples corresponding to true labels train the discriminator to improve its discrimination ability. In subsequent iterations, the features of the data from each distributed device, after training with their corresponding feature extractors, become more similar. The data includes samples and their corresponding labels. The labels represent whether the sample is correctly classified; true labels indicate correct classification, and fake labels indicate incorrect classification. In each iteration, the feature extractor and discriminator compete against each other. The discriminator determines the direction of parameter adjustment for the feature extractor. Through multiple iterations, the discriminator's ability to adjust the feature extractor parameters becomes increasingly sophisticated. By using the discriminator's discriminative function to adjust the feature extractor parameters, the heterogeneity of local data from each distributed device after training with its corresponding feature extractor is reduced, thus improving the performance of both the feature extractor and the discriminator. The classifier, on the other hand, classifies data and can be applied to predict the classification of unknown data. When input data is fed into the global model, the classifier classifies the input data.
[0028] The server sends the current global model parameters to each distributed device. Each distributed device, based on these global model parameters and its own data, trains its corresponding local model's feature extractor, discriminator, and classifier, obtaining the trained local model parameters. The feature extractor and discriminator form a generative adversarial network (GAN). Each distributed device sends its local model parameters back to the server. Based on these local model parameters, the server updates the current global model parameters, completing one iteration of the global model. Global model training is complete when the global model meets the convergence condition. In traditional federated learning, the data between distributed devices is heterogeneous. By introducing a discriminator, the feature extractor and discriminator form a GAN. The discriminator determines the direction of feature extractor parameter adjustment, making the features trained on different distributed devices more similar to those trained on their corresponding feature extractors. This reduces the heterogeneity of the data between different distributed devices and improves the convergence speed of the global model. This approach achieves the goal of not generating additional data, avoiding the communication overhead of extra data between the server and distributed devices, and improving the performance of federated learning.
[0029] The above scheme is applied to a federated learning system, which includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each distributed device. Both the global and local models are equipped with feature extractors, discriminators, and classifiers. The feature extractors and discriminators form a generative adversarial network (GAN), reducing the heterogeneity of data from different distributed devices through their corresponding feature extractors. The global model, initialized with the above parameters, is trained iteratively multiple times using the server and the multiple distributed devices until it meets the convergence condition, resulting in a fully trained global model. This improves the convergence speed of the global model, avoids generating additional data, and eliminates the communication overhead between the server and the distributed devices, thus enhancing the performance of federated learning. The global model is initialized using the server.
[0030] In some embodiments, the step of performing multi-round iterative training on the global model initialized with the parameters using the server and the plurality of distributed devices includes: performing the following operations for each iteration in the multi-round iterative training: sending the current global model parameters of the global model to each distributed device using the server; training the feature extractor and classifier of the corresponding local model using each distributed device based on the current global model parameters and the local dataset of each distributed device to obtain first feature extractor parameters and classifier parameters; training the discriminator of the corresponding local model using each distributed device based on the current global model parameters, the local dataset, and the first feature extractor parameters to obtain discriminator parameters; training the feature extractor of the corresponding local model using each distributed device based on the local dataset, the first feature extractor parameters, and the discriminator parameters to obtain second feature extractor parameters; sending the classifier parameters, discriminator parameters, and second feature extractor parameters associated with each distributed device to the server; and updating the current global model parameters using the server based on multiple classifier parameters, multiple discriminator parameters, and multiple second feature extractor parameters.
[0031] In this embodiment, the server sends the current global model parameters to each distributed device. Each distributed device trains its local model using the current global model parameters and its local dataset. Each distributed device does not need to share its local dataset with other distributed devices, thus protecting the privacy of each distributed device's local dataset. Each iteration in the multi-round training includes the training of the feature extractor, discriminator, and classifier. Based on the local dataset and the current global model parameters, the feature extractor and classifier are trained separately, improving the speed of the feature extractor in processing the local dataset and the performance of the classifier. After the first training, the feature extractor obtains its first set of parameters, which are then used to update the current feature extractor parameters.
[0032] The discriminator is trained based on the current global model parameters, local dataset, and first feature extractor parameters, improving its discriminative ability. The discriminator determines the direction of feature extractor parameter adjustment; through multiple iterations, the discriminator's ability to adjust feature extractor parameters becomes increasingly sophisticated. A second training iteration of the feature extractor, based on the local dataset, first feature extractor parameters, and discriminator parameters, yields second feature extractor parameters, further enhancing its performance. This iterative training of the feature extractor and discriminator reduces the heterogeneity of data from the local datasets of each distributed device after training with their corresponding feature extractors. The global model parameters in the server are updated by receiving classifier parameters, discriminator parameters, and second feature extractor parameters from each distributed device, achieving one round of iterative training for the global model. Improving the performance of the feature extractor, discriminator, and classifier on each distributed device accelerates the convergence speed of the updated global model parameters, achieving the goal of not generating additional data and avoiding communication overhead between the server and distributed devices.
[0033] In some embodiments, the current global model parameters include current feature extractor parameters, and the local dataset includes multiple sets of data, each set including samples and their corresponding labels; based on the current global model parameters and the local dataset of each distributed device, the feature extractor of its corresponding local model is trained using each distributed device to obtain the first feature extractor parameters, including: training the feature extractor using each distributed device through the following first loss function: Among them, w 1t Here, w1 represents the parameters of the first feature extractor during the t-th training round, and w1 represents the parameters of the current feature extractor. For learning rate, The gradient calculated for the k1-th group of data in the local dataset randomly selected in round t. For the k1th group of samples randomly selected in the t-th round, Let t be the label corresponding to the k1th group of samples randomly selected in the tth round, where t is the number of training rounds.
[0034] In this embodiment, a sample is an instance of data; for example, a sample can be a picture of a cat. The label corresponding to the sample is used to characterize whether the classification of the sample is correct. For example, the model is trained using historical cat pictures labeled as true labels. The current cat picture is then input into the trained model. If the model classifies the current cat picture into the cat category, the label corresponding to the current cat picture is a true label, indicating that the classification of the sample is correct. If the model classifies the current cat picture into other animal categories with equal probability, the label corresponding to the current cat picture is a false label, indicating that the classification of the sample is incorrect. This embodiment uses the stochastic gradient descent algorithm to minimize the loss function to train the feature extractor. The process involves randomly selecting a set of data from the local dataset, training, updating it once according to the gradient, and then selecting another set of data and updating it again. With a large sample size, a model with an acceptable loss value can be obtained without training the entire local dataset. The loss function is a function that maps the value of a random event or its related random variables to a non-negative real number to represent the "loss" of that random event. In this embodiment, the model is solved and evaluated by minimizing the loss function.
[0035] The gradient represents the direction of the fastest change in the model's independent variables along the vector, where the independent variables are the current feature extractor parameters, the k1-th sample, and the label corresponding to the k1-th sample. The stochastic gradient descent algorithm approximates the average loss using the loss of a single sample, and can update the feature extractor parameters with only one set of data, thus accelerating the convergence speed of the feature extractor. It should be noted that to reduce the variance of the gradient and make the feature extractor iteration more stable, several sets of data are needed to train the feature extractor. The purpose of randomly selecting multiple sets of data from the local dataset is to avoid getting trapped in local optima of the local model. Multiplying the gradient by the learning rate yields the change in the feature extractor parameters during the current iteration. Subtracting this change from the current feature extractor parameters gives the trained feature extractor parameters. This improves the speed at which the feature extractor processes local datasets.
[0036] It should be noted that the learning rate in this application is used to control the local model so that its weights conform to the gradient loss. The learning rate can be set based on empirical values, or it can be determined by iterating through the learning rate and dynamically adjusting it to find the most suitable learning rate for the local model.
[0037] In some embodiments, the current global model parameters include current classifier parameters, and the local dataset includes multiple sets of data, each set including samples and their corresponding labels; based on the current global model parameters and the local dataset of each distributed device, the classifier of its corresponding local model is trained using each distributed device to obtain classifier parameters, including: training the classifier using each distributed device through the following second loss function: Among them, w 2t Let w1 be the classifier parameters trained in the t-th round, and w2 be the current classifier parameters. For learning rate, The gradient calculated for the k2th group of data in the local dataset randomly selected in round t. For the k2th group of samples randomly selected in the t-th round, Let t be the label corresponding to the k2th sample group randomly selected in the tth round, where t is the training round number.
[0038] In this embodiment, stochastic gradient descent is used to minimize the loss function to train the classifier. Stochastic gradient descent approximates the average loss using the loss of a single sample, allowing the classifier parameters to be updated with only one set of data, thus accelerating the convergence speed. It should be noted that to reduce the variance of the gradient and make the classifier's iterations more stable, several sets of data are needed to train the classifier. Randomly selecting multiple sets of data from the local dataset aims to avoid getting trapped in local optima. The gradient represents the direction of the fastest change in the model's independent variables along the vector, where the independent variables are the current classifier parameters, the k2-th sample, and the label corresponding to the k2-th sample. Multiplying the gradient by the learning rate yields the change in the classifier parameters during the current iteration. Subtracting this change from the current classifier parameters gives the trained classifier parameters, thus improving the classifier's performance.
[0039] In some embodiments, the current global model parameters include current discriminator parameters, and the local dataset includes multiple sets of data, each set including samples and their corresponding labels; the step of training the discriminator of its corresponding local model using each distributed device based on the current global model parameters, the local dataset, and the first feature extractor parameters to obtain discriminator parameters includes: using each distributed device to label the label corresponding to the sample as the true label corresponding to the sample, wherein the true label corresponding to the sample is used to characterize the label that correctly classifies the sample; and using each distributed device to train the discriminator using the following third loss function: Where, θ t Let θ be the discriminator parameters trained in the t-th round, and θ be the current discriminator parameters. For learning rate, The gradient w is calculated for the k3th group of data in the local dataset randomly selected in round t. 1t The parameters of the first feature extractor during the t-th round of training are... For the k3th group of samples randomly selected in the t-th round, Let t be the true label corresponding to the k3th sample randomly selected in the t-th round, where t is the number of training rounds.
[0040] In this embodiment, stochastic gradient descent (SDD) is used to minimize the loss function to train the discriminator. SDD approximates the average loss using the loss of a single sample, allowing for the updating of discriminator parameters with only one set of data, thus accelerating the discriminator's convergence. It should be noted that to reduce gradient variance and make the discriminator's iterations more stable, several sets of data are needed for training. Randomly selecting multiple sets of data from the local dataset aims to avoid getting trapped in local optima. The gradient represents the direction of the fastest change in the model's independent variables along the vector, where the independent variables are the current discriminator parameters, the first feature extractor parameters, the k3th sample, and the label corresponding to the k3th sample. During gradient calculation, the local dataset is processed by the updated feature extractor parameters, and the processed local dataset and the current global model parameters are used to train the discriminator. Multiplying the gradient by the learning rate yields the change in the discriminator parameters during this iteration. Subtracting this change from the current discriminator parameters gives the trained discriminator parameters, thus improving the discriminator's performance. It's important to note that the true labels corresponding to the samples are used to characterize the labels that correctly classify the samples. Training the discriminator using samples with true labels improves its ability to distinguish data, thereby enabling the adjustment of feature extractor parameters. The discriminative function of the discriminator allows for the adjustment of feature extractor parameters. In the next training iteration, this ensures that the features of the training data from each distributed device, trained with their corresponding feature extractors, become more similar. In the next training iteration, the adjusted feature extractors are then trained on the local data, reducing the heterogeneity of the local data from each distributed device after training with their corresponding feature extractors, thus improving the convergence speed of the global model.
[0041] In some embodiments, the step of training the feature extractor of the corresponding local model using each distributed device based on the local dataset, the first feature extractor parameters, and the discriminator parameters to obtain the second feature extractor parameters includes: using each distributed device to label the label corresponding to the sample as a false label corresponding to the sample, wherein the false label corresponding to the sample is used to characterize the label that misclassifies the sample; and using each distributed device to train the feature extractor using the following fourth loss function: Among them, w3t Let w be the parameter of the second feature extractor during the t-th round of training. 1t The parameters of the first feature extractor in the t-th round of training are... For learning rate, The gradient θ is calculated for the k4th set of data in the local dataset randomly selected in round t. t Let be the discriminator parameters trained in the t-th round. For the k4th sample group randomly selected in the t-th round, The false label is the k4th sample randomly selected in the t-th round, where t is the number of training rounds.
[0042] In this embodiment, stochastic gradient descent (STDD) is used to minimize the loss function to train the feature extractor. STDD approximates the average loss using the loss of a single sample, allowing for updates to the feature extractor parameters with only one set of data, thus accelerating the convergence speed. It should be noted that to reduce gradient variance and make the feature extractor iteration more stable, several sets of data are needed to train the feature extractor. Randomly selecting multiple sets of data from the local dataset aims to avoid getting trapped in local optima. The gradient represents the direction of the fastest change in the model's independent variables along the vector, where the independent variables are the current discriminator parameters, the first feature extractor parameters, the k4th sample, and the label corresponding to the k4th sample. During gradient calculation, the local dataset is processed using the updated discriminator parameters, and the processed local dataset and the current global model parameters are used for a second training of the feature extractor. Multiplying the gradient by the learning rate yields the change in the feature extractor parameters during this iteration. Subtracting this change from the current feature extractor parameters gives the trained feature extractor parameters, thus improving the performance of the feature extractor. It should be noted that the fake labels corresponding to the samples are used to represent the labels that misclassify the samples. The feature extractor is trained using the samples corresponding to the fake labels, so that the parameters of the feature extractor can confuse the discriminator. The discriminator improves its ability to adjust the parameters of the feature extractor by adversarial with the feature extractor.
[0043] In some embodiments, updating the current global model parameters using the server based on a plurality of classifier parameters, a plurality of discriminator parameters, and a plurality of second feature extractor parameters includes: using the server to calculate a first average value of a plurality of classifier parameters, a second average value of a plurality of discriminator parameters, and a third average value of a plurality of second feature extractor parameters; and updating the current global model parameters using the server based on the first average value, the second average value, and the third average value.
[0044] In this embodiment, the server receives classifier parameters, discriminator parameters, and second feature extractor parameters from each device. To improve the accuracy of the current global model, the server averages the values of these parameters. The average value more closely approximates the parameters trained on the local models of each distributed device. This average value, calculated based on the improved local model training parameters, accelerates the convergence speed of the global model. Updating the current global model parameters using this average value enhances the performance of federated learning.
[0045] In some embodiments, the global model satisfies the convergence condition, including: in response to determining that the current global model parameters are equal to the global model parameters obtained in the previous iteration of training, determining that the global model satisfies the convergence condition.
[0046] In this embodiment, if the current global model parameters are equal to those obtained in the previous iteration of training, it indicates that the current global model parameters have not changed, meaning the global model meets the convergence condition and has achieved convergence. It should be noted that the booster and discriminator in this application are located in the shallow layers of the model, improving their training efficiency, while the classifier is located in the deep layers, making its mapping of the data more accurate. The global model training process in this application does not require the transmission of data from distributed devices, nor does it generate new data from the distributed devices, thus protecting the data privacy of each distributed device and reducing additional communication overhead.
[0047] In one embodiment provided in this application, a handwritten digit recognition task is performed on the MNIST (Mixed National Institute of Standards and Technology) dataset, a digit database collected and organized by the National Institute of Standards and Technology (NIST). The MNIST dataset contains 60,000 training data points and 10,000 test data points, with a data resolution of 28*28. This example uses 10 distributed devices for distributed training to complete this federated learning task of digit recognition. First, the 60,000 training data points are sorted according to the size of the digits. Then, the sorted training data is sliced into 20 slices, each containing 3,000 data points. The first 3,000 data points are the first slice, and so on. Afterward, the data is randomly distributed among the 10 distributed devices, with each device receiving two slices. Through these operations, it is ensured that the data received by each distributed device is different, achieving the instance operation setting of non-independent and identically distributed distributed data.
[0048] This example sets up the neural network as follows: The feature extractor consists of an input layer with 28*28 neurons, a hidden layer with 128 neurons, a hidden layer with 256 neurons, a hidden layer with 512 neurons, a hidden layer with 1024 neurons, and an output layer with 28*28 neurons and a Tanh output function. The discriminator consists of an input layer with 28*28 neurons, a hidden layer with 512 neurons, a hidden layer with 256 neurons, and an output layer with 10 neurons and a Sigmoid output function. The classifier consists of an input layer with 28*28 neurons, a hidden layer with 64 neurons, and an output layer with 10 neurons and a Sigmoid output function. The activation function of the intermediate layers in the feature extractor and discriminator is Leaky ReLU, and the activation function of the intermediate layers in the classifier is ReLU. Stochastic gradient descent is employed to minimize the loss function, which is defined as the binary cross-entropy function. The learning rate is set to 0.01. A global model is trained to complete the federated learning task of digit recognition.
[0049] It should be noted that the method in this embodiment can be executed by a single device, such as a computer or server. The method can also be applied in a distributed scenario, where multiple devices cooperate to complete the task. In such a distributed scenario, one of these devices may execute only one or more steps of the method in this embodiment, and the multiple devices will interact with each other to complete the method described.
[0050] It should be noted that the above description describes some embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in a different order than that shown in the above embodiments and still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0051] Based on the same inventive concept, corresponding to any of the above embodiments, this application also provides a training device for a global model.
[0052] refer to Figure 2This is applied to a federated learning system, which includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each distributed device. Both the global model and each local model are equipped with a feature extractor, a discriminator, and a classifier. The feature extractor and the discriminator form a generative adversarial network. The training device for the global model includes:
[0053] Initialization module 10 is configured to use the server to initialize the parameters of the global model.
[0054] The iterative training module 20 is configured to use the server and the multiple distributed devices to perform multiple rounds of iterative training on the global model initialized with the parameters until the global model meets the convergence condition, thereby obtaining the trained global model.
[0055] The aforementioned apparatus is applied to a federated learning system, which includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each distributed device. Both the global and local models are equipped with feature extractors, discriminators, and classifiers. The feature extractors and discriminators form a generative adversarial network (GAN), reducing the heterogeneity of data from different distributed devices through their corresponding feature extractors. The global model is initialized with parameters using the server. Multiple rounds of iterative training are performed on the initialized global model using the server and the multiple distributed devices until the global model meets the convergence condition, resulting in a trained global model. This improves the convergence speed of the global model, avoids generating additional data, eliminates communication overhead between the server and the distributed devices, and enhances the performance of federated learning.
[0056] In some embodiments, the iterative training module 20 is further configured to perform the following operations for each iteration in the multi-round iterative training: sending the current global model parameters of the global model to each distributed device using the server; training the feature extractor and classifier of the corresponding local model using each distributed device based on the current global model parameters and the local dataset of each distributed device to obtain first feature extractor parameters and classifier parameters; training the discriminator of the corresponding local model using each distributed device based on the current global model parameters, the local dataset, and the first feature extractor parameters to obtain discriminator parameters; training the feature extractor of the corresponding local model using each distributed device based on the local dataset, the first feature extractor parameters, and the discriminator parameters to obtain second feature extractor parameters; sending the classifier parameters, discriminator parameters, and second feature extractor parameters associated with each distributed device to the server; and updating the current global model parameters using the server based on multiple classifier parameters, multiple discriminator parameters, and multiple second feature extractor parameters.
[0057] In some embodiments, the iterative training module 20 is further configured such that the current global model parameters include the current feature extractor parameters, the local dataset includes multiple sets of data, each set of data including samples and their corresponding labels; and the feature extractor is trained using each distributed device through the following first loss function: Among them, w 1t Here, w1 represents the parameters of the first feature extractor during the t-th training round, and w1 represents the parameters of the current feature extractor. For learning rate, The gradient calculated for the k1-th group of data in the local dataset randomly selected in round t. For the k1th group of samples randomly selected in the t-th round, Let t be the label corresponding to the k1th group of samples randomly selected in the tth round, where t is the number of training rounds.
[0058] In some embodiments, the iterative training module 20 is further configured such that the current global model parameters include the current classifier parameters, the local dataset includes multiple sets of data, each set of data including samples and their corresponding labels; and the classifier is trained using each distributed device through the following second loss function: Among them, w 2t Let w1 be the classifier parameters trained in the t-th round, and w2 be the current classifier parameters. For learning rate, The gradient calculated for the k2th group of data in the local dataset randomly selected in round t. For the k2th group of samples randomly selected in the t-th round, Let t be the label corresponding to the k2th sample group randomly selected in the tth round, where t is the training round number.
[0059] In some embodiments, the iterative training module 20 is further configured such that the current global model parameters include the current discriminator parameters, the local dataset includes multiple sets of data, each set of data including samples and their corresponding labels; each distributed device is used to label the labels corresponding to the samples as the true labels corresponding to the samples, wherein the true labels corresponding to the samples are used to characterize the labels that correctly classify the samples; each distributed device is used to train the discriminator using the following third loss function: Where, θ t Let θ be the discriminator parameters trained in the t-th round, and θ be the current discriminator parameters. For learning rate, The gradient w is calculated for the k3th group of data in the local dataset randomly selected in round t. 1t The parameters of the first feature extractor during the t-th round of training are... For the k3th group of samples randomly selected in the t-th round, Let t be the true label corresponding to the k3th sample randomly selected in the t-th round, where t is the number of training rounds.
[0060] In some embodiments, the iterative training module 20 is further configured to use each distributed device to label the label corresponding to the sample as a false label corresponding to the sample, wherein the false label corresponding to the sample is used to characterize the label of misclassification of the sample; and to train the feature extractor using each distributed device through the following fourth loss function: Among them, w 3t Let w be the parameter of the second feature extractor during the t-th round of training. 1t The parameters of the first feature extractor in the t-th round of training are... For learning rate, The gradient θ is calculated for the k4th set of data in the local dataset randomly selected in round t. t Let be the discriminator parameters trained in the t-th round. For the k4th group of samples randomly selected in the t-th round, The false label is the k4th sample randomly selected in the t-th round, where t is the number of training rounds.
[0061] In some embodiments, the iterative training module 20 is further configured to use the server to calculate a first average value of a plurality of classifier parameters, a second average value of a plurality of discriminator parameters, and a third average value of a plurality of second feature extractor parameters; and to update the current global model parameters using the server based on the first average value, the second average value, and the third average value.
[0062] In some embodiments, the iterative training module 20 is further configured to determine that the global model satisfies the convergence condition in response to determining that the current global model parameters are equal to the global model parameters obtained in the previous round of iterative training.
[0063] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, in implementing this application, the functions of each module can be implemented in one or more software and / or hardware.
[0064] The apparatus described above is used to implement the training method of the corresponding global model in any of the foregoing embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0065] Based on the same inventive concept, corresponding to the methods of any of the above embodiments, this application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the training method of the global model described in any of the above embodiments.
[0066] Figure 3 This embodiment illustrates a more specific hardware structure of an electronic device, which may include a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, memory 1020, input / output interface 1030, and communication interface 1040 are interconnected internally via the bus 1050.
[0067] The processor 1010 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0068] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010.
[0069] The input / output interface 1030 is used to connect input / output modules to realize information input and output. Input / output modules can be configured as components within the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Input devices may include keyboards, mice, touchscreens, microphones, various sensors, etc., while output devices may include displays, speakers, vibrators, indicator lights, etc.
[0070] The communication interface 1040 is used to connect a communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0071] Bus 1050 includes a pathway for transmitting information between various components of the device, such as processor 1010, memory 1020, input / output interface 1030, and communication interface 1040.
[0072] It should be noted that although the above-described device only shows the processor 1010, memory 1020, input / output interface 1030, communication interface 1040, and bus 1050, in specific implementations, the device may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the components necessary for implementing the embodiments of this specification, and not necessarily all the components shown in the figures.
[0073] The electronic devices described above are used to implement the training method of the corresponding global model in any of the foregoing embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0074] Based on the same inventive concept, corresponding to the methods of any of the above embodiments, this application also provides a non-transitory computer-readable storage medium that stores computer instructions for causing the computer to execute the training method of the global model as described in any of the above embodiments.
[0075] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.
[0076] The computer instructions stored in the storage medium of the above embodiments are used to cause the computer to execute the training method of the global model as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0077] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of this application (including the claims) is limited to these examples; within the framework of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of the embodiments of this application as described above, which are not provided in the details for the sake of brevity.
[0078] Additionally, to simplify the description and discussion, and to avoid obscuring the embodiments of this application, the well-known power / ground connections to integrated circuit (IC) chips and other components may or may not be shown in the provided drawings. Furthermore, the apparatus may be shown in block diagram form to avoid obscuring the embodiments of this application, and this also takes into account the fact that the details of the implementation of these block diagram apparatuses are highly dependent on the platform on which the embodiments of this application will be implemented (i.e., these details should be fully understood by those skilled in the art). While specific details (e.g., circuits) have been set forth to describe exemplary embodiments of this application, it will be apparent to those skilled in the art that the embodiments of this application can be implemented without these specific details or with variations thereof. Therefore, these descriptions should be considered illustrative rather than restrictive.
[0079] Although this application has been described in conjunction with specific embodiments thereof, many substitutions, modifications, and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may be used with the embodiments discussed.
[0080] The embodiments of this application are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of this application should be included within the protection scope of this application.
Claims
1. A method for training a global model, characterized in that, The method is applied to a federated learning system, which includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each distributed device. The global model and each local model are equipped with a feature extractor, a discriminator, and a classifier. The feature extractor and the discriminator form a generative adversarial network. The method includes: The global model is initialized using the server. The global model initialized with the parameters is trained in multiple rounds using the server and the multiple distributed devices until the global model meets the convergence condition, thus obtaining the trained global model. The step of using the server and the multiple distributed devices to perform multiple rounds of iterative training on the global model initialized with the parameters includes: For each iteration in the multi-round iterative training, the following operation is performed: The server is used to send the current global model parameters of the global model to each distributed device; Based on the current global model parameters and the local dataset of each distributed device, the feature extractor and classifier of the corresponding local model are trained using each distributed device to obtain the first feature extractor parameters and classifier parameters. Based on the current global model parameters, the local dataset, and the first feature extractor parameters, the discriminator of the corresponding local model is trained using each distributed device to obtain the discriminator parameters, wherein the local dataset is an image dataset; Based on the local dataset, the first feature extractor parameters, and the discriminator parameters, the feature extractor of the corresponding local model is trained using each distributed device to obtain the second feature extractor parameters. Each distributed device sends its associated classifier parameters, discriminator parameters, and second feature extractor parameters to the server. The server updates the current global model parameters based on multiple classifier parameters, multiple discriminator parameters, and multiple second feature extractor parameters.
2. The method according to claim 1, characterized in that, The current global model parameters include the current feature extractor parameters, and the local dataset includes multiple sets of data, each set of data including samples and the labels corresponding to the samples; Based on the current global model parameters and the local dataset of each distributed device, the feature extractor of the corresponding local model is trained using each distributed device to obtain the first feature extractor parameters, including: The feature extractor is trained using each distributed device through the following first loss function: , in, For the first The parameters of the first feature extractor in the first round of training, The parameters of the current feature extractor are... For learning rate, For the first The first round of random selection of the local dataset The gradient calculated from the set of data, For the first The first round of random selection Group samples, For the first The first round of random selection The labels corresponding to the group samples This represents the number of training rounds.
3. The method according to claim 1, characterized in that, The current global model parameters include the current classifier parameters, and the local dataset includes multiple sets of data, each set of data including samples and the labels corresponding to the samples; Based on the current global model parameters and the local dataset of each distributed device, the classifier of the corresponding local model is trained using each distributed device to obtain the classifier parameters, including: The classifier is trained using each distributed device through the following second loss function: , in, For the first Classifier parameters during round training, The parameters of the current classifier, For learning rate, For the first The first round of random selection of the local dataset The gradient calculated from the set of data, For the first The first round of random selection Group samples, For the first The first round of random selection The labels corresponding to the group samples This represents the number of training rounds.
4. The method according to claim 1, characterized in that, The current global model parameters include the current discriminator parameters, and the local dataset includes multiple sets of data, each set of data including samples and the labels corresponding to the samples; The process of training a discriminator for each distributed device on its corresponding local model based on the current global model parameters, the local dataset, and the first feature extractor parameters to obtain discriminator parameters includes: Each distributed device is used to mark the label corresponding to the sample as the true label corresponding to the sample, wherein the true label corresponding to the sample is used to characterize the label that correctly classifies the sample; The discriminator is trained using each distributed device through the following third loss function: , in, For the first Discriminator parameters during round training, The current discriminator parameters, For learning rate, For the first The first round of random selection of the local dataset The gradient calculated from the set of data, For the first The parameters of the first feature extractor in the first round of training, For the first The first round of random selection Group samples, For the first The first round of random selection The true labels corresponding to the group of samples. This represents the number of training rounds.
5. The method according to claim 2, characterized in that, The step of training the feature extractor of the corresponding local model using each distributed device based on the local dataset, the first feature extractor parameters, and the discriminator parameters to obtain the second feature extractor parameters includes: Each distributed device is used to mark the label corresponding to the sample as a false label corresponding to the sample, wherein the false label corresponding to the sample is used to characterize the label that misclassifies the sample; The feature extractor is trained using each distributed device through the following fourth loss function: , in, For the first The parameters of the second feature extractor in the first round of training, For the first The parameters of the first feature extractor in the first round of training, For learning rate, For the first The first round of random selection of the local dataset The gradient calculated from the set of data, For the first Discriminator parameters during round training, For the first The first round of random selection Group samples, For the first The first round of random selection The fake labels corresponding to the group samples The training round number is [number].
6. The method according to claim 1, characterized in that, The step of updating the current global model parameters using the server based on multiple classifier parameters, multiple discriminator parameters, and multiple second feature extractor parameters includes: The server is used to calculate a first average value of a plurality of classifier parameters, a second average value of a plurality of discriminator parameters, and a third average value of a plurality of second feature extractor parameters; Based on the first average value, the second average value, and the third average value, the current global model parameters are updated using the server.
7. The method according to claim 1, characterized in that, The global model satisfies convergence conditions, including: In response to determining that the current global model parameters are equal to the global model parameters obtained in the previous iteration of training, the global model is determined to satisfy the convergence condition.
8. A training device for a global model, characterized in that, The method is applied to a federated learning system, which includes a server and multiple distributed devices. A global model is deployed on the server, and local models are deployed on each distributed device. The global model and each local model are equipped with a feature extractor, a discriminator, and a classifier. The feature extractor and the discriminator form a generative adversarial network. The device includes: The initialization module is configured to use the server to initialize the parameters of the global model. The iterative training module is configured to use the server and the multiple distributed devices to perform multiple rounds of iterative training on the global model initialized with the parameters until the global model meets the convergence condition, thereby obtaining the trained global model. The iterative training module is further configured to perform the following operation for each iteration in the multi-round iterative training: The server is used to send the current global model parameters of the global model to each distributed device; Based on the current global model parameters and the local dataset of each distributed device, the feature extractor and classifier of the corresponding local model are trained using each distributed device to obtain the first feature extractor parameters and classifier parameters. Based on the current global model parameters, the local dataset, and the first feature extractor parameters, the discriminator of the corresponding local model is trained using each distributed device to obtain the discriminator parameters, wherein the local dataset is an image dataset; Based on the local dataset, the first feature extractor parameters, and the discriminator parameters, the feature extractor of the corresponding local model is trained using each distributed device to obtain the second feature extractor parameters. Each distributed device sends its associated classifier parameters, discriminator parameters, and second feature extractor parameters to the server. The server updates the current global model parameters based on multiple classifier parameters, multiple discriminator parameters, and multiple second feature extractor parameters.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Federal learning modeling optimization method and device, readable storage medium and program product
CN113869533A
Domain generalization method based on federal learning
CN114399055A