Block chain-based distributed federal learning method and device and terminal equipment

文档序号:8748 发布日期:2021-09-17 浏览:59次 中文

1. A distributed federated learning method based on a block chain is characterized in that the method comprises the following steps:

determining a pre-created blockchain, wherein the blockchain at least comprises participant nodes referring to federal learning and intelligent contracts used for executing federal learning tasks;

the participant node sends a calling transaction to an intelligent contract corresponding to federal learning, and determines global model parameters of a global network model through the intelligent contract;

the participant node updates the model parameters of the local network model stored in the participant node based on the global model parameters, and trains the updated local network model based on local training data to obtain local model parameters;

the participant node sends the local model parameters to the intelligent contract, and aggregates all the local model parameters received by the intelligent contract through the intelligent contract so as to update the global model parameters of the global network model;

and determining the reward resources corresponding to each participant node in the training process of the round through an intelligent contract, and writing the reward resources into the block chain.

2. The blockchain-based distributed federated learning method of claim 1, wherein the blockchain further includes a requester node for federated learning; before the participant node sends a call transaction to an intelligent contract corresponding to federal learning and determines global model parameters of a global network model through the intelligent contract, the method further comprises:

and the requester node stores the global network model in a preset storage space and writes training parameters corresponding to the global network model in the intelligent contract.

3. The distributed federal learning method based on blockchains according to claim 1, wherein the participant node sends a call transaction to an intelligent contract corresponding to federal learning, and the determining of global model parameters of a global network model by the intelligent contract specifically includes:

a participant node sends a calling transaction to an intelligent contract corresponding to federal learning, and a hash value of a global network model carried by the intelligent contract is obtained through the calling transaction;

and the reference node acquires the global model parameters in the preset storage space according to the hash value.

4. The blockchain-based distributed federated learning method of claim 1, wherein the participant node sends the local model parameters to the intelligent contract, and aggregates all the local model parameters received by the intelligent contract via the intelligent contract to update global model parameters of a global network model specifically includes:

participating the node to send the local model parameters to the intelligent contract;

when the received local model parameters of the intelligent contract reach a preset threshold value, calling a pre-compilation contract in the block chain through the intelligent contract, and aggregating all the local model parameters received by the intelligent contract through the compilation contract to update the global model parameters of the global network model.

5. The distributed federal learning method as claimed in claim 1 or 4, wherein the aggregation formula corresponding to all local model parameters received by the intelligent contract is:

where | D | represents the total amount of data for all local training data for all participant nodes, N represents the number of participant nodes, i represents the ith participant node,local model parameters, w, representing the ith round of training for the ith participant nodet+1The global model parameters obtained by the t-th round of training aggregation are shown as the t + 1-th round of training.

6. The distributed federal learning method based on blockchains as claimed in claim 1, wherein the determining, by means of a smart contract, the reward resource corresponding to each participant node in the current round of training process, and writing the reward resource into a blockchain specifically includes:

calling a precompiled contract in the block chain through an intelligent contract, determining reward resources corresponding to each participant node in the training process of the round through the precompiled contract, and writing the reward resources into the block chain.

7. The blockchain-based distributed federated learning method of claim 1, wherein a model structure of a local network model in each participant node is the same as a model structure of a global network model.

8. A distributed federal learning system based on blockchains, the system comprising:

the system comprises a determining module, a searching module and a searching module, wherein the determining module is used for determining a pre-created block chain, and the block chain at least comprises participant nodes for referring to federal learning and intelligent contracts for executing federal learning tasks;

the calling module is used for controlling the participant nodes to send calling transactions to intelligent contracts corresponding to federal learning, and determining global model parameters of the global network model through the intelligent contracts;

the training module is used for controlling the participant node to update the model parameters of the local network model stored in the participant node based on the global model parameters and train the updated local network model based on local training data to obtain local model parameters;

the aggregation module is used for controlling the participant node to send the local model parameters to the intelligent contract and aggregating all the local model parameters received by the intelligent contract through the intelligent contract so as to update the global model parameters of the global network model;

and the reward module is used for determining reward resources corresponding to each participant node in the training process of the round through an intelligent contract and writing the reward resources into the block chain.

9. A computer readable storage medium, storing one or more programs, which are executable by one or more processors, to implement the steps in the block chain based distributed federal learning method as claimed in any of claims 1-7.

10. A terminal device, comprising: a processor, a memory, and a communication bus; the memory has stored thereon a computer readable program executable by the processor;

the communication bus realizes connection communication between the processor and the memory;

the processor, when executing the computer readable program, implements the steps in the blockchain-based distributed federal learning method as claimed in any of claims 1-7.

Background

In the process of industry 4.0, the full utilization of data information has become an important force for enterprises to promote industrial revolution. But for privacy protection and competition among enterprises, small companies can hold relatively small amount of data, which is not favorable for the development of the companies in the 4.0 industrial process. The technology of federal learning is presented to solve the problem of small data volume mastered by small companies to a certain extent. That is, these companies may first perform model training locally using their own data, and then upload the trained local models to the central server for aggregation. And then, each company downloads the aggregated global model from the server and continues to use the data of the company to perform local training on the basis of the global model so as to obtain the global model with better performance.

The federal learning framework commonly used for the purpose needs to coordinate the whole federal learning process by a trusted central server, that is, in the traditional federal learning process, a participant pre-selects a third party as the central server to assist the third party in completing the model training process. However, the central server cannot guarantee complete honesty, thus making the federal learning process a security issue.

Thus, the prior art has yet to be improved and enhanced.

Disclosure of Invention

The technical problem to be solved by the present application is to provide a distributed federal learning method and apparatus based on a block chain, and a terminal device, aiming at the defects of the prior art.

In order to solve the above technical problem, a first aspect of the embodiments of the present application provides a distributed federated learning method based on a blockchain, where the method includes:

determining a pre-created blockchain, wherein the blockchain at least comprises participant nodes referring to federal learning and intelligent contracts used for executing federal learning tasks;

the participant node sends a calling transaction to an intelligent contract corresponding to federal learning, and determines global model parameters of a global network model through the intelligent contract;

the participant node updates the model parameters of the local network model stored in the participant node based on the global model parameters, and trains the updated local network model based on local training data to obtain local model parameters;

the participant node sends the local model parameters to the intelligent contract, and aggregates all the local model parameters received by the intelligent contract through the intelligent contract so as to update the global model parameters of the global network model;

and determining the reward resources corresponding to each participant node in the training process of the round through an intelligent contract, and writing the reward resources into the block chain.

The distributed federal learning method based on the block chain is characterized in that the block chain further comprises a requester node for federal learning; before the participant node sends a call transaction to an intelligent contract corresponding to federal learning and determines global model parameters of a global network model through the intelligent contract, the method further comprises:

and the requester node stores the global network model in a preset storage space and writes training parameters corresponding to the global network model in the intelligent contract.

The distributed federal learning method based on the block chain is characterized in that the participant node sends a call transaction to an intelligent contract corresponding to the federal learning, and the determination of the global model parameters of the global network model through the intelligent contract specifically comprises the following steps:

a participant node sends a calling transaction to an intelligent contract corresponding to federal learning, and a hash value of a global network model carried by the intelligent contract is obtained through the calling transaction;

and the reference node acquires the global model parameters in the preset storage space according to the hash value.

The distributed federal learning method based on the block chain includes the steps that the participant node sends the local model parameters to the intelligent contract, and all the local model parameters received by the intelligent contract are aggregated through the intelligent contract, so that the global model parameters of the global network model are updated specifically including:

participating the node to send the local model parameters to the intelligent contract;

when the received local model parameters of the intelligent contract reach a preset threshold value, calling a pre-compilation contract in the block chain through the intelligent contract, and aggregating all the local model parameters received by the intelligent contract through the compilation contract to update the global model parameters of the global network model.

The distributed federal learning method based on the block chain is characterized in that an aggregation formula corresponding to all local model parameters received by the intelligent contract is as follows:

where | D | represents the total amount of data for all local training data for all participant nodes, N represents the number of participant nodes, i represents the ith participant node,local model parameters, w, representing the ith round of training for the ith participant nodet +1The global model parameters obtained by the t-th round of training aggregation are shown as the t + 1-th round of training.

The distributed federal learning method based on the block chain includes the following steps that reward resources corresponding to participant nodes in the training process of the current round are determined through an intelligent contract, and the step of writing the reward resources into the block chain specifically includes:

calling a precompiled contract in the block chain through an intelligent contract, determining reward resources corresponding to each participant node in the training process of the round through the precompiled contract, and writing the reward resources into the block chain.

According to the distributed federal learning method based on the block chain, the model structure of the local network model in each participant node is the same as that of the global network model.

A second aspect of an embodiment of the present application provides a distributed federated learning system based on a blockchain, where the system includes:

the system comprises a determining module, a searching module and a searching module, wherein the determining module is used for determining a pre-created block chain, and the block chain at least comprises participant nodes for referring to federal learning and intelligent contracts for executing federal learning tasks;

the calling module is used for controlling the participant nodes to send calling transactions to intelligent contracts corresponding to federal learning, and determining global model parameters of the global network model through the intelligent contracts;

the training module is used for controlling the participant node to update the model parameters of the local network model stored in the participant node based on the global model parameters and train the updated local network model based on local training data to obtain local model parameters;

the aggregation module is used for controlling the participant node to send the local model parameters to the intelligent contract and aggregating all the local model parameters received by the intelligent contract through the intelligent contract so as to update the global model parameters of the global network model;

and the reward module is used for determining reward resources corresponding to each participant node in the training process of the round through an intelligent contract and writing the reward resources into the block chain.

A third aspect of embodiments of the present application provides a computer readable storage medium storing one or more programs, which are executable by one or more processors to implement the steps in the blockchain-based distributed federated learning method as described in any one of the above.

A fourth aspect of the embodiments of the present application provides a terminal device, including: a processor, a memory, and a communication bus; the memory has stored thereon a computer readable program executable by the processor;

the communication bus realizes connection communication between the processor and the memory;

the processor, when executing the computer readable program, implements the steps in the blockchain-based distributed federated learning method as described in any one of the above.

Has the advantages that: compared with the prior art, the application provides a distributed federal learning method, a distributed federal learning device and terminal equipment based on a block chain, wherein the method comprises the following steps: determining a pre-created block chain; the participant node sends a calling transaction to an intelligent contract corresponding to federal learning, and determines global model parameters of a global network model through the intelligent contract; the participant node updates the model parameters of the local network model stored in the participant node based on the global model parameters, and trains the updated local network model based on local training data to obtain local model parameters; the participant node sends the local model parameters to the intelligent contract, and aggregates all the local model parameters received by the intelligent contract through the intelligent contract so as to update the global model parameters of the global network model; and determining the reward resources corresponding to each participant node in the training process of the round through an intelligent contract, and writing the reward resources into the block chain. The function of the central server in the traditional federal learning is realized by using the intelligent contract on the block chain, so that the central server in the federal learning is replaced by the intelligent contract capable of performing trusted calculation, and the problem that the central server in the federal learning is not trusted can be solved.

Drawings

In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without any inventive work.

Fig. 1 is a flowchart of a distributed federal learning method based on a blockchain according to the present application.

Fig. 2 is a schematic flow chart of a distributed block chain-based federated learning method provided in the present application.

Fig. 3 is a timing flow chart of a distributed federal learning method based on a blockchain according to the present application.

Fig. 4 is a structural schematic diagram of a distributed federal learning device based on a block chain according to the present application.

Fig. 5 is a schematic structural diagram of a terminal device provided in the present application.

Detailed Description

The present application provides a block chain-based distributed federal learning method, apparatus and terminal device, and in order to make the purpose, technical scheme and effect of the present application clearer and clearer, the present application is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.

As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. As used herein, the term "and/or" includes all or any element and all combinations of one or more of the associated listed items.

It will be understood by those within the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. It will be further understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.

In particular implementations, the terminal devices described in embodiments of the present application include, but are not limited to, other portable devices such as mobile phones, laptops, or tablet computers with touch sensitive surfaces (e.g., touch displays and/or touch pads). It should also be understood that in some embodiments, the device is not a portable communication device, but is a desktop computer having a touch-sensitive surface (e.g., a touch-sensitive display screen and/or touchpad).

In the discussion that follows, a terminal device that includes a display and a touch-sensitive surface is described. However, it should be understood that the terminal device may also include one or more other physical user interface devices such as a physical keyboard, mouse, and/or joystick.

The terminal device supports various applications, such as one or more of the following: a drawing application, a presentation application, a word processing application, a video conferencing application, a disc burning application, a spreadsheet application, a gaming application, a telephone application, a video conferencing application, an email application, an instant messaging application, an exercise support application, a photo management application, a data camera application, a digital video camera application, a web browsing application, a digital music player application, and/or a digital video playing application, etc.

Various applications that may be executed on the terminal device may use at least one common physical user interface device, such as a touch-sensitive surface. The first or more functions of the touch-sensitive surface and the corresponding information displayed on the terminal may be adjusted and/or changed between applications and/or within respective applications. In this way, a common physical framework (e.g., touch-sensitive surface) of the terminal can support various applications with user interfaces that are intuitive and transparent to the user.

It should be understood that, the sequence numbers and sizes of the steps in this embodiment do not mean the execution sequence, and the execution sequence of each process is determined by its function and inherent logic, and should not constitute any limitation on the implementation process of this embodiment.

The inventor has found that, in the process of industry 4.0, the full utilization of data information becomes an important force for enterprises to promote the industrial revolution. But for privacy protection and competition among enterprises, small companies can hold relatively small amount of data, which is not favorable for the development of the companies in the 4.0 industrial process. The technology of federal learning is presented to solve the problem of small data volume mastered by small companies to a certain extent. That is, these companies may first perform model training locally using their own data, and then upload the trained local models to the central server for aggregation. And then, each company downloads the aggregated global model from the server and continues to use the data of the company to perform local training on the basis of the global model so as to obtain the global model with better performance.

The federal learning framework commonly used for the purpose needs to coordinate the whole federal learning process by a trusted central server, that is, in the traditional federal learning process, a participant pre-selects a third party as the central server to assist the third party in completing the model training process. However, the central server cannot guarantee complete honesty, thus making the federal learning process a security issue.

The block chain is used as a distributed account book database, data of the block chain is stored in a block and is commonly maintained by block chain nodes on the basis of a consensus mechanism, centralized equipment and management mechanisms are not needed, and trust problems do not exist among the nodes. Each block is connected in front and back to form a chain structure, and the chain data of the block chain has the characteristics of tamper resistance, traceability and the like through the chain structure of the block and a cryptography method. However, the blockchain techniques currently used for federal learning mainly include two categories, one is to use blockchain techniques to achieve distribution of model training rewards; in the method, the income of each participant is analyzed through theories such as a reputation mechanism or a game theory and the like, information such as rewards of each party is stored in a block chain, and transparent distribution of the rewards is guaranteed through the block chain, but the method is useless for the situation that whether a central server for federal learning (namely a third party in traditional federal learning) is malignant or not; the other type is a mechanism which stores and distributes auxiliary data such as keys and hashes by using a block chain, and designs a model aggregation mechanism by removing a central server through technologies such as cryptography and the block chain, but the method has a complicated flow and cannot ensure that each participant can collaboratively perform model aggregation.

Based on this, in the embodiment of the present application, a block chain created in advance is determined; the participant node sends a calling transaction to an intelligent contract corresponding to federal learning, and determines global model parameters of a global network model through the intelligent contract; the participant node updates the model parameters of the local network model stored in the participant node based on the global model parameters, and trains the updated local network model based on local training data to obtain local model parameters; the participant node sends the local model parameters to the intelligent contract, and aggregates all the local model parameters received by the intelligent contract through the intelligent contract so as to update the global model parameters of the global network model; and determining the reward resources corresponding to each participant node in the training process of the round through an intelligent contract, and writing the reward resources into the block chain. The function of the central server in the traditional federal learning is realized by using the intelligent contract on the block chain, so that the central server in the federal learning is replaced by the intelligent contract capable of performing trusted calculation, and the problem that the central server in the federal learning is not trusted can be solved.

The following further describes the content of the application by describing the embodiments with reference to the attached drawings.

The embodiment provides a distributed federal learning method based on a block chain, as shown in fig. 1, fig. 2 and fig. 3, the method includes:

and S10, determining a block chain created in advance.

Specifically, the blockchain is pre-established, and the blockchain includes an intelligent contract for performing federal learning tasks. The intelligent contract is used as a central server for federal learning, and the intelligent contract can carry out credibility calculation by coordinating the federal learning process, so that the intelligent contract can be used as the central server, and the problem that the central server is not credible can be solved. In one implementation of this embodiment, the blockchain may be a federation chain, which is one of blockchains that only allows authorized nodes to join the network, and the generation of each block is jointly determined by all preselected nodes, which may further improve the reliability of the federated learning process.

The block chain comprises a plurality of participant nodes, each participant node in the plurality of participant nodes runs a training process in a respective local trusted execution environment, and a common federal learning training model is used based on respective locally stored local training data to complete a federal learning task. In addition, the blockchain may further include a requester node, the requester node may be one of the participant nodes or a node independent of the participant nodes, the requester node is configured to initiate a federal learning task, write a training parameter in an intelligent contract corresponding to the federal learning, and deploy the intelligent contract written with the training parameter to a pre-established blockchain to start the federal learning.

Based on this, before the participant node sends a call transaction to a corresponding intelligent contract for federal learning and determines global model parameters of a global network model through the intelligent contract, the method further includes:

and the requester node stores the global network model in a preset storage space and writes training parameters corresponding to the global network model in the intelligent contract.

Specifically, the training parameters at least include hash values of global model parameters of the global network model, and after each round of training is completed, the hash values of the global model parameters in the intelligent contract are replaced with the hash values of the global model parameters obtained by the round of training. It can be understood that before the beginning of federal learning, the requester node determines a global network model to be trained, the global network model is stored in a preset storage space as a global network model, initial model parameters of the initial network model are used as global model parameters, and hash values of the global model parameters are stored in an intelligent contract, so that each participant node can acquire the hash values of the global model parameters through the intelligent contract and acquire the global model parameters in the preset storage space through the hash values of the global model parameters.

Therefore, in the first round of training of federal learning, the global model parameters of the global network model are the initial network parameters of the global network model, the hash values stored in the intelligent contract are the hash values of the initial model parameters, in the non-first round of training, the global model parameters of the global network model are the global model parameters obtained in the previous round of training, and the hash values stored in the intelligent contract are the hash values of the global model parameters obtained in the previous round of training. Therefore, the hash value of the global model parameter is stored in the intelligent contract, and the intelligent contract is disclosed to all participant nodes, so that all the participant nodes can acquire the global network parameter in a preset storage space through the hash value in the intelligent contract.

In one implementation manner of this embodiment, the training parameters may further include training condition parameters of the network model to be trained through the federal learning, preset thresholds of the participant nodes participating in the federal learning, and the like, where the training condition parameters may include a model learning rate, a loss function, a total number of training rounds, a total reward, and the like. In the first round of training, each participant node can acquire training condition parameters and preset threshold values of the participant nodes participating in federal learning through an intelligent contract so as to train the training condition parameters of the local network model, wherein the local network model and the global network model have the same model structure, the local network model and the global network model are different in model parameters, and the local network model updates the network model carried by the local network model by acquiring the global network model through the intelligent contract before training. Of course, in the first round of training or before the first round of training, each participant node may obtain the global network model stored therein through an intelligent contract in a preset storage space, and store the obtained global network model in the local of each participant node, so as to obtain the local network model corresponding to each participant node.

And S20, the participant nodes send calling transactions to the intelligent contracts corresponding to the federal learning, and the global model parameters of the global network model are determined through the intelligent contracts.

Specifically, the invoking transaction is used for invoking a training parameter in the intelligent contract to obtain a hash value of a global model parameter in the training parameter. Therefore, the global model parameters are obtained through the transaction form of the participants and the intelligent contract, the public process of the global model parameter obtaining process can be realized, and meanwhile, the credibility of the intelligent contract can be calculated based on the transaction.

In an implementation manner of this embodiment, the sending, by the participant node, a call transaction to an intelligent contract corresponding to federal learning, and determining, by the intelligent contract, a global model parameter of a global network model specifically includes:

a participant node sends a calling transaction to an intelligent contract corresponding to federal learning, and a hash value of a global network model carried by the intelligent contract is obtained through the calling transaction;

and the reference node acquires the global model parameters in the preset storage space according to the hash value.

Specifically, the preset storage space can be an IPFS node, the global model parameters corresponding to the global network model and the global model parameters corresponding to the global network model can be stored in the IPFS node, after the participant node obtains the hash value, the global model parameters can be automatically obtained from the preset storage space through the hash value, and therefore the participant node can select a mode of updating the model parameters of the local network model by itself through a mode of obtaining the global model parameters from the preset storage space through the hash value, the global model parameters are distributed without a central server, and accordingly federal learning can be achieved in a mode without the central server.

And S30, the participant node updates the model parameters of the local network model stored by the participant node based on the global model parameters, and trains the updated local network model based on local training data to obtain local model parameters.

Specifically, the model structure of the local network model is the same as the model structure of the global network model, and the difference between the local network model and the global network model is that the model parameters of the local network model are local model parameters obtained by training based on local training data, and the model parameters of the global network model are global model parameters obtained by aggregating the local model parameters obtained by training based on all participant nodes in the previous round of training. Of course, in the first round of training, the model parameters of the local network model and the model parameters of the global network model may be both initial model parameters.

The local training data are training data provided by participant nodes, the participant nodes train local network models only based on the local training data stored by the participant nodes, and the model parameters configured by the local network models are global model parameters acquired by the participant nodes through intelligent contracts. In addition, each participant node in federal learning knows its own stored local training data and knows that the local training data stored by each participant node except the participant node is unknown, which can ensure the confidentiality of the local training data stored by each participant node.

In an implementation manner of this embodiment, after obtaining the global model parameters and updating the model parameters of the local network model stored in the participant node by using the global model parameters, the participant node trains the updated local network model by using the local training data stored in the participant node. And after the local network model training of multiple iterations is finished, transmitting the local model parameters obtained by training to the corresponding intelligent contract in a transaction mode. Thus, the personal data of the participant nodes can be subjected to federal machine learning training even if kept locally. In a specific implementation, the update formula of the model parameters of the local network model of the participant node and the loss function may be:

the loss function for participant node i may be:

the update formula for the local model parameters of the participant node i may be:

wherein, | Di| represents a data set DiSize of data of fk(w) represents the loss function of a certain data sample k under a global model w, w(t)The global model parameters representing the t-th round,representing the local model parameters of participant i at round t +1, and η representing the learning rate.

And S40, the participant node sends the local model parameters to the intelligent contract, and aggregates all the local model parameters received by the intelligent contract through the intelligent contract to update the global model parameters of the global network model.

Specifically, the participant node sends the local model parameters to the intelligent contract in a transaction form, so that the intelligent contract acquires the local model parameters obtained by training of the participant node. After the intelligent contract obtains the local model parameters sent by each participant node, all the received local model parameters can be aggregated to obtain the global model parameters. In addition, after the global model parameters are obtained, the global model parameters are stored in a preset storage space, and the hash value of the global model parameters in the intelligent contract is modified into the hash value of the global model parameters obtained in the current round of aggregation, so that each participant node can obtain the global model parameters obtained in the current round of aggregation.

In an implementation manner of this embodiment, the sending, by the participant node, the local model parameter to the intelligent contract, and aggregating, by the intelligent contract, all the local model parameters received by the intelligent contract, so as to update the global model parameter of the global network model specifically includes:

participating the node to send the local model parameters to the intelligent contract;

when the received local model parameters of the intelligent contract reach a preset threshold value, calling a pre-compilation contract in the block chain through the intelligent contract, and aggregating all the local model parameters received by the intelligent contract through the compilation contract to update the global model parameters of the global network model.

Specifically, the preset threshold is a preset constraint condition for performing aggregation operation on the intelligent contract, wherein when the received local model parameters of the intelligent contract reach the preset threshold, the intelligent contract aggregates the received local model parameters, otherwise, when the received local model parameters of the intelligent contract do not reach the preset threshold, the intelligent contract continues to receive the local model parameters sent by the participant nodes, and until the received local model parameters of the intelligent contract reach the preset threshold, the received local model parameters are aggregated.

The precompiled contract is an operation stored in the blockchain in advance for executing all local model parameters received by the aggregated intelligent contract. Precompiled contracts are functions implemented in client code at the client, and the gas consumed to execute the precompiled contracts can be defined on its own as needed, thereby reducing the required gas through the aggregate operation. Compared with the aggregation operation directly performed by an intelligent contract, the aggregation operation performed by the pre-compiled contract can reduce the gas consumed by the aggregation operation, so that the aggregation operation of local model parameters needs to involve a large amount of data calculation and complex logic operation, while the intelligent contract calculates the gas according to the content of contract codes, when the operation involving a large amount of data calculation and complex logic operation is performed, the phenomena of low efficiency and large consumption of the gas can occur, while the pre-compiled contract is a function realized by client codes at a client, and when the pre-compiled contract is executed, the required gas can be defined as required, so that the gas consumed by the operation can be aggregated.

In an implementation manner of this embodiment, the aggregation formula corresponding to all local model parameters received by the intelligent contract is:

where | D | represents the total amount of data for all local training data for all participant nodes, N represents the number of participant nodes, i represents the ith participant node,local model parameters, w, representing the ith round of training for the ith participant nodet +1The global model parameters obtained by the t-th round of training aggregation are shown as the t + 1-th round of training.

And S50, determining the reward resources corresponding to each participant node in the training process through an intelligent contract, and writing the reward resources into a block chain.

Specifically, after the aggregation operation ends and the global model parameters generated by the aggregation operation are stored to the IPFS, the model training of the round ends. At the moment, the intelligent dating carries out reward calculation and distribution of each participant node by calling a precompiled contract written into the bottom layer of the block chain in advance. The reward distribution scheme may be determined according to actual needs, for example, distribution according to the data size of the local training data of the participant node, or distribution according to the reputation value of the participant node, or calculation for distribution according to the contribution of the sharley value to the participant node, and the like. In addition, a new round of model training may be performed after the reward distribution is completed.

Based on this, in an implementation manner of this embodiment, the determining, by an intelligent contract, reward resources corresponding to each participant node in the current round of training, and writing the reward resources into a block chain specifically includes:

calling a precompiled contract in the block chain through an intelligent contract, determining reward resources corresponding to each participant node in the training process of the round through the precompiled contract, and writing the reward resources into the block chain.

Specifically, the precompiled contracts are about precompiled into the bottom of the blockchain for performing reward calculation and distribution for each participant node. Precompiled contracts are functions implemented in client code at the client, and the gas consumed to execute the precompiled contracts can be defined by itself as required, thereby reducing the required gas through reward calculation. Compared with the reward calculation operation directly carried out by an intelligent contract, the reward calculation operation carried out by adopting the precompiled contract can reduce gas consumed by the reward calculation operation, so that the reward calculation needs to involve a large amount of data calculation and complex logic operation, the intelligent contract calculates the gas according to the content of contract codes, when the operation involving a large amount of data calculation and complex logic operation is executed, the phenomena of low efficiency and large amount of gas consumption can occur, the precompiled contract is a function realized by client codes at a client, and the required gas can be defined according to needs when the precompiled contract is executed, so that the gas consumed by the reward operation can be calculated. Furthermore, it is worth mentioning that the precompiled contracts for performing the aggregation operation and the precompiled contracts for performing the reward calculation may be the same, that is, the precompiled contracts have the functions of the aggregation operation and the reward calculation; or, the aggregation operation and the reward calculation operation may correspond to different precompiled contracts respectively, and the precompiled contracts corresponding to the aggregation operation are associated with the operations, and when the aggregation operation needs to be executed, the precompiled contract corresponding to the aggregation operation may be selected; when the reward calculation operation is performed, a precompiled contract corresponding to the reward calculation operation may be selected.

In summary, the embodiment provides a distributed federal learning method based on a blockchain, and the method includes: determining a pre-created block chain; the participant node determines global model parameters through an intelligent contract, updates the model parameters of the local network model based on the global model parameters, and trains the updated local network model based on local training data to obtain local model parameters; the participant node sends the local model parameters to the intelligent contract, and all the received local model parameters are aggregated through the intelligent contract to update the global model parameters; and determining the reward resources corresponding to each participant node in the training process through the intelligent contract. The function of the central server in the traditional federal learning is realized by using the intelligent contract on the block chain, so that the central server in the federal learning is replaced by the intelligent contract capable of performing trusted calculation, and the problem that the central server in the federal learning is not trusted can be solved.

Based on the above block chain-based distributed federal learning method, this embodiment provides a block chain-based distributed federal learning system, as shown in fig. 4, where the system includes:

a determining module 100, configured to determine a pre-created blockchain, where the blockchain includes at least a participant node that refers to federal learning and an intelligent contract for performing federal learning tasks;

the calling module 200 is used for controlling participant nodes to send calling transactions to intelligent contracts corresponding to federal learning, and determining global model parameters of a global network model through the intelligent contracts;

the training module 300 is configured to control the participant node to update the model parameters of the local network model stored in the participant node based on the global model parameters, and train the updated local network model based on local training data to obtain local model parameters;

an aggregation module 400, configured to control a participant node to send the local model parameters to the intelligent contract, and aggregate all the local model parameters received by the intelligent contract through the intelligent contract to update global model parameters of a global network model;

and the reward module 500 is configured to determine reward resources corresponding to each participant node in the current round of training through an intelligent contract, and write the reward resources into the block chain.

Based on the above block chain-based distributed federal learning method, this embodiment provides a computer-readable storage medium, which stores one or more programs that can be executed by one or more processors to implement the steps in the block chain-based distributed federal learning method according to the above embodiment.

Based on the above block chain-based distributed federal learning method, the present application also provides a terminal device, as shown in fig. 5, which includes at least one processor (processor) 20; a display screen 21; and a memory (memory)22, and may further include a communication Interface (Communications Interface)23 and a bus 24. The processor 20, the display 21, the memory 22 and the communication interface 23 can communicate with each other through the bus 24. The display screen 21 is configured to display a user guidance interface preset in the initial setting mode. The communication interface 23 may transmit information. The processor 20 may call logic instructions in the memory 22 to perform the methods in the embodiments described above.

Furthermore, the logic instructions in the memory 22 may be implemented in software functional units and stored in a computer readable storage medium when sold or used as a stand-alone product.

The memory 22, which is a computer-readable storage medium, may be configured to store a software program, a computer-executable program, such as program instructions or modules corresponding to the methods in the embodiments of the present disclosure. The processor 20 executes the functional application and data processing, i.e. implements the method in the above-described embodiments, by executing the software program, instructions or modules stored in the memory 22.

The memory 22 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal device, and the like. Further, the memory 22 may include a high speed random access memory and may also include a non-volatile memory. For example, a variety of media that can store program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk, may also be transient storage media.

In addition, the specific processes loaded and executed by the storage medium and the instruction processors in the mobile terminal are described in detail in the method, and are not stated herein.

Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:模型参数更新方法、装置、计算机可读介质及电子设备

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!