Federated learning method of dynamic weights in edge scenarios
Through the federated learning method of dynamic weights in edge scenarios, the model offset problem caused by device heterogeneity and data heterogeneity in wind energy forecasting is solved, and more efficient model aggregation and prediction effects are achieved, which is suitable for edge scenarios of wind power generation.
Patent Information
- Application Number
- CN202211052967.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2042-08-31
AI Technical Summary
When traditional wind energy forecasting methods face the problems of data silos and device heterogeneity, existing federated learning algorithms fail to effectively solve the problems of model offset and communication overhead caused by data heterogeneity and device heterogeneity.
A federated learning method with dynamic weights in edge scenarios is adopted. The computing power value is updated through Gaussian distribution, the device weight is calculated, and the local model parameters are adjusted according to the weight ratio when the global model is aggregated. The residual term is added to optimize the local update direction to ensure the robustness and convergence of the global model.
In a complex environment with heterogeneous devices and data, the robustness and prediction accuracy of the model are improved, the communication overhead is reduced, and the convergence time and prediction effect of the model are optimized.
Smart Images

Figure CN115526333B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning technology, and in particular to a federated learning method for dynamic weights in edge scenarios. Background Art
[0002] Traditional wind energy forecasting methods, such as those based on numerical weather prediction (NWP), time series prediction, and artificial neural network prediction, are often of poor quality and widely distributed. Furthermore, much of this data is private, easily forming "data silos." This makes traditional methods less effective in practical wind energy forecasting. Therefore, we are considering using federated learning to enhance data and complement other wind energy forecasting methods to further optimize wind power generation.
[0003] The optimization goal of federated learning is to minimize the average loss of all samples, as shown in the formula
[0004]
[0005]
[0006] Among them, F k (w) represents the average loss of all data of the kth client, and f(w) represents the weighted average loss of all clients under the current parameters, that is, the objective function.
[0007] If all P k (data of the kth client) are formed by randomly and evenly distributing the training samples on the clients, that is, the data are independent and identically distributed, so each F k The expectation of (w) is f(w), and the deviation between the model obtained by local training and the global aggregation model is almost small.
[0008] However, data from different devices is often not independent and identically distributed. When the server initializes global parameters and distributes them to each client, each client trains for the same number of rounds based on its own local data. This can lead to model drift due to data heterogeneity (inconsistency in data distribution across clients) and device heterogeneity (only a small fraction of clients can be used for training at a given time, and different devices may have different computing capabilities). If we use the traditional stochastic gradient descent method to update the model and average the model after local training, the resulting global model will not be at the optimal solution.
[0009] Among existing federated learning optimization algorithms, the earliest proposed one focuses on training distributed data on mobile devices as a key research direction, but lacks effective solutions for data and device heterogeneity. FedProx and FdeNova control the optimization direction of different local models by adding regularization terms during local training. While this does not introduce unacceptable additional overhead, it requires local models to tune the weight parameters of the regularization terms during each training session. Scaffold, on the other hand, assumes that each local model is "visualized" and reuses previously calculated gradients to update local control variables. However, each communication requires transmitting not only the model parameters but also the control variable parameters, increasing the cost of a single communication. Furthermore, these algorithms either optimize only for data heterogeneity or device heterogeneity, failing to consider both scenarios simultaneously, making them overly idealistic. Summary of the Invention
[0010] The present invention aims to provide a federated learning method for dynamic weights in edge scenarios, which can alleviate the above problems.
[0011] In order to alleviate the above-mentioned problems, the technical solutions adopted by the present invention are as follows:
[0012] The present invention provides a federated learning method for dynamic weights in an edge scenario, which is characterized by comprising the following steps:
[0013] S1. The edge server filters several clients;
[0014] S2. The edge server initializes a global model and sends it to each client;
[0015] S3. Each client updates its own computing power value λ through Gaussian distribution * ;
[0016] S4. For each client, it performs N rounds of training on the global model based on the local wind energy dataset;
[0017] S5. For each client, it calculates the power value λ * Calculate the device weight based on the total model training time T;
[0018] S6. For each client, if the total model training time T is greater than or equal to the deadline T final , then directly execute step S7, otherwise according to the minimization objective function
[0019]
[0020] After optimizing the trained global model parameters, step S7 is executed, wherein: represents the loss value obtained by client k through local training when the communication round number is t+1, F k (w) represents the average loss of all data of the k-th client, μ represents the parameter of the bias term (fixed value, set at the beginning), and w represents the model parameter completed by this local calculation. t Represents the parameters of the global model;
[0021] S7. For each client, it returns the global model parameters and device weights to the edge server;
[0022] S8. The edge server aggregates the global model parameters returned by each client according to the device weight returned by each client to obtain the final global model parameters.
[0023] In a preferred embodiment of the present invention, the capacity value λ is calculated * The update method is as follows: set the Gaussian distribution mean μ to be randomly initialized from [0,1], and the standard deviation σ to be randomly initialized from the interval [0.25μ,0.5μ]. By truncating the normal distribution random number (0, μ+2σ) on the client, the computing power value λ of each round is obtained. * .
[0024] In a preferred embodiment of the present invention, in step S4, a model loss value needs to be calculated in each round of training to measure the quality of model training.
[0025] In a preferred embodiment of the present invention, the method for training the global model includes: calculating the error loss between the true output of the network and the true label by minimizing the loss function, obtaining the gradient value of the parameter by back propagation of the error loss between the true output of the network and the true label, and optimizing and updating the network parameters by the stochastic gradient descent algorithm.
[0026] In a preferred embodiment of the present invention, in step S4, the wind energy dataset includes a wind speed and direction dataset and a power generation dataset.
[0027] In a preferred embodiment of the present invention, in step S5, the calculation formula of the device weight is λ * / T.
[0028] In a preferred embodiment of the present invention, in step S8, the formula for aggregating the global model parameters returned by each client is as follows:
[0029]
[0030] in, is the global model parameter returned by the i-th client to the edge server in the t-th communication round between the edge server and the client, is the device weight returned by the i-th client to the edge server in the t-th communication round between the edge server and the client.
[0031] Compared with the prior art, the present invention has the following beneficial effects:
[0032] 1) A dynamic weighted federated learning optimization algorithm (FedDw) is proposed. Since the training time of devices in each communication round is different, the weight values are dynamically updated. When the final global model is aggregated, the proportion of local model parameters transmitted is defined according to the weight ratio. This can alleviate the impact of device heterogeneity to a certain extent and ensure that the aggregation results are more robust in complex real-world situations.
[0033] 2) In traditional federated learning, due to differences in computing power, when computing sample data of the same batch size, the time for each round is usually determined by the slowest device. If a device malfunctions or falls behind, the time overhead of other devices may also increase. Therefore, in each global model update, the present invention sets the same number of iterations in each round for different local devices, rather than the same time. This can reduce the time overhead of devices with high computing power.
[0034] 3) When optimizing the trained global model parameters, the current function uses a remainder term based on the existing one. This term takes the difference between the local optimized parameters and the global parameter vector transmitted by the server. This ensures that the local update does not deviate too far from the global optimization direction, while effectively integrating the differences between different data due to system heterogeneity.
[0035] In order to make the above-mentioned objects, features and advantages of the present invention more clearly understood, embodiments of the present invention are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.
[0037] Figure 1 This is the overall architecture diagram of the dynamic weighted federated learning method in edge scenarios described in the present invention;
[0038] Figure 2 This is a flow chart of the federated learning method for dynamic weights in edge scenarios according to the present invention;
[0039] Figure 3This figure compares the loss values of the three algorithms in Zone 4 as the number of training rounds decreases. FedProx and Scaffold are both existing federated learning optimization algorithms, and FedDw is the algorithm proposed in this paper. The vertical axis "Loss in Zone 4" represents the change in loss value in Zone 4, and the horizontal axis "epoch" represents the number of data updates.
[0040] Figure 4 is the average local model training time in each communication in the experiment of the present invention. FedProx and Scaffold are both existing federated learning optimization algorithms, and FedDw is the algorithm proposed by the present invention. The ordinate "calculating time" represents the calculation time, and the abscissa "communication round" represents the communication round.
[0041] Figure 5 This is the average training time for the models in zones 1-10 to converge in the experiments of this invention. FedProx and Scaffold are both existing federated learning optimization algorithms, and FedDw is the algorithm proposed in this patent. The vertical axis, training time of epoch10, represents the average convergence time for 10 updates, and the horizontal axis, average time from zone 1-10, represents zones 1-10. DETAILED DESCRIPTION
[0042] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions of the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings herein can be arranged and designed in various different configurations.
[0043] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention as claimed, but rather merely represents selected embodiments of the present invention. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without creative effort shall fall within the scope of protection of the present invention.
[0044] The present invention provides a federated learning method (FedDw) for dynamic weights in edge scenarios, which includes several communication rounds between edge servers and clients, i.e., several federated learning rounds are required. For each federated learning round, for example, Figure 1 and Figure 2 , which includes the following steps:
[0045] S1. The edge server filters several clients.
[0046] Among them, the screening process is to randomly select a group of clients from all clients to participate in training based on the set sampling probability.
[0047] S2. The edge server initializes a global model and sends it to each client.
[0048] S3. Each client updates its own computing power value λ through Gaussian distribution * .
[0049] S4. For each client, it performs N rounds of training on the global model based on the local wind energy dataset.
[0050] In the present invention, the wind energy dataset includes a wind speed and direction dataset and a power generation dataset.
[0051] S5. For each client, it calculates the power value λ * And the total model training time T, calculate the device weight, the calculation formula is as follows: λ * / T.
[0052] S6. For each client, if the total model training time T is greater than or equal to the deadline T final , then directly execute step S7, otherwise according to the minimization objective function
[0053]
[0054] After optimizing the trained global model parameters, step S7 is executed, wherein: represents the loss value obtained by client k through local training when the communication round number is t+1, F k (w) represents the average loss of all data of the k-th client, μ represents the parameter of the bias term (fixed value, set at the beginning), and w represents the model parameter completed by this local calculation. t Represents the parameters of the global model.
[0055] In this embodiment, the average loss F of all data of the current client is obtained using the existing federated average algorithm. k (w) adds a remainder μ||ww t || 2 , that is, taking the distance difference between the local optimized parameters and the global parameter vector transmitted by the server. In this way, it ensures that the local update will not deviate too far from the global optimization direction; at the same time, it can effectively integrate the differences between different data due to system heterogeneity.
[0056] S7. For each client, it returns the global model parameters and device weights to the edge server.
[0057] S8. The edge server aggregates the global model parameters returned by each client according to the device weight returned by each client to obtain the final global model parameters.
[0058] The formula for aggregating the global model parameters returned by each client is as follows:
[0059]
[0060] Among them, w t are the final global model parameters obtained in the tth round of communication between the edge server and the client. is the global model parameter returned by the i-th client to the edge server in the t-th communication round between the edge server and the client, is the device weight returned by the i-th client to the edge server in the t-th communication round between the edge server and the client.
[0061] In an optional embodiment of the present invention, the capacity value λ is calculated * The update method is as follows: set the Gaussian distribution mean μ to be randomly initialized from [0,1], and the standard deviation σ to be randomly initialized from the interval [0.25μ,0.5μ]. By truncating the normal distribution random number (0, μ+2σ) on the client, the computing power value λ of each round is obtained. * .
[0062] In an optional embodiment of the present invention, in step S4, a model loss value needs to be calculated in each round of training to measure the quality of model training.
[0063] In an optional embodiment of the present invention, the method for training a global model includes: calculating the error loss between the true output of the network and the true label by minimizing the loss function, obtaining the gradient value of the parameter by backpropagation of the error loss between the true output of the network and the true label, and optimizing and updating the network parameters by a stochastic gradient descent algorithm.
[0064] In order to verify the technical effect of the federated learning method of dynamic weights in edge scenarios described in this invention, we conducted corresponding experiments and analyzed the results.
[0065] 1. Dataset and Model
[0066] The wind energy dataset for this experiment was taken from 10 regions in Liangshan, Ganzi and Aba, Sichuan Province in 2019. The wind energy dataset contains wind speed, wind direction data and power generation measured by meteorological stations in 10 regions from January 1 to October 1, 2019, at intervals of 1 hour at 10m and 100m above the horizontal line. The data was serialized and normalized using a fixed-length sliding window, with 80% used as a training set and the remaining 20% as a test set. By realizing the prediction of wind power generation and adjusting the scale of electricity consumption, it is of great significance to improve the utilization rate of wind energy. Since the present invention mainly focuses on the problems of equipment heterogeneity and data heterogeneity, in order to prevent the impact of the model, a simple four-layer neural network is used, and the consistency of the model is guaranteed when compared with two existing federated learning algorithms FedProx and Scaffold. The average value of 10 experiments is taken as the comparison result.
[0067] 2. Experimental Setup
[0068] The FedDw algorithm in this experiment was implemented on a Pytorch-based client / server federated learning framework. By setting the same number of iterations, the contribution of local model parameters in the final aggregation was measured based on computation time, rather than a simple average weighting. To demonstrate the characteristics and performance of the FedDw algorithm in heterogeneous data and device environments, it was compared with FedProx and Scaffold, two currently leading federated learning algorithms. Due to a lack of computing resources, the server-side aggregation and the local client-side training and testing were performed on the same machine equipped with an NVIDIA 1660Ti. Device heterogeneity was simulated by assigning different computing capabilities, effectively limiting GPU utilization.
[0069] The experimental parameters were set as follows: For local training, the SGD optimizer parameters were set to a learning rate of 0.01, a momentum of 0.9, and an Adam learning rate of 0.01. By default, the number of local training rounds was 10, the number of communication rounds was 5, the total number of clients was 10, clients were randomly sampled at a sampling rate of 0.5, the sample input dimension was 28, and the batch size was set to 50. Data heterogeneity was reflected by the differences in data from different regions, and device heterogeneity was simulated by assigning different weights to regional data.
[0070] 3. Performance comparison and results analysis
[0071] This experiment uses the mean absolute error (MAE) and root mean square error (RMSE) to measure the quality of the model fitting results. Table 1 shows the prediction comparison results of different models.
[0072] Table 1
[0073]
[0074] Table 1 compares the performance of three federated learning algorithms under default settings, with the best results highlighted in bold. FedDw performs best, followed by FedProx. Based on the architectures of the three federated learning algorithms, adjustments were made to the number of clients, sampling rate, number of communication rounds, batch size, and number of local training rounds. The results were roughly equivalent, with deviations within 5%. Therefore, the default parameters are used to represent the results. Analysis of the reasons for the poor performance of the three federated learning algorithms reveals two main reasons: first, the complexity of the data and the differences in computing power of the simulation equipment; second, the relatively simple model designed in the experiment. This simplicity, however, happens to clearly distinguish the three federated learning algorithms, highlighting the advantages of the algorithms designed in this paper in scenarios with heterogeneous data and equipment. The reason why FedDw performs better than FedProx and Scaffold is that, intuitively, wind data is continuous over a certain period of time and is roughly the same over the same time period on different days, unless extreme weather conditions occur. At the same time, the computing power of the device is dynamically refreshed, which may cause connection interruption and long training time when training data in a certain area. FedDw avoids this problem and specifically handles the differences between continuous data and devices.
[0075] In order to have a more intuitive understanding of the performance of the three algorithms, we selected region 4 with the best overall effect, and took experiments where region 4 appeared more than 3 times in the random selection of 5 communications to analyze the experimental results. The loss value was compared with the Figure 3 As shown in the figure. FedDw's loss value dropped rapidly in epoch 1, then converged, and its final loss value was much smaller than the other two algorithms. The Scaffold algorithm performed well in terms of convergence speed and final optimization effect, but it was found that when it was close to convergence at the end of each round, the loss value would always increase at the beginning of epoch 1 of the next round. At the same time, during data analysis, it was found that during the convergence process of the three algorithms, the loss value did not inherit from the previous round of random selection training to the next round of training. Instead, it showed an upward trend, as shown in the figure below. Figure 3The FedProx algorithm performed poorly from epoch 10 to epoch 11, and the Scaffold algorithm performed poorly from epoch 20 to epoch 21. Initially, we suspected the model was overfitting, but analysis revealed that this was due to the dynamically updated computing power of the devices during the experiment. The global model parameters, aggregated in the previous communication, combined datasets from different regions. When these parameters were transmitted to the original client in the new round, the client's computing power had changed, and there was an offset between the global model and the previous local model, requiring the local model to re-adapt.
[0076] Communication efficiency is also an important indicator in evaluating the performance of federated learning algorithms. The average training time of the local model in each communication is recorded through the use of GPUs, such as Figure 4 As shown. The Scaffold algorithm is better than the FedProx algorithm and the FedDw algorithm in terms of both the calculation time at the beginning of training and the time at the final convergence. However, the time of the FedProx algorithm is significantly reduced after the first round, which is probably because the concept of inexact solution is used in the algorithm. The FedDw algorithm does not perform so well in terms of time because other algorithms only need to send the model parameters back to the server, while FedDw also needs to send the calculation time and the computing power obtained by this dynamic refresh together with the model parameters. While achieving good prediction results, it pays the cost of communication. The average time for the three algorithms to converge in 10 regions is shown below. Figure 5 As shown in Figure 2, it can be seen that when the heterogeneity of the data is large, FedDw can still perform relatively stably.
[0077] The present invention proposes a federated learning method (FedDw) for dynamic weights in edge scenarios. By focusing on the service quality of the equipment, the device service quality is used to determine the direction of model aggregation and obtain the final prediction model. The effectiveness of the algorithm was verified by comparing it with several other federated learning algorithms on a real wind data set. This algorithm architecture takes into account the device heterogeneity and data heterogeneity in real scenarios, so it has a certain degree of universality and can be applied to edge scenarios similar to wind power generation to solve the inconvenience caused by data confidentiality and system differences in different regions. In future work, the fluctuations generated during the convergence process will be optimized. Instead of realizing the heterogeneity of the equipment through simulation, it will be applied in real scenarios with the help of edge devices. At the same time, attention will be paid to the selection of equipment to reduce the interference to the experiment caused by random selection, and select equipment that is beneficial to model aggregation. Based on the experimental phenomena in this article, we focus on the impact of loss value on equipment selection and design a more realistic and practical federated learning algorithm.
[0078] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention are intended to be within the scope of protection of the present invention.
Claims
1. A federated learning method for dynamic weights in edge scenarios, characterized by: The following steps are involved: S1. The edge server filters several clients; S2. The edge server initializes a global model and sends it to each client; S3. Each client updates its own computing power value λ through Gaussian distribution * ; S4. For each client, it performs N rounds of training on the global model based on the local wind energy dataset; S5. For each client, it calculates the power value λ * Calculate the device weight based on the total model training time T; S6. For each client, if the total model training time T is greater than or equal to the deadline T final , then directly execute step S7, otherwise according to the minimization objective function After optimizing the trained global model parameters, step S7 is executed, wherein: represents the loss value obtained by client k through local training when the communication round number is t+1, F k (w) represents the average loss of all data of the k-th client, μ represents the parameter of the bias term, and w represents the model parameter completed by this local calculation. t Represents the parameters of the global model; S7. For each client, it returns the global model parameters and device weights to the edge server; S8. The edge server aggregates the global model parameters returned by each client according to the device weight returned by each client to obtain the final global model parameters.
2. The method for federated learning of dynamic weights in edge scenarios according to claim 1, characterized in that: In step S3, the capability value λ is calculated * The update method is as follows: Set the Gaussian distribution mean μ to be randomly initialized from [0,1], and the standard deviation σ to be randomly initialized from the interval [0.25μ,0.5μ]. By truncating the normal distribution random number (0, μ+2σ) on the client, the computing power value λ of each round is obtained. * .
3. The method for federated learning of dynamic weights in edge scenarios according to claim 2, characterized in that: In step S4, the model loss value needs to be calculated in each round of training to measure the quality of model training.
4. The method for federated learning of dynamic weights in edge scenarios according to claim 2, characterized in that: In step S4, the method for training the global model includes: calculating the error loss between the true network output and the true label by minimizing the loss function, obtaining the gradient value of the parameter by backpropagation of the error loss between the true network output and the true label, and optimizing and updating the network parameters by the stochastic gradient descent algorithm.
5. The method for federated learning of dynamic weights in edge scenarios according to claim 4, characterized in that: In step S4, the wind energy dataset includes a wind speed and direction dataset and a power generation dataset.
6. The method for federated learning of dynamic weights in edge scenarios according to claim 2, characterized in that: In step S5, the calculation formula of device weight is λ * / T.
7. The method for federated learning of dynamic weights in edge scenarios according to claim 6, characterized in that: The deadline T in step S6 final The value of is obtained through initial setting.
8. The method for federated learning of dynamic weights in edge scenarios according to claim 6, characterized in that: In step S6, the trained global model parameters are optimized by using the existing federated average algorithm to obtain the average loss F of all data of the current client. k (w) Add a remainder μ||ww t || 2 , that is, the distance difference between the local optimized parameters and the global parameter vector transmitted by the server.
9. The method for federated learning of dynamic weights in edge scenarios according to claim 8, characterized in that: In step S8, the formula for aggregating the global model parameters returned by each client is as follows: in, is the global model parameter returned by the i-th client to the edge server in the t-th communication round between the edge server and the client, is the device weight returned by the i-th client to the edge server in the t-th communication round between the edge server and the client.
Citation Information
Patent Citations
Federal learning method fusing adaptive weight distribution and personalized differential privacy
CN114595831A
Wireless service traffic prediction method based on weighted federated learning
WO2021169577A1