Federal learning method based on adaptive gradient hierarchy quantization in Internet of Vehicles
By adopting the adaptive gradient hierarchical quantization method in the Internet of Vehicles, the optimal quantization level is determined and quantified and corrected, the problems of high communication costs and low model aggregation accuracy in the Internet of Vehicles federated learning are solved, and more efficient communication and more accurate model learning are achieved.
Patent Information
- Application Number
- CN202411689110.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2025-04-11
AI Technical Summary
The communication cost of federated learning in the Internet of Vehicles is high and the model aggregation accuracy is low. The existing non-adaptive gradient quantization method cannot effectively solve this problem.
Adaptive gradient hierarchical quantization method is used to determine the optimal quantization level by calculating the variance before and after the quantization of the gradient vector, and hierarchically quantization and correction of the gradient vector is further improved the accuracy of model learning through the invalid quantization compensation mechanism.
The data amount of vehicle nodes upload model update parameters is reduced, the uplink channel bandwidth pressure is alleviated, the model convergence speed and accuracy are improved, and the communication data amount and model integrity are balanced.
Smart Images

Figure CN119808987A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of vehicle networking, and more specifically, relates to a federated learning method based on adaptive gradient hierarchical quantization in vehicle networking. Background Art
[0002] The Internet of Vehicles, which is collaboratively constructed by vehicles, roadside units, and cloud computing devices, promotes real-time information exchange and intelligent decision-making between pedestrians, vehicles, roads, environments, and service platforms by sharing vehicle driving data, environmental traffic data, and user behavior data. However, these raw data involve user privacy and decision security, and vehicles are generally reluctant to upload them to infrastructure without clear security guarantees. Therefore, the contradiction between efficient data utilization and data security protection leads to the problem of information islands in the Internet of Vehicles. To solve this problem, federated learning, as a distributed machine learning paradigm for device privacy protection, promotes secure data sharing in dynamic and complex scenarios by exchanging local model parameters, thereby achieving collaborative decision-making without uploading raw data. In addition, federated learning requires frequent parameter exchanges so that the global model converges to a predetermined accuracy through multiple iterations. Due to the high mobility of vehicle nodes and long-distance transmission with roadside units, many federated learning tasks in the Internet of Vehicles must consider complex communication issues. However, uploading a large number of gradient parameters will cause uplink channel congestion, which poses a huge challenge to real-time data exchange and service response in the Internet of Vehicles.
[0003] In response to the above challenges, existing research uses gradient compression methods to reduce computing resource consumption, reduce network bandwidth usage, and improve the performance of machine learning models. In addition, the gradient compression method only processes the transmission content, which neither affects the transmission process nor changes the model structure. Gradient compression mainly includes methods such as quantization, sparsification, and multimodal compression. The gradient quantization method uses the method of quantizing and encoding gradient parameters to map continuous floating-point numbers into discrete books with finite bits, and reduces the amount of uploaded data by limiting the number of bits of floating-point numbers. The gradient sparsification method discards some gradient terms and only uploads large gradient parameters to achieve key gradient transmission. The gradient multimodal compression method uses different gradient compression methods to work together to achieve more efficient compression. However, the existing gradient quantization methods face the following two problems: i) Due to the frequent update of model parameters in the Internet of Vehicles, the communication cost of federated learning is high; ii) Due to the non-adaptive gradient quantization strategy, the model aggregation accuracy is low. Therefore, there is an urgent need for an adaptive gradient quantization method to reduce the uplink communication overhead while maintaining the accuracy of the federated learning aggregation model. Summary of the invention
[0004] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a federated learning method based on adaptive gradient hierarchical quantization in the Internet of Vehicles. By adaptively determining the optimal quantization level of the gradient vector hierarchical quantization and performing invalid quantization compensation on the quantization gradient, the model convergence speed and accuracy are improved while reducing the communication load, thereby achieving a balance between the amount of communication data and the integrity of the model during interaction between nodes in the Internet of Vehicles.
[0005] In order to achieve the above-mentioned object of the invention, the federated learning method based on adaptive gradient hierarchical quantization in the Internet of Vehicles of the present invention comprises the following steps:
[0006] S1: Build a three-layer federated learning network architecture for the Internet of Vehicles, which includes a vehicle node layer, an edge node layer, and a service layer, where:
[0007] At the vehicle node layer, vehicle node i collects raw traffic data to train the local model and uploads the model update parameters to the roadside unit, where i = 1, 2, …, N, where N represents the number of vehicle nodes in the Internet of Vehicles;
[0008] At the edge node layer, the roadside unit j acts as a parameter server to provide data exchange services for all vehicle nodes in the service domain, including aggregating uploaded model parameters and forwarding them to the central cloud server, where j = 1, 2, …, M, where M represents the number of roadside units in the Internet of Vehicles;
[0009] After performing global data caching and aggregation computing tasks, the central cloud server C sends the updated model parameters to each roadside node, which is then forwarded to each vehicle node via the roadside unit;
[0010] Deploy the model to be learned on the central cloud server C and N vehicle nodes i;
[0011] S2: At the service layer, the central cloud server C initializes the parameters of the model to be learned and uses it as the initial model aggregation parameter W 0 , let the number of federated learning iterations t = 1;
[0012] S3: The central cloud server C aggregates the model parameters W through the roadside unit t-1 and the iteration number t is forwarded to each vehicle node;
[0013] S4: At the vehicle node layer, each vehicle node i calculates the aggregation parameter W sent by the central cloud server C. t-1 The local model parameters for this round Initialize and then collect local traffic data And train the local model to obtain the local model parameters With the loss function f i t (w), record local traffic data The number of samples in Then calculate the gradient vector of the trained local model in represents the d-th gradient value, d = 1, 2, ..., D, D represents the dimension of the gradient vector;
[0014] S5: Each vehicle node i corrects its identity according to the gradient issued by the roadside unit to which it belongs Perform gradient correction to obtain the corrected gradient vector Gradient vector for the trained local model The d-th gradient value The following formula is used for gradient correction:
[0015]
[0016] in, represents the dth gradient value after correction, represents the quantization error corresponding to the d-th gradient value in the previous round of federated learning, Indicates the gradient correction flag of vehicle node i in the previous round of federated learning, Indicates that vehicle node i needs to perform gradient correction, Indicates that vehicle node i does not need to perform gradient correction,
[0017] S6: Each vehicle node i solves the following objective function to obtain the optimal quantization level L:
[0018]
[0019] in, is the cumulative distribution function F(r i,d ) and scalar η i,d The weighted sum of |||| D Indicates the LD norm, l j represents the quantization level, j∈{0,1,…,s}, s∈{1,2,…,L};
[0020] Vehicle node i obtains the quantized gradient vector by performing hierarchical quantization on its gradient vector according to the obtained optimal quantization level L q L () represents the preset hierarchical quantization function;
[0021] S7: Each vehicle node i uses the following formula to calculate its quantization error vector
[0022]
[0023] Determine the mode of quantization error Is it less than the threshold? If yes, no invalid quantization compensation is performed. Otherwise, the following method is used to perform invalid quantization compensation to obtain the compensated quantization gradient vector:
[0024]
[0025] Among them, sign() represents the sign function;
[0026] S8: Each vehicle node i will use its loss function f i t (w), the number of local training data samples Quantized gradient vector after quantization compensation and the quantization error vector Uploaded to the roadside unit to which it belongs, each roadside unit j aggregates the quantized gradient vectors of all vehicle nodes in its service area to obtain the local gradient vector Then together with the loss function f of all vehicle nodes in its service area i t (w) and the number of local training data samples Upload to the central cloud server C;
[0027] Each roadside unit j uses the following formula to calculate the quantization error threshold
[0028]
[0029] in, represents the quantized error vector uploaded by the nth vehicle node in the service area of roadside unit j, represents the quantization error vector The model, represents the set of vehicle nodes in the service area of roadside unit j during the tth round of communication The number of vehicles in , α represents the preset compensation coefficient, and 0<α≤1;
[0030] Then the following formula is used to determine the gradient correction identifier of each vehicle node i in its service area: And feedback to the vehicle node i corresponding to the service domain:
[0031]
[0032] S9: The central cloud server C receives the local gradient vectors uploaded by each roadside unit The loss function f of the vehicle node i t (w) and the number of local training data samples Aggregate the model parameters to get the aggregation parameter W for this round t ;
[0033] S10: Determine whether the federated learning end condition is met. If not, proceed to step S10, otherwise the federated learning ends.
[0034] S11: Let the iteration round t=t+1, and return to step S3.
[0035] In the federated learning method based on adaptive gradient hierarchical quantization in the Internet of Vehicles of the present invention, the vehicle node performs local training and calculates the gradient vector, adaptively determines the gradient quantization level and performs hierarchical quantization and correction on the gradient vector, then performs invalid quantization compensation on the quantized gradient vector through the quantization error, and uploads the compensated quantized gradient vector and quantization error to the corresponding roadside unit. The roadside unit aggregates the quantized gradient vectors within its service domain and uploads them to the central cloud server, and accumulates the quantization error and feeds it back to each vehicle node for guiding gradient quantization. The central cloud server updates the model parameters according to the aggregated gradient vector uploaded by each roadside unit, and then sends it to the vehicle node to enter the next round of iterative learning until the end condition of the federated learning is met, then the federated learning ends.
[0036] The present invention has the following beneficial effects:
[0037] 1) Before the vehicle node uploads the local model update parameters, the present invention calculates the optimal gradient quantization level by solving the optimization problem, and then quantizes and compresses the gradient, thereby reducing the data transmission overhead and alleviating the bandwidth pressure caused by the overload of uplink channel data;
[0038] 2) The present invention utilizes the design of an invalid quantization compensation mechanism and incorporates the gradient residual generated by quantization into the error feedback mechanism to improve the accuracy of model learning and ensure the convergence of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 It is a flowchart of a specific implementation method of a federated learning method based on adaptive gradient hierarchical quantization in the Internet of Vehicles of the present invention;
[0040] Figure 2 It is a three-layer federated learning network architecture diagram for the Internet of Vehicles in the present invention;
[0041] Figure 3 It is a schematic diagram of gradient level quantization when the improved quantization level is s;
[0042] Figure 4 is a comparison diagram of relative errors quantized by the present invention and the comparative method in different communication rounds in this embodiment;
[0043] Figure 53 is a comparison diagram of invalid quantization ratios of the present invention and the comparative method in this embodiment. DETAILED DESCRIPTION
[0044] The specific implementation of the present invention is described below in conjunction with the accompanying drawings so that those skilled in the art can better understand the present invention. It should be noted that in the following description, when the detailed description of known functions and designs may dilute the main content of the present invention, these descriptions will be omitted here.
[0045] Example
[0046] Figure 1 1 is a flowchart of a specific implementation of the federated learning method based on adaptive gradient hierarchical quantization in the Internet of Vehicles of the present invention. Figure 1 As shown, the specific steps of the federated learning method based on adaptive gradient hierarchical quantization in the Internet of Vehicles of the present invention include:
[0047] S101: Building a three-layer federated learning architecture for the Internet of Vehicles:
[0048] The present invention proposes a three-layer federated learning network architecture for Internet of Vehicles. Figure 2 : is a three-layer federated learning network architecture diagram for the Internet of Vehicles in the present invention. Figure 2 As shown, the three-layer federated learning network architecture for the Internet of Vehicles in the present invention includes a vehicle node layer, an edge node layer, and a service layer, wherein:
[0049] At the vehicle node layer, vehicle node i collects raw traffic data to train the local model and uploads model update parameters to the roadside unit, where i = 1, 2, ..., N, where N represents the number of vehicle nodes in the Internet of Vehicles. In practical applications, on-board sensors can be configured as needed to collect traffic data, such as monocular vision cameras, stereo vision cameras, lidar, millimeter wave (mmWave) radar, and inertial measurement unit (IMU).
[0050] At the edge node layer, the roadside unit j acts as a parameter server with more abundant network resources and data processing capabilities. Therefore, the roadside unit in the present invention is responsible for providing data exchange services for all vehicle nodes in the service domain, including aggregating uploaded model parameters and forwarding them to the central cloud server, where j = 1, 2, ..., M, where M represents the number of roadside units in the Internet of Vehicles.
[0051] At the service layer, after performing global data caching and aggregation computing tasks, the central cloud server C sends the updated model parameters to each roadside node, which is then forwarded to each vehicle node via the roadside unit.
[0052] The model to be learned is deployed on the central cloud server C and N vehicle nodes i.
[0053] S102: Initialize federated learning data:
[0054] At the service layer, the central cloud server C initializes the parameters of the model to be learned and uses it as the initial model aggregation parameter W 0 , let the current iteration number t=1.
[0055] S103: Send model aggregation parameters:
[0056] The central cloud server C aggregates the model parameters W through the roadside unit t-1 and the iteration number t are forwarded to each vehicle node.
[0057] S104: Local data training:
[0058] At the vehicle node layer, each vehicle node i receives the aggregation parameter W sent by the central cloud server C. t-1 For local model parameters Initialize and then collect local traffic data And train the local model to obtain the local model parameters With the loss function f i t (w), record local traffic data The number of samples in Then calculate the gradient vector of the trained local model in Represents the d-th gradient value, d = 1, 2, …, D, and D represents the dimension of the gradient vector.
[0059] In this embodiment, the loss function f is used when training local data. i t The calculation formula of (w) can be expressed as follows:
[0060]
[0061] Among them, x i,b Represents the local traffic data data of vehicle node i i The bth data sample in Represents the preset and data sample x i,b and the model parameters to be learned The relevant loss function can be set according to the task of the model in practical applications.
[0062] S105: Gradient correction:
[0063] Each vehicle node i is identified by the gradient correction issued by the roadside unit to which it belongs Perform gradient correction to obtain the corrected gradient vector Gradient vector for the trained local model The d-th gradient value The following formula is used for gradient correction:
[0064]
[0065] in, represents the dth gradient value after correction, represents the quantization error corresponding to the d-th gradient value in the previous round of federated learning, Indicates the gradient correction flag of vehicle node i in the previous round of federated learning, Indicates that vehicle node i needs to perform gradient correction, Indicates that vehicle node i does not need to perform gradient correction,
[0066] S106: Adaptive gradient level quantization compression:
[0067] Quantization coding can map the floating-point values in the continuous gradient vector to discrete values, and realize model parameter compression before the vehicle node uploads the data to the roadside unit, thereby reducing the amount of uploaded data, reducing the pressure on the uplink channel bandwidth and communication costs. Therefore, in each round of federated learning training, the present invention performs hierarchical quantization compression on the calculated gradient vector by each vehicle node i. The specific method of hierarchical quantization compression is:
[0068] In the tth round of communication, firstly, the gradient vector set in the vehicle node Perform preliminary L-layer quantization, and the quantization function expression is defined as:
[0069]
[0070] Where L represents the quantization level, Indicates the gradient value according to the quantization level L The quantized value after quantization.
[0071] In this embodiment, the preliminary L-layer quantization adopts the quantization SGD (QSGD) algorithm. For details, please refer to the document "Alistarh D, Grubic D, Li J, et al. QSGD: Communication-Efficient SGD via Gradient Quantization and Encoding [J]. 2016. DOI: 10.48550 / arXiv.1610.02132.", and the dimension D of the gradient vector is used to improve the quantization expression, and the original L2 norm of the gradient vector is changed to the LD norm of the gradient vector, that is, p = D. Figure 3 This is a schematic diagram of gradient level quantization when the quantization level is s after improvement. Figure 3 As shown, the hierarchical quantization compression of vehicle node i can be expressed by the following formula:
[0072]
[0073] Among them, || || D Indicates the LD norm. is the gradient vector The LD norm of is taken as the scaling factor and expressed as The sign() function is used to obtain the sign. s∈{1,2,…,L} represents the number of internal L-layer quantization layers, h i (s) is a random variable that follows Bernoulli distribution. The gradient vector of vehicle node i is quantized and compressed to be The probability is 1-p(r i,d ), the value is The probability is p(r i,d ), l s Represents the quantization level and satisfies -1=l0<l1<…<l s <l s+1 =1, p() represents the probability determined according to Bernoulli distribution. Indicates the level of quantization, represents the normalized coordinates of the gradient vector. Therefore, the quantized gradient is an unbiased estimate of the floating-point gradient before quantization.
[0074] In order to further improve the compression quality, the present invention proposes an adaptive gradient hierarchical quantization method. First, the optimal quantization level L is determined according to the actual situation of the vehicle node, and then the gradient vector is hierarchically quantized and compressed. It has been found that the importance of the gradient can be determined by calculating the variance of the gradient vector before and after quantization. The more information the gradient contains, the higher its importance, and a more accurate quantization level needs to be assigned. Therefore, the present invention determines the optimal quantization level L by calculating the variance between the original gradient vector and the quantized gradient vector, thereby realizing adaptive gradient quantization.
[0075] To solve this problem, the present invention uses the variance of the gradient vector quantization as the trace of the covariance matrix, as shown below:
[0076]
[0077] in, represents the mathematical expectation of a random variable h that follows a Bernoulli distribution, is the gradient value The quantized variance of the normalized coordinates is used to indicate the importance of the gradient. Therefore, the expected variance minimization problem of gradient vector quantization is constructed by adjusting the discrete value set s∈{1,2,…,L} to minimize the expected value of the gradient variance:
[0078]
[0079] The present invention uses the law of overall expectation to approximate the expected variance minimization problem as follows:
[0080]
[0081] Among them, F(r i,d ) represents the normalized coordinate r i,d Cumulative Distribution Function (CDF). The cumulative distribution function, also known as the distribution function, is the integral of the probability density function, which is used to fully describe the probability distribution of a real random variable X. Therefore, it is used to represent the distribution probability of the normalized coordinate r.
[0082] By solving the inverse function of the expected variance minimization problem, we get the solution for the optimal quantization level, and use this solution as the objective function to be optimized for solving the optimal number of quantization levels L. The expression of this non-convex objective function is as follows:
[0083]
[0084] in, is the cumulative distribution function F(r i,d ) and scalar η i,d The weighted sum of l j Represents the quantization level, s∈{1,2,…,L}.
[0085] Therefore, in the present invention, each vehicle node i solves the above objective function to obtain the optimal quantization level L, and then performs hierarchical quantization on its gradient vector according to the obtained optimal quantization level L to obtain the quantized gradient vector q L () represents the preset hierarchical quantization function.
[0086] Since the above objective function is a non-convex objective function, existing optimization algorithms (such as stochastic gradient descent) may fall into local minima when solving non-convex problems. In addition, in high-dimensional space, saddle points are more common than local minima, and the gradient descent method may stagnate when encountering saddle points because the gradient is zero at these points, causing the update to stop. To address this problem, this embodiment uses the random quasi-Newton method to solve the objective function.
[0087] In the randomized quasi-Newton method, the random damped L-BFDS (SDL-BFGS) algorithm can generate the Hessian matrix without explicitly generating it and obtain accurate function values and gradient information at each optimization iteration, thereby achieving superlinear convergence speed when solving nonlinear optimization problems. The SDL-BFGS algorithm does not explicitly generate the Hessian matrix H in order to further reduce the time complexity of the algorithm. k , but directly calculate its product with the vector, that is, H k g k This method can maintain the Hessian matrix H without performing linear search. k In the present invention, the sampling in the k-1th optimization iteration is used to generate an auxiliary stochastic gradient at the normalized coordinate point rt:
[0088]
[0089] Among them, M k-1 represents the sampling batch size in the k-1th optimization iteration, ξ k-1,m represents the random variable generated by the mth sampling in the k-1th optimization iteration, g(r k ,ξ k-1,m ) represents the gradient produced by the mth sampling in the k-1th optimization iteration.
[0090] Therefore, the stochastic gradient difference is expressed as:
[0091]
[0092] The iterative difference is Δ k-1 =r k -r k-1 , and get a new vector
[0093]
[0094] in, It follows Bernoulli distribution, and has:
[0095]
[0096] Therefore, the update formula of the Hessian matrix is:
[0097]
[0098] Where I represents the identity matrix and p represents a preset parameter, which is used to represent the number of recently saved gradient difference and step size difference pairs, usually set to 5 or 10.
[0099] in τ>0 is a given constant and has an inverse matrix:
[0100]
[0101] Therefore, the way to solve the above equation using the random quasi-Newton method is as follows:
[0102] r k+1 =r k -α k H k g k
[0103] Among them, α k represents the step size, and {α k} k≥1 .
[0104] In summary, the randomized quasi-Newton method uses the characteristics of second-order information to better guide the optimization process, which can converge superlinearly to the local optimal solution and obtain the optimal number of quantization levels.
[0105] S106: Invalid quantization compensation:
[0106] During the adaptive gradient quantization process, some gradient vectors may be quantized to zero values, resulting in large quantization errors. In order to alleviate this problem, compensation for zeroed gradient vectors can be used. Existing work usually replaces the gradients quantized to zero values with the negative infinite norm of a set of gradient vectors. Although this alleviates the impact of a large number of gradient vectors being quantized to zero values in federated learning tasks to a certain extent, it also causes other problems: on the one hand, it will increase the amount of data transmitted in the uplink channel in the federated learning task, and on the other hand, it may also cause the zero value correction algorithm to fail. Therefore, in order to alleviate the negative impact of a large number of gradient vectors being quantized to zero values in federated learning tasks, each vehicle node i in the present invention calculates the minimum quantization factor according to the optimal quantization level L, and uses it as a substitute for the zero-value gradient value after quantization, thereby alleviating the quantization error in the gradient vector and further improving the efficiency of gradient quantization. The specific method of invalid quantization compensation is:
[0107] Each vehicle node i uses the following formula to calculate its quantization error ε i :
[0108]
[0109] Determine the mode of quantization error Is it less than the threshold? If yes, no invalid quantization compensation is performed. Otherwise, the following method is used to perform invalid quantization compensation to obtain the compensated quantization gradient vector:
[0110]
[0111] Among them, sign() represents the sign function, is the minimum quantization factor.
[0112] In this embodiment, the threshold It is calculated using the following formula:
[0113]
[0114] Among them, τ represents the error coefficient, and the calculation formula is:
[0115] τ=1 / (2 L-1 -1)
[0116] S108: Gradient upload and error feedback:
[0117] Each vehicle node i will take its loss function f i t (w), the number of local training data samples Quantized gradient vector after quantization compensation and the quantization error vector Uploaded to the roadside unit to which it belongs, each roadside unit j aggregates the quantized gradient vectors of all vehicle nodes in its service area to obtain the local gradient vector Then together with the loss function f of all vehicle nodes in its service area i t (w) and the number of local training data samples Upload to the central cloud server C.
[0118] In order to solve the problem of information loss in roadside units when aggregating models due to gradient quantization operations, existing methods usually retain the error between the actual gradient update of the current iteration round and the gradient quantization compression update, and use the error to compensate for the quantization operation in the next round. Therefore, each round of federated learning iteration needs to add the error of the previous round to the calculation, which further increases the communication overhead of the federated learning downlink. To address this problem, the present invention proposes a quantization error feedback mechanism, which calculates an adaptive threshold for the current iteration round, and only when the quantization error in the current iteration round is greater than the threshold, it will be included in the calculation range. The introduction of this method effectively reduces data communication overhead and reduces the negative impact of quantization operations. The specific method of error feedback is:
[0119] Each roadside unit j uses the following formula to calculate the quantization error threshold
[0120]
[0121] in, represents the quantized error vector uploaded by the nth vehicle node in the service area of roadside unit j, represents the quantization error vector The model, represents the set of vehicle nodes in the service area of roadside unit j during the tth round of communication The number of vehicles in , α represents the preset compensation coefficient, and 0<α≤1;
[0122] Then the following formula is used to determine the gradient correction identifier of each vehicle node i in its service area: And feedback to the vehicle node i corresponding to the service domain:
[0123]
[0124] In combination with step S105, it can be seen that in the present invention, when the quantization error exceeds the threshold, this part of the error will be used to correct the gradient vector, so that the quantization error is included in the gradient quantization operation.
[0125] S109: Model parameter aggregation:
[0126] The central cloud server C receives the local gradient vectors uploaded by each roadside unit The loss function f of the vehicle node i t (w) and the number of local training data samples Aggregate the model parameters to get the aggregation parameter W for this round t .
[0127] S109: Determine whether the federated learning end condition is met. If not, proceed to step S110; otherwise, the federated learning ends.
[0128] The end condition of federated learning can be set according to actual needs. In this embodiment, whether the end condition is reached is determined by whether the global loss function converges. Since the edge loss function and the global loss function cannot be calculated directly, the loss function f of each vehicle node is used. i t (w) is calculated in the form of weighted average on the data set, that is, the global loss function F t The calculation formula of (w) is:
[0129]
[0130] Among them, S t Represents the total amount of data samples in this round of learning, that is
[0131] S110: Let the iteration round t=t+1, and return to step S103.
[0132] In order to better illustrate the technical effect of the present invention, a specific example is used to experimentally verify the present invention.
[0133] This embodiment uses MINST, Fashion-MINST and CIFAR10 datasets for experimental verification. The MNIST dataset is a dataset for recognizing handwritten numbers. It has 60,000 training samples and 10,000 test samples, representing numbers between 0 and 9. Fashion-MNIST dataset: Fashion-MINST is used to replace the MINST dataset to verify the new deep learning model. It has 70,000 image samples and is divided into 10 categories of different objects. CIFAR-10 dataset: CIFAR-10 is a dataset for recognizing objects. It has 60,000 color images, representing different categories of objects such as airplanes, cars, birds, etc., so it has higher complexity than the first two datasets.
[0134] This embodiment selects four classic gradient quantization algorithms as comparison methods, which are:
[0135] QSGD: Randomly round the gradient vector to a linear quantization value to balance the training accuracy and gradient quantization accuracy, and use independent random variables to ensure that the obtained approximate stochastic gradient is still an unbiased estimate of the original gradient;
[0136] DGC: Use momentum masking to discard stale gradients and only send accumulated gradient vectors that exceed a threshold, thereby minimizing information loss;
[0137] SignSGD: The SignSGD algorithm only captures the sign of each coordinate in the gradient vector, limiting the attacker's influence to sign flipping;
[0138] TernGrad: Quantizes gradients to ternary precision before sending them to parameter servers.
[0139] The above comparison method is used to compare and verify the present invention (denoted as Hermes) from three aspects: aggregation model accuracy, average relative error and invalid quantization probability.
[0140] Figure 4 : is a comparison diagram of the relative errors quantized by the present invention and the comparative method in different communication rounds in this embodiment. Figure 4 As shown in the figure, with the increase of communication rounds, the relative errors of the algorithm proposed in the present invention and the DGC algorithm gradually decrease and tend to be stable. The relative error of the SignSGD algorithm is relatively high because the gradient is greatly disturbed when it is encoded with a 1-bit length of {-1,0,1}. The algorithm proposed in the present invention can stabilize the relative error of gradient quantization encoding at about 3% under different communication rounds, which shows that although the hierarchical quantization encoding will cause a large disturbance to the original gradient, the gradient decoded in the parameter server in the roadside base station is still close to the original gradient. Moreover, the relative error that is stable at around 3% also means that more rounds of iterative training and communication will not cause a large change in the error. This also further confirms the motivation of this study: to prove that gradient compression can improve the convergence speed of the model and reduce the transmission cost while hardly affecting the accuracy of model learning.
[0141] Figure 5 : is a comparison chart of invalid quantization ratios of the present invention and the comparative method in this embodiment. Figure 5As shown, the invalid quantization ratio of the QSGD algorithm under three different data sets is approximately 62%, 14%, and 16%, respectively, which is much higher than the algorithm proposed in the present invention. The invalid quantization ratio of the above two algorithms on the CIFAR10 data set is higher than that of the MNIST and FMNIST data sets. This is because the CIFAR10 data set itself has a higher complexity, and the quantization method produces more quantization errors when processing complex data, resulting in a higher invalid quantization ratio. In addition, compared with the QSGD algorithm, the algorithm proposed in the present invention performs well on the three test data sets, which shows that the algorithm can effectively maintain the integrity and accuracy of the data during the quantization process, and has stronger adaptability to data sets with higher complexity.
[0142] Although the above describes the illustrative specific embodiments of the present invention to facilitate those skilled in the art to understand the present invention, it should be clear that the present invention is not limited to the scope of the specific embodiments. For those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the attached claims, these changes are obvious, and all inventions and creations using the concept of the present invention are protected.
Claims
1. A federated learning method based on adaptive gradient hierarchical quantization in an Internet of Vehicles, characterized in that: The following steps are involved: S1: Build a three-layer federated learning network architecture for the Internet of Vehicles, which includes a vehicle node layer, an edge node layer, and a service layer, where: At the vehicle node layer, vehicle node i collects raw traffic data to train the local model and uploads the model update parameters to the roadside unit, where i = 1, 2, …, N, where N represents the number of vehicle nodes in the Internet of Vehicles; At the edge node layer, the roadside unit j acts as a parameter server to provide data exchange services for all vehicle nodes in the service domain, including aggregating uploaded model parameters and forwarding them to the central cloud server, where j = 1, 2, …, M, where M represents the number of roadside units in the Internet of Vehicles; After performing global data caching and aggregation computing tasks, the central cloud server C sends the updated model parameters to each roadside node, which is then forwarded to each vehicle node via the roadside unit; Deploy the model to be learned on the central cloud server C and N vehicle nodes i; S2: At the service layer, the central cloud server C initializes the parameters of the model to be learned and uses it as the initial model aggregation parameter W 0 , let the number of federated learning iterations t = 1; S3: The central cloud server C aggregates the model parameters W through the roadside unit t-1 and the iteration number t is forwarded to each vehicle node; S4: At the vehicle node layer, each vehicle node i calculates the aggregation parameter W sent by the central cloud server C. t-1 The local model parameters for this round Initialize and then collect local traffic data And train the local model to obtain the local model parameters With the loss function f i t (w), record local traffic data The number of samples in Then calculate the gradient vector of the trained local model in represents the d-th gradient value, d = 1, 2, ..., D, D represents the dimension of the gradient vector; S5: Each vehicle node i corrects its identity according to the gradient issued by the roadside unit to which it belongs Perform gradient correction to obtain the corrected gradient vector Gradient vector for the trained local model The d-th gradient value The following formula is used for gradient correction: in, represents the dth gradient value after correction, represents the quantization error corresponding to the d-th gradient value in the previous round of federated learning, Indicates the gradient correction flag of vehicle node i in the previous round of federated learning, Indicates that vehicle node i needs to perform gradient correction, Indicates that vehicle node i does not need to perform gradient correction, S6: Each vehicle node i solves the following objective function to obtain the optimal quantization level L: in, is the cumulative distribution function F(r i,d ) and scalar η i,d The weighted sum of |||| D Indicates the LD norm, l j represents the quantization level, j∈{0,1,…,s}, s∈{1,2,…,L}; Vehicle node i obtains the quantized gradient vector by performing hierarchical quantization on its gradient vector according to the obtained optimal quantization level L q L () represents the preset hierarchical quantization function; S7: Each vehicle node i uses the following formula to calculate its quantization error vector Determine the model of quantization error Is it less than the threshold? If yes, no invalid quantization compensation is performed. Otherwise, the following method is used to perform invalid quantization compensation to obtain the compensated quantization gradient vector: Among them, sign() represents the sign function; S8: Each vehicle node i will use its loss function f i t (w), the number of local training data samples Quantized gradient vector after quantization compensation and the quantization error vector Uploaded to the roadside unit to which it belongs, each roadside unit j aggregates the quantized gradient vectors of all vehicle nodes in its service area to obtain the local gradient vector Then together with the loss function f of all vehicle nodes in its service area i t (w) and the number of local training data samples Upload to the central cloud server C; Each roadside unit j uses the following formula to calculate the quantization error threshold in, represents the quantized error vector uploaded by the nth vehicle node in the service area of roadside unit j, Represents the quantization error vector The model, represents the set of vehicle nodes in the service area of roadside unit j during the tth round of communication The number of vehicles in , α represents the preset compensation coefficient, and 0<α≤1; Then the following formula is used to determine the gradient correction identifier of each vehicle node i in its service area: And feedback to the vehicle node i corresponding to the service domain: S9: The central cloud server C receives the local gradient vectors uploaded by each roadside unit The loss function f of the vehicle node i t (w) and the number of local training data samples Aggregate the model parameters to get the aggregation parameter W for this round t ; S10: Determine whether the federated learning end condition is met. If not, proceed to step S10, otherwise the federated learning ends. S11: Let the iteration round t=t+1, and return to step S3.
2. The federated learning method according to claim 1, characterized in that: In step S6, the objective function is solved by using the random quasi-Newton method.
3. The federated learning method according to claim 1, characterized in that: The specific formula of the hierarchical quantization function in step S6 is: in, is the gradient vector LD norm, sign() function indicates the sign; s∈{1,2,…,L} indicates the number of internal L-layer quantization layers, h i (s) is a random variable that follows Bernoulli distribution. The gradient vector of vehicle node i is quantized and compressed to be The probability is 1-p(r i,d ), the value is The probability is p(r i,d ), l s Represents the quantization level and satisfies -1=l0<l1<…<l s <l s+1 =1, p() represents the probability determined according to Bernoulli distribution; Indicates the level of quantization, Represents the normalized coordinates of the gradient vector.
4. The federated learning method according to claim 1, characterized in that: The threshold value in step S7 The calculation method is: Among them, τ represents the error coefficient, and the calculation formula is: τ=1 / (2 L-1 -1).
5. The federated learning method according to claim 1, characterized in that: The end condition of the federated learning in step S10 is whether the global loss function converges. t The calculation formula of (w) is: Among them, S t Represents the total amount of data samples in this round of learning, that is
Citation Information
Cited By
Distributed training method and system for hierarchical network
CN121031718A
A distributed training method and system for hierarchical networks
CN121031718B
Distributed model training method and system based on training and compression layering
CN121031719A