Personalized federal learning method based on knowledge distillation
By using unstructured pruning and knowledge distillation technology in federated learning, the global model is pruned and knowledge transferred, which solves the client offset problem caused by data heterogeneity in the Internet of Things and improves the accuracy and generalization of the model. capabilities and reduce communication costs.
Patent Information
- Application Number
- CN202411253260.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-10-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the field of Internet of Things, data heterogeneity problems in federated learning due to the diversity of device types and usage scenarios lead to client bias, affecting the accuracy and generalization ability of the model, and existing solutions increase communication costs. .
Using a personalized federated learning method based on knowledge distillation, the global model is pruned through unstructured pruning technology to generate a teacher model, and the attention graph knowledge is combined for knowledge distillation and passed to the local model for update to improve the personalization of the model. performance and generalization capabilities while reducing communication costs.
It effectively alleviates the client drift problem caused by data heterogeneity, improves the accuracy and generalization ability of the local model on the test data set, reduces communication costs, and optimizes the knowledge transfer process.
Smart Images

Figure CN118761455A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of federated learning and knowledge distillation technology, and in particular to a personalized federated learning method based on knowledge distillation. Background Art
[0002] In the field of Internet of Things (IoT), the network of devices and systems is committed to improving efficiency, automation and intelligence through data collection and exchange. In this context, federated learning, as a distributed machine learning paradigm with high adaptability and security, allows devices to share knowledge while ensuring data privacy, opening up broad development opportunities for the interconnection and interoperability of smart devices. However, due to the diversity of device types, usage scenarios and user interaction methods, the collected data often exhibits non-independent and identically distributed characteristics, which may cause the so-called "client drift" problem. On IoT devices, such as smart sensors, automated control systems, etc., the challenges brought by data heterogeneity will cause the federated learning process to converge slowly, and local devices may not be able to train models with good performance.
[0003] The existing methods to solve the data heterogeneity problem in the federated learning environment mainly use sparsification methods to compress the local model, thereby personalizing the local model, alleviating the impact of data heterogeneity, and improving the accuracy of the model on the test set. However, although the existing methods have alleviated the poor accuracy performance of traditional federated learning through methods such as sparse training and personalized models, they still face some challenges. On the one hand, in the personalized model, although the performance impact caused by data heterogeneity is effectively alleviated, the amount of parameters transmitted is increased, which greatly increases the communication cost; on the other hand, in the method based on federated distillation, by using knowledge distillation technology, the knowledge in the global model is refined and transferred to the local model, thereby guiding the training of the local model to improve the personalized performance and generalization ability of the local model. However, many personalized federated learning methods based on knowledge distillation ignore the transferability of global model knowledge during the distillation process, which may affect the effect of knowledge transfer. Summary of the invention
[0004] In order to solve the above technical problems, the present invention provides a personalized federated learning method based on knowledge distillation, so as to alleviate the client drift problem caused by data heterogeneity, improve the model accuracy performance, and reduce the communication cost between local devices.
[0005] To achieve the above object, the technical solution of the present invention is as follows: A personalized federated learning method based on knowledge distillation includes the following steps: S1, initialize the global model of the central server and the number of local devices; S2, broadcast the initialized global model to the local device, and set the local device training rounds, batch number and learning rate; S3, all local devices use local private data for model training; S4. After all local training is performed, each device uploads the local model parameters to the central server to aggregate and generate a new global model; S5. After the new global model is aggregated, the new global model generated by the aggregation is pruned according to the set pruning rate through the unstructured pruning technology, and the global model is turned into a student-friendly teacher model; S6. The final prediction and attention map knowledge in the teacher model obtained after pruning is passed to the local model. The local model now acts as a student model and is updated based on the transferred knowledge.
[0006] In the above scheme, in step S1, the number of all local devices participating in federated learning is 20, and the participation rate in each round is 50%.
[0007] In the above scheme, in step S5, pruning the new global model includes the following steps: Step 1: Convert the weight parameters in the global model from a multidimensional array to a one-dimensional vector and connect them; Step 2: Determine the pruning threshold according to the connected vector and the preset pruning rate; Step 3: Generate a mask matrix with the same shape as the weight parameter according to the pruning threshold; Step 4: Apply the mask matrix to prune the weight parameters to obtain the pruned weight parameters; Step 5: Assign the pruned weight parameters to the original global model and obtain the final pruned teacher model.
[0008] In a further technical solution, step 1 is specifically as follows: For the global model , it has Weight parameter , each parameter is a multidimensional array, all weight parameters are converted into one-dimensional vectors and connected into a large vector : ; Here, T represents the transpose operation.
[0009] In a further technical solution, step 2 is specifically as follows: Calculating vectors The absolute value of and given a pruning rate To calculate the pruning threshold ; ; in, Indicates the return vector Middle percentile elements.
[0010] In a further technical solution, step 3 is specifically as follows: For each weight parameter , generates a mask matrix of the same shape : ; in, express No. weights, express No. The mask matrix of weights.
[0011] In a further technical solution, step 4 is as follows: multiply each weight parameter by its corresponding mask matrix to obtain the pruned weight parameter : ; in, represents element-wise multiplication, represents the i-th weight parameter, represents the i-th mask matrix, Represents the i-th weight parameter after pruning.
[0012] In a further technical solution, step 5 is as follows: the pruned weight parameters Assign to the global model , and get the final pruned model : .
[0013] In the above scheme, the specific method of step S6 is as follows: Step 1: For the final prediction knowledge, use KL divergence to measure the difference between the final prediction of the teacher model and the student model after pruning: ; in, represents the difference between the teacher model and the student model in the final prediction, that is, the KL divergence; t represents the temperature coefficient in knowledge distillation, represents the value of the softmax output of the teacher model at temperature t on the i-th category, Represents the value of the softmax output of the student model at temperature t on the i-th category; Step 2: For the attention map knowledge, it is defined as: ; in, Represents the difference between the teacher model and the student model in the intermediate features, represents the cross entropy loss, represents the output of the student model, x represents the label, and Represent the attention graphs of the student model and the teacher model in vector form, p represents the norm type, Represents the proportion of adjusted attention distillation loss in the entire loss; Step 3: Finally, we get the total loss function. The local model is based on the total loss function. Complete self-update; ; in, Represents the knowledge distillation weight parameter.
[0014] Furthermore, and The calculation formula is as follows: ; ; in, represents the logit output of the teacher model in class i, Represents the logit output of the student model in the i-th category, where logit represents the original predicted value without being processed by the softmax function.
[0015] Through the above technical solution, the personalized federated learning method based on knowledge distillation provided by the present invention has the following beneficial effects: 1. In order to solve the problem of client drift caused by data heterogeneity in federated learning, which leads to the decline in the accuracy of local models, the present invention further extends the concept of knowledge distillation to attention transfer, and realizes a more efficient distillation process by combining attention graph knowledge and final prediction knowledge. This method not only inherits the advantages of traditional knowledge distillation, but also further optimizes the transfer and application of knowledge through a specific attention mechanism. The extracted knowledge will be used by local devices in the subsequent training phase, which will ultimately help to achieve better personalized performance of local models. It effectively solves the problem of a significant decline in the prediction accuracy of local models on test data sets when the data are not independent and identically distributed, alleviates the impact of client drift, improves the accuracy of local models on test data sets, and also enhances the generalization ability of local models, making local models more suitable for data with other distributions.
[0016] 2. In response to the problems of low knowledge transfer efficiency and high communication cost in existing federated distillation learning, the present invention innovatively combines unstructured pruning and knowledge distillation in federated learning. Unstructured pruning is a method to reduce the number of weights in a neural network. It simplifies the model structure and reduces the complexity of the model by selectively removing connections with smaller weights. This method does not change the depth or width of the network, but can significantly reduce the number of parameters of the model. Before the global model transfers knowledge to the local model, the global model is pruned to enhance its knowledge transferability, thereby better transferring knowledge and reducing communication costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0018] Figure 1 A schematic diagram showing a comparison between a personalized federated learning method based on knowledge distillation of the present invention and a traditional knowledge distillation method; Figure 2 A schematic diagram of a process flow of a personalized federated learning method based on knowledge distillation disclosed in an embodiment of the present invention; Figure 3 This is the overall framework diagram of the federated learning based on pruning followed by distillation in the present invention; Figure 4 Flowchart for pruning a new global model. DETAILED DESCRIPTION
[0019] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0020] The present invention provides a personalized federated learning method based on knowledge distillation, such as Figure 1 As shown, the traditional knowledge distillation method directly extracts the knowledge of the global model into the local model (solid box), and the method of the present invention first prunes the global model, and then extracts the knowledge of the pruned global model into the local model (dashed box).
[0021] like Figure 2 and Figure 3 As shown, a personalized federated learning method based on knowledge distillation of the present invention includes the following steps: S1. Initialize the global model of the central server and the number of local devices.
[0022] For all local devices participating in federated learning, the number of local devices defaults to 20, and the participation rate in each round is 50%.
[0023] S2. Broadcast the initialized global model to the local device and set the local device training round E, batch size L and learning rate η.
[0024] S3. All local devices use local private data for model training. Local private data needs to be preprocessed first, including data cleaning, standardization and normalization.
[0025] S4. After all local training is completed, each device uploads the local model parameters to the central server to aggregate and generate a new global model.
[0026] S5. After the new global model is aggregated, the new global model generated by the aggregation is pruned according to the set pruning rate through unstructured pruning technology, turning the global model into a student-friendly teacher model.
[0027] like Figure 4 As shown in Figure 2, pruning the new global model includes the following steps: Step 1: Convert the weight parameters in the global model from a multidimensional array to a one-dimensional vector and connect them; The details are as follows: For the global model , it has Weight parameter , each parameter is a multidimensional array, all weight parameters are converted into one-dimensional vectors and connected into a large vector : ; Here, T represents the transpose operation.
[0028] Step 2: Determine the pruning threshold according to the connected vector and the preset pruning rate; The details are as follows: Calculate the vector The absolute value of and given a pruning rate To calculate the pruning threshold ; ; in, Indicates the return vector Middle percentile elements.
[0029] Step 3: Generate a mask matrix with the same shape as the weight parameter according to the pruning threshold; The details are as follows: For each weight parameter , generates a mask matrix of the same shape : ; in, express No. weights, express No. The mask matrix of weights.
[0030] Step 4: Apply the mask matrix to prune the weight parameters to obtain the pruned weight parameters; The details are as follows: Multiply each weight parameter with its corresponding mask matrix to obtain the pruned weight parameter : ; in, represents element-wise multiplication, represents the i-th weight parameter, represents the i-th mask matrix, Represents the i-th weight parameter after pruning.
[0031] Step 5: Assign the pruned weight parameters to the original global model and obtain the final pruned teacher model.
[0032] The details are as follows: Assign to the global model , and get the final pruned model : .
[0033] S6. The final prediction and attention map knowledge in the teacher model obtained after pruning is passed to the local model. The local model now acts as a student model and is updated based on the transferred knowledge.
[0034] The specific method is as follows: Step 1: For the final prediction knowledge, use KL divergence to measure the difference between the final prediction of the teacher model and the student model after pruning: ; in, represents the difference between the teacher model and the student model in the final prediction, that is, the KL divergence; t represents the temperature coefficient in knowledge distillation, represents the value of the softmax output of the teacher model at temperature t on the i-th category, Represents the value of the softmax output of the student model at temperature t on the i-th category; and The calculation formula is as follows: ; ; in, represents the logit output of the teacher model in class i, Represents the logit output of the student model in the i-th category, where logit represents the original predicted value without being processed by the softmax function.
[0035] Step 2: For the attention map knowledge, it is defined as: ; in, Represents the difference between the teacher model and the student model in the intermediate features, represents the cross entropy loss, represents the output of the student model, x represents the label, and Represent the attention graphs of the student model and the teacher model in vector form, p represents the norm type, Represents the proportion of adjusted attention distillation loss in the entire loss; Step 3: Finally, we get the total loss function. The local model is based on the total loss function. Complete self-update; ; in, Represents the knowledge distillation weight parameter.
[0036] The specific embodiments are as follows: The construction of the experimental environment is the first step in the experimental design. Choosing the right hardware platform and software tools is crucial for the smooth progress of the experiment. In terms of hardware, a high-performance GPU server was selected to accelerate the training and reasoning process of the model. In terms of software, the widely used deep learning framework PyTorch and its corresponding dependent libraries were used.
[0037] Specifically, experiments are conducted on three public datasets including Fashion-MNIST, CIFAR10 and CIFAR100.
[0038] Fashion-MNIST is an image dataset that replaces the MNIST handwriting recognition dataset. It contains 70,000 images of different products in 10 categories. The size, format, and division of the training and test sets of Fashion-MNIST are exactly the same as those of the MNIST dataset. The image size is 28*28 grayscale images, the training set size is 60,000 images, and the test set size is 10,000 images.
[0039] The CIFAR10 dataset is a small dataset for object recognition compiled by Alex Krizhevsky and others. The dataset consists of 60,000 32*32 color images. There are 10 categories, including airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships and trucks, with 6,000 images in each category, including 5 training images and 10,000 test images. Compared with the traditional MNIST dataset, CIFAR10 is a 3-channel color RGB image, while MNIST is a grayscale image. Secondly, the image size of the CIFAR10 dataset is 23*32, while the size of the MNIST dataset is 28*28. Finally, compared with the handwritten data recognition dataset, the CIFAR10 dataset contains real objects in the real world. Not only is the noise very large, but the proportions and features of the objects are also different, making classification more difficult. The accuracy of general linear models on the CIFAR10 dataset is very poor.
[0040] The CIFAR100 dataset is similar to the CIFAR10 dataset. The CIFAR100 dataset has 100 classes, each class has 600 color images of size 32*32, of which 500 images are used as training sets and 100 images are used as test sets. The 100 classes in CIFAR100 are divided into 20 super classes, and each image has a fine-grained category and a coarse-grained category.
[0041] In order to simulate the data heterogeneity scenario, the method of dividing the data set using Dirichlet distribution (β) is used for implementation. Specifically, β represents the degree of non-independent and identically distributed (Non-IID). The smaller β is, the greater the degree of non-independent and identically distributed (Non-IID) of the local data is, and the stronger the heterogeneity of the data is. In order to explore the impact of different degrees of non-independent and identically distributed local data on performance, the embodiment of the present invention conducts experiments on three data sets and uses different β values (in ϵ{0.05, 0.1, 0.5, 1}) for testing.
[0042] In the early stages of the experiment, data preprocessing is a key step to ensure that the data set is suitable for model training. The purpose of data preprocessing is to improve the training efficiency and performance of the model while ensuring the consistency and reliability of the data. The specific steps of data preprocessing include data cleaning, standardization, and normalization. The specific process is as follows:
[0043] Step 1: First, data cleaning is the process of removing noise and outliers from the data set. In the FashionMNIST, CIFAR10, and CIFAR100 data sets, it is necessary to check whether the image files are complete and whether the labels are consistent with the image content. The cleaned data will reduce interference factors in the model learning process and improve the generalization ability of the model.
[0044] Step 2: Secondly, standardization and normalization are common methods for adjusting the scale of data. In image processing, normalization usually involves scaling pixel values from [0, 255] to the range of [0, 1] to ensure consistency between different images.
[0045] In the embodiment of the present invention, a convolutional neural network (CNN) is used as the basic model because it performs well in image recognition tasks. CNN can effectively extract the spatial hierarchical structure information of images, which is crucial for processing images in data sets such as FashionMNIST, CIFAR10 and CIFAR100.
[0046] In order to verify the effectiveness of the method (PFedPKD) of the present invention in dealing with data heterogeneity problems, and compare its performance differences with other federated learning algorithms. First, the classic federated averaging algorithm FedAvg is used as a baseline for comparison. The classic federated learning contains a large number of local devices and central servers. Each local device trains a small number of rounds locally and uploads the local training model parameters to the central server for aggregation operations. Finally, the performance of PFedPKD is explored and compared with methods such as FedGen and FedProto. FedGen obtains a generator model by aggregating the knowledge of all client models to assist in local model training. FedProto aggregates local prototypes collected from different clients, and then sends the global prototypes back to all clients to standardize the training of local models.
[0047] In order to evaluate and verify the embodiments of the present invention, extensive experiments were conducted on the three common image datasets mentioned above by setting different data distributions, and compared with other related federated learning methods to prove the effectiveness of our method in data heterogeneous scenarios. The results are shown in Table 1. It can be observed from Table 1 that when the data heterogeneity β is small, that is, when the data heterogeneity is large, the difference between different baselines is large, and the performance of the method of the present invention is higher than that of other baselines. This shows that when β is small, the algorithm of the present invention can adapt well to non-independent and identically distributed data, and when β is large, the algorithm of the present invention can also achieve better performance than it.
[0048] Table 1 Comparison of accuracy at different levels of data heterogeneity
[0049] The method of the present invention first prunes the global model and then performs knowledge distillation on the local model to explore the performance changes of the local model. The experimental results are shown in Table 2.
[0050] Table 2 Performance changes of local models under different pruning rates
[0051] "NONE" indicates the global model is not pruned.
[0052] As shown in the experimental results in Table 2, the method of the present invention shows different performances at different pruning rates, especially when the pruning rate is 50%, it achieves the best test accuracy on the CIFAR10 and CIFAR100 datasets. This shows that the method of the present invention can optimize the model by pruning and improve the generalization ability of the model. In practical applications, this means that the accuracy and efficiency of the model can be balanced by adjusting the pruning rate, especially in resource-constrained environments.
[0053] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A personalized federated learning method based on knowledge distillation, characterized in that: The steps include: S1, initialize the global model of the central server and the number of local devices; S2, broadcast the initialized global model to the local device, and set the local device training rounds, batch number and learning rate; S3, all local devices use local private data for model training; S4. After all local training is performed, each device uploads the local model parameters to the central server to aggregate and generate a new global model; S5. After the new global model is aggregated, the new global model generated by the aggregation is pruned according to the set pruning rate through the unstructured pruning technology, and the global model is turned into a student-friendly teacher model; S6. The final prediction and attention map knowledge in the teacher model obtained after pruning is passed to the local model. The local model now acts as a student model and is updated based on the transferred knowledge.
2. According to claim 1, a personalized federated learning method based on knowledge distillation is characterized in that: In step S1, the number of all local devices participating in federated learning is 20, and the participation rate in each round is 50%.
3. According to claim 1, a personalized federated learning method based on knowledge distillation is characterized in that: In step S5, pruning the new global model includes the following steps: Step 1: Convert the weight parameters in the global model from a multidimensional array to a one-dimensional vector and connect them; Step 2: Determine the pruning threshold according to the connected vector and the preset pruning rate; Step 3: Generate a mask matrix with the same shape as the weight parameter according to the pruning threshold; Step 4: Apply the mask matrix to prune the weight parameters to obtain the pruned weight parameters; Step 5: Assign the pruned weight parameters to the original global model and obtain the final pruned teacher model.
4. A personalized federated learning method based on knowledge distillation according to claim 3, characterized in that: Step 1 is as follows: For the global model , it has Weight parameter , each parameter is a multidimensional array, all weight parameters are converted into one-dimensional vectors and connected into a large vector : ; Here, T represents the transpose operation.
5. A personalized federated learning method based on knowledge distillation according to claim 4, characterized in that: Step 2 is as follows: Calculating vectors The absolute value of and given a pruning rate To calculate the pruning threshold ; ; in, Indicates the return vector Middle percentile elements.
6. A personalized federated learning method based on knowledge distillation according to claim 4, characterized in that: Step 3 is as follows: For each weight parameter , generates a mask matrix of the same shape : ; in, express No. weights, express No. The mask matrix of weights.
7. A personalized federated learning method based on knowledge distillation according to claim 4, characterized in that: Step 4 is as follows: multiply each weight parameter by its corresponding mask matrix to obtain the pruned weight parameter : ; in, represents element-wise multiplication, represents the i-th weight parameter, represents the i-th mask matrix, Represents the i-th weight parameter after pruning.
8. The personalized federated learning method based on knowledge distillation according to claim 5, characterized in that: Step 5 is as follows: Assign to the global model , and get the final pruned model : 。 9. The personalized federated learning method based on knowledge distillation according to claim 1, characterized in that: The specific method of step S6 is as follows: Step 1: For the final prediction knowledge, use KL divergence to measure the difference between the final prediction of the teacher model and the student model after pruning: ; in, represents the difference between the teacher model and the student model in the final prediction, that is, the KL divergence; t represents the temperature coefficient in knowledge distillation, represents the value of the softmax output of the teacher model at temperature t on the i-th category, Represents the value of the softmax output of the student model at temperature t on the i-th category; Step 2: For the attention map knowledge, it is defined as: ; in, Represents the difference between the teacher model and the student model in the intermediate features, represents the cross entropy loss, represents the output of the student model, x represents the label, and Represent the attention graphs of the student model and the teacher model in vector form, p represents the norm type, Represents the proportion of adjusted attention distillation loss in the entire loss; Step 3: Finally, the total loss function is obtained. The local model is based on the total loss Complete self-update; ; in, Represents the knowledge distillation weight parameter.
10. A personalized federated learning method based on knowledge distillation according to claim 7, characterized in that: and The calculation formula is as follows: ; ; in, represents the logit output of the teacher model in class i, Represents the logit output of the student model in the i-th category, where logit represents the original predicted value without being processed by the softmax function.
Citation Information
Patent Citations
Federal learning model aggregation method based on dynamic adaptive knowledge distillation
CN116681144A
Cited By
Distillation and image recognition method, apparatus, device and program for visual large model
CN119600411A
Heterogeneous federated learning method based on spatio-temporal data distillation
CN119692436A
Federal learning defense method, electronic equipment and storage medium
CN120030536A
A Federated Learning Defense Method, Electronic Device, and Storage Medium
CN120030536B
