Model training method, device and equipment based on block chain
By building a multi-node joint training model on the blockchain, using dense state aggregation and decryption technology, the problem of insufficient training results of large language models is solved, and more accurate and reliable model training is achieved, while protecting data privacy.
Patent Information
- Application Number
- CN202510771889.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-06-11
Smart Images

Figure CN120277162A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and particularly to a model training method, device and equipment based on blockchain. Background Art
[0002] With the continuous development of science and technology, various prediction models have emerged. In the field of natural language processing, large language models have provided convenience for text classification, intelligent question answering, etc.
[0003] However, the existing training methods for large language models have the problem that the training results are not accurate enough. Summary of the Invention
[0004] In view of this, the present invention provides a model training method, device and equipment based on blockchain, mainly aiming to solve the problem that the existing training methods for large language models have inaccurate training results.
[0005] To solve the above problems, the present application provides a model training method based on blockchain, including: Obtaining initial second encrypted training parameters stored by each second node and initial first encrypted training parameters stored by the first node from the blockchain; Invoking a smart contract to perform encrypted aggregation on the initial first encrypted training parameters and each initial second encrypted training parameter to obtain initial aggregated encrypted training parameters; Decrypting the initial aggregated encrypted training parameters to obtain initial aggregated training parameters; Performing the next round of model training based on the initial aggregated training parameters, and storing the initial aggregated training parameters in the blockchain for each second node to perform the next round of model training based on the initial aggregated parameters, and obtaining the current second encrypted training parameters stored by each second node and the current first encrypted training parameters stored by the first node from the blockchain, until the predetermined training conditions are met, stopping the model training, taking the current aggregated training parameters as the target aggregated training parameters, and obtaining the target large language model.
[0006] To solve the above problems, the present application provides a model training method based on blockchain, which is applied to a second node in the blockchain and includes: Encrypting the initial second training parameters to obtain initial second encrypted training parameters, where the initial second training parameters are obtained by the second node through model training on the initial large language model; Storing the initial second encrypted training parameters in the blockchain; Obtaining the initial aggregated training parameters from the blockchain, where the initial aggregated training parameters are obtained by the first node through performing encrypted aggregation on each initial second encrypted training parameter obtained from the blockchain and the initial first encrypted training parameter of the first node and then decrypting. Perform the next round of model training based on the initial aggregated training parameters, encrypt the currently obtained second training parameters after training, and store them in the blockchain. Stop the model training until the predetermined training conditions are met. Use the received current aggregated training parameters as the target aggregated training parameters to obtain the target large language model.
[0007] To solve the above problems, the present application provides a blockchain-based model training device, including: A first acquisition module, configured to obtain the initial second encrypted training parameters stored by each second node and the initial first encrypted training parameters stored by the first node from the blockchain; An aggregation module, configured to call a smart contract to perform encrypted aggregation on the initial first encrypted training parameters and each initial second encrypted training parameter to obtain initial aggregated encrypted training parameters; A first decryption module, configured to decrypt the initial aggregated encrypted training parameters to obtain the initial aggregated training parameters; A first training module, configured to perform the next round of model training based on the initial aggregated training parameters, store the initial aggregated training parameters in the blockchain for each second node to perform the next round of model training based on the initial aggregated parameters, and obtain the currently obtained second encrypted training parameters stored by each second node and the currently obtained first encrypted training parameters stored by the first node from the blockchain. Stop the model training until the predetermined training conditions are met. Use the current aggregated training parameters as the target aggregated training parameters to obtain the target large language model.
[0008] To solve the above problems, the present application provides a blockchain-based model training device, including: An encryption module, configured to encrypt the initial second training parameters to obtain initial second encrypted training parameters, where the initial second training parameters are obtained by the second node through model training on the initial large language model; A storage module, configured to store the initial second encrypted training parameters in the blockchain; A second acquisition module, configured to obtain the initial aggregated training parameters from the blockchain, where the initial aggregated training parameters are obtained by the first node through encrypted aggregation and decryption based on each initial second encrypted training parameter obtained from the blockchain and the initial first encrypted training parameter of the first node; A second training module, configured to perform the next round of model training based on the initial aggregated training parameters, encrypt the currently obtained second training parameters after training, and store them in the blockchain. Stop the model training until the predetermined training conditions are met. Use the received current aggregated training parameters as the target aggregated training parameters to obtain the target large language model.
[0009] To solve the above problems, the present application provides an electronic device, which at least includes a memory and a processor. A computer program is stored on the memory, and when the processor executes the computer program on the memory, the steps of the above-mentioned blockchain-based model training method are implemented.
[0010] In the blockchain-based model training method, device, and equipment of the present application, by constructing a blockchain and jointly performing model training based on multiple nodes (the first node and the second node) in the blockchain, the obtained target large language model can be made more accurate and reliable. Moreover, the first node obtains the second encrypted training parameters encrypted by each second node from the blockchain, and performs encrypted aggregation based on each second encrypted training parameter and the first encrypted training parameter of the first node, which can prevent the leakage of training parameters and protect data privacy.
[0011] The above description is only an overview of the technical solution of the present invention. In order to be able to understand the technical means of the present invention more clearly, it can be implemented according to the content of the description. And in order to make the above and other purposes, features, and advantages of the present invention more obvious and understandable, the following specifically describes the embodiments of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] By reading the following detailed description of the preferred embodiments, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only for the purpose of showing the preferred embodiments and are not considered to be a limitation of the present invention. Moreover, throughout the drawings, the same reference numerals are used to represent the same components. In the drawings: Figure 1 It is a flowchart of a blockchain-based model training method according to an embodiment of the present application; Figure 2 It is a flowchart of a blockchain-based model training method according to another embodiment of the present application; Figure 3 It is a structural block diagram of another blockchain-based model training device according to an embodiment of the present application; Figure 4 It is a structural block diagram of another blockchain-based model training device according to an embodiment of the present application; Figure 5 It is a structural block diagram of another electronic device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0013] Reference is made herein to the various aspects and features of the present application with reference to the drawings.
[0014] It should be understood that various modifications can be made to the embodiments applied herein. Therefore, the above description should not be regarded as a limitation, but only as an example of the embodiments. Those skilled in the art will think of other modifications within the scope and spirit of the present application.
[0015] The accompanying drawings, which are included in and form a part of this specification, illustrate embodiments of the present application and, together with the general description of the present application given above and the detailed description of the embodiments given below, serve to explain the principles of the present application.
[0016] These and other features of the present application will become apparent from the following description of the preferred forms of the embodiments, given by way of non-limiting example with reference to the accompanying drawings.
[0017] It should also be understood that although the present application has been described with reference to some specific examples, those skilled in the art can surely implement many other equivalent forms of the present application.
[0018] The above and other aspects, features and advantages of the present application will become more apparent in view of the following detailed description when taken in conjunction with the accompanying drawings.
[0019] Specific embodiments of the present application will be described hereinafter with reference to the accompanying drawings; however, it should be understood that the embodiments claimed are merely examples of the present application and can be implemented in many ways. Well-known and / or repetitive functions and structures are not described in detail to avoid obscuring the present application with unnecessary or redundant details. Therefore, the specific structural and functional details claimed herein are not intended to be limiting, but are merely a basis for the claims and a representative basis for teaching those skilled in the art to use the present application in substantially any suitable detailed structure in a variety of ways.
[0020] This specification may use the phrases "in one embodiment", "in another embodiment", "in yet another embodiment" or "in other embodiments", each of which may refer to one or more of the same or different embodiments according to the present application.
[0021] Embodiments of the present application provide a blockchain-based model training method. In the present application, a financial infrastructure may be pre-determined as the leading party / first node for constructing a federated large language model; other financial facilities or large financial institutions may be direct participating parties / second nodes for joint modeling. Then, the first node and each second node jointly construct a consortium chain / blockchain. The method in this embodiment is specifically applied to the first node in the blockchain, such as Figure 1 as shown, and includes the following steps: Step S101, obtaining the initial second encrypted training parameters stored by each second node and the initial first encrypted training parameters stored by the first node from the blockchain; In the specific implementation process of this step, the first node can send the initial parameters of the large language model (base model) as the base to each second node through the GRPC communication component within the federated learning framework. Thus, each second node can use the local training set to train the base model / initial large language model to obtain the initial second training parameters, then encrypt the initial second training parameters to obtain the initial second encrypted training parameters, and store the initial second encrypted training parameters in the blockchain. Similarly, the first node will also use the local training set to train the base model / initial large language model to obtain the initial first training parameters, then encrypt the initial first training parameters to obtain the initial first encrypted training parameters, and store the initial first encrypted training parameters in the blockchain. Thus, the first node can call the smart contract pre-stored in the blockchain, and obtain each initial second encrypted training parameter and the initial first encrypted training parameter from the blockchain through the smart contract, laying a foundation for subsequent encrypted aggregation and decryption of the aggregated encrypted training parameters.
[0022] In the specific implementation process of this embodiment, each second node can encrypt the initially obtained second training parameters using the first public key of the first node.
[0023] Step S102: Call the smart contract to perform encrypted aggregation on the initial first encrypted training parameter and each initial second encrypted training parameter to obtain the initial aggregated encrypted training parameter; In the specific implementation process of this step, the first node can execute the smart contract to perform encrypted aggregation on all the intermediate parameters (the initial first encrypted training parameter and each initial second encrypted training parameter) obtained in this training in the blockchain, so as to obtain the initial aggregated encrypted training parameter.
[0024] Step S103: Decrypt the initial aggregated encrypted training parameter to obtain the initial aggregated training parameter; In the specific implementation process of this step, the first node can use the first private key corresponding to the first public key to decrypt the initial aggregated encrypted training parameter.
[0025] Step S104: Based on the initial aggregated training parameter, perform the next round of model training, and store the initial aggregated training parameter in the blockchain for each second node to perform the next round of model training based on the initial aggregated parameter, and obtain the current second encrypted training parameter stored by each second node and the current first encrypted training parameter stored by the first node from the blockchain. When the predetermined training conditions are met, stop the model training, use the current aggregated training parameter as the target aggregated training parameter, and obtain the target large language model.
[0026] In the specific implementation of this step, after obtaining the initial aggregation training parameters, the first node can perform the next round of model training based on the initial aggregation training parameters and store the initial aggregation training parameters in the blockchain. Thus, each second node can obtain the initial aggregation training parameters from the blockchain and then perform the next round of model training based on the initial aggregation training parameters until the model training is stopped when the predetermined training conditions are met. For example, when the number of training rounds is greater than the predetermined number of rounds, or the error value of the currently obtained aggregation training parameters is less than the predetermined error threshold, the model training can be stopped. At this time, the currently obtained aggregation training parameters can be used as the target aggregation training parameters, thereby obtaining the target large language model.
[0027] In the method of this embodiment, by constructing a blockchain and jointly performing model training based on multiple nodes (the first node and the second node) in the blockchain, the obtained target large language model can be made more accurate and reliable. Moreover, the first node can prevent the leakage of training parameters and protect data privacy by obtaining the encrypted second encryption training parameters of each second node from the blockchain and performing encrypted aggregation based on the second encryption training parameters of each second node and the first encryption training parameters of the first node.
[0028] Based on the above embodiment, another embodiment of the present application provides a blockchain-based model training method, which is applied to the first node in the blockchain and specifically includes the following steps: Step S201, construct a blockchain; In this step, as the leading party / first node, the financial infrastructure, as the main computing node of federated learning and the central node / first node of the consortium chain, installs and deploys a distributed network in its data center and provides a distributed network node deployment installation package, which is sent to the direct participants / second nodes (other financial infrastructures and large financial institutions) participating in the joint modeling. The second node deploys and installs the above program in its data center and becomes a slave computing node of federated learning and a full node of the consortium chain to join the distributed network.
[0029] Step S202, install the on-chain smart contract and initialize the federated large language model.
[0030] In this step, a smart contract can be pre-installed in the blockchain. Specifically, the first node (the leading party) on the consortium blockchain / blockchain proposes to install the smart contract used for the encrypted training of the federated large language model on the chain. Each second node (the direct participating party) votes respectively. After obtaining more than half of the weight approval, the required smart contract will be installed in the consortium blockchain. In this embodiment, the architecture of the consortium blockchain can be implemented using other software products with the same functions such as Hyperledger Fabric, FISCO BCOS, Chang'an Chain, and CITA. In this embodiment, Fabric 2.2 version can be used as the consortium blockchain base, and domestic cryptographic algorithms and self-developed domestic components are used to replace all components involved in encryption and decryption, digital certificates, and communication, etc., to improve the system security and the degree of core independent control.
[0031] After installing the smart contract, the first node can send the initial parameters of the large language model (the base model) used as the base to each second node through the GRPC communication component within the federated learning framework. For example, the first node can call the pre-trained smart contract to generate the dimensionality reduction matrix A0 and the dimensionality increase matrix B0 as training objects / initial parameters and save them plainly on the chain. Among them, matrix A0 is initialized to a random Gaussian distribution, and matrix B0 is initialized to a zero matrix. In this embodiment, the framework of the federated learning collaboration network can be implemented using other software products with the same functions such as FATE and PaddleFL. In this embodiment, the open-source large language model used as the base can be other large language models with the same functions such as Chinese-LLaMA and OpenChineseLLaMA. In the data preprocessing step, the first node and the second node respectively process the local bond data into the raw data used in the pre-training step and the instruction tuning step of the federated large language model, and then perform model training on the base model locally.
[0032] Step S203, generate the homomorphic encryption key.
[0033] In this step, the first node can pre-generate the first key pair; then store the first public key pk in the first key pair center in the blockchain for each second node to encrypt the second training parameters obtained by local training of the second node based on the first public key to obtain the second encrypted training parameters.
[0034] That is, the first node can generate the first key pair for homomorphic encryption used in this model training (including the first public key pk center and the first private key sk center ) based on the learning with errors problem on the RLWE ring in lattice cryptography, and call the homomorphic encryption key storage contract to store the first public key pk center is saved on the chain. Similarly, each second node i can generate a second key pair (including a second public-private key pair pk node_i and a second private key sk node_i ) in the same way, and can also call the homomorphic encryption key storage contract to save the second public key pk node_i on the chain.
[0035] Step S204, perform encrypted pre-training of the federated large language model on the chain to obtain the target large language model; In this step, the LoRA method can be specifically used for pre-training of the federated large language model. The first node and each second node can train the initial parameters (A0 and B0) of the base model / initial large language model based on their respective local data to obtain the initial first training parameters and each initial second training parameter (A j and B j ). Then the first node can encrypt the initial first training parameters based on the first public key and store the encrypted initial first encrypted training parameters on the blockchain. At the same time, each second node can first obtain the first public key of the first node from the blockchain, and then use the first public key to encrypt the initial second training parameters and store the encrypted initial second encrypted training parameters on the blockchain.
[0036] Thus, the first node can call the smart contract pre-stored in the blockchain, obtain each initial second encrypted training parameter and the initial first encrypted training parameter from the blockchain through the smart contract, and then can perform encrypted aggregation on each initial second encrypted training parameter and the initial first encrypted training parameter to obtain the initial aggregated encrypted training parameter. Specifically, taking the obtained each initial second encrypted training parameter and initial first encrypted training parameter as EA nj and EB nj as an example, where n represents the nth round of training and j represents the jth node (including the first node and each second node), the first node can perform encrypted aggregation in the following way to obtain the initial aggregated training parameters EA n and EB n . ; . Where m represents the total number of nodes of the first node and the second node; A nj represents the dimensionality reduction matrix obtained by the jth node in the nth round of training, and B nj represents the dimensionality increase matrix obtained by the jth node in the nth round of training.
[0037] In this embodiment, after the first node obtains the initial aggregated encrypted training parameter, it can decrypt the initial aggregated encrypted training parameter based on the first private key sk center it holds to obtain the initial aggregated training parameters A n and Bn Moreover, the first node can save the initial aggregated training parameters in plaintext on the blockchain for each second node to perform the next round of model training based on the initial aggregation parameters, and obtain the current second encrypted training parameters stored by each second node and the current first encrypted training parameters stored by the first node from the blockchain. The model training stops until the predetermined training conditions are met, and the current aggregated training parameters are used as the target aggregated training parameters to obtain the target large language model.
[0038] In this step, by adopting the method of encrypted aggregation to aggregate the intermediate parameters obtained by each node during training and then decrypting them, data security can be further ensured and the leakage of intermediate training parameters can be prevented.
[0039] Step S205: Optimize the target large language module to obtain an optimized target large language model. In the specific implementation of this step, corresponding weights can be pre-configured for each node according to the importance of the first node (the leading party) and each second node (the direct participating parties) in the blockchain. That is, the more important the node, the greater the corresponding weight value.
[0040] Thus, before model optimization, it is possible to determine whether to allow a third node to join the blockchain based on the response information of each node to the third node's join request and the weights of each node, so as to perform model optimization based on the optimization dataset of the third node.
[0041] Specifically, the first node can receive the join request of the third node to be added to the blockchain, send the join request to each second node, and receive the second response information of each second node to the join request. Based on the second response information of each node and the first response information of the first node to the join request, determine the passing rate of the join request, so as to control the third node to join the blockchain based on the passing rate. That is, the first node can determine the target second nodes that agree to the third node to join according to the second response information of each node, and at the same time determine whether the first node itself agrees to the third node to join according to the first response information. That is, the first node determines the target nodes that agree to the third node to join according to the second response information of each node and the first response information, and then determines the passing rate based on the sum of the weights corresponding to each target node and the total sum of the weights corresponding to all nodes. That is, if the passing rate is greater than or equal to 50%, the third node can be allowed to join the blockchain to participate in model optimization as an indirect participant method; otherwise, the third node is not allowed to join the blockchain. Specifically, the calculation formula for the passing rate P is:
[0042] Among them, represents the first weight sum of the weights corresponding to each node (including the first node and the second node) that agrees to the third node to join. Represents the total weight sum of the weights corresponding to each second node (a total of i second nodes) and the first node.
[0043] In this step, when optimizing the target large language model, the third node added to the blockchain can obtain the second public key of any second node from the blockchain, use the second public key of the second node to encrypt the local optimization dataset of the third node to obtain an encrypted optimization set, and then the third node stores the encrypted optimization set in the blockchain. Thus, the second node can obtain the encrypted optimization set of the third node from the blockchain and decrypt the encrypted optimization set based on the second private key held by the second node itself to obtain the optimization dataset. Thus, the target large language model is optimized based on the optimization dataset to obtain an optimized target large language model.
[0044] Specifically, the first node can obtain the initial second encrypted optimization parameters stored by each second node from the blockchain and the initial first encrypted optimization parameters stored by the first node; the initial second encrypted optimization parameters are obtained by the second node after optimizing the target large language model based on the optimization dataset of the third node and then encrypting; call the smart contract to perform encrypted aggregation on the initial first encrypted optimization parameters and each initial second encrypted optimization parameter to obtain the initial aggregated encrypted optimization parameter; decrypt the initial aggregated encrypted optimization parameter to obtain the initial aggregated optimization parameter; perform the next round of model optimization based on the initial aggregated optimization parameter and store the initial aggregated optimization parameter in the blockchain for each second node to perform the next round of model optimization based on the initial aggregated optimization parameter and obtain the current second encrypted optimization parameters stored by each second node and the current first encrypted optimization parameters stored by the first node from the blockchain until the predetermined optimization condition is met, stop the model optimization, use the current aggregated optimization parameter as the target aggregated optimization parameter, and obtain the optimized target large language model. In this embodiment, when optimizing the target large language model, the specific process is similar to the model training process, except for the dataset, so the specific optimization process will not be elaborated here.
[0045] In this embodiment, by jointly performing model training based on multiple nodes (the first node and the second node) in the blockchain, the obtained target large language model can be made more accurate and reliable. By further controlling the addition of the third node and optimizing the obtained target large language model based on the data of the third node, the optimized target large language model can be made more precise, further ensuring the accuracy of model training.
[0046] Based on the above embodiments, another embodiment of the present application provides a blockchain-based model training method. In this embodiment, when performing step S204, that is, training the target large language model, when the number of training rounds is greater than 2 rounds, the first node can also adjust the loss function, specifically including: determining a constraint parameter based on the aggregated training parameters obtained in the nth round of training and the first training parameters obtained in the (n + 1)th round of training, where n is a positive integer; determining the loss function for the (n + 2)th round of model training based on the constraint parameter. Specifically, in the nth round of training, the first node has aggregated and generated the global model parameter Mcenter n , in the (n + 1)th round of training, the first node j trains locally and generates the local model parameter Mnode_ j n+1 . Thus, the first node can set the constraint term Lnode _j n+1 based on the Jacobi matrix to control the offset of the local model. The calculation formula for the constraint parameter is as follows:
[0047] where δM n+1 is the matrix difference between the local model and the global model parameters, and δM n+1 = Mnode_j n+1 - Mcenter n , is the transpose of the Jacobi matrix of the global model parameters in the nth round. will be used as a part of the loss function during the local model training, and the weight it occupies is an adjustable hyperparameter. By adjusting the weight of the dynamic constraint, the parameter adjustment range during the local model update can be restricted, thereby reducing the impact of inconsistent data distributions among different institutions and avoiding forgetting important knowledge in the global model. That is, taking the first node as node j as an example, based on the aggregated training parameter Mcenter n obtained from the nth round of model training, and Mnode_ j n+1 obtained by the first node j in the (n + 1)th round of model training, the constraint parameter / constraint term can be calculated using the above constraint parameter calculation formula. Thus, the loss function for the (n + 2)th round of model training can be further determined according to .
[0048] In this embodiment, by dynamically adjusting the constraint parameter, a reasonable adjustment of the loss function can be achieved, laying a foundation for accurate model training based on the loss function in the future.
[0049] In the specific implementation process of this embodiment, after the training and optimization of the target large language model are completed, if the prediction effect of the final target large language model is not good, the first node can further trace the abnormal node. That is, generally, there are two situations that can cause the poor effect of the large language model obtained by training: Situation 1: The participating party / second node processes the local data incorrectly. Since each party processes the original data locally under the federated learning architecture and only exchanges intermediate parameters, it is possible that during the training process, a certain party may use inappropriate training data due to reasons such as the misunderstanding or operational error of the operator, thereby affecting the model performance.
[0050] Situation 2: The training process encounters a network virus / poisoning attack. If a certain party in the distributed network is attacked or a certain party is malicious, the large language model will be subjected to a poisoning attack. At this time, it is necessary to trace the ciphertext on the chain, analyze the intermediate parameters provided by each node in each batch of training, troubleshoot problems and protect the entire network.
[0051] In this embodiment, the first node can specifically use the following method to determine the abnormal node. For the same round of training, based on each second encrypted training parameter and the first encrypted training parameter, determine the sum of the rank distances corresponding to each second node and the sum of the rank distances corresponding to the first node; based on the sum of the rank distances of each second node and the sum of the rank distances of the first node in each round of training, determine the abnormal node from each second node and the first node. Specifically, after determining the sum of the rank distances corresponding to each second node and the sum of the rank distances corresponding to the first node, the ranking of each node can be determined based on the sum of the rank distances of each second node and the sum of the rank distances of the first node in the same round of training. Then, after determining the ranking of each node based on the ranking of each node in each round of training, finally, the node with the smallest ranking is determined as the abnormal node.
[0052] In the specific implementation process, the first node can call the ciphertext traceability smart contract on the blockchain to calculate the rank distance between the intermediate parameters of each node's training in each round, and arrange them according to the sum of the rank distances between the intermediate parameters provided by each node and the parameters of all other nodes. For example, in round n, calculate the dimensionality reduction matrix A obtained by node j's training nj and the rank distance sum RA of A of all other nodes n …, and the rank distance sum RB of the dimensionality increase matrix B nj and B of all other nodes nj … When the total rank distance sum RA n +RB nj of the same node in the same round of training nj +RB njWhen it is the largest, node j is ranked first in the nth round of training. By calculating the sum of the rankings of all nodes in all training rounds, the node with the smallest sum of rankings can be determined as the abnormal node. The node with the smallest sum of rankings has the largest gap with other nodes and has stronger suspicion. After determining the abnormal node, the leading node, the first node, can use the first private key sk center to decrypt the intermediate parameter matrix stored on the chain by the abnormal node, and use the same conversation as when the problem was discovered for testing to confirm whether it is a parameter problem provided by this node. If it has nothing to do with this node, sequentially calculate the next node with stronger suspicion until the problem node is located.
[0053] In this embodiment, by adopting the above method, the abnormal node can be accurately and quickly determined, which lays a foundation for re-training and optimizing the model by excluding the abnormal node later, and provides a guarantee for accurately training to obtain the target large language model.
[0054] Another embodiment of this application provides a model training method based on blockchain. In this application, a financial infrastructure can be pre-designated as the leading party / first node for constructing the federated large language model; other financial facilities or large financial institutions are direct participating parties / second nodes for joint modeling. Then, the first node and each second node jointly construct a consortium blockchain / blockchain. The method in this embodiment is specifically applied to the second node in the blockchain, as Figure 2 shown, and includes the following steps: Step S301, encrypt the initial second training parameters to obtain the initial second encrypted training parameters, where the initial second training parameters are obtained by the second node through model training on the initial large language model; In the specific implementation process of this step, the first node can pre-send the initial parameters of the large language model (base model) as the foundation to each slave second node through the GRPC communication component within the federated learning framework. Thus, each second node can use the local training set to perform model training on the base model / initial large language model, thereby obtaining the initial second training parameters, and then encrypt the initial second training parameters to obtain the initial second encrypted training parameters.
[0055] In the specific implementation process of this embodiment, each second node can encrypt the obtained initial second training parameters using the first public key of the first node. That is, the first node can pre-generate a first key pair and then store the first public key in the first key pair to the blockchain.
[0056] When encrypting, the second node can obtain the first public key of the first node from the blockchain, and encrypt the initial second training parameters based on the first public key of the first node obtained from the blockchain to obtain the initial second encrypted training parameters. In this step, by encrypting the initial second training parameters, the leakage of training parameters can be prevented and data privacy can be protected.
[0057] Step S302: Store the initial second encrypted training parameters in the blockchain; In this step, each second node stores the initial second encrypted training parameters in the blockchain, which facilitates the first node to obtain each initial second encrypted training parameter from the blockchain for parameter aggregation later.
[0058] Specifically, the first node will also use the local training set to train the model / initial large language model, thereby obtaining the initial first training parameters, and encrypt the initial first training parameters to obtain the initial first encrypted training parameters. Similarly, the first node will also store the initial first encrypted training parameters in the blockchain.
[0059] Step S303: Obtain the initial aggregated training parameters from the blockchain, where the initial aggregated training parameters are obtained by the first node through homomorphic aggregation based on each initial second encrypted training parameter obtained from the blockchain and the initial first encrypted training parameter of the first node, and then decrypted; In this step, the first node can call the smart contract pre-stored in the blockchain, obtain each initial second encrypted training parameter and the initial first encrypted training parameter from the blockchain through the smart contract, and then perform homomorphic aggregation to obtain the initial aggregated encrypted training parameters. At the same time, the first node can use the first private key corresponding to the first public key to decrypt the initial aggregated encrypted training parameters to obtain the initial aggregated training parameters. Finally, the first node can store the initial aggregated training parameters in the blockchain for each second node to obtain the initial aggregated training parameters.
[0060] Step S304: Perform the next round of model training based on the initial aggregated training parameters, encrypt the currently obtained second training parameters after training, and store them in the blockchain. When the predetermined training conditions are met, stop the model training, and use the currently received aggregated training parameters as the target aggregated training parameters to obtain the target large language model.
[0061] In this step, after each second node obtains the initial aggregation training parameters from the blockchain, it can perform the next round of model training based on the initial aggregation training parameters until the model training stops when the predetermined training conditions are met. For example, when the number of training rounds is greater than the predetermined number of rounds, or the error value of the currently obtained aggregation training parameters is less than the predetermined error threshold, the model training can be stopped. At this time, the currently obtained aggregation training parameters can be used as the target aggregation training parameters, so as to obtain the target large language model.
[0062] In the method of this embodiment, by constructing a blockchain and jointly performing model training based on multiple nodes (the first node and the second node) in the blockchain, the obtained target large language model can be made more accurate and reliable. Moreover, the second node encrypts the training parameters and stores the encrypted second encrypted training parameters in the blockchain for the first node to obtain each second encrypted training parameter from the blockchain and perform encrypted aggregation based on each second encrypted training parameter and the first encrypted training parameter of the first node, which can prevent the leakage of training parameters and protect data privacy.
[0063] Based on the above embodiment, another embodiment of the present application provides a blockchain-based model training method, which is applied to the second node and specifically includes the following steps: Step S401, construct a blockchain; In this step, the financial infrastructure as the leading party / first node, as the main computing node of federated learning and the central node / first node of the consortium chain, installs and deploys a distributed network in its data center, and provides a distributed network node deployment installation package, which is sent to the direct participants / second nodes (other financial infrastructures and large financial institutions) of the joint modeling. Thus, the second node can deploy and install the above program in its data center based on the installation package sent by the first node, and become a slave computing node of federated learning and a full node of the consortium chain / second node to join the distributed network.
[0064] Step S402, install the on-chain smart contract and initialize the federated large language model.
[0065] In this step, a smart contract can be pre-installed in the blockchain. Specifically, the first node (the leading party) on the consortium blockchain / blockchain proposes to install the smart contract used for the encrypted training of the federated large language model on the chain. Each second node (direct participant) votes separately. After obtaining the consent of more than half of the weights, the required smart contract will be installed in the consortium blockchain. In this embodiment, the architecture of the consortium blockchain can be implemented using other software products with the same functions such as Hyperledger Fabric, FISCO BCOS, Chang'an Chain, and CITA. In this embodiment, Fabric 2.2 version can be used as the consortium blockchain base, and domestic cryptographic algorithms and self-developed domestic components are used to replace all components related to encryption and decryption, digital certificates, and communication, etc., to improve the system security and the degree of core independent control.
[0066] After installing the smart contract, the second node can receive the initial parameters of the initial large language model (base model) sent by the first node. For example, the first computing node can call the pre-trained smart contract to generate the dimensionality reduction matrix A0 and the dimensionality increase matrix B0 as training objects / initial parameters and save them in plaintext on the chain. Thus, each second node can obtain the generated dimensionality reduction matrix A0 and dimensionality increase matrix B0 from the blockchain. Among them, the matrix A0 is initialized to a random Gaussian distribution, and the matrix B0 is initialized to a zero matrix. In this embodiment, the framework of the federated learning collaboration network can be implemented using other software products with the same functions such as FATE, PaddleFL, etc. In this embodiment, the open-source large language model used as the base can be other large language models with the same functions such as Chinese-LLaMA, OpenChineseLLaMA, etc. In the data preprocessing step, the first node and the second node respectively process the local bond data into the raw data used in the pre-training step and the instruction tuning step of the federated large language model, and then perform model training on the base model locally.
[0067] Step S403, generate a homomorphic encryption key.
[0068] In this step, the second node i can generate a second key pair (including the second public key pk node_i and the second private key sk node_i ) based on the learning with errors problem on the RLWE ring in lattice cryptography, and then call the homomorphic encryption key storage contract to save the second public key pk node_i on the chain. At the same time, the first node can also generate a first key pair (including the first public key pk center and the first private key sk center ), and then store the first public key pk center in the first key pair in the blockchain for each second node to encrypt the second training parameters obtained from local training of the second node and obtain the second encrypted training parameters based on the first public key.
[0069] Step S404, perform encrypted pre-training on the federated large language model chain to obtain the target large language model; In this step, the LoRA method can be specifically used for pre-training the federated large language model. The first node and each second node can train the initial parameters (A0 and B0) of the base model / initial large language model based on their respective local data to obtain the initial first training parameter and each initial second training parameter (A j and B j ).
[0070] Then, each second node can obtain the first public key from the blockchain, encrypt the initial second training parameter based on the first public key, and store the encrypted initial second encrypted training parameter in the blockchain. At the same time, the first node will also encrypt the initial first training parameter using the first public key and store the encrypted initial first encrypted training parameter in the blockchain.
[0071] Thus, the first node can call the smart contract pre-stored in the blockchain, obtain each initial second encrypted training parameter and the initial first encrypted training parameter from the blockchain through the smart contract, and then can perform encrypted aggregation on each initial second encrypted training parameter and the initial first encrypted training parameter to obtain the initial aggregated encrypted training parameter. Specifically, taking the obtained initial second encrypted training parameters and initial first encrypted training parameters as EA nj and EB nj as an example, where n represents the nth round of training and j represents the jth node (including the first node and the second nodes), the first node can perform encrypted aggregation in the following manner to obtain the initial aggregated training parameters EA n and EB n . ; . Where m represents the total number of nodes of the first node and the second nodes; A nj represents the reduced-dimensional matrix obtained by the jth node in the nth round of training, and B nj represents the up-dimensional matrix obtained by the jth node in the nth round of training.
[0072] In this embodiment, after the first node obtains the initial aggregated encrypted training parameter, it can decrypt the initial aggregated encrypted training parameter based on the first private key sk center it holds to obtain the initial aggregated training parameters A n and B n . And the first node can save the initial aggregated training parameters in the blockchain in plaintext form.
[0073] Thus, each second node can obtain the initial aggregated training parameters from the blockchain. Then, based on the initial aggregated training parameters, the next round of model training is carried out, and the currently obtained second training parameters after training are encrypted and stored in the blockchain. When the predetermined training conditions are met, the model training is stopped, and the currently received aggregated training parameters are used as the target aggregated training parameters to obtain the target large language model.
[0074] Step S405: Optimize the target large language module to obtain an optimized target large language model; In the specific implementation process of this step, corresponding weights can be pre-configured for each node according to the importance of the first node (the leading party) and each second node (the direct participating party) in the blockchain. That is, the more important the node, the larger the corresponding weight value.
[0075] In this embodiment, before model optimization, it is possible to determine whether to allow the third node to join the blockchain based on the response information of each node (each second node and the first node) to the third node's joining request and the weights of each node, so as to perform model optimization based on the optimization dataset of the third node.
[0076] Specifically, each second node can receive the joining request of the third node to be joined to the blockchain forwarded by the first node; send the second response information for the joining request to the first node, so that the first node can determine the passing rate of the joining request based on the second response information of each second node and the first response information of the first node for the joining request, and control the third node to join the blockchain based on the passing rate.
[0077] That is, the first node can determine the target second nodes that agree to the third node joining the blockchain according to the second response information of each node, and at the same time determine whether the first node itself agrees to the third node joining according to the first response information. That is, the first node determines the target nodes that agree to the third node joining according to the second response information of each node and the first response information, and then determines the passing rate based on the sum of the weights corresponding to each target node and the total weight sum corresponding to all nodes. That is, if the passing rate is greater than or equal to 50%, the third node can be allowed to join the blockchain to participate in model optimization as an indirect participation method; otherwise, the third node is not allowed to join the blockchain. Specifically, the calculation formula for the passing rate P is:
[0078] Among them, represents the first weight sum of the weights corresponding to the nodes (including the first node and the second node) that agree to the third node joining; represents the total weight sum of the weights corresponding to each second node (a total of i second nodes) and the first node.
[0079] In this step, when optimizing the target large language model, the third node of the blockchain can obtain the second public key of any second node from the blockchain, use the second public key of the second node to encrypt the local optimization dataset of the third node to obtain an encrypted optimization set, and then the third node stores the encrypted optimization set in the blockchain. Thus, the second node can obtain the encrypted optimization set of the third node from the blockchain, where the encrypted optimization set is obtained by the third node encrypting the local optimization dataset of the third node based on the second public key of the second node obtained from the blockchain; decrypt the encrypted optimization set based on the second private key corresponding to the second public key to obtain the optimization dataset; optimize the target large language model based on the optimization dataset to obtain the optimized target large language model.
[0080] When each second node optimizes the target large language model based on the optimization dataset, each second node can encrypt the initial second optimization parameter based on the first public key of the first node to obtain the initial second encrypted optimization parameter, where the initial second optimization parameter is obtained by the second node optimizing the target large language model based on the optimization dataset of the third node; the second node stores the initial second encrypted optimization parameter in the blockchain; the second node obtains the initial aggregated optimization parameter from the blockchain, where the initial aggregated optimization parameter is obtained by the first node performing encrypted aggregation on the obtained initial second encrypted optimization parameters of each node from the blockchain and the initial first encrypted optimization parameter of the first node and then decrypting; perform the next round of model optimization based on the initial aggregated optimization parameter, and encrypt the currently obtained second optimization parameter after optimization based on the first public key and store it in the blockchain. When the predetermined optimization condition is met, stop the model optimization, take the currently received aggregated optimization parameter as the target aggregated optimization parameter, and obtain the optimized target large language model. In this embodiment, when optimizing the target large language model, the specific process is similar to the model training process, except for the dataset, so the specific optimization process will not be elaborated here.
[0081] In this embodiment, by jointly performing model training based on multiple nodes (the first node and the second node) in the blockchain, the obtained target large language model can be made more accurate and reliable. By further controlling the addition of the third node and optimizing the obtained target large language model based on the data of the third node, the optimized target large language model can be made more precise, further ensuring the accuracy of model training.
[0082] Based on the above embodiments, another embodiment of the present application provides a blockchain-based model training method. In this embodiment, when performing step S404, that is, training the target large language model, when the number of training rounds is greater than 2 rounds, each second node can also adjust the loss function, specifically including: determining a constraint parameter based on the aggregated training parameters obtained in the nth round of training and the second training parameters obtained in the (n + 1)th round of training, where n is a positive integer; determining the loss function for the (n + 2)th round of model training based on the constraint parameter. Specifically, in the nth round of training, the first node has aggregated and generated the global model parameter Mcenter n , in the (n + 1)th round of training, the second node j performs local training and generates the local model parameter Mnode_ j n+1 . Thus, the second node can set a constraint term Lnode _j n+1 based on the Jacobi matrix to control the offset of the local model. The calculation formula for the constraint parameter is as follows:
[0083] where δM n+1 is the matrix difference between the local model and the global model parameters, and δM n+1 = Mnode_j n+1 - Mcenter n . is the transpose of the Jacobi matrix of the global model parameters in the nth round. will be used as part of the loss function during local model training, and the weight it occupies is an adjustable hyperparameter. By adjusting the weight of the dynamic constraint, the parameter adjustment range during local model update can be restricted, thereby reducing the impact of inconsistent data distributions among different institutions and avoiding forgetting important knowledge in the global model. That is, taking the second node as node j as an example, based on the aggregated training parameter Mcenter n obtained from the nth round of model training, and Mnode_ j n+1 obtained by the second node j in the (n + 1)th round of model training, the constraint parameter / constraint term can be calculated using the above constraint parameter calculation formula. Thus, each second node can determine the loss function for the (n + 2)th round of model training through the calculated by itself.
[0084] In this embodiment, by dynamically adjusting the constraint parameter, a reasonable adjustment of the loss function can be achieved, laying a foundation for accurate model training based on the loss function in the subsequent stage.
[0085] Another embodiment of the present application provides a blockchain-based model training device, asFigure 3 As shown in The first acquisition module 11 is configured to acquire initial second encrypted training parameters stored by each second node and initial first encrypted training parameters stored by the first node from the blockchain; The aggregation module 12 is configured to call a smart contract to perform encrypted aggregation on the initial first encrypted training parameters and each initial second encrypted training parameter to obtain an initial aggregated encrypted training parameter; The first decryption module 13 is configured to decrypt the initial aggregated encrypted training parameter to obtain an initial aggregated training parameter; The first training module 14 is configured to perform the next round of model training based on the initial aggregated training parameter, and store the initial aggregated training parameter in the blockchain for each second node to perform the next round of model training based on the initial aggregated parameter, and acquire the current second encrypted training parameters stored by each second node and the current first encrypted training parameters stored by the first node from the blockchain, and stop the model training until a predetermined training condition is met, and use the current aggregated training parameter as the target aggregated training parameter to obtain the target large language model.
[0086] In the specific implementation process of this embodiment, the model training device based on the blockchain further includes a first generation module, and the first generation module is configured to: pre-generate a first key pair; Store the first public key pk in the first key pair center In the blockchain for each second node to encrypt the second training parameters obtained by local training of the second node to obtain second encrypted training parameters.
[0087] In the specific implementation process of this embodiment, the first decryption module is specifically configured to: decrypt the initial aggregated encrypted training parameter based on the first private key corresponding to the first public key to obtain the initial aggregated training parameter.
[0088] In the specific implementation process of this embodiment, the model training device based on the blockchain further includes a first receiving module, a first sending module, and a passing rate determination module. The first receiving module is configured to: receive a joining request from a third node to be added to the blockchain; the first sending module is configured to: send the joining request to each second node and receive second response information of each second node for the joining request; the passing rate determination module is configured to: determine the passing rate of the joining request based on each second response information and the first response information of the first node for the joining request, so as to control the third node to join the blockchain based on the passing rate.
[0089] In the specific implementation process of this embodiment, the first acquisition module is further configured to: obtain the initial second encrypted tuning parameters stored by each second node and the initial first encrypted tuning parameters stored by the first node from the blockchain; the initial second encrypted tuning parameters are obtained by the second node encrypting the target large language model after tuning based on the tuning data set of the third node. The aggregation module is further configured to: call a smart contract to perform encrypted aggregation on the initial first encrypted tuning parameters and each initial second encrypted tuning parameter to obtain an initial aggregated encrypted tuning parameter. The first decryption module is further configured to: decrypt the initial aggregated encrypted tuning parameter to obtain an initial aggregated tuning parameter. The first training module is further configured to: perform the next round of model tuning based on the initial aggregated tuning parameter, store the initial aggregated tuning parameter in the blockchain for each second node to perform the next round of model tuning based on the initial aggregated parameter, and obtain the current second encrypted tuning parameters stored by each second node and the current first encrypted tuning parameters stored by the first node from the blockchain. When the predetermined tuning condition is met, stop the model training, use the current aggregated tuning parameter as the target aggregated tuning parameter, and obtain the tuned target large language model.
[0090] In the specific implementation process of this embodiment, the blockchain-based model training device further includes: a first loss function determination module, and the first loss function determination module is configured to: determine a constraint parameter based on the aggregated training parameter obtained in the nth round of training and the first training parameter obtained in the (n + 1)th round of training, where n is a positive integer; determine the loss function for performing the (n + 2)th round of model training based on the constraint parameter.
[0091] In the specific implementation process of this embodiment, the blockchain-based model training device further includes: an abnormal node determination module, and the abnormal node determination module is configured to: for the same round of training, determine the sum of the rank distances corresponding to each second node and the sum of the rank distances corresponding to the first node based on each second encrypted training parameter and the first encrypted training parameter; determine the abnormal node from each second node and the first node based on the sum of the rank distances of each second node and the sum of the rank distances of the first node in each round of training.
[0092] In this embodiment, by constructing a blockchain and jointly performing model training based on multiple nodes (the first node and the second node) in the blockchain, the obtained target large language model can be made more accurate and reliable. Moreover, the first node can prevent the leakage of training parameters and protect data privacy by obtaining the encrypted second encrypted training parameters of each second node from the blockchain and performing encrypted aggregation based on each second encrypted training parameter and the first encrypted training parameter of the first node.
[0093] Another embodiment of the present application provides a model training device based on blockchain, as Figure 4 shown, including: An encryption module, configured to encrypt the initial second training parameter to obtain an initial second encrypted training parameter, where the initial second training parameter is obtained by the second node performing model training on the initial large language model; A storage module, configured to store the initial second encrypted training parameter into the blockchain; A second acquisition module, configured to acquire an initial aggregated training parameter from the blockchain, where the initial aggregated training parameter is obtained by the first node performing encrypted aggregation on each initial second encrypted training parameter obtained from the blockchain and the initial first encrypted training parameter of the first node and then decrypting; A second training module, configured to perform the next round of model training based on the initial aggregated training parameter, encrypt the currently obtained second training parameter after training, and store it into the blockchain. When the predetermined training condition is satisfied, stop the model training, use the received current aggregated training parameter as the target aggregated training parameter, and obtain the target large language model.
[0094] In the specific implementation process of this embodiment, the encryption module is specifically configured to: encrypt the initial second training parameter based on the first public key of the first node obtained from the blockchain to obtain the initial second encrypted training parameter.
[0095] In the specific implementation process of this embodiment, the model training device based on blockchain further includes a second generation module, and the second generation module is configured to: pre-generate a second key pair; store the second public key in the second key pair into the blockchain; The second acquisition module is further configured to: after training to obtain the target large language model, acquire an encrypted tuning set of the third node from the blockchain, where the encrypted tuning set is obtained by the third node encrypting the local tuning data set of the third node based on the second public key of the second node obtained from the blockchain; The model training device based on blockchain further includes a second decryption module; the second decryption module is configured to: decrypt the encrypted tuning set based on the second private key corresponding to the second public key to obtain the tuning data set; The second training module is further configured to: tune the target large language model based on the tuning data set to obtain the tuned target large language model.
[0096] In the specific implementation process of this embodiment, the model training device based on blockchain further includes a second loss function determination module; the second loss function determination module is specifically configured to: determine a constraint parameter based on the aggregated training parameter obtained in the nth round of training and the second training parameter obtained in the (n + 1)th round of training, where n is a positive integer; determine a loss function for performing the (n + 2)th round of model training based on the constraint parameter.
[0097] In this embodiment, by constructing a blockchain and jointly training a model based on multiple nodes (the first node and the second node) in the blockchain, the obtained target large language model can be made more accurate and reliable. Moreover, the second node encrypts the training parameters and stores the encrypted second encrypted training parameters in the blockchain, so that the first node can obtain each second encrypted training parameter from the blockchain and perform encrypted aggregation based on each second encrypted training parameter and the first encrypted training parameter of the first node, which can prevent the leakage of training parameters and protect data privacy.
[0098] Another embodiment of this application provides an electronic device, as Figure 5 shown, which at least includes a memory 1 and a processor 2. A computer program is stored on the memory 1, and when the processor 2 executes the computer program on the memory 1, the following method steps are implemented: Step 1: Obtain the initial second encrypted training parameters stored by each second node and the initial first encrypted training parameters stored by the first node from the blockchain; Step 2: Invoke a smart contract to perform encrypted aggregation on the initial first encrypted training parameter and each initial second encrypted training parameter to obtain an initial aggregated encrypted training parameter; Step 3: Decrypt the initial aggregated encrypted training parameter to obtain an initial aggregated training parameter; Step 4: Perform the next round of model training based on the initial aggregated training parameter, and perform the next round of model training based on the initial aggregated training parameter, and store the initial aggregated training parameter in the blockchain for each second node to perform the next round of model training based on the initial aggregated parameter, and obtain the current second encrypted training parameters stored by each second node and the current first encrypted training parameters stored by the first node from the blockchain. When a predetermined training condition is met, stop the model training, use the current aggregated training parameter as the target aggregated training parameter, and obtain the target large language model.
[0099] Or, implement the following method steps: Step 1: Encrypt the initial second training parameter to obtain an initial second encrypted training parameter, where the initial second training parameter is obtained by the second node training the initial large language model; Step 2: Store the initial second encrypted training parameter in the blockchain; Step 3: Obtain the initial aggregated training parameter from the blockchain, where the initial aggregated training parameter is obtained by the first node performing encrypted aggregation based on each initial second encrypted training parameter obtained from the blockchain and the initial first encrypted training parameter of the first node and then decrypting; Step 4: Perform the next round of model training based on the initial aggregated training parameters, encrypt the currently obtained second training parameters after training, and store them in the blockchain. Stop the model training until the predetermined training conditions are met. Use the currently received aggregated training parameters as the target aggregated training parameters to obtain the target large language model.
[0100] For the specific implementation process of the above method steps, reference can be made to the embodiments of any of the above blockchain-based model training methods, which will not be repeated here.
[0101] The electronic device in this application can make the obtained target large language model more accurate and reliable by constructing a blockchain and jointly performing model training based on multiple nodes (the first node and the second node) in the blockchain. Moreover, the first node can prevent the leakage of training parameters and protect data privacy by obtaining the second encrypted training parameters encrypted by each second node from the blockchain and performing encrypted aggregation based on each second encrypted training parameter and the first encrypted training parameter of the first node.
[0102] The above embodiments are only exemplary embodiments of this application and do not limit this application. The protection scope of this application is defined by the claims. Those skilled in the art can make various modifications or equivalent replacements to this application within the essence and protection scope of this application, and such modifications or equivalent replacements should also be regarded as falling within the protection scope of this application.
Claims
1. A blockchain-based model training method, applied to a first node in a blockchain, characterized in that Including: Obtain the initial second encrypted training parameters stored in each second node and the initial first encrypted training parameters stored in the first node from the blockchain; Invoke a smart contract to perform encrypted aggregation on the initial first encrypted training parameters and each initial second encrypted training parameter to obtain initial aggregated encrypted training parameters; Decrypt the initial aggregated encrypted training parameters to obtain initial aggregated training parameters; Based on the initial aggregated training parameters, perform the next round of model training, and store the initial aggregated training parameters in the blockchain for each second node to perform the next round of model training based on the initial aggregated parameters, and obtain the current second encrypted training parameters stored in each second node and the current first encrypted training parameters stored in the first node from the blockchain. When the predetermined training conditions are met, stop the model training, use the current aggregated training parameters as the target aggregated training parameters, and obtain the target large language model.
2. The method according to claim 1, wherein Before obtaining the initial second encrypted training parameters stored in each second node and the initial first encrypted training parameters stored in the first node from the blockchain, the method further includes: Pre-generate a first key pair; Store the first public key in the first key pair in the blockchain for each second node to encrypt the second training parameters obtained by local training of the second node using the first public key to obtain second encrypted training parameters.
3. The method according to claim 1, characterized in that The initial second encrypted training parameters are obtained by encrypting the initial second training parameters obtained by local training of the second node using the first public key; the initial first encrypted parameters are obtained by encrypting the initial first training parameters obtained by local training of the first node using the first public key; The step of decrypting the initial aggregated encrypted training parameters to obtain initial aggregated training parameters specifically includes: Based on the first private key corresponding to the first public key, decrypt the initial aggregated encrypted training parameters to obtain initial aggregated training parameters.
4. The method according to claim 1, characterized in that, Before obtaining the initial second encrypted training parameters stored in each second node and the initial first encrypted training parameters stored in the first node from the blockchain, the method further includes: Receive a join request from a third node to join the blockchain; Send the join request to each second node and receive the second response information of each second node for the join request; Based on the second response information of each second node and the first response information of the first node for the join request, determine the passing rate of the join request to control the third node to join the blockchain based on the passing rate.
5. The method according to claim 4, wherein After obtaining the target large language model, the method further includes: Obtain the initial second encrypted tuning parameters stored in each second node and the initial first encrypted tuning parameters stored in the first node from the blockchain; the initial second encrypted tuning parameters are obtained by the second node encrypting after tuning the target large language model based on the tuning dataset of the third node; Invoke a smart contract to perform encrypted aggregation on the initial first encrypted tuning parameters and each initial second encrypted tuning parameter to obtain initial aggregated encrypted tuning parameters; Decrypt the initial aggregated encrypted tuning parameters to obtain initial aggregated tuning parameters; Perform the next round of model tuning based on the initial aggregated tuning parameters, and store the initial aggregated tuning parameters in the blockchain for each second node to perform the next round of model training based on the initial aggregated parameters, and obtain the current second encrypted tuning parameters stored by each second node and the current first encrypted tuning parameters stored by the first node from the blockchain. Stop the model training until the predetermined tuning conditions are met, and use the current aggregated tuning parameters as the target aggregated tuning parameters to obtain the tuned target large language model.
6. The method according to claim 1, characterized in that, When the number of training rounds is greater than 2, the method further includes: adjusting the loss function, specifically including: Determine the constraint parameter based on the aggregated training parameter obtained from the nth round of training and the first training parameter obtained from the (n + 1)th round of training, where n is a positive integer; Determine the loss function for the (n + 2)th round of model training based on the constraint parameter.
7. A blockchain-based model training method, applied to a second node in a blockchain, characterized in that Include: Encrypt the initial second training parameter to obtain the initial second encrypted training parameter, where the initial second training parameter is obtained by the second node through model training on the initial large language model; Store the initial second encrypted training parameter in the blockchain; Obtain the initial aggregated training parameter from the blockchain, where the initial aggregated training parameter is obtained by the first node through performing encrypted aggregation on each initial second encrypted training parameter obtained from the blockchain and the initial first encrypted training parameter of the first node and then decrypting; Perform the next round of model training based on the initial aggregated training parameter, encrypt the obtained current second training parameter and store it in the blockchain. Stop the model training until the predetermined training conditions are met, and use the received current aggregated training parameter as the target aggregated training parameter to obtain the target large language model.
8. A model training device based on blockchain, characterized in that, Include: The first acquisition module is used to obtain the initial second encrypted training parameters stored by each second node and the initial first encrypted training parameter stored by the first node from the blockchain; The aggregation module is used to call the smart contract to perform encrypted aggregation on the initial first encrypted training parameter and each initial second encrypted training parameter to obtain the initial aggregated encrypted training parameter; The first decryption module is used to decrypt the initial aggregated encrypted training parameter to obtain the initial aggregated training parameter; The first training module is used to perform the next round of model training based on the initial aggregated training parameter, and store the initial aggregated training parameter in the blockchain for each second node to perform the next round of model training based on the initial aggregated parameters, and obtain the current second encrypted training parameters stored by each second node and the current first encrypted training parameters stored by the first node from the blockchain. Stop the model training until the predetermined training conditions are met, and use the current aggregated training parameter as the target aggregated training parameter to obtain the target large language model.
9. A blockchain-based model training device, characterized in that, Include: The encryption module is used to encrypt the initial second training parameter to obtain the initial second encrypted training parameter, where the initial second training parameter is obtained by the second node through model training on the initial large language model; The storage module is used to store the initial second encrypted training parameter in the blockchain; A second acquisition module, configured to acquire initial aggregated training parameters from a blockchain, where the initial aggregated training parameters are obtained by the first node through performing encrypted aggregation on each initial second encrypted training parameter acquired from the blockchain and the initial first encrypted training parameter of the first node and then decrypting the result; A second training module, configured to perform the next round of model training based on the initial aggregated training parameters, encrypt the currently obtained second training parameters after training, and store them in the blockchain. When a predetermined training condition is met, stop the model training, use the currently received aggregated training parameters as the target aggregated training parameters, and obtain a target large language model.
10. An electronic device, characterized in that, It includes at least a memory and a processor. A computer program is stored on the memory, and when the processor executes the computer program on the memory, the steps of the model training method based on blockchain according to any one of claims 1-6 or 7 above are implemented.
Citation Information
Patent Citations
Financial data information federal transfer learning method and device based on block chain
CN113011598A
Block chain-based model joint training method and device
CN113268776A
Federated learning method and device based on block chain, equipment and storage medium
CN113609508A
Model training method and device based on transverse federated learning
CN114006769A
Model training method and device, storage medium, system and block chain node
CN114254360A