A Federated Learning Method and Related Devices
By introducing the main chain and slave chain blockchain structure into the federated learning system, and using the training nodes and consensus nodes in the slave chain to work together, the problem of excessive dependence on the central server in the existing technology is solved, and higher reliability and stability are achieved.
Patent Information
- Application Number
- CN202111651216.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2041-12-30
AI Technical Summary
In the existing federated learning architecture, collaboration between decentralized clients relies too much on the central server, resulting in the system being unreliable when the central server fails or is maliciously attacked.
By building a federated learning system including the main chain and the slave chain, the information consistency characteristics of the blockchain structure are utilized to reduce dependence on the central server. Work together from the training nodes in the chain and the consensus nodes, perform model training and parameter verification, and upload target local parameters to the main chain node.
Improve the reliability and stability of federated learning, and realize the security and consistency of data and models through distributed ledger technology, avoiding the risk of single point of failure.
Smart Images

Figure CN114372589B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of federated learning, and in particular, to a federated learning method and related devices. Background Art
[0002] In order to achieve rapid learning to obtain a machine learning model, Google's Artificial Intelligence Laboratory proposed a federated learning architecture, specifically for enabling multiple decentralized clients and a central server to collaboratively learn a machine learning model to improve the efficiency of training to obtain a machine learning model. However, in the existing federated learning architecture, the collaboration between decentralized clients highly depends on the central server, that is, there is an excessive dependence on the central server. Once the central server fails or is maliciously attacked, it will directly lead to the inability to generate an accurate machine learning model, or even the inability to generate a machine learning model. Therefore, there is an urgent need for a technical solution to solve the above technical problems. Summary of the Invention
[0003] The main technical problem to be solved by this application is to provide a federated learning method and related devices, which reduce the dependence on a certain server or electronic device and can improve the reliability and stability of federated learning.
[0004] To solve the above technical problem, a technical solution adopted by this application is: providing a federated learning method, which is executed by training nodes in a sub-chain. The sub-chain includes several sub-chain nodes, and the sub-chain nodes can interact with main-chain nodes in the main chain. The sub-chain nodes include training nodes and consensus nodes. The method includes:
[0005] The training node obtains a first training algorithm;
[0006] Determine a first type of data and first initial parameters, and use the first training algorithm, the first type of data, and the first initial parameters for model training to obtain first local parameters;
[0007] Transmit the first local parameters to the consensus node to use the consensus nodes in the sub-chain to perform consensus verification on the first local parameters;
[0008] Determine the first local parameters that pass the consensus verification as target local parameters, and upload the target local parameters to the main-chain nodes.
[0009] To solve the above technical problem, another technical solution adopted by this application is: providing a federated learning method, which is executed by consensus nodes in a sub-chain. The sub-chain includes several sub-chain nodes, and the sub-chain nodes can interact with main-chain nodes in the main chain. The sub-chain nodes include training nodes and consensus nodes. The method includes:
[0010] The consensus node receives the first local parameter to be verified sent by the training node;
[0011] Perform consensus verification on the first local parameter;
[0012] Output the first local parameter that passes the consensus verification as the target local parameter, and upload the target local parameter to the side-chain distributed ledger.
[0013] To solve the above technical problems, another technical solution adopted by this application is: to provide a federated learning method, which is executed by the main-chain node in the main chain. The main-chain node can interact with the side-chain nodes in the side chain. The side chain includes several side-chain nodes. The side-chain nodes interact with the main-chain nodes in the main chain. The side-chain nodes include training nodes and consensus nodes. The method includes:
[0014] The main-chain node obtains the target local parameters uploaded by the first preset number of side-chain nodes;
[0015] Aggregate the first preset number of target local parameters to obtain the first global parameter;
[0016] Output the first global parameter.
[0017] To solve the above technical problems, another technical solution adopted by this application is: to provide an electronic device, which includes a processor and a memory coupled to the processor; wherein,
[0018] The memory is used to store a computer program;
[0019] The processor is used to run the computer program to execute the method described in any one of the above.
[0020] To solve the above technical problems, another technical solution adopted by this application is: to provide a computer-readable storage medium, which stores a computer program that can be run by a processor. The computer program is used to implement the method described in any one of the above.
[0021] The beneficial effects of the present application are as follows: Different from the prior art, the federated learning method provided by the present application is executed by the training nodes in the slave chain, and the slave chain includes several slave chain nodes. The slave chain nodes can interact with the master chain nodes in the master chain. The slave chain nodes include training nodes and consensus nodes. By setting the training nodes to obtain the first training algorithm, the slave chain nodes determine the first type of data and the first initial parameters, and use the first training algorithm, the first type of data and the first initial parameters to perform model training to obtain the first local parameters. The first local parameters are uploaded to the slave chain distributed ledger to use the consensus nodes in the slave chain to perform consensus verification on the first local parameters. Then, the first local parameters that pass the consensus verification are determined as the target local parameters, and the target local parameters are uploaded to the master chain nodes. By using several training nodes and consensus nodes in the slave chain to cooperate, the safe and reliable target local parameters can be obtained quickly, and it is set that each slave chain node in the slave chain interacts with the master chain nodes in the master chain, so as to upload the target local parameters to the master chain nodes. By setting that the slave chain nodes and the master chain nodes in the slave chain can interact, and using the information consistency characteristics of the slave chain and the master chain respectively, the dependence on a certain server or electronic device in the federated learning process is reduced, and the reliability and stability of the federated learning are further improved, achieving good technical effects. Description of the Drawings
[0022] Figure 1 It is a schematic structural diagram in an embodiment of a federated learning system of the present application;
[0023] Figure 2 It is a schematic flowchart in an embodiment of a federated learning method of the present application;
[0024] Figure 3 It is a schematic flowchart in another embodiment of a federated learning method of the present application;
[0025] Figure 4 It is a schematic flowchart in an embodiment of a federated learning method of the present application;
[0026] Figure 5 It is a schematic flowchart in another embodiment of a federated learning method of the present application;
[0027] Figure 6 It is a schematic flowchart in yet another embodiment of a federated learning method of the present application;
[0028] Figure 7 It is a schematic flowchart in an embodiment of a federated learning method of the present application;
[0029] Figure 8 It is a schematic flowchart in an embodiment of a federated learning of the present application;
[0030] Figure 9Schematic flowchart of another embodiment of a federated learning method of this application;
[0031] Figure 10 Schematic flowchart of yet another embodiment of a federated learning method of this application;
[0032] Figure 11 Schematic flowchart of an embodiment of a federated learning method of this application;
[0033] Figure 12 Schematic structural diagram of an embodiment of an electronic device of this application;
[0034] Figure 13 Schematic structural diagram of an embodiment of a computer-readable storage medium of this application. Detailed implementation manners
[0035] Next, the technical solutions in the embodiments of this application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of this application. It can be understood that the specific embodiments described herein are only used to explain this application, rather than limiting this application. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of this application.
[0036] In the description of this application, "a plurality of" means at least two, such as two, three, etc., unless otherwise specifically defined. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes unlisted steps or units, or optionally further includes other steps or units inherent to these processes, methods, products or devices.
[0037] Referring to "embodiments" herein means that specific features, structures, or characteristics described in connection with the embodiments can be included in at least one embodiment of this application. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0038] To facilitate the understanding of the technical solution provided in this application, the concept of federated learning involved in the solution of this application is first elaborated herein. Federated learning is a learning method in which multiple decentralized clients can collaborate to learn a machine learning model, while storing at least part of the training data of the clients and the parameters of the obtained machine learning model locally, uploading them to a central server, and then aggregating them by the central server to obtain overall parameters. The federated learning method provided in this application is to build a federated learning system including a main chain and a sub-chain, and utilize the feature of information consistency of the blockchain structure to reduce the dependence on a certain server or electronic device during the federated learning process, and further improve the reliability and stability of the federated learning.
[0039] First, to facilitate the understanding of the technical solution provided in this application, the federated learning system provided in this application is first elaborated. Please refer to Figure 1 , Figure 1 which is a schematic structural diagram of an embodiment of a federated learning system of this application.
[0040] In the current embodiment, the federated learning system 100 provided in this application includes a sub-chain A and a main chain B that can interact with each other. Among them, the sub-chain A is a blockchain structure for training to obtain target local parameters, and the sub-chain A includes several sub-chain nodes ( Figure 1 shown as A1 to Am). The sub-chain nodes include training nodes and consensus nodes, that is, it can be understood that according to the functions executed by each sub-chain node in the current round, each sub-chain node in the current sub-chain A is divided into a training node and a consensus node. The main chain B is a consortium chain structure for executing the aggregation of the target local parameters obtained by training the sub-chain A to obtain global parameters, and the main chain B includes several main chain nodes.
[0041] Furthermore, the sub-chain node can be any one of electronic devices such as terminal devices, sensors, wearable devices, etc. that can execute training functions, and the sub-chain nodes included in the same sub-chain A can be different types of devices, which are not limited herein. For example, the device types of several sub-chain nodes included in the same sub-chain A can include terminal devices, intercom devices, sensors, and wearable devices. Each sub-chain node and the user corresponding to the sub-chain node have their own private keys and public keys. Among them, the hash value of the public key of the sub-chain node can be used as the ID for identifying its identity and / or the wallet account address of the sub-chain node.
[0042] As described above, according to the functions performed by the slave chain nodes in each round, the slave chain nodes can be classified into training nodes and consensus nodes. Among them, the training nodes are the slave chain nodes used to perform training to obtain the target local parameters, and the consensus nodes are the slave chain nodes used to perform consensus verification on the local parameters obtained by the training nodes. It should be noted that in the process of federated learning in different rounds, both the training nodes and the consensus nodes are dynamically changing. For example, a certain slave chain node acts as a consensus node to perform the consensus verification function in the first round of training, and in the next round or other rounds, this slave chain node cannot act as a consensus node to perform the consensus verification function. As Figure 1 shown, A1 to An in the current round refer to the training nodes in the slave chain A, and An+1 to Am refer to the consensus nodes in the slave chain A in the current round. An+1 to Am constitute the consensus committee 101.
[0043] Furthermore, it should be noted that when each slave chain node in the slave chain A executes the federated learning in the current round, it is first necessary to clarify its own function in the current training round. Specifically, when executing the federated learning in the current round, the slave chain node can obtain the qualification to perform consensus verification through a competition.
[0044] Each main chain node can perform data interaction with at least some of the slave chain nodes in the slave chain A. The device types corresponding to the main chain nodes include server devices and computer devices. It can be understood that in other embodiments, the main chain node can also be other types of devices, which will not be listed one by one here. As Figure 1 , Figure 1 shown, B1 to Bk in refer to the main chain nodes in the main chain B.
[0045] Furthermore, the training nodes are used to train and obtain the first local parameters, and are also used to determine the first local parameters that pass the consensus verification as the target local parameters, and upload the target local parameters to the main chain nodes. The consensus nodes are used to perform consensus verification on the first local parameters obtained by the training nodes. In other embodiments, it can also be set that the target local parameters are uploaded to the main chain nodes by the consensus nodes, specifically based on the actual settings.
[0046] Please refer to Figure 2 , Figure 2 which is a schematic flowchart of an embodiment of a federated learning method of the present application. In the current embodiment, the method provided by the present application is executed by the training nodes in the slave chain. As described above, the slave chain includes several slave chain nodes. The slave chain nodes can interact with the main chain nodes in the main chain. The slave chain nodes include training nodes and consensus nodes. In the current embodiment, the method provided by the present application includes steps S210 to S240.
[0047] S210: The training node obtains the first training algorithm.
[0048] When performing federated learning, each training node in the sub-chain first needs to obtain the first training algorithm required for training the machine learning model. Among them, the first training algorithm can be pre-stored in each sub-chain node. Then, when the training node needs to perform federated learning for model training to obtain the target local parameters, the training node can directly obtain the first training algorithm from its own storage area. In another embodiment, the first training algorithm can also be sent by the main-chain node in the main chain to the sub-chain node before performing federated learning. In this embodiment, when the training node in the sub-chain performs federated learning, it first obtains the first training algorithm from the main-chain node in the main chain.
[0049] Furthermore, when the machine learning models to be trained in the current round of the main chain and the sub-chain are the same as those trained in the previous round, and the first training algorithm is sent by the main-chain node to the sub-chain node, then it can be set that each sub-chain node in the current round does not need to obtain the first training algorithm from each main-chain node. Correspondingly, the main-chain node also does not need to send the first training algorithm to the sub-chain node, so as to save the time cost required for performing federated learning.
[0050] Among them, the first training algorithm includes the gradient descent algorithm. It can be understood that in other embodiments, the first training algorithm can also be adjusted according to the type and function of the machine learning model to be trained in federated learning. In other embodiments, the first training algorithm can also include other types of algorithms, which are specifically based on actual settings and will not be listed one by one here.
[0051] Furthermore, in one embodiment, before each round of performing federated learning for model training by the training node, that is, before the training node executes step S210, it will further determine that the function it needs to execute in the current round is to train to obtain the target local parameters. Specifically, each sub-chain node needs to determine whether it is selected as a consensus node based on the consensus node selection result broadcast in the sub-chain. If it is judged that the current consensus node selection result does not include itself, then this sub-chain node will automatically be determined as a training node for performing the function of training to obtain the target local parameters, and then execute steps S210 to S240 described in the current embodiment. Among them, the consensus node selection result can include the identity information of all selected consensus nodes in the current round.
[0052] In another embodiment, the consensus node selection result can also be only the consensus selection result corresponding to a certain slave chain node. In this embodiment, it can be set to generate a consensus node selection result for each participating slave chain node respectively, and then broadcast the generated consensus node selection result in the slave chain, so that each slave chain node in the slave chain can know whether the slave chain node is successfully selected as a consensus node, and further determine the functions executed by each slave chain node in the current round of federated learning.
[0053] S220: Determine the first type of data and the first initial parameters, and use the first training algorithm, the first type of data, and the first initial parameters to perform model training to obtain the first local parameters.
[0054] After obtaining the first training algorithm, the training node further determines the first type of data and the first initial parameters. Among them, the first type of data is the data used by the training node for model training in the current round of federated learning. The first type of data can be at least part of the data stored by the training node itself. Specifically, it can be set to allow the user to select the first type of data by themselves, that is, open a port for the user to select the first type of data. The user can choose to use all the data stored in the training node for model training, or the user can select part of the data stored by themselves for model training according to their own needs. The user is the owner of each slave chain node, and correspondingly, an operation key will be issued to the user for user identity verification. The slave chain node can judge whether the current user has the permission to change the setting parameters of the slave chain node based on the operation key input by the user, and judge whether the user has the permission to select the first type of data. The first initial parameter is the initial value required for model training. The first initial parameter can be sent to the slave chain node by the master chain node when sending the first training algorithm, or can be a preset initial default value stored in the slave chain node. Correspondingly, when the types of machine learning models to be trained are different, different first initial parameters can be set for different machine learning models.
[0055] In the technical solution provided by this application, a local machine learning model is obtained by performing model training using the first training algorithm, the first type of data, and the first initial parameters, and then it is judged whether the current obtained local machine learning model can make the loss function of the target reach the minimum value. If the current obtained local machine learning model can make the loss function of the target be the minimum value, then determine the current local machine learning model as the first local machine learning model and output the first local machine learning model; otherwise, continue to loop train until a local machine learning model with the minimum loss function is obtained.
[0056] Further, the first type of data includes labeled data and / or unlabeled data. Among them, labeled data is data that indicates the target information included. For example, labeled data includes: images indicating the included people and buildings, bill screenshots, shopping list screenshots, etc. Unlabeled data is data without any annotation information. It should be noted that the specific types of labeled data and unlabeled data are not limited here and may include image data, sound data, video data, etc.
[0057] Furthermore, in one embodiment, when the determined first type of data includes both labeled data and unlabeled data, then when the slave node executes the above step S220, the slave node is based on the first initial parameter and uses the first training algorithm to separately perform model training on the labeled data and the unlabeled data, so as to obtain the first local parameter. When using the first training algorithm to perform model training on the labeled data and performing multiple loop iterations until the second local machine learning model with the minimum loss function is obtained and output, and then the parameters of the second local machine learning model are output as the second local parameter. Similarly, when using the first training algorithm to perform model training on the unlabeled data and performing multiple loop iterations until the third local machine learning model with the minimum loss function is obtained and output, and then the parameters of the third local machine learning model are output as the third local parameter. After obtaining the second local parameter and the third local parameter, further output the mean value of the second local parameter and the third local parameter as the first local parameter.
[0058] In another embodiment, when the determined first type of data includes both labeled data and unlabeled data, then when the slave node executes the above step S220, the slave node is based on the first initial parameter and uses the first training algorithm to separately perform model training on the labeled data and the unlabeled data, and performs loop iterations synchronously. After each loop ends, the sum of the loss functions of the two local machine learning models obtained by separately performing model training on the labeled data and the unlabeled data will be further calculated, and the two local machine learning models with the minimum sum of the loss functions will be aggregated to obtain the first local machine learning model, and the parameters of the first local machine learning model will be output as the first local parameter.
[0059] After determining the first type of data and the first initial parameter, further use the first training algorithm, the first type of data and the first initial parameter to perform model training to obtain the first local parameter. Among them, the first local parameter is the model parameter of the first local machine learning model obtained by the training node performing model training.
[0060] In the technical solution provided by this application, the local machine learning model refers to the machine learning model obtained by training from the slave chain nodes. The first local machine learning model is used to refer to the machine learning model with the smallest loss function value obtained by training from the slave chain nodes. Each first local machine learning model obtained by training from the slave chain nodes is applicable to perform the machine learning process with the smallest loss function on the data stored in the corresponding slave chain node. The initial global machine learning model is used to refer to the machine learning model aggregated by the master chain node based on each target local parameter. The first global machine learning model is used to refer to the global machine learning model with the smallest loss function obtained by training from a certain master chain node. The first global machine learning model is applicable to perform machine learning on the data stored in the corresponding master chain node, and is also applicable to perform the machine learning process with the smallest loss function on the data stored in each slave chain node. After the slave chain node obtains the first local machine learning model through training, it will upload the first local parameters of the first local machine learning model to the consensus node for consensus verification. Therefore, after obtaining the first local machine learning model through training, the first local parameters corresponding to the first local machine learning model are further extracted, and then the following step S230 is executed. Among them, the first local parameters are the constant parameters in the first local machine learning model. For example, if a certain first local machine learning model obtained through training is f(x) = ax3 + bx 2 + cx + d, the corresponding first local parameters include a, b, c, and d.
[0061] Further, in an embodiment, the model training using the first training algorithm, the first type of data, and the first initial parameters in the above step S220 to obtain the first local parameters further includes: using the first training algorithm, the first type of data, and the first initial parameters to perform model training on the cloud simulator to obtain the first local parameters. Among them, the cloud simulator is a system simulated by software and having all hardware functions, which can be understood as a virtual system in the system. In the current embodiment, by setting the slave chain node to perform model training on the cloud simulator, the operation and calculation pressure of the slave chain node can be better reduced, and the consumption of resources for the slave chain node can be reduced.
[0062] S230: Transmit the first local parameters to the consensus node to use the consensus node in the slave chain to perform consensus verification on the first local parameters.
[0063] After the training node obtains the first local parameters, the first local parameters corresponding to the obtained first local machine learning model are further transmitted to the consensus node. Among them, the consensus node is the slave chain node that has won the consensus verification qualification in the current round of federated learning. Here, there is no limit on the number of consensus nodes selected in the slave chain, and the number of consensus nodes can be specifically adjusted and set according to actual needs.
[0064] Specifically, the training node can broadcast within the slave chain to transmit the first local parameter to each consensus node, and then use each consensus node in the slave chain to perform consensus verification on the first local parameter. In another embodiment, the training node can also upload the obtained first local parameter to the distributed ledger corresponding to the slave chain, so that each consensus node can obtain the first local parameter by accessing the distributed ledger corresponding to the slave chain. In yet another embodiment, the training node can also directly send the obtained first local parameter to each consensus node to use each consensus node in the slave chain to perform consensus verification on the first local parameter.
[0065] It should be noted that since the data volumes included in each training node in the slave chain are different, and the performance and computing capabilities of each training node may vary, the time required for each training node to train the first local model is different. Therefore, after each training node obtains the first local parameter through training, it will immediately transmit the obtained first local parameter to the consensus node respectively to minimize the time for itself to perform federated learning.
[0066] S240: Determine the first local parameter that passes the consensus verification as the target local parameter, and upload the target local parameter to the main chain node.
[0067] After the training node uploads the obtained first local parameter to the consensus node and the first local parameter passes the consensus verification of each consensus node in the slave chain, the consensus node will output the verified first local parameter to each slave chain node. In the current embodiment, when the training node obtains the first local parameter corresponding to itself and passing the consensus verification, it further determines the first local parameter passing the consensus verification as the target local parameter, and then the training node will further upload the target local parameter to the main chain node.
[0068] Furthermore, the training node can directly upload the target local parameter to the main chain node with which it can interact by itself, so as to make each main chain node in the main chain obtain the target local adoption number due to the information consistency of each main chain node in the main chain.
[0069] In another embodiment, it is also possible to set the training node to upload the target local parameter to the main chain node through an upload node. The upload node is a slave chain node dedicated to performing interaction with the main chain node in the slave chain, and the upload node can be any slave chain node in the slave chain. It should be noted that the upload node can also be a training node performing training functions or a consensus node performing consensus verification functions at the same time.
[0070] Further, to better achieve fairness and impartiality, it can be set that the training nodes do not upload their own target local parameters to the main chain node, and it can be set that the consensus nodes upload the target local parameters corresponding to each training node to the main chain node. In another embodiment, the uploading nodes can also be dynamically set for each training node based on each round of federated learning. Please combine the above Figure 1 , for example, the slave chain nodes can be cycled forward and backward, and the next training node can be set as the uploading node of the previous training node in the order of ID numbers, and the last training node can be set as the uploading node of the first training node. It can also be cycled corresponding to the head and tail, and the last slave chain node can be set as the uploading node of the first slave chain node, and the penultimate slave chain node can be set as the uploading node of the second training node. For example, in the previous round, it is set that the slave chain node Am is the uploading node of the training node A1, the slave chain node Am-1 is the uploading node of the training node A2, the slave chain node Am-2 is the uploading node of the training node A3, and so on; in the current round, Am can be dynamically cycled and set as the uploading node of the training node A2, and in the next round, Am can be dynamically set as the uploading node of the training node A3, and so on. If the number of slave chain nodes is odd, the corresponding uploading node can be randomly set for the remaining last slave chain node.
[0071] Further, uploading the target local parameter to the main chain node includes: digitally signing the target local parameter with the public key of the main chain node, and uploading the signed target local parameter to the main chain node through itself or the uploading node in the slave chain. Wherein, the uploading node is the node in the slave chain used to interact with the main chain node. In the current embodiment, when uploading the target local parameter to the main chain node, by digitally signing the target local parameter with the public key of the main chain node, and setting that the main chain node needs to use the private key for verification when receiving the target local parameter, and only after the verification is successful can the main chain node actually read the target local parameter sent by the slave chain node, realizing the method of signing with the public key of the main chain node during the transmission of the target local parameter. Even if there are unauthorized nodes or devices obtaining the target local parameter signed by the main chain node during the transmission of the target local parameter, since the unauthorized nodes or devices do not have the private key of the main chain node, the unauthorized nodes or devices are still unable to parse and obtain the target local parameter, protecting the security of the target local parameter, and thus better realizing the protection of the security of the data of the slave chain node used for training to obtain the target local parameter.
[0072] This application Figure 1The federated learning method provided in the corresponding embodiment is executed by the training nodes in the slave chain, and the slave chain includes several slave chain nodes. The slave chain nodes can interact with the master chain nodes in the master chain. The slave chain nodes include training nodes and consensus nodes; by setting the training nodes to obtain the first training algorithm, the slave chain nodes determine the first type of data and the first initial parameters, and use the first training algorithm, the first type of data and the first initial parameters to perform model training to obtain the first local parameters; upload the first local parameters to the slave chain distributed ledger to use the consensus nodes in the slave chain to perform consensus verification on the first local parameters; then determine the first local parameters that pass the consensus verification as the target local parameters, and upload the target local parameters to the master chain nodes. By using several training nodes and consensus nodes in the slave chain to cooperate, the safe and reliable target local parameters can be obtained quickly, and the slave chain nodes in the slave chain are set to interact with the master chain nodes in the master chain, so as to upload the target local parameters to the master chain nodes. By setting that the slave chain nodes and the master chain nodes in the slave chain can interact, and using the information consistency characteristics of the slave chain and the master chain respectively, the dependence on a certain server or electronic device in the federated learning process is reduced, and the reliability and stability of the federated learning are further improved.
[0073] Please refer to Figure 3 , Figure 3 which is a schematic flowchart of another embodiment of a federated learning method of the present application. In the current embodiment, the method provided by the present application includes steps S301 to S307.
[0074] S301: The training node obtains the first training algorithm.
[0075] Step S301 is the same as the above step S210. For specific details, please refer to the corresponding part above and will not be repeated here.
[0076] Further, in the current embodiment, before step S301, the method provided by the present application further includes: sending a slave chain joining request to the master chain node in the current area to obtain the slave chain ID and the CA certificate issued by the master chain node.
[0077] In the technical solution provided by this application, a slave chain access mechanism is set up so that an electronic device can join the current slave chain according to the set access mechanism, and thus can perform federated learning. In the technical solution provided by this application, several geographical regions are pre-divided according to geographical locations, and a plurality of master chain nodes that can interact are set in each geographical region. The master chain nodes between different geographical regions can perform data interaction, and the slave chain nodes in each geographical region can at least interact with the master chain nodes in the current geographical region. For example, a third preset number of master chain nodes can be set in each geographical region. An electronic device belonging to this region can send a slave chain joining request to any one of the master chain nodes in this geographical region to obtain the slave chain ID and CA (Certificate Authority) certificate issued by the master chain node. It should be noted that, in the current embodiment, the CA certificate can be issued by the CA center to the slave chain node through the master chain node, and the CA certificate is a certificate used to complete secure communication.
[0078] Further, before each slave chain node joins the slave chain, by sending a slave chain joining request to the master chain node in the current region, it is required that more than the first preset ratio of the master chain nodes in the master chain review and determine that the slave chain node meets the set access mechanism of the slave chain node. Then, the master chain node will issue the corresponding slave chain ID and CA certificate to the slave chain node. The first preset ratio can be set and adjusted according to actual needs, and will not be listed one by one here.
[0079] Further, in another embodiment, each slave chain node needs to obtain the approval of all the master chain nodes in the master chain before it can obtain the slave chain ID and CA certificate issued by the master chain node.
[0080] S302: Determine the first type of data and the first initial parameters, and use the first training algorithm, the first type of data and the first initial parameters to perform model training to obtain the first local parameters.
[0081] In the current embodiment, step S302 is the same as step S220 above. For details, reference can be made to the description in the corresponding embodiment above. At the same time, in the current embodiment, after the slave chain node obtains the first local parameters and before transmitting the first local parameters to the consensus node, the method provided by this application further includes the following step S303.
[0082] S303: Calculate the first hash value of the first local parameters and store the first hash value.
[0083] After the slave chain node obtains the first local parameter through training, the slave chain node will further perform a hash operation on the obtained first local parameter to obtain a first hash value, and store the first hash value corresponding to the first local parameter. The first hash value is the basis for determining whether the target local parameter passed the consensus verification has been tampered with. Specifically, the SHA-256 algorithm is used to perform a hash operation on the first local parameter to obtain the first hash value.
[0084] Further, the slave chain node may store the first hash value in its own storage area. The first hash value is used for subsequent verification of the target local parameter uploaded to the master chain node to determine whether there is a risk of the target local parameter being tampered with. Furthermore, when a digital wallet is set up in the slave chain node, the slave chain node may also store the first hash value in the digital wallet. Still further, the slave chain node may also store the first hash value in its own blockchain distributed ledger.
[0085] In another embodiment, the slave chain node may also store the first hash value on-chain within the slave chain. After the first local parameter passes the consensus verification of the consensus node and becomes the target parameter, the uploading node further verifies whether there is a risk of the target local parameter being tampered with based on the first hash value. Specifically, the uploading node can obtain the first hash value of the first local parameter corresponding to the target local parameter by accessing the distributed ledger of the slave chain, and then determine whether the target local parameter has been tampered with based on the obtained first hash value.
[0086] S304: Transmit the first local parameter to the consensus node to utilize the consensus node in the slave chain to perform consensus verification on the first local parameter.
[0087] In the current embodiment, step S304 is the same as step S230 above. For specific details, reference can be made to the corresponding description above. And to prevent the first local parameter generated by the slave chain node from being tampered with during the process of uploading it to the consensus node for verification, in the current embodiment, after determining the target local parameter and before uploading the target local parameter to the master chain node, the method provided in this application further includes steps S305 to S307 to prevent the first local parameter that has passed the consensus verification and has been tampered with from being uploaded to the master chain node.
[0088] S305: Calculate the second hash value of the target local parameter.
[0089] In the current embodiment, after the slave chain node obtains the target local parameter that has passed the consensus verification, it further performs a hash operation on the obtained target local parameter to calculate and obtain the second hash value of the target local parameter.
[0090] S306: Determine whether the second hash value is equal to the first hash value.
[0091] After obtaining the second hash value of the target local parameter, further obtain the first hash value of the first local parameter corresponding to the target local parameter. Then determine whether the second hash value is equal to the first hash value. If it is determined that the second hash value is equal to the first hash value, perform the following step S307.
[0092] S307: If so, perform the step of uploading the target local parameter to the main chain node.
[0093] When it is determined that the second hash value is equal to the first hash value, the slave chain node will further perform the step of uploading the target local parameter to the main chain node.
[0094] Furthermore, if it is determined that the second hash value is not equal to the first hash value, do not perform the step of uploading the target local parameter to the main chain node, and re - execute the step of training the model using the first training algorithm, the first type of data, and the first initial parameter to obtain the first local parameter. Specifically, when it is determined that the second hash value is not equal to the first hash value, the first local parameter obtained from the latest training can be output as the first initial parameter, and using the first training algorithm and the first type of data, further perform loop training to obtain a new first local parameter.
[0095] It should be noted that in other embodiments, it can also be set that the upload node in the slave chain executes the step of uploading the target local parameter to the main chain node. Correspondingly, it can be set that the upload node executes the steps of calculating the second hash value of the target local parameter and determining whether the second hash value is equal to the first hash value. And when it is determined that the second hash value is equal to the first hash value, continue to perform the step of uploading the target local parameter to the main chain node. On the contrary, if the upload node determines that the second hash value is not equal to the first hash value, it will further broadcast the judgment result within the slave chain so that the corresponding training node can learn that the target local parameter has been tampered with, and then the corresponding training node will re - use the latest first local parameter obtained by itself as the first initial parameter, and use the first training algorithm and the first type of data to perform model training to obtain the first local parameter.
[0096] In Figure 3 In the corresponding embodiment, by determining whether the second hash value is equal to the first hash value and based on the judgment result to determine whether to perform the step of uploading the target local parameter to the main chain node, it can be ensured that the target local parameter uploaded by the slave chain node each time is always transparent, tamper - proof, reliable, and not maliciously changed to poison the global parameter training.
[0097] Further, the federated learning method provided by the present application further includes: after receiving the global parameters sent by the main chain node, updating the target local machine learning model using the global parameters.
[0098] Please refer to Figure 4 , Figure 4 which is a schematic flowchart of an embodiment of a federated learning method of the present application. In the current embodiment, the method provided by the present application is executed by the consensus nodes in the sub-chain. As described above, the sub-chain includes several sub-chain nodes, and the sub-chain nodes can interact with the main chain nodes in the main chain. According to the functions performed by each sub-chain node in the current round of federated learning process, the sub-chain nodes include training nodes and consensus nodes. Among them, the method includes steps S410 to S430.
[0099] S410: The consensus node receives the first local parameter to be verified sent by the training node.
[0100] After the training node in the sub-chain obtains the first local parameter through training, the training node will transmit the obtained first local parameter to the consensus node. After the consensus node receives the first local parameter to be verified sent by the training node, it performs consensus verification on the first local parameter to be verified.
[0101] As described above, the training node transmits the first local parameter to each consensus node by broadcasting. After each consensus node in the sub-chain receives the first local parameter to be verified broadcast by the training node, it will respectively execute the following step S420.
[0102] Further, it should be noted that in the technical solution provided by the present application, before the consensus node executes step S410, it also needs to obtain the qualification for consensus verification by competing within the sub-chain, so as to become the consensus node in the current round. Among them, the process of the sub-chain node competing to become the consensus node in the current round of federated learning process can be specifically referred to Figure 5 and the method described in the corresponding embodiment thereof.
[0103] Further, it should be noted that in the technical solution provided by the present application, since there are multiple consensus nodes set in the sub-chain, and there is no limit to the number of consensus nodes, and it is not limited that the number of consensus nodes in each round of federated learning is equal, the number of consensus nodes in the sub-chain can be set and adjusted when selecting consensus nodes in a round of federated learning.
[0104] Further, in another embodiment, due to the feature of information consistency among the slave chain nodes in the chain, it is not limited herein that the consensus node must obtain the first local parameter to be verified from the self-training node. In the current embodiment, the consensus node may obtain the first local parameter to be verified from other consensus nodes based on the feature of information consistency among nodes.
[0105] For example, when a leader node is set among multiple consensus nodes of the present application, it may be set that the leader node among the consensus nodes obtains the first local parameters transmitted by each training node, and then the leader node transmits the received first local parameters to each consensus node. Specifically, the leader node packs the first local parameter (w) transmitted by the training node and the proof and random number generated during the process of the training node competing for the consensus node (proof: π, random number: seed e ) into a candidate block. Then, it broadcasts the candidate block to the consensus nodes in the slave chain so that the consensus nodes can obtain the candidate block and perform consensus verification on the first local parameter (w) included in the candidate block.
[0106] S420: Perform consensus verification on the first local parameter.
[0107] The consensus node performs consensus verification on the received first local parameter to determine whether the first local parameter is obtained by the training node through training based on the legal data stored by itself.
[0108] Further, since the times when the first local parameters are obtained by each training node in the slave chain through training are not consistent, the consensus node may receive multiple first local parameters simultaneously. When the consensus node receives multiple first local parameters corresponding to different training nodes simultaneously, the consensus node may perform the consensus verification process on the multiple received first local parameters respectively to determine whether each first local parameter is obtained by the corresponding training node through training based on the legal data stored by itself.
[0109] Further, step S420 performing consensus verification on the first local parameter includes: calling the Verify function in the random function to verify the first local parameter to determine whether the first local parameter is obtained by the training node through training based on the legal data stored by itself.
[0110] In the technical solution provided by the present application, after obtaining multiple consensus nodes, a leader node will be further determined in the consensus committee. After receiving the candidate block, the consensus node calls the verification (verify) function of the VRF to check whether the selection proof of the block is correct.
[0111] Specifically, after the consensus node receives the first local parameter to be verified, the consensus node will, based on the hash value of the selection proof transmitted following the first local parameter, use the public key of the leader node to verify whether the selection proof is generated based on the original first local parameter. If so, it is determined that the current first local parameter is obtained by the training node through training based on legal data.
[0112] As in the above example, the leader node packs the first local parameter (w) transmitted by the training node, as well as the selection proof and random number generated during the process of the training node competing for the consensus node (selection proof: π, random number: seed e ) into a candidate block, and then broadcasts the candidate block to the consensus nodes in the sub-chain. After receiving the candidate block, the consensus node will convert the selection proof (π) in the candidate block into a hash value, that is, perform a hash operation on the selection proof in the candidate block to obtain VRF_proof_to_hash(π). Verify VRF_verify(PK, w, π, seed e ) = True / False, and use the public key of the leader node to check whether the selection proof π is a proof generated based on the original parameter w, that is, check whether VRF_hash(SK, w) is equal to VRF_proof_to_hash(π), and output whether it is legal. If it is legal, the candidate block passes the consensus verification and becomes a valid block, that is, it is determined that the first local parameter is obtained by training based on the legal data stored by itself. Among them, SK is the verification private key generated by the sub-chain node during the process of competing for the consensus node, and PK is the public key of the leader node.
[0113] S430: Output the first local parameter that has passed the consensus verification as the target local parameter, and transmit the target local parameter to the upload node.
[0114] After the consensus node completes the consensus verification of the first local parameter uploaded by the sub-chain node and determines that the first local parameter is obtained by the training node through training based on the legal data stored by itself, the consensus node will output the first local parameter that has passed the consensus verification as the target local parameter, and then transmit the target local parameter to the upload node. Among them, the upload node is the sub-chain node that uploads the target local parameter to the main-chain node. Further, the upload node can be the training node corresponding to the target local parameter, or any other sub-chain node, which is not specifically limited here and is subject to the actual setting. Further, the consensus node can transmit the target local parameter to the upload node in the form of broadcasting.
[0115] In another embodiment, the consensus node is also used to upload the target local parameter to the sub-chain distributed ledger, so that the upload node in the sub-chain can obtain the target local parameter.
[0116] In yet another embodiment, when a leader node is set among multiple consensus nodes, after the consensus nodes complete the consensus verification of the target local parameters, the consensus nodes are further configured to transmit the target local parameters to the leader node, and then transmit the target local parameters to the uploading node through the leader node.
[0117] Furthermore, transmitting the target local parameters to the uploading node further includes: signing the target local parameters by using the leader node, and transmitting the target local parameters signed by the leader node to the uploading node. The leader node is selected by voting among all the consensus nodes in the sub-chain. Specifically, the public key of the leader node is used to sign the target local parameters to obtain the signed target local parameters. In the current embodiment, by signing the target local parameters by using the leader node, the security of the target local parameters is better protected.
[0118] Further, the federated learning method provided by the present application further includes: based on the result of the consensus verification, scoring the current round of training of each training node corresponding to each received first local parameter, and associating and storing the scoring result with the training node in the sub-chain distributed ledger. In the current embodiment, in order to better evaluate the training work of each training node, each consensus node also scores each training node according to the result of the consensus verification.
[0119] Furthermore, the accuracy of verifying the effectiveness of the target local parameters is used as the scoring criterion. The total score obtained by each training node is the median or average value of the scores given by all consensus nodes. When a new round of training starts, the scores of each training node in the previous round of training will be considered to select new consensus nodes and form a consensus committee for the new round of federated learning to perform the consensus verification of the new round of training. More precisely, this is a dynamically changing consensus committee. Note that in each round of training, the (client) consensus nodes participating in the consensus verification process will not participate in the model training of the current round. Further, in another embodiment, as the consensus nodes in the current round of training, they will not be selected as consensus nodes again in the next round to ensure fairness and impartiality.
[0120] In the technical solution provided by this application, considering that the consensus nodes determined in this case are applied to the consortium chain, and in the scenarios where the slave chains in the technical solution provided by this application are used, there are factors such as a large number of edge clients, unstable networks, lightweight storage, and computing capabilities. The algorithms for selecting consensus nodes commonly used in PoW, DPoS, and PoS in the prior art usually have a long consensus duration and high costs. To solve the above technical problems, this application improves the distributed Raft algorithm to make the selection of consensus nodes applied in the federated learning process more effective and low-cost, and has a certain degree of fault tolerance. The method for selecting consensus nodes is briefly described as: randomly select a certain number of slave chain nodes from the slave chain as consensus nodes to form a consensus committee for a certain round of training.
[0121] Further, to ensure fairness for all participants, in the technical solution provided by this application, a verifiable random function is also used to generate a leader in each round, which becomes the leading node of the selected consensus nodes, ensuring fairness for all participants and without consuming a large amount of computing resources during this process.
[0122] The specific process is briefly described as: when electing consensus nodes, the binomial distribution is used to calculate the probability of each candidate node according to the weight of each consensus candidate node (which can also be understood as each slave chain node in the slave chain). The consensus nodes in the new round of federated learning process are elected according to the probability of each consensus candidate node. To increase randomness and ensure fairness for each participant as much as possible, the probability calculation here uses a random number generated by a verifiable random function (VRF). Among them, the weight of the consensus candidate node can be understood as: the accuracy score of the local first local machine learning model obtained by the slave chain node in the previous round of federated learning process.
[0123] Further, please refer to Figure 5 , Figure 5 which is a schematic flowchart of another embodiment of a federated learning method of this application. In the current embodiment, the process of slave chain nodes being selected as consensus nodes is emphasized. It should be noted that Figure 5 each method step described in the corresponding embodiment is executed by each slave chain node that hopes to run for a consensus node. In the current embodiment, the federated learning method provided by this application includes steps S501 to S505.
[0124] S501: Generate auxiliary global parameters based on preset security parameters.
[0125] When a slave chain node runs for becoming a consensus node, it will first generate auxiliary global parameters based on preset security parameters by using a probability algorithm. Among them, the security parameters are parameters that are common to each slave chain node in the chain and are preset for generating auxiliary global parameters. In another embodiment, the security parameters can also be uniformly distributed to each slave chain node by a user or a main chain node before each round of federated learning is executed.
[0126] For example, in one embodiment, the preset security parameter of the slave chain node is 1 λ , then the slave chain node can generate some common auxiliary global parameters by calling the probability algorithm based on the preset security parameter. The formula is as follows: ParamGen(1 λ ) → pp. Where pp is the auxiliary global parameter and ParamGen is the called probability algorithm.
[0127] S502: Generate a verification public key and a verification private key based on the auxiliary global parameters.
[0128] The slave chain node intending to participate in the election to become a consensus node further generates a verification key and a verification private key by using a key generation algorithm based on the auxiliary global parameters generated by each of them. Among them, the verification key and the verification private key are used in the process of performing consensus verification on the first local parameters uploaded by the training nodes after the election is successful.
[0129] For example, in one embodiment, the formula for generating a verification key and a verification private key based on the auxiliary global parameters is as follows: KeyGen(pp) → (PK i , SK i ). Where KeyGen refers to the key generation algorithm, the input is the auxiliary global parameter pp, and PK and SK are used to represent the generated verification public key and verification private key respectively, and the subscript i refers to the identification number of the slave chain node.
[0130] S503: Calculate the signature of the current training round information, the random number in the previous round of federated learning, the first global parameter obtained in the previous round of federated learning, and the number of consensus nodes required for this round of training to obtain a random number.
[0131] After obtaining the auxiliary global parameters, verification public key, and verification key, the sub-chain node further calculates a random number. Here, the current training round information refers to the round of federated learning currently being executed. For example, for the same machine learning model, if the federated learning process is currently being executed for the third time, the corresponding current round information is 3. The random number in the previous round of federated learning refers to the random number generated by the training node when competing for the consensus node in the previous round of federated learning. The first global parameter obtained in the previous round of federated learning is the first global parameter finally aggregated by each main-chain node in the main chain and sent to each sub-chain node in the sub-chain during the previous round of federated learning. The number of consensus nodes required for this round of training refers to the number of consensus nodes required in the currently set round of federated learning process.
[0132] Furthermore, it should be noted that before executing step S503, the method provided by this application further includes: generating an initial random number using the random generator algorithm. Correspondingly, if the current is the first round of federated learning process for a certain machine learning model, the initial random number can be directly output as the random number. If the current is the first round of federated learning process for a certain machine learning model, the obtained initial random number will be directly output as the random number of the sub-chain node in the current round.
[0133] Specifically, the calculation formula for the random number is as follows:
[0134]
[0135] Among them, seed0 represents the initial random number, which can also be understood as the initialization random seed, that is, the random number of the first round of training, and seede represents the random number of the current round. epoch refers to the round information, epoch = 1 indicates the first round, and epoch ≥ 1 indicates the second round and above.
[0136] Represents the private key signature of the leader node (Leader) selected by the consensus node in the previous round of federated learning process.
[0137] e represents the current training round information, which is used to refer to the round of federated learning for the same machine learning model currently.
[0138] seed e-1 Represents the random number calculated when selecting the consensus node in the previous round of training.
[0139] Represents the first global parameter obtained in the previous round of federated learning.
[0140] Let τ denote the number of consensus nodes to be selected in the current round of federated learning process, and it can be set such that the number of consensus nodes to be selected in different rounds of federated learning for the same machine learning model can be different, that is, the number of consensus nodes required in each round of federated learning process can be adjusted according to requirements.
[0141] Furthermore, in another embodiment, since all the information for calculating the random number comes from the chain, all the slave chain nodes will calculate the same random number. This random number will be continuously updated in each round of iterative training, and it cannot be predicted or controlled by the attacker, making the consensus verification of federated learning more secure and reliable.
[0142] Furthermore, in each round of consensus process, a verifiable random function VRF can be announced according to the random seed. That is, in the current embodiment, according to the preset, the system announces a random function according to the random number generated in the previous round. In the technical solution provided in this application, an interface will be reserved among the slave chain nodes in the slave chain for calling the random function VRF. The random function VRF can be stored in the storage area accessible by the slave chain nodes, so that the training nodes can call it when calculating the random number.
[0143] S504: Calculate the hash result based on the verification private key and the random number.
[0144] Furthermore, specifically, each (intending to participate in consensus) slave chain node calls the hash function to calculate the hash result based on the verification private key and the random number.
[0145] For example, the slave chain nodes in the slave chain can call the VRF_Hash(.) function, and use the verification private key obtained by itself in the above step S502 and the random number determined in step S503 as inputs, and output a hash value, denoted as hash = VRF_val(SK,S e )
[0146] Furthermore, in another embodiment, while generating the hash result using the random verifiable function based on the random number and the verification private key, the method provided in this application further includes: calculating and selecting a proof based on the verification private key and the random number. Specifically, it is to call the Prove function of VRF (i.e., VRF_proof(·)), and use the verification private key and the random number obtained by itself in the above steps as inputs, and output a selected proof π, denoted as π = VRF_proof(SK,Se).
[0147] S505: Normalize the hash result and determine the selection result based on the normalization result.
[0148] The slave chain nodes normalize the respective calculated hash results, compare the obtained normalization results with the comparison threshold, and determine their own selection results based on the comparison results. If the normalization result is less than or equal to the comparison threshold, the slave chain node can privately know that it is selected as a consensus node; otherwise, it knows that it is not selected as a consensus node.
[0149] Further, the comparison threshold can be preset in each round.
[0150] Further, in another embodiment, the comparison threshold can also be calculated based on the rewards obtained by the slave chain nodes in the previous round of federated learning process and the expected number of consensus nodes selected from the sum of the rewards obtained by each slave chain node in the slave chain.
[0151] Further, please refer to Figure 6 , Figure 6 which is a schematic flowchart of another embodiment of a federated learning method of this application. In the current embodiment, the above step S505 normalizes the hash result and determines the selection result based on the normalization result, which further includes steps S601 to S603.
[0152] S601: The slave chain node normalizes the hash result to obtain a normalization result.
[0153] Specifically, the normalization result d is calculated from the hash result using the formula where d also represents the difficulty value = maximum target value / current target value (the solution formula of d can also be understood as: hash result to the power of 2 to the length of the hash result), d ∈ [0, 1), and hashlen represents the length of the hash result output by the hash algorithm (which can also be understood as the number of bits of the hash result).
[0154] Further, the process of the slave chain node normalizing the hash result can also be understood as a process of converting the hash result to a value in the interval [0, 1).
[0155] Use λ to identify the set threshold. Further, the set threshold can be calculated by constructing a binomial distribution function, that is, perform the following step S602.
[0156] S602: Based on the rewards obtained by the slave chain node in the previous round of federated learning process and the expected number of consensus nodes selected from the sum of the rewards obtained by each slave chain node in the slave chain, use the binomial distribution algorithm to construct the binomial distribution of the slave chain node.
[0157] Among them, the constructed binomial distribution is denoted by the following formula:
[0158]
[0159] Among them, the constructed binomial distribution represents the probability that a certain slave chain node i is selected as a consensus node after multiple lotteries.
[0160] Among them: B(.) represents the binomial distribution algorithm.
[0161] m represents the reward obtained by each slave chain node (slave chain node i) in the previous round of federated learning process. Further, here m is the value obtained by standard integerizing the reward obtained by the slave chain node, specifically calculated based on the standard integerization formula.
[0162] The standard integerization formula is as follows: Among them, is the average value of the rewards obtained by all slave chain nodes in the previous round of federated learning, is the standard deviation of the rewards obtained by all slave chain nodes in the previous round of federated learning. For example, when m i = 8.6, based on the average value of all rewards and the standard deviation and using the above standard integerization formula to standardize 8.6, the first processed value obtained is 10.
[0163] R = ∑r i represents the sum of the rewards of all participating slave chain nodes in one round of training.
[0164] k represents the number of consensus nodes expected to be selected in the current round of model training. For example, when a certain slave chain node mi = 10, k = 4 means that this slave chain node is allowed to draw lots 10 times, and 4 of the lots are written as "selected", that is, there are 4 possibilities to be drawn as a consensus node.
[0165] τ represents the effective reward value, and all "effective" means the slave chain nodes that have actually contributed to the first global parameter in the previous round of model training.
[0166] represents the probability of being drawn as a consensus node in one lottery.
[0167] S603: Determine the cumulative probability density curve of the binomial distribution, and determine the selection result based on the cumulative probability density curve and the normalization result.
[0168] After completing the construction of the binomial distribution, further determine the cumulative probability density curve of the currently constructed binomial distribution:
[0169] Each slave chain node draws lots from 0 to ri times, accumulates the probabilities of each draw, and records it as the probability of the slave chain node being drawn. Finally, based on the cumulative probability density curve of the determined binomial distribution and the normalized result of d after normalization processing of the hash result, it determines whether it can run for the consensus node itself.
[0170] Specifically, if the normalized result d satisfies d < f(j), then record j = 0, indicating that the slave chain node is not selected in this run for the consensus node; if there exists a j in the above curve that satisfies f(j) ≤ d < f(j + 1), record the value of j at this time, and further determine whether the current j is greater than zero. If it is judged that j > 0 for which f(j) ≤ d < f(j + 1) holds, then the slave chain node successfully runs for the consensus node in the current round of the federated learning process. Further, when the slave chain node is successfully drawn as the consensus node, the consensus node will announce its hash result, selection proof, and the j for which the formula f(j) ≤ d < f(j + 1) holds to other slave chain nodes. Here, j represents the number of times the slave chain node draws lots.
[0171] In another embodiment, based on the cumulative probability density curve and the normalized result to determine the selection result, that is, to judge whether the normalized result obtained by normalizing the hash result belongs to the interval where the set threshold is located. Specifically, it can also be understood as a process of judging whether the following formula holds:
[0172]
[0173] Among them, the interval range corresponding to the set threshold λ is as follows: Judge whether the normalized result d is within the set threshold range; if it is within this range, it means that the current slave chain node is selected as the consensus node for the current round of federated learning, and if it is not within this range, it means that the current slave chain node is not selected as the consensus node.
[0174] Further, in the technical solution provided by this application, after selecting the consensus node, a unique leader node (Leader node) will be further elected among the selected consensus nodes.
[0175] First, according to the above method, multiple consensus nodes are selected from several slave chain nodes in the slave chain, and the selected multiple consensus nodes form a consensus committee for the current round of federated learning process. Then, these consensus nodes can each independently send requests to all slave chain nodes in the slave chain to elect themselves as the leader node, requesting other slave chain nodes to vote for themselves. Then wait for a set time, during which each slave chain node selects to conduct the leader node voting election. Within a certain time (counted by a timer), the consensus node with the most votes will become the leader node for the current round of federated learning process. The leader node has the function of sending instructions to other slave chain nodes in the slave chain. For example, if a certain slave chain node uploads the first local parameter, and the first local parameter passes the consensus verification of the consensus nodes in the consensus committee and is determined to be the target local parameter, then the leader node is used to send instructions for ledger synchronization to other slave chain nodes in the slave chain, so that each slave chain node in the slave chain saves the target local parameter to its own distributed ledger.
[0176] Furthermore, if during the process of selecting the leader node, it is determined through the vote count of the consensus nodes that two (or more) consensus nodes have equal votes, the method provided in this application further includes: initiating a new round of voting election process for the consensus nodes with equal votes. The consensus node with the most votes in the new round of voting election process becomes the leader consensus node.
[0177] Furthermore, in another embodiment, if during the process of selecting the leader node, it is determined through the vote count of the consensus nodes that two (or more) consensus nodes have equal votes, the final leader node can be further determined by combining the scores and / or rewards obtained by each consensus node. Specifically, the consensus node with the highest score and / or the most rewards obtained is determined as the leader node in the current round of federated learning.
[0178] Specifically, the technical solution provided in this application completes the consensus verification of the first local parameter by optimizing the traditional RAFT consensus.
[0179] To further encourage each slave chain node in the slave chain to actively participate in federated learning, the federated learning provided in this application also sets up an incentive mechanism. Specifically, please refer to Figure 7 , Figure 7 is a schematic flowchart of an embodiment of a federated learning method of this application. In the current embodiment, the federated learning method provided in this application is executed by the upload node in the slave chain. The upload node is a slave chain node in the slave chain used to upload the first local parameter to the main chain node in the main chain. The slave chain nodes in the slave chain include several training nodes and several consensus nodes. The method provided in this application includes steps S710 to step S730.
[0180] S710: The uploading node obtains the first local parameter to be uploaded and the first local parameter to be verified.
[0181] During the execution of federated learning, when a first local parameter passes the consensus verification of the consensus committee, the uploading node used to execute the uploading function will also obtain the first local parameter to be uploaded and the first local parameter to be verified, and then execute the following step S720.
[0182] Among them, the first local parameter to be uploaded is the first local parameter that has passed the consensus verification of several consensus nodes, which can also be understood as the target local parameter described in the above various embodiments; the first local parameter to be verified is the first local parameter that has not passed the consensus verification. It should be noted that in the technical solution provided in this application, according to the preset, the uploading node can be any slave chain node in the slave chain. For example, in one embodiment, it can be preset that the training node for training the target local parameter executes the uploading of the target local parameter to the main chain node. In another embodiment, it can also be preset that any one of the consensus nodes executes the uploading of the target local parameter to the main chain node. In yet another embodiment, it can also be set that any slave chain node other than the slave chain node that trains to obtain the target local parameter in the slave chain is used as the uploading node to execute the function of uploading the target local parameter to the main chain node.
[0183] S720: Compare the first local parameter to be uploaded and the first local parameter to be verified to determine whether the first local parameter has been tampered with.
[0184] After obtaining the first local parameter to be uploaded and the first local parameter to be verified, the uploading node further compares the first local parameter to be uploaded and the first local parameter to be verified.
[0185] Furthermore, in one embodiment, the uploading node can directly compare the first local parameter (target local parameter) to be uploaded and the first local parameter to be verified to determine whether they are the same. If they are the same, it is determined that the first local parameter has not been tampered with, and the first local parameter to be uploaded is uploaded to the main chain node; otherwise, if it is obtained through comparison that they are different, it is determined that the current first local parameter has been tampered with, and then the following step S730 will be executed.
[0186] In another embodiment, it can also be by performing hash operations on the first local parameter to be uploaded and the first local parameter to be verified respectively. A first hash value is obtained by performing a hash operation on the first local parameter to be verified, and a second hash value is obtained by performing a hash operation on the first local parameter to be uploaded. Then, it is compared whether the first hash value is equal to the second hash value. If so, it means that the currently to-be-uploaded first local parameter has not been tampered with, and the to-be-uploaded first local parameter is uploaded to the main chain node; otherwise, if the first hash value is not equal to the second hash value, it means that the currently to-be-uploaded first local parameter has been tampered with, and the following step S730 is executed.
[0187] Furthermore, the first hash value of the first local parameter to be verified can be obtained by the training node that trained the first local parameter performing a hash operation before transmitting the first local parameter to the consensus node during the process of training the first local parameter, and storing the first hash value in its own storage area or storing it on the sub-chain. Then, when executing the above step S720, this first hash value is obtained and compared with the calculated second hash value.
[0188] S730: If so, it is determined that the first training node meets the processing conditions, and the digital tokens of the first training node are deducted according to the preset processing strategy.
[0189] Among them, the first training node is the training node that trained the first local parameter. If the uploading node determines that the first local parameter has been tampered with, it is determined that the training node (i.e., the first training node) that trained the to-be-uploaded first local parameter meets the processing conditions. After determining that the first training node meets the processing conditions, the digital tokens of this first training node are further deducted according to the preset processing strategy.
[0190] In one embodiment, the preset processing strategy is: deducting a preset number of digital tokens from the first training node that meets the processing conditions. In the current embodiment, the same digital tokens will be deducted from the first training node that meets the processing conditions.
[0191] In another embodiment, the preset processing strategy is: combining the time consumed by the first training node to train and obtain the first local parameter to determine the deduction amount of the digital tokens of the first training node that meets the processing conditions. Among them, the deduction amount of the digital tokens is positively correlated with the time consumed to train and obtain the first local parameter. When the time consumed by the first training node that meets the processing conditions to train and obtain the first local parameter is longer, more digital tokens are deducted correspondingly; conversely, when the time consumed by the first training node that meets the processing conditions to train and obtain the first local parameter is shorter, fewer digital tokens are deducted correspondingly.
[0192] This application is in Figure 7In the corresponding embodiment, a reward and punishment mechanism is set up. Specifically, an account is set up for each user bound to the slave chain node, and this account is used to receive and send digital tokens. If the slave chain node sends the correct target local parameters or target local parameters that make sufficient contributions to the first global parameter, digital tokens are rewarded; conversely, if malicious parameters are sent, digital tokens are punished. And in some embodiments, the number of digital tokens rewarded is also positively correlated with the time when each slave chain node uploads the target local parameters to the main chain. The faster the upload, the more digital tokens are rewarded, which can form an incentive ecological closed-loop and promote the training and optimization of the global parameter (global machine learning model).
[0193] Please refer to Figure 8 , Figure 8 FIG. is a schematic flowchart of a process in an embodiment of federated learning of the present application. In the current embodiment, in the current embodiment, the federated learning method provided by the present application is executed by the main chain nodes in the main chain. The main chain nodes can interact with the slave chain nodes in the slave chain. The slave chain includes several slave chain nodes, and the slave chain nodes interact with the main chain nodes in the main chain. According to the functions performed by each slave chain node in each round of federated learning process, the slave chain nodes include training nodes and consensus nodes. The method provided by the present application includes steps S810 to S830.
[0194] S810: The main chain node obtains the target local parameters uploaded by the first preset number of slave chain nodes.
[0195] When the main chain node executes the federated learning method provided by the present application, the main chain node first needs to obtain the target local parameters uploaded by the first preset number of slave chain nodes. Among them, the first preset number can be set and adjusted in advance according to requirements.
[0196] Furthermore, before the main chain node obtains the local parameters uploaded by the first preset number of slave chain nodes, the method further includes: randomly selecting the first preset number of slave chain nodes from all the slave chain nodes in the slave chain.
[0197] In one embodiment, when the total number of training nodes included in the slave chain that cooperates with the current main chain to execute federated learning is relatively large, in order to improve the efficiency of federated learning, the user can adjust the first preset number according to the total number of training nodes included in the slave chain. For example, in one embodiment, when the total number of slave chain nodes included in the slave chain is 10,000, the first number can be set to 1,000.
[0198] In another embodiment, when the total number of slave chain nodes included in the chain is 100, the first preset number can be correspondingly set to 100. That is, in some embodiments, the first preset number can also be set to be equal to the number of slave chain nodes included in the slave chain, that is, it is set that the master chain node obtains the target local parameters uploaded by all the slave chain nodes included in the slave chain, and then performs the following step S820 based on the obtained target local parameters.
[0199] Further, the master chain node randomly determines the first preset number of slave chain nodes from the slave chain, and then obtains the target local parameters uploaded by the determined first preset number of slave chain nodes. It should be noted that usually, after all the selected first preset number of slave chain nodes upload their local parameters, the master chain node in the master chain will perform aggregation. Among them, the master chain node includes at least a server.
[0200] In another embodiment, the master chain node can also be based on the accuracy (or score) ranking of the slave chain nodes, extract the first preset number of slave chain nodes with the top accuracy (or score) ranking, and then perform the following step S820 based on the target local parameters uploaded by the extracted first preset number of slave chain nodes.
[0201] S820: Aggregate the first global parameter based on the target local parameters of the first preset number.
[0202] After obtaining the target local parameters of the first preset number, the master chain node further aggregates the target local parameters of the first preset number to obtain the first global parameter. The first global machine learning model corresponding to the first global parameter can minimize the loss function on the entire training data set (that is, the union of the data on all slave chain nodes and / or all master chain nodes).
[0203] Further, after the master chain node aggregates the target local parameters of the first preset number to obtain the first global parameter, it needs to be broadcast within the master chain. After the consensus confirmation of the consistency by each master chain node within the master chain, a unique first global parameter is obtained, and then the step of outputting the first global parameter is performed to feedback the first global parameter to the slave chain nodes and trigger the next round of learning iteration. Among them, the aggregation of the first local parameters of different slave chain nodes is completed through a smart contract.
[0204] Further, after aggregating the first global parameter based on the target local parameters of the first preset number in step S820, the method provided by this application further includes: uploading the first global parameter to the master chain distributed ledger for storage. In this embodiment, by uploading the first global parameter to the master chain distributed ledger, it can be realized that each master chain node in the master chain can obtain the first global parameter by accessing the master chain distributed ledger, and it can also better avoid the first global parameter being tampered with.
[0205] S830: Output the first global parameter.
[0206] After aggregating to obtain the first global parameter, further output the first global parameter.
[0207] Furthermore, outputting the first global parameter includes: outputting the first global parameter to each main chain node and / or each sub-chain node.
[0208] Furthermore, the main chain node can output the first global parameter to each main chain node in the main chain. Further still, the main chain node can also output the first global parameter to each main chain node in the main chain and each sub-chain node in the sub-chain.
[0209] Specifically, the main chain node can output the first global parameter to each main chain node in the main chain and / or each sub-chain node included in the sub-chain by means of broadcasting.
[0210] In the current embodiment, by setting a main chain including a plurality of main chain nodes to cooperate with the sub-chain, dependence on a single server is avoided. In the technical solution provided by the present application, since the main chain and the sub-chain are the same and both have information consistency, when any main chain node aggregates to obtain the first global parameter, it will be output to each main chain node within the main chain, thereby achieving consistency of information among each main chain node in the main chain. In this way, when any main chain node fails, it can still stably cooperate with the sub-chain to complete federated learning, obtain the first global parameter and output it, improving the security and reliability of federated learning.
[0211] Please refer to Figure 9 , Figure 9 which is a schematic flowchart of another embodiment of a federated learning method of the present application. In the current embodiment, the method provided by the present application includes steps S901 to S904.
[0212] S901: The main chain node obtains the target local parameters uploaded by the first preset number of sub-chain nodes.
[0213] Step S901 in the current embodiment is the same as step S810 described above. Specifically, reference can be made to the corresponding part described above and will not be repeated here. In the current embodiment, in order to make the obtained first global parameter more accurate and make the loss function value of the first global parameter smaller, the above step S820 aggregates to obtain the first global parameter based on the first preset number of target local parameters. In the current embodiment, it further includes steps S902 to S903.
[0214] S902: Aggregate to obtain the initial global parameter based on the target local parameters.
[0215] After obtaining the target local parameters uploaded by the first preset number of slave chain nodes, the master chain node will first aggregate based on the obtained first preset number of target local parameters, and output the aggregated result as the initial global parameters. In the current embodiment, the initial global parameters are the global parameters aggregated based on the target local parameters.
[0216] After the slave chain nodes train to obtain the first local parameters, they can be sent to the master chain node for aggregation through TCP protocol communication. In the current embodiment, the initial global parameters can be obtained by performing weighted aggregation on the target local parameters. Among them, the weighting coefficient is related to two factors. One is the proportion of the data volume possessed by each slave chain node in the total training data volume, and the other is the accuracy of the local machine learning model corresponding to the target local parameters. The accuracy of the local machine learning model corresponding to the target local parameters can be verified using a public validation set.
[0217] Among them, the specific calculation formula for the global parameters after aggregation is as follows:
[0218]
[0219] Among them: represents the local data volume stored by the slave chain node numbered i (the total amount of training data used by each slave chain node to train the target local parameters), represents the total amount of training data used by all slave chain nodes to train the target local parameters.
[0220] represents the accuracy of the local machine learning model corresponding to the target local parameters obtained by the slave chain node numbered i when running on the validation data set, represents the sum of the accuracies of the local machine learning models corresponding to the target local parameters obtained by each of the slave chain nodes numbered from i to A when running on the validation data set.
[0221] D 1:A represents the set of all slave chain nodes numbered from 1 to A.
[0222] α represents the weight coefficient, which can be adjusted according to requirements.
[0223] S903: Perform cyclic training based on the initial global parameters and the second type of data stored by itself to obtain the first global parameters.
[0224] After aggregating the initial global parameters, the main-chain nodes further perform cyclic training based on the initial global parameters and the second type of data stored by themselves, and use the second training algorithm to obtain the first global parameter. Among them, the second training algorithm includes the gradient descent algorithm, and the second type of data is the data stored by the main-chain nodes. In the current embodiment, the first type of data for training the first local parameter includes unlabeled data, and the corresponding second type of data includes labeled data.
[0225] Further, in other embodiments, the type of the second type of data may also include unlabeled data.
[0226] Among them, the first global parameter is the global parameter with the smallest loss function value obtained in the cyclic training.
[0227] S904: Output the first global parameter.
[0228] Step S904 is the same as the above-mentioned step S830, and reference can be made to the corresponding part described above.
[0229] Figure 9 In the corresponding embodiment, the initial global parameter is determined based on the randomly selected first preset number of target local parameters, and then the global parameter is obtained by training based on the initial global parameter and the second type of data stored by the main-chain nodes themselves. Determine whether the loss function of the global parameter is the smallest, that is, determine whether the global parameter is the optimal global parameter. If so, output it as the first global parameter and end the current loop; if not, train the second type of data stored by itself again based on the current global parameter to obtain a new global parameter, and so on, iterating in a loop until the global parameter with the smallest loss function is output, and the global parameter with the smallest loss function is output as the first global parameter and synchronized to each main-chain node and each slave-chain node.
[0230] In addition, in Figure 9 In the corresponding embodiment, the labeled data participating in the machine learning model training is stored at the main-chain node end, while a large amount of unlabeled data is stored at the slave-chain nodes. That is, the supervised learning process with labels and the unsupervised learning process without labels will be carried out at the main-chain node end and the slave-chain nodes respectively, which can better improve the accuracy of the machine learning model and the training efficiency.
[0231] Further, connect Figure 9In the corresponding embodiment, after each slave chain node receives the first global parameter sent by the nearby master chain node, the slave chain node further performs model detection / evaluation of the first global parameter (the first global machine learning model) on its local test data set. Among them, the model accuracy obtained by the evaluation can be output as the reward basis for the slave chain node in this round (epoch) of model training. At the same time, the first global parameter will be used as the first global parameter for the slave chain node to perform another round of training in the next round of the federated learning process, and so on in an iterative loop for multiple rounds of training.
[0232] It should be noted that the local data stored by each slave chain node is split into two parts: the first type of data and the test data. Among them, the first type usually accounts for a relatively large proportion and is used as training data to train local parameters and / or for model construction, and the test data is used to verify whether the updated first global parameter is accurate.
[0233] Please refer to Figure 10 , Figure 10 which is a schematic flowchart of another embodiment of a federated learning method of the present application. In the current embodiment, the above step S902 aggregates the initial global parameter based on the first preset number of target local parameters, and further includes steps S1001 to S1002.
[0234] S1001: Determine the first weight of each of the first preset number of slave chain nodes.
[0235] Among them, the first weight is determined by each master chain node in the master chain based on the data information and historical service capabilities stored by the slave chain node. Each master chain node's weight selection for each slave chain node is the same. If different master chain nodes cannot reach a unified opinion on the weight, the average value of the weights will be taken as the first weight by default.
[0236] S1002: Aggregate each local parameter according to the first weight to obtain the initial global parameter.
[0237] After determining the first weight of each slave chain node, further aggregate each local parameter according to the first weight to obtain the initial global parameter.
[0238] Furthermore, at the master chain node side, the federated learning method provided by the present application further includes:
[0239] Sending the first training algorithm to the slave chain nodes in the target area. Among them, the master chain node can send the first training algorithm to the slave chain node in the form of broadcasting or point-to-point communication. The first training algorithm is an algorithm for the slave chain node to train and obtain local parameters. The first training algorithm includes the gradient descent algorithm.
[0240] After the main-chain node obtains the target local parameters uploaded by the first preset number of sub-chain nodes, the federated learning method provided by this application further includes: the main-chain node verifies the identity of the sub-chain nodes according to the hash values of the preset tuples in the local parameters. Specifically, the main-chain node verifies the identity of the sub-chain nodes based on the hash values of the preset tuples in the received local parameters. Among them, the hash values of the preset tuples include UUID, and the preset tuples contain <sub-chain node address, parameter byte size, parameter type, sub-chain node ID>.
[0241] After aggregating the first global parameter based on the first preset number of target local parameters, the federated learning method further includes: respectively scoring the first preset number of sub-chain nodes according to the contribution of each target local parameter to the first global parameter and performing preset reward and punishment processing.
[0242] Among them, the number of digital tokens for rewards in the preset reward and punishment processing is positively correlated with the time when each sub-chain node uploads the target local parameters to the main-chain node.
[0243] Further, when the number of sub-chain nodes included in the sub-chain is greater than the first preset number, after the main-chain node obtains the first global parameter, the main-chain node is further used to calculate the mean value of the contribution values of the first preset number of target local parameters. After obtaining the mean value of the contribution values, the main-chain node further determines the mean value as the contribution value of the second local parameter, and based on the contribution value of the second local parameter, performs preset reward and punishment processing on each sub-chain node associated with the second local parameter. Among them, the second local parameter is the first local parameter received by the main-chain node except for the target local parameter.
[0244] Please refer to Figure 11 , Figure 11 which is a schematic flow chart in an embodiment of a federated learning method of this application. In the current embodiment, the schematic diagram of the interaction between each node in the federated learning system is mainly shown. Specifically, the method provided by this application is as follows:
[0245] 1. The main-chain node sends the first training algorithm to the sub-chain nodes.
[0246] 2. The sub-chain nodes obtain the first training algorithm.
[0247] 3. The sub-chain nodes determine the first type of data and the first initial parameters, and use the first training algorithm, the first type of data and the first initial parameters to perform model training to obtain the first local parameters.
[0248] 4. Transmit the first local parameters to the consensus nodes.
[0249] 5. The consensus nodes perform consensus verification on the first local parameters.
[0250] 6. The consensus node outputs the first local parameter that has passed consensus verification as the target local parameter.
[0251] 7. The consensus node transmits the target local parameter to the sub-chain node.
[0252] 8. The sub-chain node transmits the target local parameter to the main-chain node.
[0253] 9. The main-chain node obtains the target local parameters uploaded by the first preset number of sub-chain nodes.
[0254] It should be noted that in some embodiments, when the node that uploads the target local parameter to the main-chain node is an upload node in the sub-chain, this step can be understood as obtaining the target local parameters of the first preset number, and the target local parameters of the first preset number are obtained by different training nodes.
[0255] 10. Aggregate the first global parameter based on the target local parameters of the first preset number.
[0256] 11. Output the first global parameter to each main-chain node and / or sub-chain node.
[0257] In the technical solution provided in this application, blockchain technology is used to enhance the data and model security in the training stage of the machine learning model. The parameters obtained in each time period and each iteration (the parameters here include the first local parameter, the target local parameter, the first global parameter, and the initial parameter) and other results obtained in the iteration process are automatically uploaded to the corresponding data block and quickly synchronized among each node to achieve sharing and reduce the transmission cost. At the same time, the characteristics of immutability and hash chain connection of the blockchain ensure the security of sensitive data in the storage stage of the first global parameter (i.e., the global machine learning model obtained by training).
[0258] Please refer to Figure 12 , Figure 12 which is a schematic structural diagram of an electronic device according to an embodiment of the present application. In the current embodiment, the electronic device 1200 provided in the present application includes a processor 1201 and a memory 1202 coupled to the processor 1201. The electronic device 1200 can execute Figures 2 to 11 the method described in any one of the corresponding embodiments thereof.
[0259] Among them, the memory 1202 includes local storage (not shown in the figure) and is used to store a computer program, and when the computer program is executed, it can implement Figures 2 to 11 the method described in any one of the corresponding embodiments thereof.
[0260] The processor 1201 is coupled to the memory 1202. The processor 1201 is used to run the computer program to execute as above Figures 2 to 11and the method described in any of its corresponding embodiments. Further, in some embodiments, the electronic device may include any one of a mobile terminal, a vehicle-mounted terminal, a camera, a computer terminal, a computer, an image acquisition device with computing and storage capabilities, a server, etc., or may also include any other device with computing and processing functions.
[0261] See Figure 13 , Figure 13 which is a schematic structural diagram of an embodiment of a computer-readable storage medium according to the present application. The computer-readable storage medium 1300 stores a computer program 1301 that can be run by a processor, and the computer program 1301 is used to implement the method described above Figures 2 to 11 and the method described in any of its corresponding embodiments. Specifically, the above computer-readable storage medium 1300 may be one of a memory, a personal computer, a server, a network device, a USB flash drive, etc., and no specific limitation is made here.
[0262] The above are only the embodiments of the present application, and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present application.
Claims
1. A federated learning method, characterized in that, The method is executed by training nodes in a sub-chain, where the sub-chain includes several sub-chain nodes that can interact with main-chain nodes in the main chain. The sub-chain nodes include training nodes and consensus nodes. The method includes: The training node obtains a first training algorithm; Determine a first type of data and first initial parameters, and use the first training algorithm, the first type of data, and the first initial parameters for model training to obtain first local parameters; Transmit the first local parameters to the consensus nodes to use the consensus nodes in the sub-chain to perform consensus verification on the first local parameters; Determine the first local parameters that pass the consensus verification as target local parameters, and upload the target local parameters to the main-chain nodes, so that after the main-chain nodes aggregate the first preset number of target local parameters to obtain a first global parameter, use the first global parameter as a new first training algorithm and output it to the sub-chain nodes for the next round of training; The training nodes and consensus nodes in different rounds are different. The consensus nodes in the next round are selected from several sub-chain nodes based on the training scores of the current round of training nodes. The training score is determined based on the accuracy of the target local parameters corresponding to the training nodes; among them, the higher the training score of the training node, the greater the probability of becoming the consensus node in the next round; Among them, the step of selecting consensus nodes from several sub-chain nodes includes: generating auxiliary global parameters based on a preset security parameter; generating a verification public key and a verification private key based on the auxiliary global parameters; performing signature calculation on the current training round information, the first random number in the previous round of federated learning, the first global parameter obtained in the previous round of federated learning, and the number of consensus nodes required for this round of training to obtain a second random number; calculating a hash result based on the verification private key and the second random number; performing normalization processing on the hash result, and determining the selection result based on the comparison result between the normalization processing result and a comparison threshold; among them, the comparison threshold is calculated based on the rewards obtained by the sub-chain nodes in the previous round of federated learning, the sum of the rewards obtained by each sub-chain node in the sub-chain, and the expected number of consensus nodes to be selected. The reward obtained by the previous round of training nodes is determined based on the accuracy of the target local parameters corresponding to the training nodes.
2. The method according to claim 1, wherein Before transmitting the first local parameters to the consensus nodes, the method further includes: Calculating a first hash value of the first local parameters and storing the first hash value; Before uploading the target local parameters to the main-chain nodes, the method further includes: Calculating a second hash value of the target local parameters; Judging whether the second hash value is equal to the first hash value; If so, execute the step of uploading the target local parameters to the main-chain nodes.
3. The method according to claim 2, characterized in that, If the second hash value is not equal to the first hash value, do not execute the step of uploading the target local parameters to the main-chain nodes, and re-execute the step of using the first training algorithm, the first type of data, and the first initial parameters for model training to obtain the first local parameters.
4. The method according to claim 1, characterized in that, Performing model training using the first training algorithm, the first type of data, and the first initial parameters to obtain first local parameters further includes: Performing model training using the first training algorithm, the first type of data, and the first initial parameters on a cloud simulator to obtain the first local parameters.
5. The method according to claim 1, characterized in that Before obtaining the first training algorithm, the method further includes: Sending a side-chain joining request to the main-chain node in the current region to obtain the side-chain ID and CA certificate issued by the main-chain node.
6. The method according to claim 1, characterized in that, Uploading the target local parameters to the main-chain node includes: Digitally signing the target local parameters using the public key of the main-chain node and uploading the signed target local parameters to the main-chain node through itself or the uploading node in the side-chain, where the uploading node is the node in the side-chain used to interact with the main-chain node; And / or, performing normalization processing on the hash result and determining the selection result based on the normalization processing result includes: The side-chain node performs normalization processing on the hash result to obtain a normalization result; Based on the rewards obtained by the side-chain node in the previous round of federated learning, the rewards obtained by each side-chain node in the side-chain, and the expected number of consensus nodes to be selected, a binomial distribution of the side-chain node is constructed using the binomial distribution algorithm; Determining the cumulative probability density curve of the binomial distribution and determining the selection result based on the cumulative probability density curve and the normalization result.
7. A federated learning method, characterized in that, The method is executed by a consensus node in the side-chain. The side-chain includes several side-chain nodes. The side-chain nodes can interact with the main-chain nodes in the main-chain. The side-chain nodes include training nodes and consensus nodes. The method includes: The consensus node receives the first local parameters to be verified sent by the training node; Performing consensus verification on the first local parameters; Output the first local parameter verified by the consensus as the target local parameter, and transmit the target local parameter to the uploading node, so that after the main chain node aggregates the first preset number of target local parameters to obtain the first global parameter, use the first global parameter as the new first training algorithm and output it to the slave chain node for the next round of training; the training nodes and consensus nodes in different rounds are different, and the consensus node in the next round is selected from a number of slave chain nodes based on the training score of the current round of training nodes, and the training score is determined based on the accuracy of the target local parameter corresponding to the training node; among them, the higher the training score of the training node, the greater the probability of becoming the consensus node in the next round; among them, the step of selecting the consensus node from a number of slave chain nodes includes: generating an auxiliary global parameter based on a preset security parameter; generating a verification public key and a verification private key based on the auxiliary global parameter; performing a signature calculation on the current training round information, the first random number in the previous round of federated learning, the first global parameter obtained in the previous round of federated learning, and the number of consensus nodes required for this round of training to obtain a second random number; calculating a hash result based on the verification private key and the second random number; performing a normalization process on the hash result, and determining the selection result based on the comparison result between the normalization process result and the comparison threshold; among them, the comparison threshold is calculated based on the rewards obtained by the slave chain nodes in the previous round of federated learning, the sum of the rewards obtained by each of the slave chain nodes in the slave chain, and the expected number of consensus nodes to be selected, and the rewards obtained by the previous round of training nodes are determined based on the accuracy of the target local parameter corresponding to the training node.
8. The method according to claim 7, wherein The performing consensus verification on the first local parameter includes: Call the Verify function in the random function to verify the first local parameter to determine whether the first local parameter is obtained by the training node based on the legal data stored by itself.
9. The method according to any one of claims 7 to 8, characterized in that, The method further includes: Based on the result of the consensus verification, score the current round of training of the training nodes corresponding to each of the received first local parameters, and associate and store the scoring result with the training nodes in the slave chain distributed ledger.
10. The method according to claim 7, wherein The transmitting the target local parameter to the uploading node includes: Use the leader node to sign the target local parameter, and transmit the target local parameter signed by the leader node to the uploading node, where the leader node is selected by voting of each of the consensus nodes in the slave chain, and the uploading node is the slave chain node that uploads the target local parameter to the main chain node; And / or, the performing a normalization process on the hash result and determining the selection result based on the normalization process result includes: The slave chain node performs a normalization process on the hash result to obtain a normalization result; Based on the rewards obtained by the slave chain node in the previous round of federated learning, the rewards obtained by each of the slave chain nodes in the slave chain, and the expected number of consensus nodes to be selected, use the binomial distribution algorithm to construct the binomial distribution of the slave chain node; Determine the cumulative probability density curve of the binomial distribution, and determine the selection result based on the cumulative probability density curve and the normalization result.
11. A federated learning method, characterized in that, The method is executed by the main-chain nodes in the main chain. The main-chain nodes can interact with the sub-chain nodes in the sub-chain. The sub-chain includes a number of sub-chain nodes. The sub-chain nodes interact with the main-chain nodes in the main chain. The sub-chain nodes include training nodes and consensus nodes. The method includes: The main-chain nodes obtain the target local parameters uploaded by the first preset number of sub-chain nodes; Aggregate the first global parameter based on the target local parameters of the first preset number; Output the first global parameter to the sub-chain nodes for the next round of training; wherein, the training nodes and consensus nodes in different rounds are different. The consensus nodes in the next round are selected from a number of sub-chain nodes based on the training scores of the training nodes in the current round. The training score is determined based on the accuracy of the target local parameters corresponding to the training nodes; wherein, the higher the training score of the training node, the greater the probability of becoming the consensus node in the next round; wherein, the step of selecting the consensus node from a number of sub-chain nodes includes: generating an auxiliary global parameter based on a preset security parameter; generating a verification public key and a verification private key based on the auxiliary global parameter; performing signature calculation on the current training round information, the first random number in the previous round of federated learning, the first global parameter obtained in the previous round of federated learning, and the number of consensus nodes required for this round of training to obtain a second random number; calculating a hash result based on the verification private key and the second random number; performing normalization processing on the hash result, and determining the selection result based on the comparison result between the normalization processing result and the comparison threshold; wherein, the comparison threshold is calculated based on the rewards obtained by the sub-chain nodes in the previous round of federated learning, the sum of the rewards obtained by each sub-chain node in the sub-chain, and the expected number of consensus nodes to be selected. The rewards obtained by the training nodes in the previous round of training are determined based on the accuracy of the target local parameters corresponding to the training nodes.
12. The method according to claim 11, wherein After aggregating the first global parameter based on the target local parameters of the first preset number, the method further includes: Aggregate the initial global parameter based on the target local parameters; Perform cyclic training based on the initial global parameter and the second type of data stored by itself to obtain the first global parameter, wherein the first global parameter is the global parameter with the smallest loss function value obtained in the cyclic training.
13. The method according to claim 12, wherein The step of aggregating the initial global parameter based on the target local parameters of the first preset number further includes: Determine the first weight of each of the first preset number of sub-chain nodes, wherein the first weight is determined by each main-chain node in the main chain based on the data information and historical business capabilities stored by the sub-chain nodes; Aggregate each local parameter according to the first weight to obtain the initial global parameter.
14. The method according to any one of claims 11 to 12, characterized in that After aggregating the first global parameter based on the target local parameters of the first preset number, the method further includes: Upload the first global parameter to the main-chain distributed ledger for storage; Outputting the first global parameter further includes: outputting the first global parameter to each of the main chain nodes.
15. The method according to any one of claims 11 to 12, characterized in that The method further includes: Sending a first training algorithm to the slave chain nodes in the target area, where the first training algorithm is an algorithm for the slave chain nodes to train to obtain the local parameters.
16. The method according to any one of claims 11 to 12, characterized in that After the main chain node obtains the target local parameters uploaded by the first preset number of slave chain nodes, the method further includes: The main chain node verifies the identities of the slave chain nodes according to the hash values of the preset tuples in the local parameters.
17. The method according to any one of claims 11 to 12, characterized in that After aggregating the first global parameter based on the first preset number of target local parameters, the method further includes: Scoring and performing preset reward and punishment processing on the first preset number of slave chain nodes respectively according to the contributions of the respective target local parameters to the first global parameter; wherein, the reward in the preset reward and punishment processing is positively correlated with the time when each slave chain node uploads the target local parameter to the main chain node; And / or, the normalizing the hash result and determining the selection result based on the normalization result includes: The slave chain node normalizes the hash result to obtain a normalization result; Based on the reward obtained by the slave chain node in the previous round of federated learning, the rewards obtained by each slave chain node in the slave chain, and the expected number of consensus nodes to be selected, a binomial distribution of the slave chain node is constructed using the binomial distribution algorithm; Determining the cumulative probability density curve of the binomial distribution, and determining the selection result based on the cumulative probability density curve and the normalization result.
18. A federated learning system, characterized in that, The system includes a main chain and a slave chain capable of interacting, where the slave chain includes a number of slave chain nodes, the slave chain nodes include training nodes and consensus nodes, and the main chain includes a number of main chain nodes; The training node is used to train and obtain the first local parameter, the consensus node is used to perform consensus verification on the first local parameter obtained by the training of the training node, the training node is further used to determine the target local parameter by passing the consensus verification of the first local parameter, and upload the target local parameter to the main chain node; The main-chain node can interact with at least one of the sub-chain nodes in the sub-chain. The main-chain node is used to obtain target local parameters uploaded by a first preset number of the sub-chain nodes, aggregate the first preset number of target local parameters to obtain a first global parameter, and output the first global parameter to the sub-chain nodes for the next round of training. Among them, the training nodes and consensus nodes are different in different rounds. The consensus nodes in the next round are selected from a number of sub-chain nodes based on the training scores of the current round of training nodes. The training score is determined based on the accuracy of the target local parameters corresponding to the training nodes. Among them, the higher the training score of the training node, the greater the probability of becoming a consensus node in the next round. Among them, the step of selecting consensus nodes from a number of sub-chain nodes includes: generating an auxiliary global parameter based on a preset security parameter; generating a verification public key and a verification private key based on the auxiliary global parameter; performing signature calculation on the current training round information, the first random number in the previous round of federated learning, the first global parameter obtained in the previous round of federated learning, and the number of consensus nodes required for this round of training to obtain a second random number; calculating a hash result based on the verification private key and the second random number; performing normalization processing on the hash result, and determining the selection result based on the comparison result between the normalization processing result and a comparison threshold. Among them, the comparison threshold is calculated based on the rewards obtained by the sub-chain nodes in the previous round of federated learning, the sum of the rewards obtained by each of the sub-chain nodes in the sub-chain, and the expected number of consensus nodes to be selected. The rewards obtained by the previous round of training nodes are determined based on the accuracy of the target local parameters corresponding to the training nodes.
19. An electronic device, characterized in that, The electronic device includes a processor and a memory coupled to the processor. Among them, The memory is used to store a computer program. The processor is used to run the computer program to execute the method according to any one of claims 1 to 17.
20. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that can be run by a processor, and the computer program is used to implement the method according to any one of claims 1 to 17.
Citation Information
Patent Citations
Block processing method, node and system
CN110648137A
Transaction processing method, device, apparatus, system and medium of multi-chain system
CN111488202A
Federal learning task credible supervision and scheduling method and device based on state channel
CN113779617A
Federal learning method and system based on block chain and trusted execution environment
CN113837761A