A semi-asynchronous federated learning method based on tree graph blockchain
By using a semi-asynchronous federated learning method based on tree-graph blockchain, the problem of balancing security and efficiency in existing technologies is solved, achieving faster model training convergence and higher accuracy in distributed systems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUNAN UNIV
- Filing Date
- 2024-03-19
- Publication Date
- 2026-06-12
Smart Images

Figure CN118211674B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of information security and artificial intelligence, and in particular to a semi-asynchronous federated learning method based on tree-graph blockchain. Background Technology
[0002] Federated learning, as a machine learning method, can train models in a distributed manner while meeting user data privacy requirements. However, federated learning requires a fully trustworthy central node to coordinate the entire training process. This leads to performance limitations and vulnerability to single points of failure. To reduce this over-reliance on a central node, distributed federated learning distributes the functions of the central node across multiple nodes. However, in open and untrusted network environments, it is unable to cope with threats such as poisoning attacks and Byzantine attacks.
[0003] To address the aforementioned issues, existing technologies leverage the distributed and highly reliable characteristics of blockchain to propose a blockchain-based federated learning approach. This approach ensures that nodes can train models distributedly even in untrusted network environments. However, several problems remain to be solved. Currently, blockchain-based federated learning is primarily categorized into two types based on the blockchain's organizational structure: linked list-based and directed acyclic graph-based. Linked list-based federated learning ensures algorithm security, but its disadvantage is that it requires synchronous model training and generates significant consensus load, especially when node devices are highly heterogeneous, leading to a substantial decrease in efficiency. Directed acyclic graph-based federated learning, on the other hand, allows for asynchronous model training, and its consensus protocol reduces the consensus load, greatly improving its operational efficiency. However, its characteristic of not requiring all nodes to verify block validity also results in a lack of security guarantees. Furthermore, personalized training on individual nodes makes it difficult to generate a globally applicable model with strong generalization capabilities.
[0004] In summary, existing technologies for blockchain-based federated learning leverage the advantages of blockchain's decentralization, non-repudiation, and traceability to partially address the problems in federated learning. However, they also introduce the challenge of balancing security and efficiency. Summary of the Invention
[0005] To address the aforementioned technical problems, this invention proposes a semi-asynchronous federated learning method based on tree-graph blockchain.
[0006] The objective of this invention is achieved through the following technical solution:
[0007] This invention provides a semi-asynchronous federated learning method based on tree-graph blockchain, comprising the following steps:
[0008] S1. The initiator of the federated learning task generates a genesis block, which is then propagated via a P2P network. This genesis block contains the initial global model. Training batch size Learning rate Number of local training iterations The number of local models required for the verifier aggregation block Tolerable number of delayed blocks Longest running time of the algorithm and target accuracy .
[0009] S2. The client selects a suitable leaf block from the tree-graph blockchain, trains the global model in the leaf block to obtain a local model, packages the local model into a transaction, and finally propagates the transaction in the form of a P2P network.
[0010] S3. The verifier retrieves transactions from the P2P network and saves them to the local model pool. Suitable transactions are selected for aggregation to generate new blocks, which are then propagated through the P2P network.
[0011] As a further improvement, in step S2, the client selects a suitable leaf block from the tree-graph blockchain, including the following steps:
[0012] S21. The client collects all leaf blocks in the tree-graph blockchain as a candidate block pool. The client selects the leaf block with the highest global model accuracy from the candidate block pool as a candidate block.
[0013] S22. Calculate the length of the backbone chain containing the candidate block. Calculate the length of the backbone chain containing the leaf block from the client's last training iteration. If the length of the backbone chain containing the candidate block is greater than the length of the backbone chain containing the leaf block from the client's last training iteration, the candidate block meets the condition; otherwise, it does not.
[0014] S23. If the condition is not met, the client deletes the candidate block from the candidate block pool. Steps S21 to S23 are repeated until the candidate block meets the condition or the candidate block pool is empty.
[0015] As a further improvement, step S22 also includes determining the reference relationship of the blocks. The process involves backtracking to the genesis block using the edge with the highest weight to determine the backbone.
[0016] As a further improvement, if the candidate block pool is empty in step S23, the client will wait randomly for a period of time.
[0017] As a further improvement, before packaging the local model into a transaction in step S2, it should be checked whether the local model has made progress compared to the global model. If there is no progress, the client will not package and publish the local model.
[0018] As a further improvement, in step S2, packaging the local model into a transaction means creating a transaction number based on the local model and the leaf block. The client number timestamp The hash value of the leaf block The parameters of the local model and local model accuracy The transactions that constitute a whole.
[0019] As a further improvement, step S3 involves selecting appropriate transactions for aggregation to generate new blocks, including the following steps:
[0020] S31. The verifier uses the leaf block with the highest accuracy as the endpoint block of the backbone to calculate the backbone.
[0021] S32. The verifier uses the leaf block as the endpoint and backtracks from the main chain to count the number of tolerable lagging blocks. And sequentially obtain the timestamps of all blocks on the path. .
[0022] S33. The verifier uses the timestamp. The time interval for formation is selected from the local model pool based on the principle of having the highest proportion of the newest blocks while also taking into account lagging blocks. One matter.
[0023] S34. The verifier verifies the transaction and runs the Multi-krum algorithm from the... Filter out from each transaction One matter.
[0024] S35. According to the above Each transaction aggregates a model and generates a new block.
[0025] As a further improvement, in step S33, blocks are selected from the local model pool based on the principle of having the highest proportion of the newest blocks while also taking into account lagging blocks. A transaction, if the local model pool is at the timestamp The number of transactions within is less than Then the verifier will wait for a random period of time.
[0026] As a further improvement, in step S35, according to the... After a transaction aggregation model is completed and a new block is generated, all blocks with timestamps less than or equal to a certain value should be removed from the local model pool. The affairs.
[0027] As a further improvement, generating a new block in step S3 means generating a block with a block number. Reference relationships timestamp Merkel roots Global model parameters and global model accuracy For the block header and the appropriate transactions participating in the aggregation global model A new block for the block body.
[0028] Compared with the prior art, the advantages of the present invention are as follows:
[0029] 1. By introducing a tree-graph blockchain, this invention proposes a semi-asynchronous federated learning method based on tree-graph blockchain. This method provides better support for anomaly detection and semi-asynchronous training, achieving a good balance between the security and efficiency of distributed systems.
[0030] 2. This invention proposes a backbone-based sampling algorithm to guide clients and verifiers in selecting appropriate local and global models, thereby promoting faster convergence of model training in a distributed environment.
[0031] 3. This invention designs a consensus mechanism, which includes rules for block generation and verification, to ensure the correctness of the model and the security of the blockchain system. Attached Figure Description
[0032] Figure 1 This is a schematic diagram of the workflow of a specific embodiment of the present invention.
[0033] Figure 2 A comparison of the accuracy of this invention with BFL, BAFL, and DAGFL models on the MNIST dataset, based on a specific embodiment of the invention.
[0034] Figure 3 A comparison of the accuracy of this invention with the BFL, BAFL, and DAGFL models on the FMNIST dataset, based on a specific embodiment of the invention.
[0035] Figure 4 This invention provides a comparison of accuracy with BFL, BAFL, and DAGFL models on the CIFAR-10 dataset for specific embodiments.
[0036] Figure 5This invention provides a comparison of accuracy with BFL, BAFL, and DAGFL models on the SVHN dataset for specific embodiments. Detailed Implementation
[0037] The following is in conjunction with the instruction manual. Figure 1 The present invention will be further described with reference to specific preferred embodiments, but this does not limit the scope of protection of the present invention.
[0038] In this embodiment of the semi-asynchronous federated learning method based on tree-graph blockchain, there are requesters, clients, and verifiers. The requester refers to the initiator of the federated learning task, whose responsibilities specifically include: S1. The initiator of the federated learning task generates a genesis block and propagates it in a P2P network. The genesis block contains the initial global model. Training batch size Learning rate Number of local training iterations The number of local models required for the verifier aggregation block Tolerable number of delayed blocks Longest running time of the algorithm and target accuracy The client possesses private data and participates in the model training process. Its specific responsibilities include: S2. The client selects suitable leaf blocks from the tree-graph blockchain, trains the global model within those leaf blocks to obtain a local model, packages the local model into a transaction, and finally propagates the transaction via a P2P network. The verifier collects transactions from the client, aggregates the local model, and publishes new blocks. Its specific responsibilities include: S3. The verifier retrieves transactions from the P2P network and saves them to the local model pool. It selects suitable transactions, aggregates them to generate new blocks, and propagates the blocks via a P2P network. It should be noted that any node can play one or more roles.
[0039] In this embodiment, the communication delay between nodes follows... The Poisson distribution is used. Furthermore, to simulate the heterogeneous device problem under heterogeneous federated learning, this embodiment sets the node training capability to follow a Poisson distribution. The distribution follows a Poisson pattern, and the time points at which nodes join the system also follow a Poisson pattern. The Poisson distribution.
[0040] In this embodiment, the client repeatedly executes the following steps until a suitable leaf block is obtained from the blockchain: S21. The client collects all leaf blocks in the tree graph blockchain as a candidate block pool. The client selects the leaf block with the highest global model accuracy from the candidate block pool as a candidate block. S22. The client calculates the length of the backbone chain where the candidate block is located and calculates the length of the backbone chain where the leaf block in the client's last training was located. When the length of the backbone chain where the candidate block is located is greater than the length of the backbone chain where the leaf block in the client's last training was located, the candidate block meets the condition; otherwise, it does not meet the condition. S23. If the condition is not met, the client deletes the candidate block from the candidate block pool. Steps S21 to S23 are repeated until the candidate block meets the condition or the candidate block pool is empty.
[0041] In this embodiment, step S22 further includes determining the reference relationship of the blocks. The process involves backtracking to the genesis block using the edge with the highest weight to determine the backbone.
[0042] In this embodiment, if the candidate block pool is empty in step S23, the client waits for 5 seconds.
[0043] In this embodiment, before packaging the local model into a transaction in step S2, it is necessary to check whether the local model has made progress compared to the global model. That is, compared to the global model, the loss value of the local model... Has it decreased or is the accuracy rate low? Whether it progresses. If there is no progress, the client will not package and publish the local model.
[0044] In this embodiment, the step S2 of packaging the local model into a transaction refers to creating a transaction based on the local model and the leaf block, using the transaction number. The client number timestamp The hash value of the leaf block The parameters of the local model and local model accuracy The transactions that constitute a whole.
[0045] In this embodiment, the verifier selects suitable and sufficient transactions to aggregate and generate new blocks, which includes the following steps: S31. The verifier calculates the backbone using the leaf block with the highest accuracy as the endpoint block of the backbone. S32. The verifier uses the leaf block as the endpoint and backtracks from the backbone to the number of tolerable lagging blocks. And sequentially obtain the timestamps of all blocks on the path. S33. The verifier calculates based on the timestamp. The time interval for formation is selected from the local model pool based on the principle of having the highest proportion of the newest blocks while also taking into account lagging blocks. A transaction. S34. The verifier verifies the transaction and runs the Multi-krum algorithm from the... Filter out from each transaction One transaction. S35. According to the above Each transaction aggregates a model and generates a new block.
[0046] In this embodiment, step S33 selects blocks from the local model pool based on the principle of having the highest proportion of the newest blocks while also taking into account lagging blocks. A transaction, if the local model pool is at the timestamp The number of transactions within is less than Then the verifier will randomly select a time of 5 seconds.
[0047] In this embodiment, the Multi-krum algorithm in step S34 refers to calculating using the second norm data. The distances between the models in each transaction are calculated, and these distances are summed to obtain the score for each transaction. Then select from them. smallest One matter.
[0048] In this embodiment, step S35 is based on the... After a transaction aggregation model is completed and a new block is generated, all blocks with timestamps less than or equal to a certain value should be removed from the local model pool. The affairs.
[0049] In this embodiment, generating a new block in step S3 refers to generating a block with a block number. Reference relationships timestamp Merkel roots Global model parameters and global model accuracy For the block header and the appropriate transactions participating in the aggregation global model This is a new block within the block body. It is a dictionary consisting of the block numbers on which all transactions in the new block are based and the proportion of that block in all different blocks.
[0050] This example employs two different but carefully designed sets of hyperparameters for four different datasets. For MNIST and FMNIST, this example trains the local model using the SGD optimizer with a learning rate adjusted to 0.01. Simultaneously, this example trains the CIFAR-10 and SVHN models using the Adam optimizer with a learning rate set to 0.001. Both model update rules use the same batch size and local rounds, 64 and 5 respectively. The hysteresis tolerance threshold τ is set to 2, with a tolerance interval ratio of 0.4:0.6. Inter-node communication latency follows a set parameter. The Poisson distribution and node training ability follow The distribution follows a Poisson pattern, and the time points at which nodes join the system also follow a Poisson pattern. The Poisson distribution is used. This example tests the performance of 50 clients and 5 verifiers. Here, BFL represents federated learning based on a linear blockchain, where each block corresponds to a round number in traditional federated learning; BAFL represents federated learning based on a linear blockchain, where each trained model is aggregated with the global model to generate a new block, executing federated learning asynchronously; DAGFL represents federated learning based on a directed acyclic graph blockchain, where clients can asynchronously obtain the global model from the blockchain for training and publish new blocks without verifiers.
[0051] Figure 2 , Figure 3 , Figure 4 and Figure 5 The changes in the average accuracy of the global model of this example (TGFL) and the comparison schemes over time are shown. It can be observed that TGFL converges faster than other methods and outperforms all comparison schemes in terms of model accuracy. Specifically, DAGFL, which has a similar DAG structure to TGFL, shows competitive convergence speed, surpassing the comparison schemes based on linear blockchains, demonstrating the efficiency advantage of asynchronous training. However, in some cases, due to the smaller number of local models aggregated each time, DAGFL cannot achieve convergence accuracy equal to TGFL or even other linear comparison schemes. Furthermore, there are some noteworthy observations. TGFL and DAGFL are also more efficient than BAFL, which uses an asynchronous training mode. This is because BAFL is limited by its underlying linear blockchain structure, resulting in a slower consensus speed.
[0052] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the invention. Therefore, any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention should fall within the protection scope of the present invention.
Claims
1. A semi-asynchronous federated learning method based on tree-graph blockchain, characterized in that, Includes the following steps: S1. The initiator of the federated learning task generates a genesis block, which is propagated in the form of a P2P network. The genesis block contains the initial global model. Training batch size Learning rate Number of local training iterations The number of local models required for the verifier aggregation block Tolerable number of delayed blocks Longest running time of the algorithm and target accuracy , S2. The client selects a suitable leaf block from the tree-graph blockchain, trains the global model in the leaf block to obtain a local model, packages the local model into a transaction, and finally propagates the transaction in the form of a P2P network. The step S2, in which the client selects a suitable leaf block from the tree-graph blockchain, includes the following steps: S21. The client collects all leaf blocks in the tree-graph blockchain as a candidate block pool, and selects the leaf block with the highest global model accuracy from the candidate block pool as a candidate block. S22. Calculate the length of the backbone chain containing the candidate block, and calculate the length of the backbone chain containing the leaf block from the client's last training iteration. If the length of the backbone chain containing the candidate block is greater than the length of the backbone chain containing the leaf block from the client's last training iteration, the candidate block meets the condition; otherwise, it does not meet the condition. S23. If the condition is not met, the client deletes the candidate block from the candidate block pool and repeats steps S21 to S23 until the candidate block meets the condition or the candidate block pool is empty. S3. The verifier retrieves transactions from the P2P network and saves them to the local model pool. It then selects suitable transactions to aggregate and generate new blocks, and propagates these blocks through the P2P network. Step S3, selecting suitable transactions to aggregate and generate new blocks, includes the following steps: S31. The verifier uses the leaf block with the highest accuracy as the endpoint block of the backbone to calculate the backbone. S32. The verifier uses the leaf block as the endpoint and backtracks from the main chain to count the number of tolerable lagging blocks. And sequentially obtain the timestamps of all blocks on the path. , S33, The verifier calculates based on the timestamp The time interval for formation is selected from the local model pool based on the principle of having the highest proportion of the newest blocks while also taking into account lagging blocks. One transaction, S34, The verifier verifies the transaction and runs the Multi-krum algorithm from the... Filter out from each transaction One transaction, S35, according to the above Each transaction aggregates a model and generates a new block.
2. The semi-asynchronous federated learning method based on tree-graph blockchain according to claim 1, characterized in that: Step S22 also includes determining the reference relationship of the blocks. The process involves backtracking to the genesis block using the edge with the highest weight to determine the backbone.
3. The semi-asynchronous federated learning method based on tree-graph blockchain according to claim 2, characterized in that: If the candidate block pool is empty in step S23, the client will wait randomly for a period of time.
4. The semi-asynchronous federated learning method based on tree-graph blockchain according to claim 3, characterized in that: Before packaging the local model into a transaction in step S2, it should be checked whether the local model has made progress compared to the global model. If there is no progress, the client will not package and publish the local model.
5. The semi-asynchronous federated learning method based on tree-graph blockchain according to claim 4, characterized in that: In step S2, packaging the local model into a transaction means creating a transaction based on the local model and the leaf block, using the transaction number... The client number timestamp The hash value of the leaf block The parameters of the local model and local model accuracy The transactions that constitute a whole.
6. The semi-asynchronous federated learning method based on tree-graph blockchain according to claim 5, characterized in that: In step S33, blocks are selected from the local model pool based on the principle of having the highest proportion of the newest blocks while also taking into account lagging blocks. A transaction, if the local model pool is at the timestamp The number of transactions within is less than Then the verifier will wait for a random period of time.
7. The semi-asynchronous federated learning method based on tree-graph blockchain according to claim 6, characterized in that: In step S35, according to the... After a transaction aggregation model is completed and a new block is generated, all blocks with timestamps less than or equal to a certain value should be removed from the local model pool. The affairs.
8. The semi-asynchronous federated learning method based on tree-graph blockchain according to claim 7, characterized in that: In step S3, generating a new block refers to generating a block with a block number. Reference relationships timestamp Merkel roots Global model parameters and global model accuracy For block headers and appropriate transactions participating in the aggregation global model A new block for the block body.