A generalization adjustment method and a federated learning system for federated learning
By calculating the generalization difference and adjusting the aggregation weights in federated learning, the generalization problem caused by the difference in terminal data distribution is solved, and the performance of the model on new terminals is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI ARTIFICIAL INTELLIGENCE INNOVATION CENT
- Filing Date
- 2023-04-20
- Publication Date
- 2026-07-03
AI Technical Summary
Existing federated learning techniques have poor generalization ability under different data distributions on different terminals, and cannot adapt to new data distributions, resulting in limited model performance.
The generalization difference is calculated on the local terminal, and the aggregation weights are adjusted on the server side based on the generalization difference. The model is trained using the gradient descent principle, and the global model parameters are dynamically adjusted to reduce the variance of the generalization difference across terminals.
It effectively reduces the generalization error of the global model under cross-domain distribution conditions and improves the applicability and generalization ability of the model on different data distributions.
Smart Images

Figure CN116796865B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine learning technology, and in particular to a generalization adjustment method and a federated learning system for federated learning. Background Technology
[0002] Machine learning technology has been widely applied in fields such as data mining, and machine learning models trained on large amounts of data can be applied to various scenarios. However, with the deepening of digitalization and informatization, data privacy and security issues, such as sensor data from mobile phones, surveillance camera data, and hospital medical data, are receiving increasing attention. Traditional deep learning technologies based on a centralized learning paradigm often aggregate data collected from various channels to a central node for unified model training, which makes it impossible to guarantee that data privacy will not be leaked during the collection process. To solve this problem, research has proposed a federated learning framework. Its core idea is that when multiple data sources participate in model training, there is no need for raw data to be transferred; the model is jointly trained only by interacting with intermediate model parameters, and the raw data does not need to leave the local machine. This approach can achieve a balance between data privacy protection and data sharing analysis, namely a "data usable but not visible" data application model, thereby ensuring the privacy and security of the terminal that owns the data during the training process. Specifically, the federated learning framework is structurally divided into a central server and multiple terminals. Data is stored on each terminal, and each terminal is responsible for completing local training on its own data and uploading its local model parameters or gradients to the central server. The central server is only responsible for aggregating the parameters passed in by the terminals and distributing the aggregated parameters to each terminal. The local training and central aggregation phases alternate, and finally, the aggregated model on the central server converges on the data of each terminal, resulting in a converged global model.
[0003] Because of the differences in data distribution across different terminals, the models trained locally on each terminal exhibit significant differences, resulting in poor performance of the final global model and potentially leading to data heterogeneity issues in federated learning. Currently, two main approaches are used to address the generalization problem of the global model to new data distributions under these inconsistent data distribution conditions: First, incorporating generalization-enhancing techniques from the centroid learning paradigm into the local training phase of federated learning, including data augmentation and feature regularization; second, constraining the differences between the local and global models during local training, thereby limiting the optimization direction of the local model to achieve convergence of the global model. However, these methods do not consider the different data distributions across terminals in their global optimization objectives, still employing the traditional assumption of independent and identically distributed data, treating all training data as samples sampled from a single distribution. Algorithms designed under this assumption are inherently unable to adapt to new terminals with different data distributions, resulting in unavoidable algorithmic bias and thus poor model generalization. Summary of the Invention
[0004] To address some or all of the problems in the prior art, the first aspect of this invention provides a generalization adjustment method for federated learning, comprising:
[0005] Calculate the generalization difference on the local terminal;
[0006] The local model is obtained by performing the r-th round of training on the local terminal.
[0007] Upload the local model from the r-th round and the generalization difference to the server; and
[0008] Global model parameters are aggregated on the server side to obtain the global model for the (r+1)th round.
[0009] Furthermore, the generalization difference is the difference between the loss function value of the local model obtained from the (r-1)th round of federated training and the loss function value of the global model on the local data in the rth round.
[0010] Furthermore, the r-th round of training is performed on the local terminal using a neural network training method based on the gradient descent principle.
[0011] Furthermore, global model parameter aggregation includes:
[0012] Adjust the aggregation weights based on the generalization differences; and
[0013] Global model parameter aggregation is performed based on the aggregated weights.
[0014] Further, adjusting the aggregation weight based on the generalization difference includes calculating the aggregation weight of the i-th local terminal in the r-th round according to the following formula:
[0015]
[0016] in,
[0017] in, Let be the aggregation weight of the i-th local terminal in the (r-1)-th round. Let be the generalization difference of the i-th local terminal in the r-th round, μ be the mean of the generalization differences uploaded by the local terminals, M be the total number of local terminals, and d be the generalization difference of the local terminals in the r-th round. r To adjust the step size.
[0018] Furthermore, the adjustment step size decreases linearly with each training round.
[0019] Furthermore, the initial value of the aggregation weight of the i-th local terminal is 1 / M.
[0020] A second aspect of the present invention provides a federated learning system, comprising:
[0021] The local terminal includes a generalization error calculation module, which is used to calculate the generalization error for each round; and
[0022] The server-side includes a weight adjustment module, which is used to adjust the aggregate weights based on the generalization difference.
[0023] A third aspect of the present invention provides a computer-readable storage medium having machine-readable instructions stored thereon, which, when executed by a processor, perform steps according to the generalization adjustment method described above.
[0024] This invention provides a generalization adjustment method and system for federated learning, which employs generalization adjustment techniques. Specifically, it introduces an additional generalization difference calculation step during the local terminal training phase, and adjusts the aggregation weights based on the generalization differences uploaded by each local terminal during the global model parameter aggregation phase. This generalization adjustment technique minimizes the variance of generalization differences among local terminals during federated learning training. Variance minimization effectively reduces the generalization error of the global model across domains, ensuring that the final global optimization objective closely approximates the true desired optimization objective under conditions of cross-domain data distribution. This allows the parameter model trained by federated learning to be applicable to new terminals with different data distributions, improving the generalization problem in the federated domain. Attached Figure Description
[0025] To further illustrate the above and other advantages and features of the various embodiments of the present invention, a more specific description of the various embodiments of the present invention will be presented with reference to the accompanying drawings. It is to be understood that these drawings depict only typical embodiments of the invention and are therefore not intended to limit its scope. In the drawings, identical or corresponding parts will be indicated by identical or similar reference numerals for clarity.
[0026] Figure 1 This diagram illustrates a flowchart of a generalization adjustment method for federated learning according to an embodiment of the present invention; and
[0027] Figure 2 A schematic diagram of the structure of a federated learning system according to an embodiment of the present invention is shown. Detailed Implementation
[0028] In the following description, the invention is described with reference to various embodiments. However, those skilled in the art will recognize that the embodiments may be practiced without one or more specific details or in conjunction with other alternatives and / or additional methods or components. In other instances, well-known structures or operations are not shown or described in detail so as not to obscure the inventive points of the invention. Similarly, for illustrative purposes, specific numbers and configurations are set forth to provide a comprehensive understanding of embodiments of the invention. However, the invention is not limited to these specific details.
[0029] In this specification, references to "an embodiment" or "this embodiment" mean that a particular feature, structure, or characteristic described in connection with that embodiment is included in at least one embodiment of the invention. The phrase "in one embodiment" appearing throughout this specification does not necessarily refer to the same embodiment in all instances.
[0030] It should be noted that the embodiments of the present invention describe the method steps in a specific order; however, this is only for illustrating the specific embodiment and not for limiting the order of the steps. On the contrary, in different embodiments of the present invention, the order of the steps can be adjusted according to actual needs.
[0031] In this invention, the modules of the system according to the invention can be implemented using software, hardware, firmware, or a combination thereof. When a module is implemented using software, its function can be implemented through computer program flow. For example, the module can be implemented using code segments (such as code segments in languages like C and C++) stored in a storage device (such as a hard disk, memory, etc.), wherein the corresponding function of the module can be implemented when the code segment is executed by a processor. When a module is implemented using hardware, its function can be implemented by setting a corresponding hardware structure. For example, the module's function can be implemented by hardware programming a programmable device such as a field-programmable gate array (FPGA), or by designing an application-specific integrated circuit (ASIC) including multiple transistors, resistors, capacitors, and other electronic devices. When a module is implemented using firmware, the module's function can be written into a read-only memory such as an EPROM or EEPROM in the form of program code, and the corresponding function of the module can be implemented when the program code is executed by a processor. In addition, some functions of the module may need to be implemented by separate hardware or by working in cooperation with the hardware. For example, the detection function is implemented by the corresponding sensor (such as a proximity sensor, accelerometer, gyroscope, etc.), the signal transmission function is implemented by the corresponding communication device (such as a Bluetooth device, infrared communication device, baseband communication device, Wi-Fi communication device, etc.), the output function is implemented by the corresponding output device (such as a display, speaker, etc.), and so on.
[0032] Existing federated learning techniques do not consider the different data distributions of different terminals in their global optimization objective. Instead, they employ the assumption of independent and identically distributed (IOD) data, treating all training data as samples drawn from a single, identical distribution. Algorithms designed under this assumption are inherently unable to adapt to new terminals with different data distributions, resulting in poor generalization ability. Specifically, let the set of data from all terminals be denoted as... The datasets corresponding to the M terminals that actually participated in the training are as follows: Each dataset consists of data x and labels y, denoted as . Existing technical solutions all involve designing a model f(x; θ) with parameters θ and setting a classification loss function. And the final optimization goal is as follows:
[0033]
[0034] In this optimization objective, the proportion p of different terminals in the global optimization objective is... iThis approach is solely dependent on the amount of data and is typically a fixed value, completely disregarding the distribution differences between different terminals and the ease of training. Algorithms based on this optimization objective prioritize terminals with large datasets, neglecting those with smaller datasets. However, in practical applications, the importance of a terminal cannot be represented by the amount of data. Conversely, terminals with smaller datasets often have higher requirements for algorithm generalization and require more attention. Existing solutions neglect in-depth research on the global optimization objective, resulting in unavoidable algorithmic bias. This leads to a discrepancy between the final global optimization objective and the actual desired optimization objective under conditions of cross-domain data distribution. This discrepancy limits the performance of the parameter model trained by federated learning on new terminals with different data distributions. Addressing the characteristics of domain generalization problems in federated learning, this invention proposes a generalization adjustment method for federated learning. This method dynamically adjusts the global optimization objective by estimating the generalization of parameters contributed by each terminal node to the server during the global model aggregation process. The generalization adjustment method monitors the generalization indices of each local terminal in real time during training, specifically adjusting the global optimization objective towards a more generalized perspective. The generalization adjustment method can complement existing technical means and, when combined with most existing technical solutions, better solve the generalization problem in the federal domain.
[0035] In embodiments of the present invention, the generalization adjustment method comprises a local terminal component and a server-side component, alternately performing cross-domain generalization enhancement improvements during the model training phase on the local terminal and the global aggregation phase on the server side. Specifically, the local terminal training phase utilizes a local model training step based on gradient descent and calculates a generalization metric based on the difference between the global model and the local model. Furthermore, the server-side generalization adjustment phase employs a dynamic weight adjustment technique based on the variance of generalization differences across terminals, and aggregates a new global model using the generalized adjustment parameters.
[0036] The technical solution of the present invention will be further described below with reference to the accompanying drawings of the embodiments.
[0037] Figure 1 This diagram illustrates a flowchart of a generalization adjustment method for federated learning according to an embodiment of the present invention. Figure 1 As shown, a generalization adjustment method for federated learning includes:
[0038] First, in step 101, the generalization difference is calculated. The generalization difference is calculated before each training round on the local terminal. This step can be omitted before the first training round. Simultaneously, the global model parameters required for the first training round are initialized by the server and distributed to each local terminal. In one embodiment of the invention, the generalization difference is based on the local model loss function value obtained from the previous round (r-1th round) of federated training. The loss function value of the corresponding global model generated by local training on local data The calculation yielded:
[0039]
[0040] Wherein, the corresponding global model generated by local training refers to the global model of the rth round obtained by aggregating the parameters of the local model of the previous round (r-1 round);
[0041] Next, in step 102, local training is performed. The r-th round of training is conducted on the local terminal to obtain the local model in the r-th round. In embodiments of this invention, the training algorithm for the local terminal is not limited; any federated learning training algorithm for the local terminal can be used. For example, in one embodiment of this invention, a neural network training method based on gradient descent is used on the local terminal for the r-th round of training. The specific training method and steps are basically the same as those of traditional federated learning techniques and will not be described in detail here.
[0042] Next, in step 103, the local models and generalization differences are uploaded. The generalization differences for each local terminal calculated in step 101, and the local models for each local terminal trained in step 102, are uploaded to the server.
[0043] Finally, in step 104, parameter aggregation occurs. After receiving the local model and generalization differences, the server performs global model parameter aggregation to obtain the global model for round r+1. As mentioned earlier, to better improve the generalization problem, in one embodiment of the present invention, during the global model parameter aggregation stage on the server side, the aggregation weights are first adjusted based on the generalization differences uploaded by each local terminal, and then global model parameter aggregation is performed based on the adjusted aggregation weights. The basis or goal of adjusting the aggregation weights is to minimize the variance of the generalization differences of all local terminals in the entire system. The inventors have found through research that increasing the weight of a local terminal during parameter aggregation can effectively reduce the generalization error on the corresponding local terminal. However, for nodes with small generalization errors, appropriately reducing the corresponding weights does not significantly change the generalization error. Based on this, in one embodiment of the present invention, the aggregation weights of each local terminal are adjusted according to the following formula:
[0044]
[0045] in,
[0046] The aggregate weight refers to the weight of the i-th local terminal in the r-th round. In one embodiment of the present invention, for a federated learning system with M local nodes, the initial value of the aggregate weight can be set to, for example, 1 / M; and
[0047] in, Let be the aggregation weight of the i-th local terminal in the (r-1)-th round. Let μ be the generalization difference of the i-th local terminal in the r-th round, μ be the mean of the generalization differences uploaded by M local nodes, M be the total number of local terminals, and d be the generalization difference of the i-th local terminal in the r-th round. r To adjust the step size.
[0048] Following the steps described above, perform multiple training rounds until preset conditions are met, completing the overall federated training. These preset conditions may include, for example, a preset number of training rounds or a preset generalization error.
[0049] To facilitate overall training convergence, in one embodiment of the present invention, the magnitude of weight adjustment needs to be gradually reduced as training progresses. Therefore, the adjustment step size employs a linear step size decay strategy, meaning the adjustment step size decreases linearly with each training round. However, it should be understood that other dynamic adjustment strategies are employed in other embodiments of the present invention, such as fixed step size adjustment, non-linear step size decay, etc.
[0050] The generalization adjustment method described above can be combined with most existing federated learning algorithms to effectively improve the generalization ability of the global model in the federated learning framework for unknown data distributions with minimal computational and communication overhead. To verify its effectiveness, tests were conducted on four benchmark datasets for federated domain generalization. The tests show that the generalization adjustment method achieves state-of-the-art performance compared to various federated learning approaches, and that the generalization adjustment technique can significantly reduce the mean and variance of generalization discrepancies. Furthermore, visualization of the loss function surface over the test domain distribution reveals that, compared to existing federated learning methods, the generalization weight adjustment method in this embodiment of the invention achieves higher consistency between the local and global models, with the global model falling into the high generalization region of the loss function surface. Therefore, it can greatly improve the generalization ability of the overall federated learning model under heterogeneous data conditions with distributional drift. Moreover, the approach of using node variance to reflect the generalization ability of the global model in this embodiment can also be applied to the design of other algorithms with cross-domain data distributions to improve generalization problems.
[0051] Based on the generalization adjustment method described above Figure 2 A schematic diagram of the structure of a federated learning system according to an embodiment of the present invention is shown. Figure 2As shown, a federated learning system includes M local terminals 2011, 2012, ..., 201M and a server 202. Compared to traditional federated learning systems, each local terminal further includes a generalization error calculation module 211, which calculates the generalization error of each local terminal in each round according to the method described above. The server 202 also includes a weight adjustment module 221, which adjusts the aggregate weights based on the generalization differences according to the method described above. The other modules of the federated learning system are basically the same as those of traditional federated learning systems and will not be described further here.
[0052] Although various embodiments of the invention have been described above, it should be understood that they are presented by way of example only and not as limitations. It will be apparent to those skilled in the art that various combinations, modifications, and alterations can be made without departing from the spirit and scope of the invention. Therefore, the breadth and scope of the invention disclosed herein should not be limited by the exemplary embodiments disclosed above, but should be defined solely by the appended claims and their equivalents.
Claims
1. A method for generalization adjustment of federated learning, characterized in that, Including the following steps: Calculate generalization differences on the local terminal; The local terminal performs training for the rth round to obtain the local model for the rth round, where r is a natural number; The local model of the r-th round and the generalization difference are uploaded to the server. as well as On the server side, the aggregation weights are adjusted based on the generalization differences, and global model parameters are aggregated based on the aggregation weights to obtain the global model for the (r+1)th round. The adjustment of aggregation weights based on the generalization differences includes the following steps: The aggregated weight of the rth round of the local terminal is calculated according to the following formula: ; in, ,in, For the first The aggregate weight of each local terminal in round r-1. For the first Generalization differences of local terminals in round r, This represents the mean of the generalized differences uploaded from the local terminal. The total number of local terminals, and To adjust the step size.
2. The generalized adjustment method of claim 1, wherein, The generalization difference is based on the local model loss function value obtained from the (r-1)th round of federated training. The loss function value of the global model in the r-th round on the local data The calculation yielded: 。 3. The generalized adjustment method of claim 1, wherein, The r-th round of training is performed on the local terminal using a neural network training method based on the gradient descent principle.
4. The generalized adjustment method of claim 1, wherein, The adjustment step size decreases linearly with each training round.
5. The generalized adjustment method of claim 1, wherein, The initial value of the aggregation weight of the first local terminal is . .
6. A federated learning system, comprising: include: The local terminal includes a generalization error calculation module, which is configured to calculate the generalization error for each round. as well as The server-side includes a weight adjustment module configured to adjust aggregated weights based on generalization differences. The server-side is configured to perform global model parameter aggregation based on the aggregated weights. The adjustment of aggregated weights based on generalization differences includes the following steps: The aggregated weight of the rth round of the local terminal is calculated according to the following formula: ; in, ,in, For the first The aggregate weight of each local terminal in round r-1. For the first Generalization differences of local terminals in round r, This represents the mean of the generalized differences uploaded from the local terminal. The total number of local terminals, and To adjust the step size.
7. A computer-readable storage medium having stored thereon machine-readable instructions, the method comprising: The machine-readable instructions, when executed by a processor, perform the steps of the generalization adjustment method according to any one of claims 1 to 5.