Federal learning method and system based on many-to-many dynamic similarity aggregation
By employing a many-to-many dynamic similarity aggregation method within the federated learning framework, and utilizing Euclidean distance and cosine distance to calculate similarity, and dynamically selecting collaborative models for aggregation, the problems of client drift and gradient conflict are resolved, thus optimizing the model training effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JIUJIANG UNIV
- Filing Date
- 2025-12-11
- Publication Date
- 2026-05-08
AI Technical Summary
In existing federated learning frameworks, when the data heterogeneity among multiple clients is large, client drift occurs, and gradient conflicts between models are inevitable, leading to application limitations.
A dynamic similarity aggregation method based on many-to-many is adopted. Middleware models are randomly distributed between the cloud server and multiple clients for training and updating. Similarity is calculated by normalized weighting of Euclidean distance and cosine distance. Collaborative models are dynamically selected for aggregation until a preset number of iterations is reached to generate a global model.
It reduces the impact of gradient conflicts and client drift, optimizes the federated learning framework, and improves the training efficiency and accuracy of the model.
Smart Images

Figure CN121998035A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of federated learning technology, and in particular to a federated learning method and system based on many-to-many dynamic similarity aggregation. Background Technology
[0002] The performance of deep learning models largely depends on large-scale, high-quality data. However, in real-world scenarios, data is often distributed across different devices, organizations, and even geographical locations. Furthermore, due to increasing concerns about user privacy, the collection, management, and use of data are facing increasingly stringent legal and ethical restrictions. Therefore, the traditional centralized training paradigm—where all data is aggregated onto a central server for unified training—is severely constrained in practical deployments. Against this backdrop, federated learning, as an emerging distributed machine learning framework, is gradually becoming a viable solution to the problems of data silos and privacy protection.
[0003] In existing technologies, federated learning frameworks primarily use a one-to-many model. This framework maintains a unique global model in the cloud and multiple local client models with their own private data. After training on the local clients, these models are uploaded to the cloud server for aggregation. When the data from multiple clients exhibits significant heterogeneity, client drift occurs, and gradient conflicts between models become unavoidable, leading to clear limitations in the application of existing methods. Summary of the Invention
[0004] Therefore, the purpose of this invention is to provide a federated learning method and system based on many-to-many dynamic similarity aggregation, in order to overcome the limitations of existing federated learning frameworks.
[0005] This invention provides a federated learning method based on many-to-many dynamic similarity aggregation. The federated learning model includes a cloud server and multiple clients. The cloud server includes multiple middleware models and a global model. The number of clients and middleware models is matched. The method is applied to the cloud server.
[0006] The method includes:
[0007] Randomly distribute middleware models to clients and obtain the updated middleware models trained by the clients;
[0008] Calculate the Euclidean distance and cosine distance between the two updated middleware models and perform normalized weighted processing to obtain the similarity between the two updated middleware models. Based on the similarity, obtain the collaborative model of the current updated middleware model.
[0009] The updated middleware model and collaboration model are aggregated based on a dynamic aggregation strategy to update the middleware model again and return to the step of randomly distributing the middleware model to the client to iterate the middleware model until the preset number of iterations is reached to obtain the target middleware model.
[0010] The target middleware model and its corresponding collaboration model are aggregated to obtain multiple aggregated middleware models, and a global model is generated based on the multiple aggregated middleware models.
[0011] In addition, the federated learning method based on many-to-many dynamic similarity aggregation according to the present invention may also have the following additional technical features:
[0012] Furthermore, the collaboration model is selected from the remaining updated middleware models excluding the currently updated middleware model among all updated middleware models, wherein the selection strategy includes:
[0013] When the actual number of iterations is less than the preset number of iterations, the middleware model with the highest similarity is selected as the collaboration model to complete the aggregation;
[0014] When the actual number of iterations is not less than the preset number of iterations, the middleware model with the lowest similarity is selected as the collaboration model to complete the aggregation;
[0015] The expression for the selection strategy is:
[0016]
[0017] In the formula, CoMSel represents the selection strategy; W i W represents the parameters of the i-th middleware model. j λ represents the parameters of the j-th middleware model; e represents the number of training iterations; and λ is the system boundary parameter.
[0018] Furthermore, the similarity calculation formula is as follows:
[0019] Sim(W i W j ) = 0.5S Euc +0.5S Cos ;
[0020] In the formula, W i W represents the parameters of the i-th middleware model. j S represents the parameters of the j-th middleware model; Euc The middleware model parameters W are obtained after Euclidean distance normalization. i With middleware model parameter W j Similarity; S Cos The middleware model parameters W are obtained after cosine distance normalization.i With middleware model parameter W j Similarity;
[0021] in:
[0022]
[0023] In the formula, d Euc d represents Euclidean distance; Cos Represents cosine distance;
[0024] in:
[0025]
[0026] Furthermore, in the step of aggregating the target middleware model and its corresponding collaboration model to obtain multiple aggregated middleware models, and generating a global model based on these multiple aggregated middleware models, the expression for the global model is:
[0027]
[0028] In the formula, W g K represents the global model; T represents the number of middleware models; i represents the preset number of iterations; and i represents the number of middleware models.
[0029] In one aspect, the present invention also provides a federated learning method based on many-to-many dynamic similarity aggregation. The federated learning model includes a cloud server and multiple clients. The cloud server includes multiple middleware models and a global model. The number of clients matches the number of middleware models. The method is applied to the clients.
[0030] The method includes:
[0031] Obtain the middleware model randomly distributed by the cloud server;
[0032] The middleware model is trained and updated using the dataset, and then uploaded to the cloud server.
[0033] Another aspect of the present invention provides a federated learning system based on many-to-many dynamic similarity aggregation, applied to a cloud server, the system comprising:
[0034] The acquisition module is used to randomly distribute middleware models to clients and obtain the middleware models updated by client training.
[0035] The calculation module is used to calculate the Euclidean distance and cosine distance between two updated middleware models, perform normalized weighted processing to obtain the similarity between the two updated middleware models, and obtain the collaborative model of the current updated middleware model based on the similarity.
[0036] The iteration module is used to aggregate the updated middleware model and collaboration model based on a dynamic aggregation strategy to update the middleware model again and return to the step of randomly distributing the middleware model to the client to iterate the middleware model until the preset number of iterations is reached to obtain the target middleware model.
[0037] The aggregation module is used to aggregate the target middleware model and the corresponding collaborative model to obtain multiple aggregated middleware models, and generate a global model based on the multiple aggregated middleware models.
[0038] In another aspect, this invention provides a federated learning system based on many-to-many dynamic similarity aggregation, applied to a client, the system comprising:
[0039] The acquisition module is used to acquire middleware models randomly distributed by the cloud server;
[0040] The training module is used to train and update the middleware model using the dataset and then upload the trained and updated middleware model to the cloud server.
[0041] The aforementioned federated learning method and system based on many-to-many dynamic similarity aggregation optimizes the federated learning framework through a multi-middleware model dynamic similarity aggregation method for multiple clients. This framework includes a cloud server with multiple middleware models and a global model, as well as multiple local clients containing private data. Furthermore, it addresses the limitations of existing technologies through a similarity-based dynamic cross-aggregation approach. Specifically, middleware is randomly assigned to different clients for training and updates to learn local knowledge. Simultaneously, a dynamic aggregation strategy based on similarity is used to update the middleware models, reducing the impact of gradient conflicts and client drift. Attached Figure Description
[0042] Figure 1 This is a flowchart of the federated learning method based on many-to-many dynamic similarity aggregation in the first embodiment of the present invention;
[0043] Figure 2 This is a flowchart of the federated learning method based on many-to-many dynamic similarity aggregation in the second embodiment of the present invention;
[0044] The following detailed description, in conjunction with the accompanying drawings, will further illustrate the present invention. Detailed Implementation
[0045] To facilitate understanding of the present invention, a more complete description will be given below with reference to the accompanying drawings. Several embodiments of the invention are illustrated in the drawings. However, the invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0047] To address the technical challenges of client drift and unavoidable gradient conflicts between models in existing federated learning frameworks when data heterogeneity among multiple clients is high, this application provides a federated learning method and system based on many-to-many dynamic similarity aggregation. The federated learning model includes a cloud server and multiple clients. The cloud server comprises multiple middleware models and a global model. The number of clients and middleware models is matched. The federated learning framework is optimized through dynamic similarity aggregation of multiple clients using multiple middleware models. This framework includes a cloud server with multiple middleware models and a global model, and multiple local clients containing private data. Furthermore, the limitations of existing technologies are overcome through dynamic cross-aggregation based on similarity. Specifically, middleware is randomly assigned to different clients for training and updates to learn local knowledge. Simultaneously, a dynamic aggregation strategy based on similarity is used to update the middleware models, reducing the impact of gradient conflicts and client drift.
[0048] To facilitate understanding of the present invention, several embodiments are given below. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that the disclosure of the present invention will be more thorough and complete.
[0049] Example 1
[0050] Please see Figure 1 The diagram illustrates a federated learning method based on many-to-many dynamic similarity aggregation in the first embodiment of the present invention, applied to a cloud server. The method includes steps S101 to S105:
[0051] S101. Randomly distribute the middleware model to the client and obtain the middleware model updated by the client after training.
[0052] As a concrete example, FedDC (Federated Learning with Local Drift Decoupling and Correction) randomly distributes middleware to different clients for training and updates to learn local knowledge. Simultaneously, it uses a dynamic aggregation strategy based on similarity to update the middleware models, reducing the impact of gradient conflicts and client drift. Specifically, taking a cloud server with K middleware models as an example, the cloud server initializes the parameters of the K middleware models using a random initialization method and randomly selects K clients to distribute the middleware models. The middleware models use CNN, ResNet20, and VGG16 as backbone networks. The middleware models are trained using private data from local clients, and after training, the updated middleware models are uploaded to the cloud server.
[0053] S102. Calculate the Euclidean distance and cosine distance between the two updated middleware models and perform normalized weighted processing to obtain the similarity between the two updated middleware models. Based on the similarity, obtain the collaborative model of the current updated middleware model.
[0054] Different models converge towards different valleys during training; some converge towards narrow valleys, while others converge towards flat valleys. Therefore, the technical solution of this application employs a collaborative aggregation strategy, enabling different models to learn from each other and converge together towards a flatter valley. Specifically, the collaborative model is selected from the remaining updated middleware models excluding the currently updated middleware model. The selection strategy includes: when the actual number of iterations is less than a preset number of iterations, the middleware model with the highest similarity is selected as the collaborative model to complete the aggregation; when the actual number of iterations is not less than the preset number of iterations, the middleware model with the lowest similarity is selected as the collaborative model to complete the aggregation.
[0055] The expression for the selection strategy is:
[0056]
[0057] In the formula, CoMSel represents the selection strategy; W i W represents the parameters of the i-th middleware model. j λ represents the parameters of the j-th middleware model; λ is the system boundary parameter; e represents the number of training iterations, i.e., the number of training iterations of the entire model using the entire dataset. Its initial value is 0, and it is incremented by 1 after each training iteration. In this system, the maximum value of e is set to 1000, i.e., the preset number of iterations is 1000, which means the number of training iterations is 1000.
[0058] Furthermore, λ is the system boundary parameter, i.e. the boundary of the policy transformation. From the test experiments on λ, it can be seen that the value of λ was set to 25, 50, 100 and 300 respectively in the test. According to the test results, the test accuracy of the system is the highest when λ = 50. Therefore, in all experiments in this embodiment, λ is 50.
[0059] In this embodiment, the similarity calculation formula is: Sim(W i W j ) = 0.5S Euc +0.5S Cos ;
[0060] In the formula, W i W represents the parameters of the i-th middleware model. j S represents the parameters of the j-th middleware model; Euc The middleware model parameters W are obtained after Euclidean distance normalization. i With middleware model parameter W j Similarity; S Cos The middleware model parameters W are obtained after cosine distance normalization. i With middleware model parameter W j The similarity.
[0061] in:
[0062]
[0063] In the formula, d Euc d represents Euclidean distance; Cos Represents cosine distance;
[0064] in:
[0065]
[0066]
[0067] S103. Aggregate the updated middleware model and collaboration model based on the dynamic aggregation strategy to update the middleware model again.
[0068] S104. Determine whether the current update count has reached the preset iteration count based on the updated middleware model.
[0069] If the current update count has not reached the preset iteration count, return to step S101 to iterate the middleware model; if the current update count has reached the preset iteration count, the updated and iterated middleware model is the target middleware model, and step S105 is executed.
[0070] S105. Aggregate the target middleware model and the corresponding collaboration model to obtain multiple aggregated middleware models, and generate a global model based on the multiple aggregated middleware models.
[0071] Specifically, the expression for the global model is:
[0072]
[0073] In the formula, W g K represents the global model; T represents the number of middleware models; i represents the preset number of iterations; and i represents the number of middleware models.
[0074] As a concrete example, after generating the global model, we evaluated it using Cifar10 and Cifar100 test data, using accuracy as the evaluation criterion. The final results are shown in Table 1:
[0075] Table 1:
[0076]
[0077] It should be further noted that the technical solution in this application is specifically implemented under the PyTorch framework, and PyCharm is used as the simulation experimental platform.
[0078] In summary, the federated learning method based on many-to-many dynamic similarity aggregation in the above embodiments of the present invention optimizes the federated learning framework through dynamic similarity aggregation of multiple clients using multiple middleware models. This framework includes a cloud server with multiple middleware models and a global model, as well as multiple local clients containing private data. Furthermore, it overcomes the limitations of existing technologies by using a similarity-based dynamic cross-aggregation method. Specifically, middleware is randomly assigned to different clients for training and updating to learn local knowledge, while a dynamic aggregation strategy based on similarity is used to update the middleware models, thereby reducing the impact of gradient conflicts and client drift.
[0079] Example 2
[0080] Please see Figure 2 The diagram illustrates a federated learning method based on many-to-many dynamic similarity aggregation in the second embodiment of the present invention, applied to a client. The method includes steps S201 to S202:
[0081] S201. Obtain the middleware model randomly distributed by the cloud server.
[0082] S202. Train and update the middleware model using the dataset and upload the trained and updated middleware model to the cloud server.
[0083] In this embodiment, the open-source datasets Cifar10 and Cifar100 are used as datasets. Cifar10 contains 10 categories with 5000 samples per category; Cifar100 contains 100 categories with 500 samples per category. Image sizes are normalized to 32×32 pixels. After receiving the middleware model, the client trains and updates the middleware model using local data. After training, the client uploads the middleware model to the cloud server. Upon receiving the middleware model, the cloud server simultaneously calculates the Euclidean distance and cosine distance between the models, and then normalizes and weights these values as the basis for similarity evaluation.
[0084] In summary, the federated learning method based on many-to-many dynamic similarity aggregation in the above embodiments of the present invention optimizes the federated learning framework through dynamic similarity aggregation of multiple clients using multiple middleware models. This framework includes a cloud server with multiple middleware models and a global model, as well as multiple local clients containing private data. Furthermore, it overcomes the limitations of existing technologies by using a similarity-based dynamic cross-aggregation method. Specifically, middleware is randomly assigned to different clients for training and updating to learn local knowledge, while a dynamic aggregation strategy based on similarity is used to update the middleware models, thereby reducing the impact of gradient conflicts and client drift.
[0085] Example 3
[0086] The federated learning system based on many-to-many dynamic similarity aggregation in the third embodiment of the present invention is applied to a cloud server, and the system includes:
[0087] The acquisition module is used to randomly distribute middleware models to clients and obtain the middleware models updated by client training.
[0088] The calculation module is used to calculate the Euclidean distance and cosine distance between two updated middleware models, perform normalized weighted processing to obtain the similarity between the two updated middleware models, and obtain the collaborative model of the current updated middleware model based on the similarity.
[0089] The iteration module is used to aggregate the updated middleware model and collaboration model based on a dynamic aggregation strategy to update the middleware model again and return to the step of randomly distributing the middleware model to the client to iterate the middleware model until the preset number of iterations is reached to obtain the target middleware model.
[0090] The aggregation module is used to aggregate the target middleware model and the corresponding collaborative model to obtain multiple aggregated middleware models, and generate a global model based on the multiple aggregated middleware models.
[0091] In summary, the federated learning system based on many-to-many dynamic similarity aggregation in the above embodiments of the present invention optimizes the federated learning framework through a dynamic similarity aggregation method for multiple clients using multiple middleware models. This framework includes a cloud server with multiple middleware models and a global model, and multiple local clients containing private data. Furthermore, it overcomes the limitations of existing technologies through a similarity-based dynamic cross-aggregation approach. Specifically, middleware is randomly assigned to different clients for training and updates to learn local knowledge, while a dynamic aggregation strategy based on similarity is used to update the middleware models, thereby reducing the impact of gradient conflicts and client drift.
[0092] Example 4
[0093] The federated learning system based on many-to-many dynamic similarity aggregation in the fourth embodiment of the present invention is applied to a client, and the system includes:
[0094] The acquisition module is used to acquire middleware models randomly distributed by the cloud server;
[0095] The training module is used to train and update the middleware model using the dataset and then upload the trained and updated middleware model to the cloud server.
[0096] In summary, the federated learning system based on many-to-many dynamic similarity aggregation in the above embodiments of the present invention optimizes the federated learning framework through a dynamic similarity aggregation method for multiple clients using multiple middleware models. This framework includes a cloud server with multiple middleware models and a global model, and multiple local clients containing private data. Furthermore, it overcomes the limitations of existing technologies through a similarity-based dynamic cross-aggregation approach. Specifically, middleware is randomly assigned to different clients for training and updates to learn local knowledge, while a dynamic aggregation strategy based on similarity is used to update the middleware models, thereby reducing the impact of gradient conflicts and client drift.
[0097] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0098] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0099] Although embodiments of the invention have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the claims and their equivalents.
Claims
1. A federated learning method based on many-to-many dynamic similarity aggregation, characterized in that, The federated learning model includes a cloud server and multiple clients. The cloud server includes multiple middleware models and a global model. The number of clients matches the number of middleware models. The method is applied to the cloud server. The method includes: Randomly distribute middleware models to clients and obtain the updated middleware models trained by the clients; Calculate the Euclidean distance and cosine distance between the two updated middleware models and perform normalized weighted processing to obtain the similarity between the two updated middleware models. Based on the similarity, obtain the collaborative model of the current updated middleware model. The updated middleware model and collaboration model are aggregated based on a dynamic aggregation strategy to update the middleware model again and return to the step of randomly distributing the middleware model to the client to iterate the middleware model until the preset number of iterations is reached to obtain the target middleware model. The target middleware model and its corresponding collaboration model are aggregated to obtain multiple aggregated middleware models, and a global model is generated based on the multiple aggregated middleware models.
2. The federated learning method based on many-to-many dynamic similarity aggregation according to claim 1, characterized in that, The collaboration model is selected from the remaining updated middleware models excluding the currently updated middleware model, among all updated middleware models. The selection strategy includes: When the actual number of iterations is less than the preset number of iterations, the middleware model with the highest similarity is selected as the collaboration model to complete the aggregation; When the actual number of iterations is not less than the preset number of iterations, the middleware model with the lowest similarity is selected as the collaboration model to complete the aggregation; The expression for the selection strategy is: In the formula, CoMSel represents the selection strategy; W i W represents the parameters of the i-th middleware model. j λ represents the parameters of the j-th middleware model; e represents the number of training iterations; and λ is the system boundary parameter.
3. The federated learning method based on many-to-many dynamic similarity aggregation according to claim 1, characterized in that, The formula for calculating similarity is: Sim(W i ,W j )=0.5S Euc +0.5S Cos ; In the formula, W i W represents the parameters of the i-th middleware model. j S represents the parameters of the j-th middleware model; Euc The middleware model parameters W are obtained after Euclidean distance normalization. i With middleware model parameter W j Similarity; S Cos The middleware model parameters W are obtained after cosine distance normalization. i With middleware model parameter W j Similarity; in: In the formula, d Euc d represents Euclidean distance; Cos Represents cosine distance; in:
4. The federated learning method based on many-to-many dynamic similarity aggregation according to claim 1, characterized in that, In the step of aggregating the target middleware model and its corresponding collaboration model to obtain multiple aggregated middleware models, and then generating a global model based on these multiple aggregated middleware models, the expression for the global model is: In the formula, W g K represents the global model; T represents the number of middleware models; and T represents the preset number of iterations. i represents the number of middleware models.
5. A federated learning method based on many-to-many dynamic similarity aggregation, characterized in that, The federated learning model includes a cloud server and multiple clients. The cloud server includes multiple middleware models and a global model. The number of clients matches the number of middleware models. The method is applied to the clients. The method includes: Obtain the middleware model randomly distributed by the cloud server; The middleware model is trained and updated using the dataset, and then uploaded to the cloud server.
6. A federated learning system based on many-to-many dynamic similarity aggregation, characterized in that, The system, applied to a cloud server, includes: The acquisition module is used to randomly distribute middleware models to clients and obtain the middleware models updated by client training. The calculation module is used to calculate the Euclidean distance and cosine distance between two updated middleware models, perform normalized weighted processing to obtain the similarity between the two updated middleware models, and obtain the collaborative model of the current updated middleware model based on the similarity. The iteration module is used to aggregate the updated middleware model and collaboration model based on a dynamic aggregation strategy to update the middleware model again and return to the step of randomly distributing the middleware model to the client to iterate the middleware model until the preset number of iterations is reached to obtain the target middleware model. The aggregation module is used to aggregate the target middleware model and the corresponding collaborative model to obtain multiple aggregated middleware models, and generate a global model based on the multiple aggregated middleware models.
7. A federated learning system based on many-to-many dynamic similarity aggregation, characterized in that, The system, applied to a client, includes: The acquisition module is used to acquire middleware models randomly distributed by the cloud server; The training module is used to train and update the middleware model using the dataset and then upload the trained and updated middleware model to the cloud server.