Decentralized federated learning method, device and electronic device based on blockchain
By dividing clients into groups in federated learning and using blockchain for intra-group and inter-group training, the problems of central server dependency and privacy leakage in federated learning are solved, and training efficiency and robustness are improved, ensuring that Security of data privacy.
Patent Information
- Application Number
- CN202111659352.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2041-12-30
AI Technical Summary
Existing federated learning methods rely too much on central servers, resulting in privacy leaks, trust crisis and inefficient training, especially when there are high numbers of clients, network congestion affects efficiency.
Adopt a decentralized federated learning method based on blockchain, divide the client into several groups, update the model and gradient transmission through intra-group and inter-group training sequences, avoid single point failure of the central server and network congestion, and use blockchain Encryption ensures data privacy.
Improve training efficiency and robustness, reduce the dependence of central servers, enhance data privacy protection, and avoid network congestion and trust crisis.
Smart Images

Figure CN114327901B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a decentralized federated learning method, device and electronic device based on blockchain. Background Art
[0002] As data privacy issues become increasingly serious, supervision of data sharing becomes increasingly strict, and the direct isolation of data means that government and enterprises cannot obtain enough data to train models that meet their needs, so federated learning came into being. Federated learning achieves data sharing by training its own model locally and encrypting and uploading model parameters. This model can also be well combined with blockchain.
[0003] In real-world scenarios, federated learning is often trained according to the following process: the model training initiator publishes the task and provides the initial global model; the data provider trains the model based on its own data and uploads its own gradient to the central server. However, if the central server is malicious, privacy leaks and other issues often occur, resulting in a crisis of trust, and if the central server fails, training will stagnate. In addition, when the number of clients is large, when the clients send gradient information to the central server at the same time, it may cause network congestion and affect training efficiency. In other words, the existing implementation methods of federated learning have the problem of over-reliance on central servers. Summary of the invention
[0004] The purpose of the present invention is to provide a decentralized federated learning method, device and electronic device based on blockchain to alleviate the technical problem of over-reliance on central servers in the prior art.
[0005] In order to achieve the above purpose, the technical solution adopted by the embodiment of the present invention is as follows:
[0006] In a first aspect, an embodiment of the present invention provides a decentralized federated learning method based on blockchain, which is applied to a model training initiation node in a blockchain system. The method includes:
[0007] According to the data set size of each client, the multiple clients are divided into several groups, and the training order within the group and the training order between the groups are determined; the clients include the initial global model sent by the blockchain; each of the clients corresponds to a blockchain node;
[0008] Based on the above intra-group training sequence, the initial global model of the above client in each group is trained intra-group to generate a standard update gradient for each group and a client model after intra-group training;
[0009] Based on the above inter-group training order, the above standard update gradient of the current group is sent to the next adjacent group;
[0010] The last client of the next adjacent group performs inter-group training based on the standard update gradient of the current group until all the clients are trained to generate a target model.
[0011] In some possible implementations, the method further includes: sharing the target model to all clients via blockchain; determining whether the target model converges; if the target model converges, ending the training; if the target model does not converge, repeating the steps of intra-group training and inter-group training until the target model converges.
[0012] In some possible implementations, before dividing the plurality of clients into a plurality of groups according to the data set size of each client, the method further includes: collecting the initial data set size of each client; determining the updated data set size of each client according to a data set size calculation formula as the data set size of the client; the data set size calculation formula is as follows: D′ i =D i *(1+Δ); where D i is the size of the actual data set of each client, Δ is a random number between the closed interval [-0.2, 0.2], D i 'The calculated dataset size for each client.
[0013] In some possible implementations, the plurality of clients are divided into a plurality of groups according to the data set size of each client, including: calculating the expected data set size of each group according to the data set size expectation formula; and grouping the plurality of clients based on the expected data set size of each group so that the difference in data set size between the groups is within a first preset range; the data set size expectation formula is as follows: Where N is the number of groups and K is the number of clients.
[0014] In some possible implementations, based on the above-mentioned intra-group training order, the initial global model of the above-mentioned client in each group is intra-group trained to generate a standard update gradient for each group and a client model after intra-group training, including: based on the above-mentioned intra-group training order, the initial global model of the first client in each group is trained at the same time, and a first update gradient and a first client model after intra-group training are generated respectively; according to the public key of the second client in each group, the above-mentioned first update gradient is encrypted respectively; the encrypted first update gradient is sent to the second client in each group; according to the private key of the second client in each group, the encrypted first update gradient is decrypted respectively; based on the decrypted first update gradient, the initial global model of the second client in each group is updated, and the updated initial global model of the second client in each group is trained to generate a second update gradient and a second client model after intra-group training respectively.
[0015] In some possible implementations, the method further includes: based on the training order within the group, storing the encrypted first update gradient of each group in the first block; based on the training order within the group, storing the encrypted second update gradient of each group in the second block.
[0016] In a second aspect, an embodiment of the present invention provides a decentralized federated learning device based on blockchain, comprising:
[0017] The first determination module is used to divide the plurality of clients into a plurality of groups according to the size of the data set of each client, and determine the intra-group training order and the inter-group training order; the client includes an initial global model sent by the blockchain; each of the clients corresponds to a blockchain node;
[0018] A first generating module is used to perform in-group training on the initial global model of the client in each group based on the in-group training sequence, and generate a standard update gradient for each group and a client model after in-group training;
[0019] A first sending module, configured to send the standard update gradient of the current group to the next adjacent group based on the inter-group training sequence;
[0020] The second generation module is used for the last client of the next adjacent group to perform inter-group training based on the standard update gradient of the current group until all the clients are trained to generate a target model.
[0021] In some possible implementations, the above device further includes:
[0022] Sharing module, used to share the above target model to all clients through blockchain;
[0023] The second determination module is used to determine whether the target model converges; if the target model converges, the training ends;
[0024] If the above target model does not converge, the above steps of within-group training and between-group training are repeated until the target model converges.
[0025] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, and when the processor executes the computer program, the steps of any one of the methods described in the first aspect are implemented.
[0026] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores machine-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to execute any method described in the first aspect above.
[0027] The present invention provides a decentralized federated learning method, device and electronic device based on blockchain, the method comprising: dividing multiple clients into several groups according to the data set size of each client, and determining the intra-group training order and the inter-group training order; based on the intra-group training order, performing intra-group training on the initial global model of the clients in each group, generating the standard update gradient of each group and the client model after intra-group training; based on the inter-group training order, sending the standard update gradient of the current group to the next adjacent group; the last client of the next adjacent group performs inter-group training based on the standard update gradient of the current group until all the client training is completed and the target model is generated. The above method solves the technical problem of high centralization of the traditional federated learning method and achieves the technical effect of improving training efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 A flowchart of a decentralized federated learning method based on blockchain provided in an embodiment of the present invention;
[0030] Figure 2 A schematic diagram of grouping and training sequence of a decentralized federated learning method based on blockchain provided in an embodiment of the present invention;
[0031] Figure 3 A schematic diagram of the structure of a decentralized federated learning device based on blockchain provided in an embodiment of the present invention;
[0032] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0034] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0035] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings. Some embodiments of the present invention are described in detail below in conjunction with the drawings. The following embodiments and features in the embodiments can be combined with each other without conflict.
[0036] In real-world scenarios, federated learning is often trained according to the following process: the model training initiator publishes the task and provides the initial global model; the data provider trains the model based on its own data and uploads its own gradient to the central server. However, if the central server is malicious, privacy leaks and other issues often occur, resulting in a trust crisis, and if the central server fails, the training will stagnate. In addition, when the number of clients is large, when the clients send gradient information to the central server at the same time, it may cause network congestion and affect training efficiency.
[0037] To solve this problem, the present invention proposes a decentralized federated learning algorithm based on blockchain. To facilitate understanding of this embodiment, the decentralized federated learning method based on blockchain disclosed in the embodiment of the present invention is first introduced in detail. Figure 1 The flowchart of a decentralized federated learning method based on blockchain is shown. The method is applied to a model training initiation node in a blockchain system and can be executed by an electronic device. The method mainly includes the following steps S101 to S104:
[0038] S101: Divide multiple clients into several groups according to the data set size of each client, and determine the intra-group training order and inter-group training order; the client includes an initial global model sent by the blockchain; each client corresponds to a blockchain node;
[0039] S102: Based on the intra-group training order, perform intra-group training on the initial global model of the client in each group, generate a standard update gradient for each group and a client model after the intra-group training;
[0040] S103: Based on the inter-group training order, send the standard update gradient of the current group to the next adjacent group;
[0041] S104: The last client of the next adjacent group performs inter-group training based on the standard update gradient of the current group until all clients are trained and a target model is generated.
[0042] In one embodiment, the method further includes: sharing the target model to all clients via blockchain;
[0043] Determine whether the target model converges; if the target model converges, end the training; if the target model does not converge, repeat the above steps of within-group training and between-group training until the target model converges.
[0044] In one embodiment, before the above step S101, it is necessary to determine the size of the data set of each client, that is, the method may further include:
[0045] (1) Collect the initial size of the dataset for each client;
[0046] (2) According to the data set size calculation formula, the size of the data set after each client update is determined as the client data set size;
[0047] (3) The formula for calculating the dataset size is as follows: D′ i =D i *(1+Δ);
[0048] Where D i is the size of the actual data set of each client, Δ is a random number between the closed interval [-0.2, 0.2], D i 'The calculated dataset size for each client.
[0049] As a specific example, the above step S101 includes:
[0050] (1) Calculate the expected dataset size of each group according to the expected dataset size formula;
[0051] (2) based on the expected data set size of each group, grouping the plurality of clients so that the difference in data set size between the groups is within a first preset range;
[0052] The expected formula for the dataset size is as follows:
[0053] Where N is the number of groups and K is the number of clients.
[0054] In one embodiment, the above step S120 includes:
[0055] First, based on the intra-group training order, the initial global model of the first client in each group is trained simultaneously, and the first update gradient and the first client model after the intra-group training are generated respectively;
[0056] Then, the first update gradient is encrypted respectively according to the public key of the second client in each group;
[0057] Then the encrypted first updated gradient is sent to the second client in each group;
[0058] and decrypting the encrypted first update gradient according to the private key of the second client in each group;
[0059] Based on the decrypted first update gradient, the initial global model of the second client in each group is updated; the updated initial global model of the second client in each group is trained to generate a second update gradient and a second client model after training in the group, respectively.
[0060] In an embodiment of the present invention, after each client node obtains the gradient information of the previous client, it uses the gradient information of the previous client to update its own initial global model, and then trains to obtain its own gradient. After the training of the last client node is completed, the target model is shared with all other nodes.
[0061] In an embodiment of the present invention, each group of encrypted first updated gradients is stored in a first block, and each group of encrypted second updated gradients is stored in a second block. That is, after grouping, the gradient information transmitted by each group of corresponding client nodes is placed in the same block. For example: there are 9 nodes, divided into three groups A, B, and C, and each group has three nodes. When uploading the updated gradient, the gradient information of the first node of A is placed in the same block as the gradient information of the first node of group B and the first node of group C. The purpose is to save blocks. Each round of training uses fewer blocks to store and send gradients, and the generation of blocks takes time, which means that the communication cost of each round is saved.
[0062] The present invention provides a decentralized federated learning method, device and electronic device based on blockchain, the method comprising: dividing multiple clients into several groups according to the data set size of each client, and determining the intra-group training order and the inter-group training order; based on the intra-group training order, performing intra-group training on the initial global model of the clients in each group, generating the standard update gradient of each group and the client model after intra-group training; based on the inter-group training order, sending the standard update gradient of the current group to the next adjacent group; the last client of the next adjacent group performs inter-group training based on the standard update gradient of the current group until all the client training is completed and the target model is generated. The above method solves the technical problem of high centralization of the traditional federated learning method, avoids the training stagnation caused by the downtime of the central server, and achieves the technical effect of improving robustness and enhancing training efficiency.
[0063] As a specific example, an embodiment of the present invention provides a decentralized federated learning method based on blockchain, comprising the following steps:
[0064] First, the training initiator collects the data set size of each client through the blockchain, and requires each client to publish its own public key. Each client saves the public keys of all other nodes.
[0065] Then the first round of training begins, and the training initiator updates the size formula D′ through the data set. i =D i *(1+Δ), where D i is the actual data set size of each client, Δ is a random number between the closed interval [-0.2, 0.2] and needs to be regenerated for each calculation, and D′ is the data set size calculated by each client, which helps to achieve dynamic grouping and avoid the same members in each group in each round of training.
[0066] According to the formula Calculate the expected data set size of each group to group the clients, and try to make the data set size of each group similar, where N is the number of groups and K is the number of clients. The number of groups is specified by the training initiator, and the update order within the group is specified.
[0067] Then each group starts training synchronously. After each client completes training, its updated gradient is encrypted with the public key of the next client and sent to the next client through the blockchain.
[0068] After receiving the updated gradient from the previous client, the client uses its own private key to decrypt it, then uses the gradient from the previous client to update its own model, trains the model again, and encrypts the gradient and sends it to the next client. Repeat the above process until each group of clients has completed training.
[0069] Then the last updated client in the first group sends its gradient to the last client in the next group through public key encryption. The last client in the next group updates its own model with the gradient, trains the model again and sends the gradient to the next client after encryption (see Figure 2 The above process is repeated until the last client in each group has completed training. At this time, the last trained client shares its model with every node through blockchain broadcast.
[0070] At this point, the first round of training ends, and the first round of training process is repeated until the model converges.
[0071] As a specific example, there are 9 clients A, B, C, D, E, F, G, H, and I, and the training initiator specifies that the number of groups is 3.
[0072] The training initiator publishes the training task and sends the initial global model to all clients through the blockchain.
[0073] After receiving the model, each client uploads its own public key and data set size D1~D9 through the blockchain.
[0074] After the training initiator receives the data set size D1~D9 of each client, it uses the formula D′ i =D i *(1+Δ) calculate D′1~D′9 respectively, and then calculate the expected data set size of each group Group clients so that the size of each group is as close to D as possible e .
[0075] Assume that the grouping is A, D, G as the first group, B, E, H as the second group, and C, F, I as the third group. And the training order within the group is specified as A→D→G, B→E→H, C→F→I.
[0076] Then each group starts training. In the first group, A starts training. After the training, the updated gradient is encrypted with D's public key and sent to the blockchain. After D obtains A's encrypted information, it first decrypts it with its own private key, and updates its own model with A's gradient and then trains. After the training, the gradient is encrypted with G's public key and sent to the blockchain. After G receives D's encrypted information, it first decrypts it with its own key, and updates its own model with D's gradient and then trains. After G's training, one group of training is finished. The second and third groups are trained in the same way. It should be noted that the gradient information of A, B, and C is placed in the same block. The same is true for D, E, and F. This can save the blocks required for training and reduce communication costs.
[0077] When all groups have completed training, the last client in the first group, G, encrypts its own gradient with H's public key and sends it to the blockchain. After H receives G's encrypted information, it decrypts it with its own private key, and updates its own model with H's gradient and then trains. After the training, the gradient is encrypted with I's public key and sent to the blockchain. After receiving H's encrypted information, I first decrypts it with its own key, and updates its own model with H's gradient and then trains. After the training, I sends its own model through the blockchain, and each client updates its model.
[0078] At this point, the first round of training ends. If the model converges, training will not continue. If it does not converge, the training initiator will calculate D′1~D′9 and D e , regroup and train until the model converges and the training ends.
[0079] It should be noted that the training of the three nodes A, B, and C was carried out simultaneously at the beginning. After the training, each node's own gradient was encrypted with a public key and placed on the same block. For example, node A should be encrypted with the public key of node D to ensure that other nodes cannot obtain the gradient information and that D can obtain the gradient information. At this time, D, E, and F have each obtained the gradient information of the previous node, and use this gradient to update their own models respectively. After the update, they are sent to G, H, and I in the above manner. After G, H, and I update the model, G starts training first, and encrypts its own gradient with H's public key and uploads it to the block. After receiving the gradient, H updates the model and then trains again, and similarly sends the gradient to I. After I completes training, a round of training is completed, and I's model is sent to all clients via blockchain.
[0080] The present invention provides a decentralized federated learning method based on blockchain, comprising: dividing a plurality of clients into a plurality of groups according to the data set size of each client, and determining an intra-group training order and an inter-group training order; based on the intra-group training order, performing intra-group training on the initial global model of the clients in each group, generating a standard update gradient for each group and a client model after the intra-group training; based on the inter-group training order, sending the standard update gradient of the current group to the next adjacent group; performing inter-group training on the last client of the next adjacent group based on the standard update gradient of the current group, until all the client training is completed, and a target model is generated. The method solves the technical problem of high centralization of traditional federated learning methods and achieves the technical effect of improving training efficiency.
[0081] The embodiment of the present invention provides a decentralized federated learning device based on blockchain, referring to Figure 3 , the device comprises:
[0082] The first determination module 310 is used to divide the multiple clients into several groups according to the data set size of each client, and determine the training order within the group and the training order between the groups; the client includes the initial global model sent by the blockchain; each client corresponds to a blockchain node;
[0083] A first generating module 320 is used to perform in-group training on the initial global model of the client in each group based on the in-group training order, and generate a standard update gradient for each group and a client model after in-group training;
[0084] A first sending module 330, configured to send the standard update gradient of the current group to the next adjacent group based on the inter-group training order;
[0085] The second generation module 340 is used for the last client of the next adjacent group to perform inter-group training based on the standard update gradient of the current group until all the clients are trained and the target model is generated.
[0086] In one embodiment, the device further includes: a sharing module, configured to share the target model to all clients via blockchain;
[0087] The second determination module is used to determine whether the target model converges; if the target model converges, the training is terminated; if the target model does not converge, the above steps of intra-group training and inter-group training are repeated until the target model converges.
[0088] The decentralized federated learning device based on blockchain provided in the embodiment of the present application can be specific hardware on the device or software or firmware installed on the device, etc. The implementation principle and technical effects of the device provided in the embodiment of the present application are the same as those of the aforementioned method embodiment. For the sake of brief description, for the parts not mentioned in the device embodiment, reference can be made to the corresponding contents in the aforementioned method embodiment. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above can all refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. The decentralized federated learning device based on blockchain provided in the embodiment of the present application has the same technical features as the decentralized federated learning method based on blockchain provided in the aforementioned embodiment, so it can also solve the same technical problems and achieve the same technical effects.
[0089] An embodiment of the present application further provides an electronic device. Specifically, the electronic device includes a processor and a storage device. The storage device stores a computer program, and when the computer program is executed by the processor, it executes the method described in any one of the above-mentioned embodiments.
[0090] Figure 4A structural schematic diagram of an electronic device provided in an embodiment of the present application, the electronic device 400 includes: a processor 40, a memory 41, a bus 42 and a communication interface 43, wherein the processor 40, the communication interface 43 and the memory 41 are connected via the bus 42; the processor 40 is used to execute an executable module stored in the memory 41, such as a computer program.
[0091] The memory 41 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 43 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0092] The bus 42 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0093] Among them, the memory 41 is used to store programs, and the processor 40 executes the program after receiving the execution instruction. The method executed by the device for flow process definition disclosed in any embodiment of the above-mentioned embodiment of the present invention can be applied to the processor 40 or implemented by the processor 40.
[0094] The processor 40 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 40. The above processor 40 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiments of the present invention can be directly embodied as a hardware decoding processor to execute, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 41, and the processor 40 reads the information in the memory 41 and completes the steps of the above method in combination with its hardware.
[0095] Corresponding to the above method, an embodiment of the present application also provides a computer-readable storage medium, which stores machine-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the steps of the above method.
[0096] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0097] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0098] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0099] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, electronic device, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0100] It should be noted that similar numbers and letters represent similar items in the accompanying drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0101] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A decentralized federated learning method based on blockchain, characterized in that: A model training initiating node applied to a blockchain system, the method comprising: According to the data set size of each client, the plurality of clients are divided into a plurality of groups, and the intra-group training order and the inter-group training order are determined; the client includes an initial global model sent by the blockchain; each of the clients corresponds to a blockchain node; Based on the intra-group training sequence, perform intra-group training on the initial global model of the client in each group to generate a standard update gradient for each group and a client model after the intra-group training; Based on the inter-group training order, sending the standard update gradient of the current group to the next adjacent group; The last client of the next adjacent group performs inter-group training based on the standard update gradient of the current group until all the clients are trained to generate a target model; Wherein, based on the intra-group training sequence, the initial global model of the client in each group is trained in the group, and the standard update gradient of each group and the client model after the intra-group training are generated, including: Based on the intra-group training order, the initial global model of the first client in each group is trained simultaneously, and a first update gradient and a first client model after the intra-group training are generated respectively; Encrypting the first update gradients respectively according to the public key of the second client in each group; sending the encrypted first update gradient to the second client in each group; Decrypting the encrypted first update gradients according to the private key of the second client in each group; Based on the decrypted first update gradient, the initial global model of the second client in each group is updated, and the updated initial global model of the second client in each group is trained to generate a second update gradient and a second client model after training in the group respectively; Based on the training order within the group, storing the encrypted first update gradient of each group in a first block; Based on the intra-group training order, the encrypted second updated gradients of each group are stored in a second block.
2. The method according to claim 1, characterized in that The method further comprises: Sharing the target model to all clients via blockchain; Determine whether the target model converges; if the target model converges, end the training; If the target model does not converge, the above steps of intra-group training and inter-group training are repeated until the target model converges.
3. The method according to claim 2, characterized in that Before dividing the plurality of clients into a plurality of groups according to the size of the data sets of the respective clients, the method further comprises: Collect the initial size of the dataset for each client; According to the data set size calculation formula, determine the size of the data set after each client is updated as the data set size of the client; The data set size calculation formula is as follows: ; Where D i is the size of the actual data set of each client, ∆ is a random number between the closed interval [-0.2, 0.2], and D i 'The calculated dataset size for each client.
4. The method according to claim 1, characterized in that: According to the data set size of each client, the plurality of clients are divided into several groups, including: Calculate the expected data set size of each group according to the expected data set size formula; Based on the expected data set size of each group, the plurality of clients are grouped so that the difference in data set size between the groups is within a first preset range; The expected formula for the dataset size is as follows: ; Where N is the number of groups and K is the number of clients.
5. A decentralized federated learning device based on blockchain, characterized in that: include: A first determination module, used to divide the plurality of clients into a plurality of groups according to the size of the data set of each client, and determine the intra-group training sequence and the inter-group training sequence; The client includes an initial global model sent by the blockchain; each of the clients corresponds to a blockchain node; A first generating module is used to perform in-group training on the initial global model of the client in each group based on the in-group training order, and generate a standard update gradient for each group and a client model after in-group training; A first sending module, configured to send the standard update gradient of the current group to the next adjacent group based on the inter-group training sequence; A second generation module is used for the last client of the next adjacent group to perform inter-group training based on the standard update gradient of the current group until all the clients are trained and a target model is generated; The first generating module is further used to: simultaneously train the initial global model of the first client in each group based on the intra-group training sequence, and respectively generate a first update gradient and a first client model after the intra-group training; Encrypt the first update gradients according to the public keys of the second clients in each group; send the encrypted first update gradients to the second clients in each group; decrypt the encrypted first update gradients according to the private keys of the second clients in each group; update the initial global models of the second clients in each group based on the decrypted first update gradients, and train the updated initial global models of the second clients in each group to generate second update gradients and second client models trained in the groups; A storage module, configured to store the encrypted first update gradients of each group in a first block based on the training order within the group; The storage module is further used to store the encrypted second update gradient of each group in the second block based on the training order within the group.
6. The device according to claim 5, characterized in that The device also includes: A sharing module, used to share the target model to all clients via blockchain; A second determination module is used to determine whether the target model converges; if the target model converges, the training is terminated; If the target model does not converge, the above steps of intra-group training and inter-group training are repeated until the target model converges.
7. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores machine executable instructions. When the computer executable instructions are called and executed by a processor, the computer executable instructions prompt the processor to execute the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Federal learning data auditing system and method based on block chain
CN113111124A
Federal learning-based model training method, device and equipment and storage medium
CN113537518A