Gradient quantization method and device based on federated learning, equipment and storage medium

By dynamically adjusting gradient quantization on the client side and aggregating and updating the model on the server side, the problem of low gradient quantization accuracy in federated learning is solved, improving the accuracy of model training and privacy protection, and adapting to heterogeneous network environments.

CN116739107BActive Publication Date: 2026-04-07PING AN TECH (SHENZHEN) CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-09
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

In federated learning, the low quantization accuracy of gradients leads to communication bottlenecks and insufficient privacy protection, especially in heterogeneous and dynamic network environments where existing fixed-precision quantization algorithms cannot meet the requirements.

Method used

By performing local training and compression on the client side, the gradient quantization is dynamically adjusted according to preset rules. The compression result is uploaded only when the rate of change of the quantization value is greater than the threshold and the difference in the number of training times is less than the threshold. The model is then aggregated and updated on the server side until the model converges.

Benefits of technology

It improves the accuracy and communication efficiency of gradient quantization, enhances the accuracy of model training and privacy protection, and adapts to the dynamic changes of heterogeneous network environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116739107B_ABST
    Figure CN116739107B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of artificial intelligence, and more particularly to a gradient quantization method and device based on federated learning, equipment and storage medium. The above method is applied to the medical field, and the gradient quantization method is applied to the client. According to the training task, the corresponding initial model to be trained is downloaded, the initial model is trained based on the local data in the client, the first training model is obtained, the parameters of the first training model in each client are compressed, the compression result of the current training is obtained, and if the compression result meets the uploading condition, the compression result is sent to the server. In the present application, the gradient quantization is performed according to the compression parameters of each client, which can dynamically compress the gradient parameters based on the compression parameters of each client, so as to dynamically adjust each client in the process of gradient quantization, thereby improving the accuracy of gradient quantization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a gradient quantization method, apparatus, device, and storage medium based on federated learning. Background Technology

[0002] Medical data—such as electronic health records (EHRs) and medical images—plays a foundational role in achieving precision health. However, this data is often scattered and difficult to share due to its sensitivity. Federated learning can ensure that sensitive patient data remains with local institutions or individual consumers, preventing leakage to model trainers during the federated machine learning process. Federated learning is essentially a distributed machine learning framework that allows participating parties to collaboratively model and improve model performance without sharing training data. To reduce the impact of bandwidth on the federated learning training process, participants typically compress gradients before uploading them locally. Gradient compression reduces bandwidth usage while also providing some privacy protection.

[0003] In existing technologies, gradient compression algorithms have demonstrated good speedup effects in certain specific scenarios, but they are all fixed-precision quantization algorithms, which still have some limitations in federated learning. Due to the diverse communication technologies of edge devices, the network in federated learning is heterogeneous and dynamic, with significant differences in network states between clients, sometimes exceeding tenfold. When the required global model size is large, network bandwidth limitations and the number of worker nodes exacerbate the communication bottleneck in federated learning, resulting in lower gradient quantization accuracy. Therefore, improving gradient quantization accuracy is a pressing issue to be addressed in federated learning. Summary of the Invention

[0004] Therefore, it is necessary to provide a gradient quantization method, apparatus, device, and storage medium based on federated learning to address the aforementioned technical problems and solve the problem of low gradient quantization accuracy during federated learning.

[0005] A first aspect of this application provides a gradient quantization method based on federated learning, wherein the gradient quantization method is applied to a client, and the gradient quantization method includes:

[0006] Obtain the training task sent by the server, and download the corresponding initial model to be trained according to the training task;

[0007] Based on the local data in the client, the initial model is trained to obtain the first training model corresponding to the current training. The parameters of the first training model in the client are compressed according to the preset compression rules to obtain the compression parameters corresponding to the first training model.

[0008] Based on the compression parameters, the parameters of the first training model are compressed to obtain the compression result of the current training. The compression result includes the quantized value and the rate of change of the quantized value corresponding to the gradient quantization.

[0009] If the compression result is detected to meet the upload conditions, the compression result is sent to the server. The upload conditions are: if the difference between the number of training sessions corresponding to the last compression result sent by the client to the server and the number of training sessions corresponding to the current training session is less than a first preset threshold, and the rate of change of the quantization value is greater than a second preset threshold.

[0010] A second aspect of this application provides a gradient quantization method based on federated learning, characterized in that the gradient quantization method is applied to a server, and the gradient quantization method includes:

[0011] The task creator creates a training task and sends the training task to the client.

[0012] Obtain the quantized value and quantized value change rate of the gradient quantization sent by at least one client; based on the quantized value change rate, aggregate the quantized value according to a preset aggregation rule to obtain the aggregated quantized value.

[0013] Based on the aggregated quantized values, the corresponding model parameters in the training task are updated to obtain the updated training model.

[0014] Check whether the updated training model has converged. If the updated training model has converged, stop gradient quantization.

[0015] A third aspect of this application provides a gradient quantization device based on federated learning, characterized in that the gradient quantization device is applied to a client, and the gradient quantization includes:

[0016] The download module is used to obtain the training task sent by the server and download the corresponding initial model to be trained according to the training task.

[0017] The compression ratio determination module is used to train the initial model based on local data in the client to obtain a first training model, and to compress the parameters of the first training model in each client according to a preset compression rule to obtain the compression parameters corresponding to the first training model.

[0018] A compression module is used to compress the parameters of the first training model based on the compression parameters to obtain the compression result of the current training, wherein the compression result includes the quantized value and the rate of change of the quantized value corresponding to the gradient quantization.

[0019] An upload module is used to send the compressed result to the server if the compressed result is detected to meet the upload conditions. The upload conditions are that the difference between the number of training sessions corresponding to the last time the client sent the compressed result to the server and the number of training sessions corresponding to the current training session is less than a first preset threshold, and the rate of change of the quantization value is greater than a second preset threshold.

[0020] A fourth aspect of this application provides a gradient quantization device based on federated learning, characterized in that the gradient quantization device is applied to a server, and the gradient quantization includes:

[0021] A creation module is used to create training tasks through a task creator and send the training tasks to the client;

[0022] An aggregation module is used to acquire the quantized value and quantized value change rate of the gradient quantization sent by at least one client, and aggregate the quantized value according to a preset aggregation rule to obtain the aggregated quantized value.

[0023] The update module is used to update the corresponding model parameters in the training task based on the aggregated quantized values, so as to obtain the updated training model.

[0024] The detection module is used to detect whether the updated training model has converged. If the updated training model has converged, gradient quantization is stopped.

[0025] Fifthly, embodiments of the present invention provide a computer device, the computer device including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the gradient quantization method as described in the first aspect.

[0026] In a sixth aspect, embodiments of the present invention provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the gradient quantization method as described in the first aspect.

[0027] The advantages of this invention compared to the prior art are:

[0028] The system retrieves the training task sent by the server, downloads the corresponding initial model to be trained based on the training task, trains the initial model based on local data in the client, and obtains the first training model. The parameters of the first training model in each client are compressed according to a preset compression rule to obtain the compressed parameters corresponding to the first training model. The parameters of the first training model are compressed to obtain the compression result of the current training iteration. The compression result includes the quantized value and the rate of change of the quantized value corresponding to gradient quantization. If the compression result meets the upload conditions, the compression result is sent to the server. The upload conditions are that the difference between the number of training iterations corresponding to the last compressed result sent by the client to the server and the number of training iterations corresponding to the current training iteration is less than a first preset threshold, and the rate of change of the quantized value is greater than a second preset threshold. In this invention, gradient quantization is performed based on the compressed parameters of each client, allowing each client to dynamically compress the gradient parameters based on the compression parameters, so that each client can dynamically adjust during the gradient quantization process, thereby improving the accuracy of gradient quantization. In the medical field, when training features from case documents in different hospital document formats using federated learning, the method described in this application involves each hospital client compressing parameters of its local feature extraction model to improve the accuracy of gradient quantization, thereby enhancing the accuracy of the feature extraction model. This allows for more accurate extraction of health-related factors from case documents. Attached Figure Description

[0029] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0030] Figure 1 This is a schematic diagram of an application environment for a gradient quantization method based on federated learning, provided by an embodiment of the present invention.

[0031] Figure 2 This is a flowchart illustrating a gradient quantization method based on federated learning provided in an embodiment of the present invention;

[0032] Figure 3 This is a flowchart illustrating a gradient quantization method based on federated learning provided in an embodiment of the present invention;

[0033] Figure 4 This is a schematic diagram of the structure of a gradient quantization device based on federated learning provided in an embodiment of the present invention;

[0034] Figure 5This is a schematic diagram of the structure of a gradient quantization device based on federated learning provided in an embodiment of the present invention;

[0035] Figure 6 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0036] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0037] It should be understood that, when used in this specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0038] It should also be understood that the term “and / or” as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0039] As used in this specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if [described condition or event] is detected" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once [described condition or event] is detected," or "in response to detection of [described condition or event]."

[0040] Furthermore, in the description of this invention and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0041] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of the invention include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0042] It should be understood that the sequence number of each step in the following embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0043] To illustrate the technical solution of the present invention, specific embodiments are described below.

[0044] An embodiment of the present invention provides a gradient quantization method based on federated learning, which can be applied to, for example... Figure 1 In this application environment, the client communicates with the server. Clients include, but are not limited to, PDAs, desktop computers, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). The server can be implemented using a standalone server or a server cluster consisting of multiple servers.

[0045] See Figure 2 This is a flowchart illustrating a gradient quantization method based on federated learning according to an embodiment of the present invention. The aforementioned gradient quantization method based on federated learning can be applied to... Figure 1 The server in the above-mentioned configuration connects to the corresponding client, such as... Figure 2 As shown, the gradient quantization method based on federated learning, when applied to a client, may include the following steps.

[0046] S201: Obtain the training task sent by the server, and download the corresponding initial model to be trained according to the training task.

[0047] In step S201, the server sends a model training task to the client, and the client downloads the initial model corresponding to the training task according to the received training task instruction.

[0048] In this embodiment, client data is stored on private cloud servers in each hospital and used for local training. The server collects data streams from clients, including client ID, training epochs, model parameters, local performance, etc. The server's main tasks are data management, model aggregation, and performance evaluation. The server sends model training tasks to clients. Based on the received training task instructions, the client downloads the initial model corresponding to the training task and trains the initial model using the client data. In this embodiment, the client data can be medical records in text format.

[0049] Federated learning is a distributed collaborative learning paradigm that allows clients to collaboratively train a global deep learning model while keeping data locally, achieving both model learning and privacy protection. Therefore, multiple clients receive training tasks from the server, and all participating client devices send information to the server device to register their participation in federated learning. The network is connected via a communication network, which can be either wired or wireless.

[0050] Initial model parameters are set for the initial model, including the number of convolutional layers, pooling layers, or fully connected layers and their weights. Specifically, in this embodiment, the model framework and model structure from the model construction information are obtained; all model structures are placed within the model framework and connected according to a preset connection order to obtain a combined model; and the initial model parameters are set as the model parameters of the combined model to obtain the initial model.

[0051] It should be noted that wireless or wired networks use standard communication technologies and / or protocols. The network is typically the Internet, but can be any network, including but not limited to Local Area Networks (LANs), Metropolitan Area Networks (MANs), Wide Area Networks (WANs), mobile, wired or wireless networks, private networks, or any combination of virtual private networks. In some embodiments, technologies and / or formats, including Hypertext Markup Language (HTML), Extensible Markup Language (XML), etc., are used to represent data exchanged over the network. Furthermore, conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Networks (VPNs), and Internet Protocol Security (IPsec) can be used to encrypt all or some links.

[0052] S202: Based on local data in the client, train the initial model to obtain the first training model corresponding to the current training. Compress the parameters of the first training model in the client according to the preset compression rules to obtain the compressed parameters corresponding to the first training model.

[0053] In step S202, the downloaded initial model is trained multiple times using local data in each client. Through multiple training sessions, the parameter values ​​corresponding to the initial model are continuously updated. Based on the local data in the client, the initial model is trained to obtain the first training model corresponding to the current training session. The parameters in the first training model are relatively complex and will affect the efficiency of the next training session. Therefore, the parameters of the first training model in the client are compressed according to the preset compression rules to obtain the compressed parameters corresponding to the first training model.

[0054] In this embodiment, each client uses different training samples to train the model to be trained and calculate the gradient separately. The different training samples are local data on different clients. There are many methods to train the initial model to calculate the gradient separately on each client using training samples, such as stochastic gradient descent, batch gradient descent, mini-batch gradient descent, etc. In this application, no limitation is made on the algorithm used to train the model to calculate the gradient.

[0055] Each training iteration yields the first training model corresponding to the current training iteration. The parameters of the first training model in the client are compressed according to a preset compression rule to obtain the compressed parameters corresponding to the first training model.

[0056] It should be noted that when training the model, the initial model is trained based on federated learning. Federated learning training can be a parameter server architecture including one server and multiple clients, or a ring-allreduce architecture without parameter servers. In this application, no specific limitation is made on the architecture of the federated learning training cluster.

[0057] Optionally, the initial model is trained based on local data in the client, including:

[0058] Retrieve local data from the client;

[0059] The local data is preprocessed using a preprocessor to obtain the target local data;

[0060] The initial model is trained based on the target local data.

[0061] In this embodiment, each client performs data preprocessing, including removing invalid and duplicate data, and mapping the training data and data labels in the local data to determine the target local data. Based on the target local data, the initial model is trained. In this embodiment, by setting the initiation conditions for joint learning, the model can be trained using a centralized training approach when the joint learning initiation conditions are not met, and trained using a joint learning approach when the joint learning initiation conditions are met. For example, the centralized training approach can be used when D-SDF can obtain subscription data, the computational cost of model training is small, or CA&MF has sufficient computational resources, or LA&MF has insufficient computational resources. Alternatively, model training instructions can be sent to different participating clients to instruct them to train their local models based on the initial model.

[0062] Optionally, the parameters of the first trained model in each client are compressed according to a preset compression rule to obtain the compressed parameters corresponding to the first trained model, including:

[0063] Obtain the loss function and learning rate of the client during the current training iteration;

[0064] The compression parameters of the first training model are calculated based on the loss function and learning rate of the client during the current training iteration.

[0065] In this embodiment, when compressing the model, the training model is compressed based on the loss function and learning rate of the client during the current training iteration. The formula for calculating the compression parameters is as follows:

[0066]

[0067] in, f represents the compression parameters of the m-th client after the k-th training iteration. m (ω k Let η be the loss function corresponding to the first model obtained by the m-th client after the K-th training iteration. k Let ηk be the learning rate of the central model in the k-th training iteration, and η0 be the initial learning rate of the initial model. 0 The initial compression parameters corresponding to the initial model in each client.

[0068] In this embodiment, after each training iteration, each client obtains the corresponding first training model. Based on the parameters in the obtained first training model, the corresponding loss function is obtained. The learning rate refers to the learning rate of the model to be trained in each iteration. The central model learning rate is obtained by the server aggregating the model parameters uploaded by each client according to the parameters of the corresponding first model in the client through a preset aggregation method, updating the corresponding parameters, and obtaining the corresponding central parameters on the server. Based on the central parameters, the central model on the server is obtained, and based on the central model on the server, the learning efficiency of the corresponding central model is obtained. The initial learning rate of the initial model is the initial learning rate of the central model obtained after each client performs the first training on the initial model based on local data and uploads the model parameters to the server. The initial compression parameters are the compression parameters corresponding to the first model obtained after each client performs the first training on the initial model based on local data.

[0069] S203: Based on the compression parameters, compress the parameters of the first training model to obtain the compression result of the current training.

[0070] In step S23, the compression result includes the quantized value and the rate of change of the quantized value corresponding to gradient quantization. During iterative training, the parameters in the first training model obtained in the current iteration are compressed. The compression is dynamic, based on the compression parameters of each training iteration, to obtain the compression result corresponding to the current training iteration. The compression result includes the quantized value and the rate of change of the quantized value corresponding to gradient quantization. Dynamically compressing the model parameters achieves a balance between communication efficiency and model performance, minimizing the loss of effective information.

[0071] In this embodiment, the parameters of the first training model are compressed based on compression parameters. The compression formula is as follows:

[0072]

[0073] Among them, Q m (ω k Let be the compressed quantized gradient value in the m-th client during the k-th iteration of training, corresponding to the first trained model, and let Q represent the quantization compression operator. Let be the changes in the gradient of the parameters in the first training model corresponding to the m-th client during the k-th training iteration and the changes in the gradient of the parameters in the first training model corresponding to the m-th client during the (k-1)-th training iteration. This represents the compressed quantized gradient value of the first trained model in the m-th client during the (k-1)-th iteration of training. The compression parameters for the m-th client after the K-th training iteration are given.

[0074] It should be noted that the compression result includes the corresponding quantization gradient and the rate of change of the quantization gradient. The rate of change of the quantization gradient is the difference between the quantization gradients obtained in adjacent training iterations.

[0075] After each iteration of training in each client, the parameters in the first trained model are compressed and uploaded to the server. This reduces upload time and the loss caused by communication pressure, thereby improving the training accuracy of the model.

[0076] S204: If the compression result is detected to meet the upload conditions, send the compression result to the server.

[0077] In step S204, the upload condition is that if the difference between the number of training sessions corresponding to the last compression result sent by the client to the server and the number of training sessions corresponding to the current training session is less than a first preset threshold, and the rate of change of the quantization value is greater than a second preset threshold.

[0078] In this embodiment, after each client obtains the corresponding model parameters after the k-th iteration of training, it needs to upload the model parameters to the server. The server processes the corresponding model parameters and then sends the processed parameters to each client so that each client can perform the next iteration of training.

[0079] Since each client trains independently, the model loss function and learning rate obtained in the same training iteration are different. To avoid information loss, upload conditions are set: when the rate of change of the quantized value is greater than the second preset threshold, and the difference between the number of training iterations corresponding to the last compressed result sent by the client to the server and the number of training iterations corresponding to the current training iteration is less than the first preset threshold, the compressed parameters are uploaded to the server, as shown in the following formula:

[0080]

[0081]

[0082] t m ≤t max

[0083] in, To quantify the rate of change of the gradient, Q m (ω k () represents the compressed quantized gradient value in the first trained model for the m-th client during the k-th iteration of training. This represents the compressed quantized gradient value of the first trained model in the m-th client during the (k-1)-th iteration of training. The first preset threshold, Let m be the quantized gradient error of the m-th client during the k-th iteration of training. Let m be the quantized gradient error of the m-th client during the (k-1)th training iteration. Let ξ be the change in the gradient of the parameters in the first training model corresponding to the m-th client during the k-th iteration of training, and the change in the gradient of the parameters in the first training model corresponding to the m-th client during the (k-1)-th iteration of training. Let D be the total number of training iterations, M represent the number of clients, and ξ be the value of ξ. d t is a preset parameter. max For the second threshold, t m This refers to the difference between the number of training iterations corresponding to the last time the client sent a compression result to the server and the number of training iterations corresponding to the current training iteration.

[0084] Optionally, after sending the compression result to the server, the following may also be included:

[0085] If the aggregated quantized value is received from the server, the parameters of the first training model are updated based on the aggregated quantized value to obtain the second training model;

[0086] The second training model is trained based on local data in the client.

[0087] In this embodiment, when training the initial model, after multiple iterations of training, the training ends when the model converges, and the client stops training the model. When the model does not converge, the client will continuously perform iterative training. During each iteration, the client updates the parameters of the corresponding first model based on the aggregated quantization value sent by the server. The second training model is trained based on the local data in the client.

[0088] The system retrieves the training task sent by the server, downloads the corresponding initial model to be trained based on the training task, trains the initial model based on local data in the client, and obtains the first training model. The parameters of the first training model in each client are compressed according to a preset compression rule to obtain the compressed parameters corresponding to the first training model. The parameters of the first training model are compressed to obtain the compression result of the current training iteration. The compression result includes the quantized value and the rate of change of the quantized value corresponding to gradient quantization. If the compression result meets the upload conditions, the compression result is sent to the server. The upload conditions are that the difference between the number of training iterations corresponding to the last compressed result sent by the client to the server and the number of training iterations corresponding to the current training iteration is less than a first preset threshold, and the rate of change of the quantized value is greater than a second preset threshold. In this invention, gradient quantization is performed based on the compressed parameters of each client, allowing each client to dynamically compress the gradient parameters based on the compression parameters, so that each client can dynamically adjust during the gradient quantization process, thereby improving the accuracy of gradient quantization.

[0089] See Figure 3 This is a flowchart illustrating a gradient quantization method based on federated learning according to an embodiment of the present invention. The aforementioned gradient quantization method based on federated learning can be applied to... Figure 1 The server in the above-mentioned configuration connects to the corresponding client, such as... Figure 3 As shown, the gradient quantization method based on federated learning may include the following steps.

[0090] S301: Create training tasks using the task creator and send the training tasks to the client.

[0091] In step S301, the task creator is responsible for creating tasks. During creation, the execution time and complexity of the task need to be calculated, and the created task is distributed to the client.

[0092] In this embodiment, a training task corresponding to the artificial intelligence model is created through a task creator. The training task includes task types, such as classification model, prediction model, feature extraction model, etc., and convolutional neural network model. The artificial intelligence model is a convolutional neural network model.

[0093] S302: Obtain the quantized value and quantized value change rate of at least one gradient quantization sent by a client. Based on the quantized value change rate, aggregate the quantized values ​​according to a preset aggregation rule to obtain the aggregated quantized value.

[0094] In step S302, the client uploads the quantized values ​​of the gradient quantization and the rate of change of the quantized values ​​of the parameters in the first trained model after training to the server. The server aggregates the received quantized values ​​based on the received gradient quantization values ​​to obtain new parameter values ​​corresponding to the initial model, so as to send the new parameter values ​​to the client and enable the client to continue training based on the new parameter values.

[0095] In this embodiment, the server receives quantization values ​​sent by at least one client. Since different clients have different sample data and different parameters of the first training model obtained from the initial model training, different clients may also upload different parameter values ​​to the server. When a client sends the corresponding parameter value to the server, the server needs to aggregate the received parameter values ​​in order to obtain the final quantization value and send the final quantization value to each client.

[0096] In this embodiment, the formula for calculating the aggregate quantization value is as follows:

[0097]

[0098] and,

[0099] Among them, Q m (ω k+1 Let Q be the compressed quantized gradient value in the first trained model for the m-th client during the (k+1)-th iteration of training. m (ω k () represents the compressed quantized gradient value in the first trained model for the m-th client during the k-th iteration of training. To quantize the gradient change for the m-th client between two iterations k, k-1, M k Let α represent the set of clients that can upload quantized gradient information during the k-th training iteration, and let α represent the step size. Let be the gradient value of the parameter during the k-th iteration of training.

[0100] The quantized values ​​are aggregated based on the aggregation formula to obtain the quantized values ​​for each training iteration.

[0101] In another embodiment, the aggregated quantized value can be calculated using the mean method. After calculating the quantized value of the received client, the mean of the quantized values ​​is calculated based on the number of received clients, and the mean of the quantized values ​​is used as the aggregated quantized value.

[0102] S303: Based on the aggregated quantized values, update the corresponding model parameters in the training task to obtain the updated training model.

[0103] In step S303, the model parameters in the training task are updated based on the aggregated quantization values ​​to obtain the updated training model.

[0104] In this embodiment, the model parameters in the training task are updated based on the aggregated quantized values ​​to obtain the updated training model.

[0105] S304: Check if the updated training model has converged. If the updated training model has converged, stop gradient quantization.

[0106] In step S304, the updated training model is tested to see if it has converged. If the updated training model has converged, gradient quantization is stopped.

[0107] In this embodiment, the updated training model is trained based on the sample data in the server, and the loss value corresponding to the sample data is calculated. When the loss value is less than the loss threshold, the updated training model is considered to have converged, gradient quantization is stopped, and the target model is obtained.

[0108] In another embodiment, the aggregated quantized values ​​are sent to the client. Each client updates the model parameters based on the aggregated quantized values ​​to obtain the updated training model. In each client, the convergence of the updated training model is detected based on the local data in the client. The loss value in each client is calculated. When the number of loss values ​​less than the loss threshold is greater than the preset threshold, the updated training model is considered to have converged, gradient quantization is stopped, and the target model is obtained.

[0109] Optionally, after detecting whether the updated trained model has converged, the process also includes:

[0110] If the updated training model does not converge, the aggregated quantized values ​​will be sent to the client.

[0111] In this embodiment, if the updated training model obtained on the server does not converge, it is necessary to continue training the updated training model. During training, it is necessary to train based on local data in the client. Therefore, the aggregated quantized value is sent to the client, and the client updates the training model parameters according to the received aggregated quantized value.

[0112] Please see Figure 4 , Figure 4 This is a schematic diagram of a gradient quantization device based on federated learning provided in an embodiment of the present invention. In this embodiment, the terminal includes units used for execution... Figure 2 The steps in the corresponding embodiments. Please refer to the details. Figure 2The relevant descriptions in the corresponding embodiments are shown below. For ease of explanation, only the parts relevant to this embodiment are shown. See also... Figure 2 The gradient quantization method is applied to the client. The gradient quantization device 40 includes: a download module 41, a compression ratio determination module 42, a compression module 43, and an upload module 44.

[0113] Download module 41 is used to obtain the training task sent by the server and download the corresponding initial model to be trained according to the training task.

[0114] Compression ratio determination module 42 is used to train the initial model based on local data in the client to obtain the first training model, and to compress the parameters of the first training model in each client according to the preset compression rules to obtain the compression parameters corresponding to the first training model.

[0115] Compression module 43 is used to compress the parameters of the first training model based on compression parameters to obtain the compression result of the current training. The compression result includes the quantized value and the rate of change of the quantized value corresponding to the gradient quantization.

[0116] The upload module 44 is used to send the compression result to the server if the compression result is detected to meet the upload conditions. The upload conditions are that if the difference between the number of training times corresponding to the last compression result sent by the client to the server and the number of training times corresponding to the current training is less than a first preset threshold, and the rate of change of the quantization value is greater than a second preset threshold.

[0117] Optionally, the compression ratio determination module 42 includes:

[0118] The acquisition unit is used to acquire local data from the client.

[0119] The preprocessing unit is used to preprocess the local data through a preprocessor to obtain the target local data.

[0120] The initial model training unit is used to train the initial model based on the target local data.

[0121] Optionally, the compression ratio determination module 42 includes:

[0122] The loss function and learning rate acquisition unit is used to acquire the loss function and learning rate of the client during the current training iteration.

[0123] The computation unit is used to calculate the compression parameters of the first training model based on the loss function and the learning rate of the client during the current training iteration.

[0124] Optionally, the gradient quantization device 40 further includes:

[0125] The receiving module is used to update the parameters of the first training model based on the aggregated quantized value sent by the server to obtain the second training model.

[0126] The second model training module is used to train the second training model based on local data in the client.

[0127] Please see Figure 5 , Figure 5 This is a schematic diagram of a gradient quantization device based on federated learning provided in an embodiment of the present invention. In this embodiment, the terminal includes units used for execution... Figure 3 The steps in the corresponding embodiments. Please refer to the details. Figure 3 The relevant descriptions in the corresponding embodiments are shown below. For ease of explanation, only the parts relevant to this embodiment are shown. See also... Figure 3 The gradient quantization device 50 includes: a creation module 51, an aggregation module 52, an update module 53, and a detection module 54.

[0128] Module 51 is used to create training tasks through the task creator and send the training tasks to the client.

[0129] The aggregation module 52 is used to obtain the quantization value and quantization value change rate of gradient quantization sent by at least one client, and aggregate the quantization value according to the preset aggregation rules to obtain the aggregated quantization value.

[0130] The update module 53 is used to update the corresponding model parameters in the training task based on the aggregated quantization values, so as to obtain the updated training model.

[0131] The detection module 54 is used to detect whether the updated training model has converged. If the updated training model has converged, gradient quantization is stopped.

[0132] Optionally, the gradient quantization device 50 further includes:

[0133] The sending module is used to send the aggregated quantized values ​​to the client if the updated training model does not converge.

[0134] It should be noted that the information interaction and execution process between the above-mentioned units are based on the same concept as the method embodiments of the present invention. For details on their specific functions and technical effects, please refer to the method embodiments section, which will not be repeated here.

[0135] Figure 6 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Figure 6 As shown, the computer device of this embodiment includes: at least one processor ( Figure 6Only one is shown in the diagram), a memory, and a computer program stored in the memory and executable on at least one processor, which, when executed by the processor, implements the steps in any of the above embodiments of the federated learning-based gradient quantization method.

[0136] This computer device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that... Figure 6 The examples of computer devices are merely examples and do not constitute a limitation on computer devices. Computer devices may include more or fewer components than shown, or combinations of certain components, or different components, such as network interfaces, displays, and input devices.

[0137] The processor referred to can be a CPU, but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.

[0138] Memory includes readable storage media, internal memory, etc., wherein internal memory can be the RAM of a computer device, providing an environment for the operation of the operating system and computer-readable instructions stored in the readable storage media. The readable storage media can be the hard drive of a computer device, or in other embodiments, it can be an external storage device of the computer device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, memory can include both internal storage units and external storage devices of a computer device. Memory is used to store the operating system, applications, bootloader, data, and other programs, such as program code for computer programs. Memory can also be used to temporarily store data that has been output or will be output.

[0139] Those skilled in the art will understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the functions described above can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this invention. The specific working process of the units and modules in the above device can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here. If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention can implement all or part of the processes in the methods of the above embodiments by instructing related hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the above method embodiments. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. A computer-readable medium can include at least: any entity or device capable of carrying computer program code, a recording medium, a computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.

[0140] The present invention can implement all or part of the processes in the methods of the above embodiments, or it can be accomplished by a computer program product. When the computer program product is run on a computer device, the computer device executes the steps in the above method embodiments.

[0141] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0142] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0143] In the embodiments provided by this invention, it should be understood that the disclosed apparatus / computer devices and methods can be implemented in other ways. For example, the apparatus / computer device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0144] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0145] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A gradient quantization method based on federated learning, characterized in that, The gradient quantization method is applied to the client side, and the gradient quantization method includes: Obtain the training task sent by the server, and download the corresponding initial model to be trained according to the training task; Based on the local data in the client, the initial model is trained to obtain the first training model corresponding to the current training. The parameters of the first training model in the client are compressed according to the preset compression rules to obtain the compression parameters corresponding to the first training model. The step of compressing the parameters of the first training model in each client according to a preset compression rule to obtain the compressed parameters corresponding to the first training model includes: Obtain the loss function and learning rate of the client during the current training iteration; Based on the loss function and learning rate of the client during the current training iteration, the compression parameters of the first training model are calculated. The formula for calculating compression parameters is as follows: in, This represents the compression parameters of the m-th client after the k-th training iteration. Let be the loss function corresponding to the first model obtained by the m-th client after the K-th training iteration. For the first The central model learning rate for each training iteration. This represents the initial learning rate of the initial model. Initial compression parameters corresponding to the initial model in each client; Based on the compression parameters, the parameters of the first training model are compressed to obtain the compression result of the current training. The compression result includes the quantized value and the rate of change of the quantized value corresponding to the gradient quantization. If the compression result is detected to meet the upload conditions, the compression result is sent to the server. The upload conditions are: if the difference between the number of training sessions corresponding to the last compression result sent by the client to the server and the number of training sessions corresponding to the current training session is less than a first preset threshold, and the rate of change of the quantization value is greater than a second preset threshold.

2. The gradient quantization method as described in claim 1, characterized in that, The step of training the initial model based on local data in the client includes: Obtain the client's local data; The local data is preprocessed using a preprocessor to obtain the target local data; The initial model is trained based on the target local data.

3. The gradient quantization method as described in claim 1, characterized in that, After sending the compression result to the server, the process further includes: If the aggregated quantized value sent by the server is received, the parameters of the first training model are updated based on the aggregated quantized value to obtain the second training model; The second training model is trained based on local data in the client.

4. A gradient quantization method based on federated learning, characterized in that, The gradient quantization method is applied to the server side, and the gradient quantization method includes: The task creator creates a training task and sends the training task to the client. The method involves acquiring at least one quantized value and quantization rate of change of the gradient quantization sent by a client, and aggregating the quantized values ​​based on the quantization rate of change using a preset aggregation rule to obtain an aggregated quantized value. The calculation method for the quantized value and quantization rate of change of the gradient quantization sent by the client includes: Obtain the loss function and learning rate of the client during the current training iteration; Based on the loss function and learning rate of the client during the current training iteration, the compression parameters of the first training model are calculated. The formula for calculating compression parameters is as follows: in, This represents the compression parameters of the m-th client after the k-th training iteration. Let be the loss function corresponding to the first model obtained by the m-th client after the K-th training iteration. For the first The central model learning rate for each training iteration. This represents the initial learning rate of the initial model. Initial compression parameters corresponding to the initial model in each client; Based on the compression parameters, the parameters of the first training model are compressed to obtain the compression result of the current training. The compression result includes the quantized value and the rate of change of the quantized value corresponding to the gradient quantization. Based on the aggregated quantized values, the corresponding model parameters in the training task are updated to obtain the updated training model. Check whether the updated training model has converged. If the updated training model has converged, stop gradient quantization.

5. The gradient quantization method as described in claim 4, characterized in that, After detecting whether the updated training model has converged, the method further includes: If the updated training model does not converge, the aggregated quantized values ​​are sent to the client.

6. A gradient quantization device based on federated learning, characterized in that, The gradient quantization device is applied to the client side, and the gradient quantization includes: The download module is used to obtain the training task sent by the server and download the corresponding initial model to be trained according to the training task. A compression ratio determination module is used to train the initial model based on local data in the client to obtain a first training model, and to compress the parameters of the first training model in each client according to a preset compression rule to obtain compression parameters corresponding to the first training model; the step of compressing the parameters of the first training model in each client according to the preset compression rule to obtain compression parameters corresponding to the first training model includes: Obtain the loss function and learning rate of the client during the current training iteration; Based on the loss function and learning rate of the client during the current training iteration, the compression parameters of the first training model are calculated. The formula for calculating compression parameters is as follows: in, This represents the compression parameters of the m-th client after the k-th training iteration. Let be the loss function corresponding to the first model obtained by the m-th client after the K-th training iteration. For the first The central model learning rate for each training iteration. This represents the initial learning rate of the initial model. Initial compression parameters corresponding to the initial model in each client; A compression module is used to compress the parameters of the first training model based on the compression parameters to obtain the compression result of the current training, wherein the compression result includes the quantized value and the rate of change of the quantized value corresponding to the gradient quantization. An upload module is used to send the compressed result to the server if the compressed result is detected to meet the upload conditions. The upload conditions are that the difference between the number of training sessions corresponding to the last time the client sent the compressed result to the server and the number of training sessions corresponding to the current training session is less than a first preset threshold, and the rate of change of the quantization value is greater than a second preset threshold.

7. A gradient quantization device based on federated learning, characterized in that, The gradient quantization device is applied to the server side, and the gradient quantization includes: A creation module is used to create training tasks through a task creator and send the training tasks to the client; An aggregation module is used to acquire the quantized values ​​and quantized value change rates of the gradient quantization sent by at least one client, and aggregate the quantized values ​​according to a preset aggregation rule to obtain aggregated quantized values; wherein, the calculation method for the quantized values ​​and quantized value change rates of the gradient quantization sent by the client includes: Obtain the loss function and learning rate of the client during the current training iteration; Based on the loss function and learning rate of the client during the current training iteration, the compression parameters of the first training model are calculated. The formula for calculating compression parameters is as follows: in, This represents the compression parameters of the m-th client after the k-th training iteration. Let be the loss function corresponding to the first model obtained by the m-th client after the K-th training iteration. For the first The central model learning rate for each training iteration. This represents the initial learning rate of the initial model. Initial compression parameters corresponding to the initial model in each client; Based on the compression parameters, the parameters of the first training model are compressed to obtain the compression result of the current training. The compression result includes the quantized value and the rate of change of the quantized value corresponding to the gradient quantization. The update module is used to update the corresponding model parameters in the training task based on the aggregated quantized values, so as to obtain the updated training model. The detection module is used to detect whether the updated training model has converged. If the updated training model has converged, gradient quantization is stopped.

8. A computer device, characterized in that, The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the gradient quantization method as described in any one of claims 1 to 5.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the gradient quantization method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and device for generating neural network model, electronic equipment and storage medium

    CN111667054A

  • Federal learning global model training method based on differential privacy and quantification

    CN113591145A

  • Method, system and device for optimizing federated learning compression communication

    CN114861790A