Disclosure of Invention
In order to solve the above problem, the present application provides a block chain-based federal learning method, including: determining a pre-created block chain, wherein nodes of the block chain at least comprise participant nodes participating in federated learning and coordinator nodes processing data in the federated learning; the coordinator node creates a federal learning task according to the model original data sent by each participant node, and writes the federal learning task into the block chain; receiving training data obtained by local training of the participant node, and writing the training data into the block chain; sending parameters to be updated to other participant nodes according to the training data so that the other participant nodes update the model parameters of the other participant nodes according to the parameters to be updated; and after the model training is finished, issuing reward resources according to the training data provided by each participant node in the training process, and writing the reward resources into the block chain.
In one example, receiving training data obtained by the participant node training locally comprises: receiving intermediate gradient data obtained by local training of the participant nodes; sending the intermediate gradient data to a corresponding target participant node; receiving first feedback data which are returned by the target participant node and generated by training the model according to own label data; determining total gradient data in the current training round according to the first feedback data; sending parameters to be updated to other participant nodes according to the training data, wherein the parameters to be updated comprise: and sending the parameters to be updated to other participant nodes according to the total gradient data.
In one example, the issuing of reward resources according to the training data provided by each participant node in the training process includes: and issuing reward resources according to the training data provided by each participant node in the training process and the promotion effect of the training data on the model, wherein the training data comprises the intermediate gradient data and the first feedback data.
In one example, after sending the intermediate gradient data to the corresponding target participant node, the method further comprises: receiving second feedback data which are returned by the target participant node and represent that the target participant node does not own corresponding label data; and sending the intermediate gradient data to other target participant nodes.
In one example, before sending the parameters to be updated to the other participant nodes according to the training data, the method further comprises: and determining that the historical training data which is the same as the training data does not exist according to the historical training data received by the user.
In one example, the blockchain comprises a management node, an endorsement node and an accounting node, and intelligent contracts are deployed in the blockchain; the management node is used for controlling whether an external node is allowed to be deployed in the block chain as a participant node; the endorsement node is used for executing the intelligent contract and sending an execution result to the accounting node; and the accounting node is used for sending a notice to the corresponding node and processing the issuance and transaction of the reward resource.
In one example, the smart contract includes at least one of the model raw data, third party validation data, the training data, the reward resource.
In one example, the intelligent contract is for: when the original data of the model meet the preset requirements, creating the federal learning task; or the effect of the model is verified through the third party verification data, and the verification result is written into the block chain; or issuing the reward resource according to the training data.
In one example, the method further comprises: receiving inference calculation demand information sent by a first participant node; and sending the inference calculation demand information to a second participant node so that the second participant node assists the first participant node in carrying out inference calculation, and receiving the token sent by the first participant node as a reward of the transaction after the inference calculation is finished.
On the other hand, this application has still provided a block chain-based federal learning device, includes: the system comprises a determining module, a judging module and a judging module, wherein the determining module determines a pre-created block chain, and nodes of the block chain at least comprise participant nodes participating in federated learning and coordinator nodes processing data in the federated learning; the coordinator node creates a federal learning task according to the model original data sent by each participant node, and writes the federal learning task into the block chain; the receiving module is used for receiving training data obtained by local training of the participant node and writing the training data into the block chain; the updating module is used for sending parameters to be updated to other participant nodes according to the training data so that the other participant nodes update the model parameters of the other participant nodes according to the parameters to be updated; and the reward module is used for issuing reward resources according to the training data provided by each participant node in the training process after the model training is finished, and writing the reward resources into the block chain.
The federal learning method provided by the application can bring the following beneficial effects:
the block chains are effectively utilized, related interest parties participating in federal learning are combined, and block chain infrastructure is utilized to write into the block chains, so that the chain linking of the federal learning training reasoning whole life cycle is realized; compared with the traditional mode, the method effectively solves the mutual trust problem of each party through a unified and decentralized mode, increases the cooperation of each party, and reduces the trust cost and the operation cost of federal study; all parties participating in federal learning negotiate together to generate coordinator nodes, and the coordinator nodes monitor the operation process of the coordinator nodes together, so that the process transparency is improved; the data of the whole course of the federal study are recorded in the block chain, so that the traceability of data operation is ensured, related responsible parties are more effectively traced, the behaviors of federal study participants are standardized to a certain extent, all parties are encouraged to participate actively by rewarding resources, the enthusiasm of sharing high-quality data and mutual cooperation of the participants is improved, a more efficient and accurate model is formed, and the efficiency of final business is improved.
In addition, the whole process of federated learning joint modeling and reasoning can be realized in an intelligent contract form, the automatic execution of the intelligent contract also reduces the artificial influence, and the data privacy of the joint modeling process is ensured through means such as encryption transmission, digital summarization, anonymization, secure channel transmission and the like.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
As shown in fig. 1 and fig. 5, an embodiment of the present application provides a block chain-based federal learning method, where the method includes:
s101, determining a pre-created block chain, wherein nodes of the block chain at least comprise participant nodes participating in federal learning and coordinator nodes processing data in the federal learning.
First, a pre-created blockchain is determined, and as shown in fig. 3, infrastructure in the blockchain may be established by a blockchain service provider of the cloud data center in a P2P (peer-to-peer) consensus network, and a corresponding consensus algorithm is selected to form a P2P consensus network.
The cloud data center gathers a large amount of computing storage resources and provides cloud infrastructure services for federal learning participants, wherein the infrastructure services comprise a trusted execution environment, an encryption and decryption service, a block chain infrastructure service and a third-party certificate authentication service provided by a third-party digital authentication center.
In particular, the trusted execution environment provides a secure execution environment of the authorization security system, protecting the confidentiality, integrity, and access rights of application resources and data running on the trusted execution environment. Particularly, when the trusted execution environment in the cloud data center is in safe connection with the hardware encryption device, exclusive and special cryptographic service is provided for the trusted execution environment. The encryption and decryption services are provided by the cloud data center through hardware encryption equipment and comprise asymmetric encryption, digital signature, identity authentication, homomorphic encryption and the like. The blockchain infrastructure services are provided by providers, blockchain infrastructure is established in a P2P consensus network, and all intelligent contract execution status results are recorded in blockchains by creating a reward resource, such as a token, to which value is assigned as a reward, and disclosing the intelligent contract programs to be executed in blockchains for all participants and community developers to review. The third-party digital certificate authentication center is responsible for issuing digital certificates, can be provided by the block chain infrastructure in a matching way, and realizes the safe communication and identity authentication between the joint modeling participants and the block chain nodes.
The block chain at least comprises two types of nodes, one type of node is a participant node participating in the federal learning, each participant node runs a training program in a local trusted execution environment, and a model is trained together through the federal learning and provides corresponding data so as to complete the federal learning task. The other type is a coordinator node, and the coordinator node processes various data in the federal learning, such as collection, calculation and distribution of relevant parameters of the model, and simultaneously issues relevant intelligent contract determination process data and evaluation results. The coordinator node may be generated and supervised jointly by the participant nodes,
s102, the coordinator node creates a federal learning task according to the model original data sent by each participant node, and writes the federal learning task into the block chain.
After determining the blockchain, the participant nodes may collectively negotiate raw data that determines the model, where the raw data may include metadata, validation data sets, and service specifications of the coordinator node. And the coordinator node initializes, operates in a trusted operation environment, is connected with the encryption and decryption service, and issues a digital certificate by a digital certificate certification center for identity certification. And then, after the coordinator node receives the original data, a federal learning task can be created, and the federal learning task is written into the block chain.
Of course, third party verification data may be provided by each participant node to the coordinator node over a secure channel after the federal learning task is written into the blockchain. And the coordinator node executes the verification data set, generates a verification result after verifying the validity, and writes the verification result into the block chain.
S103, receiving training data obtained by local training of the participant node, and writing the training data into the block chain.
And S104, sending the parameters to be updated to other participant nodes according to the training data so that the other participant nodes update the model parameters of the other participant nodes according to the parameters to be updated.
After the federal learning task is established, the participant nodes correspondingly train in respective local places according to model original data to obtain training data, and then the training data is sent to the coordinator nodes, and the coordinator nodes can write the training data into the block chain. After the training data is obtained, the parameters to be updated may be determined based on the training data. The parameters to be updated here refer to parameters that need to be updated in the model after the model is trained. And then the parameters to be updated are sent to other participant nodes, and the other participant nodes can update the parameters of the model of the self body according to the parameters to be updated.
Specifically, the training method of the federal learning task is usually trained by a gradient descent method, so that the participant node does not have corresponding label data, a complete gradient training cannot be completed during training, intermediate gradient data can be generated, and at this time, the participant node can send the encrypted intermediate gradient data to the coordinator node through a trusted channel. Then the coordinator node determines whether the same intermediate gradient data exists according to the historical training data which is received by the coordinator node and stored locally. If the intermediate gradient data exists, the intermediate gradient data is sent before, only the intermediate gradient data is recorded and stored locally, and the intermediate gradient data does not need to be forwarded. If the intermediate gradient data does not exist, the intermediate gradient data is indicated to be new data, the intermediate gradient data can be sent to a target participant node with corresponding label data, the target participant node calculates loss according to the label data owned by the target participant node, corresponding feedback data (called first feedback data) is encrypted and then returned to the coordinator node, the coordinator node determines total gradient data in the training round according to the first feedback data, and sends parameters to be updated to other participant nodes according to the total gradient data. After updating the parameters, the other participant nodes may send acknowledgement messages to the participant nodes. The participant node can determine that the gradient update of the current round is completed.
In addition, if the target participant node does not own the corresponding label data and cannot be trained through the intermediate gradient data, a second feedback data indicating that the target participant node does not own the corresponding label data can be returned, and the coordinator node sends the second feedback data to other target participant nodes.
And S105, after model training is finished, distributing reward resources according to the training data provided by each participant node in the training process, and writing the reward resources into the block chain.
The model is continuously trained by the method in the steps until the loss function is converged, the model training can be determined to be completed, at this time, reward resources can be issued to each participant node according to training data provided by each participant node in the training process, such as intermediate gradient data and first feedback data, and the reward resources are written into the block chain. The bonus resource may be a token, a priority level when writing data to the blockchain, or some authority, and will not be described herein.
In one embodiment, the blockchain further comprises a management node, an endorsement node and an accounting node, and the blockchain is also deployed with an intelligent contract. Each participant node can jointly select a management node, an endorsement node and an accounting node in the blockchain, and a third-party digital certificate authentication center issues a digital certificate to realize mutual trust among the nodes. In the election, the three nodes may be elected from the participant nodes, or a new node may be created separately, which is not limited herein. The management node is used to control whether the external node is allowed to be deployed in the blockchain as a participant node, i.e. is responsible for admission of the participant node. And the endorsement node is used for executing the intelligent contract and sending an execution result to the accounting node. The accounting nodes reach consensus, generate new blocks, complete related operations according to preset rules, send notifications to corresponding nodes, and process the issuance and transaction of reward resources.
Further, as shown in FIG. 4, a corresponding intelligent contract may be generated and deployed in a blockchain. Wherein the smart contract comprises at least one of model raw data, third party verification data, training data, and reward resources. The intelligent contract is used for: when the original data of the model meet the preset requirements, creating a federal learning task; or verifying the effect of the model through third-party verification data, and writing a verification result into the block chain; or awarding bonus resources based on the training data. Because the intelligent contract is deployed on the block chain, each node can be examined, the rights and interests of each node are guaranteed, and the convenience in data processing is improved.
In particular, intelligent contracts may include creating mission intelligent contracts that are examined after each participant node provides model raw data. And if the corresponding requirements or standards are met, creating a federal learning task and starting to train the model. The method can also comprise a model initial effect intelligent contract and a model training effect intelligent contract, each participant node provides third party verification data, and when the model is not trained, the initial effect of the model is verified and written into a block chain; and after the model training is finished, verifying the training effect of the model and writing the training effect into the block chain. The method can also comprise gradient updating intelligent contracts, and in the training process of the model, the training data sent by each participant node in the training process of the round and the corresponding promotion effect can be written into the block chain every time the training of one gradient is completed. And the intelligent reward contract is also included, and reward resources are issued according to the data volume provided by each participant node and the model improvement effect after the model training is finished.
In one embodiment, if a participant node needs other nodes to assist itself in performing inference calculations, corresponding inference calculation requirement information can be sent to the coordinator node. And then the coordinator node sends the inference calculation requirement information to the second participant node after receiving the inference calculation requirement information sent by the first participant node. And after receiving the information, the second participant node assists the first participant node to carry out reasoning calculation, and after the reasoning calculation is finished, the second participant node receives the token sent by the first participant node as a reward of the transaction. The coordinator node may then write the process of this transaction into the blockchain.
It should be noted that, in the foregoing embodiment of the present application, when data is transmitted and received and data is written into a block chain, original data may be written, or data may be hashed and then written, which is not limited herein.
The embodiment of the present application further provides a block chain-based federal learning device, including:
the determining module 201 is configured to determine a pre-created block chain, where nodes of the block chain at least include a participant node participating in federated learning and a coordinator node processing data in the federated learning;
a creating module 202, where the coordinator node creates a federal learning task according to the model raw data sent by each participant node, and writes the federal learning task into the block chain;
the receiving module 203 receives training data obtained by local training of the participant node, and writes the training data into the block chain;
the updating module 204 is used for sending parameters to be updated to other participant nodes according to the training data so that the other participant nodes update the model parameters of the other participant nodes according to the parameters to be updated;
and the reward module 205, after the model training is completed, issues reward resources according to the training data provided by each participant node in the training process, and writes the reward resources into the block chain.
The above description is merely one or more embodiments of the present disclosure and is not intended to limit the present disclosure. Various modifications and alterations to one or more embodiments of the present description will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement or the like made within the spirit and principle of one or more embodiments of the present specification should be included in the scope of the claims of the present specification.