A global model determination method and device based on blockchain, and storage medium
By using aggregate nodes to calculate the target mean vector and variance vector in blockchain technology, determine the target global parameters and obtain the global model, the problem of poor training model results due to non-independent and homogeneous distribution of terminal device node data is solved, and the accuracy of the model is improved.
Patent Information
- Application Number
- CN202111305848.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-05
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-11-05
AI Technical Summary
In blockchain technology, the local data of each terminal device node mostly obeys non-independent and homogeneous distribution, resulting in poor application effect of the final training model obtained by the aggregation method.
By aggregating nodes, the training results corresponding to the nodes of different target edge device are calculated, the target mean vector and the target variance vector are obtained, and the target global parameters are determined based on these vectors, thereby obtaining the target global model. The model is written to the blockchain network and broadcast to all nodes.
This method can reduce the impact of data skewness on the target global model and improve the accuracy of the target global model when the local data of each target edge device node obeys non-independent and homogeneous distribution.
Smart Images

Figure CN114185988B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a global model determination method and device based on blockchain, a storage medium, and a computer device. Background Art
[0002] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Nowadays, with the rapid development of Internet technology, blockchain technology is gaining more and more favor.
[0003] In blockchain technology, in order to ensure data privacy and break data silos, machine learning tasks can be distributed to various terminal device nodes for learning, and then the result data generated by the learning of all terminal device nodes can be aggregated to obtain the final training model. Among them, the aggregation method is usually to simply average the result data corresponding to each terminal device node. However, in reality, the local data of each terminal device node mostly obeys non-independent and identical distribution, and the final training model obtained by this aggregation method has poor application effect. Summary of the invention
[0004] In view of this, the present application provides a global model determination method and device based on blockchain, a storage medium, and a computer device, which can make the local data of each target edge device node obey non-independent and identically distributed, reduce the impact of data skewness on the target global parameters corresponding to the target global model, and improve the accuracy of the target global model.
[0005] According to one aspect of the present application, a global model determination method based on blockchain is provided, which is applied to an aggregation node and includes:
[0006] Determine multiple target edge device nodes participating in local training, and send local training instructions to the target edge device nodes, so that the target edge device nodes obtain target edge device parameters according to the local training instructions, and write a first target address corresponding to the target edge device parameters into the blockchain network;
[0007] Based on each of the first target addresses, obtaining the target edge device parameters from the target edge device node, and obtaining a target mean vector and a target variance vector according to the target edge device parameters;
[0008] According to the target mean vector and the target variance vector, target global parameters are determined, and based on the target global parameters, a target global model is obtained, the target global model is written into the blockchain network, and broadcasted to the nodes in the blockchain network.
[0009] Optionally, obtaining a target mean vector and a target variance vector according to the target edge device parameters specifically includes:
[0010] Determine a target matrix corresponding to the target edge device node according to the target edge device parameter, wherein the number of columns of the target matrix is consistent with the number of the target edge device nodes, the number of rows of the target matrix is consistent with the dimension of any of the target edge device parameters, and the dimensions corresponding to any of the target edge device parameters are the same;
[0011] Based on the target matrix, determining a row mean corresponding to any row element in the target matrix;
[0012] The corresponding row mean is subtracted from any row element in the target matrix to obtain a target distance matrix, and based on the target distance matrix, a target mean vector and a target variance vector are obtained.
[0013] Optionally, determining a target global parameter according to the target mean vector and the target variance vector specifically includes:
[0014] Based on the target mean vector and the target variance vector, a target random number vector is obtained through a preset random algorithm, and based on the target random number vector and the target mean vector, a target global parameter is determined.
[0015] Optionally, obtaining a target global model based on the target global parameter specifically includes:
[0016] By using the target global parameters, the preset global parameters corresponding to the preset global model in the aggregation node are updated to obtain an updated global model;
[0017] Testing the updated global model using a preset test set and calculating the test accuracy;
[0018] When the test accuracy is less than or equal to a preset accuracy threshold, taking the updated global model as the target global model;
[0019] When the test accuracy is greater than the preset accuracy threshold, the target global parameter is re-determined.
[0020] Optionally, when the test accuracy is greater than the preset accuracy threshold, re-determining the target global parameter specifically includes:
[0021] When the test accuracy is greater than the preset accuracy threshold, the second target address corresponding to the target global parameter is written into the blockchain network, and the second target address is broadcast to the target edge device node, so that the target edge device node obtains the target global parameter based on the second target address, and updates the target edge device parameter based on the target global parameter;
[0022] The updated target edge device parameters are obtained, and the target global parameters are re-determined.
[0023] According to another aspect of the present application, another blockchain-based global model determination method is provided, which is applied to a target edge device node, including:
[0024] Receive local training instructions sent by the aggregation node and download the preset global model from the blockchain network;
[0025] Based on the preset local data, the preset global model is trained, and after the training is completed, the target edge device parameters are obtained, and a first target address corresponding to the target edge device parameters is generated;
[0026] The first target address is written into the blockchain network, so that the aggregation node obtains the target edge device parameters according to the first target address, obtains the target mean vector and the target variance vector based on the target edge device parameters, determines the target global parameters according to the target mean vector and the target variance vector, obtains the target global model based on the target global parameters, writes the target global model into the blockchain network, and broadcasts it to the nodes in the blockchain network.
[0027] Optionally, the method further comprises:
[0028] monitoring the aggregation node in real time, and after monitoring the aggregation node broadcasting a second target address, acquiring the target global parameter from the aggregation node based on the second target address;
[0029] The preset global parameters corresponding to the preset global model in the target edge device node are updated according to the target global parameters, and the updated preset global model is trained according to the preset local data. When the training is completed, the target edge device parameters are updated.
[0030] According to another aspect of the present application, a global model determination device based on blockchain is provided, which is applied to an aggregation node, including:
[0031] A node determination module, used to determine multiple target edge device nodes participating in local training, and send local training instructions to the target edge device nodes, so that the target edge device nodes obtain target edge device parameters according to the local training instructions, and write a first target address corresponding to the target edge device parameters into the blockchain network;
[0032] A parameter acquisition module, configured to acquire the target edge device parameters from the target edge device node based on each of the first target addresses, and obtain a target mean vector and a target variance vector according to the target edge device parameters;
[0033] The model determination module is used to determine the target global parameters according to the target mean vector and the target variance vector, and obtain the target global model based on the target global parameters, write the target global model into the blockchain network, and broadcast it to the nodes in the blockchain network.
[0034] Optionally, the parameter acquisition module is specifically used to:
[0035] According to the target edge device parameters, determine the target matrix corresponding to the target edge device nodes, wherein the number of columns of the target matrix is consistent with the number of the target edge device nodes, the number of rows of the target matrix is consistent with the dimension of any of the target edge device parameters, and the dimensions corresponding to any of the target edge device parameters are the same; based on the target matrix, determine the row mean corresponding to any row element in the target matrix; subtract the corresponding row mean from any row element in the target matrix to obtain a target distance matrix, and based on the target distance matrix, obtain a target mean vector and a target variance vector.
[0036] Optionally, the model determination module is specifically used to:
[0037] Based on the target mean vector and the target variance vector, a target random number vector is obtained through a preset random algorithm, and based on the target random number vector and the target mean vector, a target global parameter is determined.
[0038] Optionally, the model determination module is further configured to:
[0039] The preset global parameters corresponding to the preset global model in the aggregation node are updated through the target global parameters to obtain an updated global model; the updated global model is tested through a preset test set, and the test accuracy is counted; when the test accuracy is less than or equal to a preset accuracy threshold, the updated global model is used as the target global model; when the test accuracy is greater than the preset accuracy threshold, the target global parameters are re-determined.
[0040] Optionally, the model determination module is further configured to:
[0041] When the test accuracy is greater than the preset accuracy threshold, the second target address corresponding to the target global parameter is written into the blockchain network, and the second target address is broadcast to the target edge device node, so that the target edge device node obtains the target global parameter based on the second target address, and updates the target edge device parameter based on the target global parameter; obtains the updated target edge device parameter, and re-determines the target global parameter.
[0042] According to another aspect of the present application, a global model determination device based on blockchain is provided, which is applied to a target edge device node, including:
[0043] The model download module is used to receive local training instructions sent by the aggregation node and download the preset global model from the blockchain network;
[0044] A parameter generation module, used to train the preset global model based on preset local data, obtain target edge device parameters after the training is completed, and generate a first target address corresponding to the target edge device parameters;
[0045] An address writing module is used to write the first target address into the blockchain network, so that the aggregation node obtains the target edge device parameters according to the first target address, obtains the target mean vector and the target variance vector based on the target edge device parameters, determines the target global parameters according to the target mean vector and the target variance vector, obtains the target global model based on the target global parameters, writes the target global model into the blockchain network, and broadcasts it to the nodes in the blockchain network.
[0046] Optionally, the device further comprises:
[0047] A monitoring module, configured to monitor the aggregation node in real time, and when the aggregation node broadcasts a second target address, obtain the target global parameter from the aggregation node based on the second target address;
[0048] A parameter updating module is used to update the preset global parameters corresponding to the preset global model in the target edge device node according to the target global parameters, and to train the updated preset global model according to the preset local data, and to update the target edge device parameters after the training is completed.
[0049] According to another aspect of the present application, a storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the above-mentioned blockchain-based global model determination method is implemented.
[0050] According to another aspect of the present application, a computer device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the above-mentioned blockchain-based global model determination method when executing the program.
[0051] Through the above technical scheme, the present application provides a blockchain-based global model determination method and device, storage medium, and computer equipment. The training results corresponding to different target edge device nodes are calculated through aggregation nodes to obtain the target mean vector and the target variance vector, and the target global parameters are obtained through the target mean vector and the target variance vector. The target global model is obtained through the target global parameters. When the local data of each target edge device node is not independent and identically distributed, the influence of data skewness on the target global parameters corresponding to the target global model is reduced, thereby improving the accuracy of the target global model.
[0052] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0054] Figure 1 A schematic diagram of a global model determination method based on blockchain provided in an embodiment of the present application is shown;
[0055] Figure 2 A schematic diagram of a process of another blockchain-based global model determination method provided in an embodiment of the present application is shown;
[0056] Figure 3 A schematic diagram of a process of another blockchain-based global model determination method provided in an embodiment of the present application is shown;
[0057] Figure 4 A schematic diagram of the structure of a global model determination device based on blockchain provided in an embodiment of the present application is shown;
[0058] Figure 5 A schematic diagram of the structure of another blockchain-based global model determination device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0059] The present application will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.
[0060] In this embodiment, a global model determination method based on blockchain is provided, which is applied to aggregation nodes, such as Figure 1 As shown, the method includes:
[0061] Step 101, determining multiple target edge device nodes participating in local training, and sending local training instructions to the target edge device nodes, so that the target edge device nodes obtain target edge device parameters according to the local training instructions, and write a first target address corresponding to the target edge device parameters into the blockchain network;
[0062] In traditional machine learning, data is distributed on the same machine, and assuming that the data is independently sampled from the same distribution, the data obeys independent and identical distribution. Later, with the rapid growth of data volume, the era of big data requires distributed algorithms for parallel computing. At this time, the main thing distributed optimization does is to use multiple machines to perform parallel computing on big data or large models, including two basic paradigms of model parallelism and data parallelism, but at this time it is still just to accelerate computing, and the data on each client still obeys independent and identical distribution. However, with the large-scale use of IoT devices, tens of thousands of devices belong to a certain user, enterprise, or scenario, so their data distribution is often extremely different, that is, the data is not independent and identically distributed. The local data corresponding to each node device in the blockchain network obeys non-independent and identical distribution. Here, non-independent and identical distribution can be understood from two aspects: first, non-identical distribution. Non-identical distribution is easy to understand, because it is caused by large differences in data distribution; second, non-independence. Due to factors such as user groups and regional associations, the data distribution of these devices is often related, that is, non-independent. In addition, frequency distribution can be divided into normal distribution and skewed distribution. Normal distribution means that most frequencies are concentrated in the central position, and the frequency distribution at both ends is roughly symmetrical. Skewed distribution means that the frequency distribution is asymmetric, and the concentrated position is biased to one side. In the prior art, the machine learning task is distributed to each terminal device node for learning, and then the result data generated by the learning of all terminal device nodes is aggregated. The aggregation result is often affected by the skewness of the data caused by the data obeying non-independent and identical distribution, and the final training model after aggregation has poor accuracy. A global model determination method based on blockchain provided in an embodiment of the present application can effectively solve the problem that the local data in each terminal device node in the prior art obeys non-independent and identical distribution, and the local data of each terminal device node is used to locally train the preset global model, and the final training model obtained after the training results are aggregated is affected by the skewness of the data. First, the aggregation node in the blockchain network can randomly determine the target edge device node participating in the local training from multiple edge device nodes. Here, local training refers to each target edge device node using the preset local data to train the preset global model locally. Through local training, the data in the target edge device node can participate in the construction of the global model without leaving the local area, thereby ensuring the data security of the user. After determining the target edge device nodes, the aggregation node sends local training instructions to these target edge device nodes respectively, so that after each target edge device node receives the local training instruction, it can obtain a preset global model from the blockchain network based on the local training instruction and train the preset global model through the preset local data, wherein the preset global model includes preset global parameters.When the number of trainings reaches a preset number threshold, or when the model error corresponding to the model obtained after training is less than the preset error threshold, the corresponding target edge device parameters are determined, and a first target address corresponding to the target edge device parameters is generated. For example, when the condition for the end of local training is that the model error is less than the preset error threshold, before the model error is less than the preset error threshold, the parameters corresponding to the preset global model can be adjusted according to the preset parameter adjustment strategy after each training, wherein the preset global parameters of the preset global model are adjusted after the first training is completed until the model error is less than the preset error threshold, and the parameters corresponding to the preset global model are the target edge device parameters. Afterwards, the first target address corresponding to the target edge device parameters is written into the blockchain network, where the first target address may include the local address corresponding to the target edge device node and the storage location of the target edge device parameters in the target edge device node.
[0063] Step 102: based on each of the first target addresses, obtain the target edge device parameters from the target edge device node, and obtain a target mean vector and a target variance vector according to the target edge device parameters;
[0064] In this embodiment, the aggregation node can then find the stored target edge device parameters from the target edge device node according to the first target address corresponding to each target edge device parameter, and then the aggregation node can calculate the target mean vector and the target variance vector based on all target edge device parameters corresponding to different target edge device nodes. Here, compared to directly storing the target edge device parameters in the blockchain network and directly obtaining the target edge device parameters from the blockchain network, the aggregation node obtains the target edge device parameters from the target edge device node through the first target address, which can greatly improve the access efficiency of the aggregation node.
[0065] Step 103: determine the target global parameters according to the target mean vector and the target variance vector, obtain the target global model based on the target global parameters, write the target global model into the blockchain network, and broadcast it to the nodes in the blockchain network.
[0066] In this embodiment, after obtaining the target mean vector and the target variance vector, the target mean vector and the target variance vector can be further used as a basis to determine the target global parameters. Here, the target global parameters are parameters corresponding to the preset global parameters in the preset global model. The target global model can be obtained by updating the preset global parameters in the preset global model through the target global parameters. In fact, if the preset local data in different target edge device nodes have high heterogeneity, the target edge device parameters obtained after local training will also have large differences. If the target global parameters are directly determined using these target edge device parameters with large differences, the results of the target global parameters will be greatly affected by these target edge device parameters, resulting in inaccurate target global parameters. The present application constrains the range of the target global parameters by the target mean vector and the target variance vector, so that the target global parameters are kept as close to the mean of the target edge device parameters as possible, so that the local data of each target edge device node can be made to obey the non-independent and identically distributed situation, and reduce the influence of data skewness on the target global parameters corresponding to the target global model. After obtaining the target global model, the target global model can also be written into the blockchain network and broadcast to all nodes of the blockchain network, so that the nodes in the blockchain network can directly download the target global model from the blockchain network.
[0067] By applying the technical solution of this embodiment, first, the aggregation node in the blockchain network can randomly determine the target edge device node participating in the local training from multiple edge device nodes. After determining the target edge device node, the aggregation node sends the local training instructions to these target edge device nodes respectively, so that each target edge device node can receive the local training instruction. Based on the local training instruction, the corresponding target edge device parameters can be finally determined according to the local training instruction, and the first target address corresponding to the target edge device parameter is written into the blockchain network. Then, the aggregation node can find the stored target edge device parameters from the target edge device node according to the first target address corresponding to each target edge device parameter, and then the aggregation node can calculate the target mean vector and target variance vector based on all target edge device parameters corresponding to different target edge device nodes. After obtaining the target mean vector and target variance vector, the target mean vector and target variance vector can be further used as the basis to determine the target global parameters, and the target global model can be obtained through the target global parameters. After obtaining the target global model, the target global model can also be written into the blockchain network and broadcast to all nodes of the blockchain network. In the embodiment of the present application, the training results corresponding to different target edge device nodes are calculated through an aggregation node to obtain a target mean vector and a target variance vector, and the target global parameters are obtained through the target mean vector and the target variance vector, and the target global model is obtained through the target global parameters. This can reduce the impact of data skewness on the target global parameters corresponding to the target global model when the local data of each target edge device node is not independent and identically distributed, thereby improving the accuracy of the target global model.
[0068] Further, as a refinement and extension of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, another global model determination method based on blockchain is provided, which is applied to the aggregation node, such as Figure 2 As shown, the method includes:
[0069] Step 201, determining multiple target edge device nodes participating in local training, and sending local training instructions to the target edge device nodes, so that the target edge device nodes obtain target edge device parameters according to the local training instructions, and write the first target address corresponding to the target edge device parameters into the blockchain network;
[0070] Step 202: based on each of the first target addresses, obtain the target edge device parameters from the target edge device node;
[0071] In this embodiment, the aggregation node in the blockchain network can randomly determine the target edge device node participating in the local training from multiple edge device nodes. After determining the target edge device node, the aggregation node sends the local training instructions to these target edge device nodes respectively, so that each target edge device node can receive the local training instruction. Based on the local training instruction, the corresponding target edge device parameters can be finally determined according to the local training instruction, and the first target address corresponding to the target edge device parameter is written into the blockchain network. Here, the local training instruction refers to an instruction requiring the target edge device node to perform a model training task locally, which may specifically include a target edge device identifier and training task information. Then, the aggregation node can find the stored target edge device parameters from the target edge device node according to the first target address corresponding to each target edge device parameter.
[0072] Step 203, based on the target edge device parameters, determine the target matrix corresponding to the target edge device nodes, wherein the number of columns of the target matrix is consistent with the number of the target edge device nodes, the number of rows of the target matrix is consistent with the dimension of any of the target edge device parameters, and the dimensions corresponding to any of the target edge device parameters are the same; based on the target matrix, determine the row mean corresponding to any row element in the target matrix; subtract the corresponding row mean from any row element in the target matrix to obtain a target distance matrix, and based on the target distance matrix, obtain a target mean vector and a target variance vector;
[0073] In this embodiment, based on the target edge device parameters corresponding to different target edge device nodes, the target edge device parameters corresponding to any target edge device node are arranged as columns, and the target edge device parameters corresponding to all target edge device nodes are used to generate a target matrix. That is, the number of rows of the target matrix can be the dimension corresponding to each target edge device parameter, and the number of columns of the target matrix can be the number of target edge device nodes. Here, the dimensions of the target edge device parameters corresponding to different target edge device nodes are the same. For example, there are 5 target edge device nodes, namely node 1 to node 5. Among them, the target edge device parameter corresponding to node 1 is The target edge device parameters corresponding to node 2 are By analogy, the target edge device parameters corresponding to node 5 are The dimensions of the parameters of the five target edge devices are all 4, so the generated target matrix can be Next, based on the target matrix, determine the row mean of all elements in each row of the target matrix. For example, for the above target matrix, the row mean corresponding to the first row of elements is By analogy, the row mean corresponding to the fourth row elements is Finally, the row mean corresponding to each row in the target matrix is subtracted from the element corresponding to the row, so that the target distance matrix corresponding to the target matrix can be obtained. For example, the target distance matrix can be expressed as:
[0074] Then, based on the target distance matrix, the target mean vector and target variance vector can be obtained. Among them, the target mean vector can be the target distance matrix, and the elements of each row of the target distance matrix are reduced in dimension. Specifically, the elements of each row are added and divided by the number of elements in each row to obtain the new row elements after dimension reduction, thereby obtaining the target mean vector; the target variance vector can be the target distance matrix, and the elements of each row of the target distance matrix are squared, added, and divided by the number of elements in each row to obtain the new row elements after dimension reduction, thereby obtaining the target mean variance. Here, both the target mean vector and the target variance vector can be column vectors. For example, the target mean vector can be The target variance vector can be
[0075] Step 204, based on the target mean vector and the target variance vector, a target random number vector is obtained by a preset random algorithm, and based on the target random number vector and the target mean vector, a target global parameter is determined;
[0076] In this embodiment, after the target mean vector and the target variance vector are calculated, the target mean vector and the target variance vector can be used as a basis, and a preset random algorithm can be used to obtain a target random number vector, wherein the number of rows of the target random number vector is consistent with the number of rows of the target mean vector and the number of rows of the target variance vector, and the elements in the target random number vector are all subject to a normal distribution. Then, the target global parameter is determined according to the target random number vector and the target mean vector. Specifically, the target random number vector and the target mean vector can be added to obtain a vector corresponding to the target global parameter, wherein each element is the target global parameter.
[0077] Step 205: updating the preset global parameters corresponding to the preset global model in the aggregation node through the target global parameters to obtain an updated global model; testing the updated global model through a preset test set, and calculating the test accuracy; when the test accuracy is less than or equal to a preset accuracy threshold, using the updated global model as the target global model; when the test accuracy is greater than the preset accuracy threshold, re-determining the target global parameters;
[0078] Step 206: write the target global model into the blockchain network and broadcast it to the nodes in the blockchain network.
[0079] In this embodiment, a preset global model is pre-stored in the blockchain network. After obtaining the target global parameters, the aggregation node can update the corresponding preset global parameters in the preset global model based on the target global parameters, and obtain the updated global model. After obtaining the updated global model, the updated global model can be further tested using a pre-prepared test data set, and when all test data are tested, the test accuracy is statistically calculated. When the test accuracy is less than or equal to the preset accuracy threshold, it means that the test accuracy of the updated global model is high, and the updated global model can be used directly, so the updated global model can be directly used as the target global model. When the test accuracy is greater than the preset accuracy threshold, it means that the test accuracy of the updated global model cannot meet the requirements, and it is necessary to perform local training again through the target edge device node, that is, the target edge device node uses the updated global model and preset local data for training, and obtains new target edge device parameters after the training is completed. The aggregation node calculates the target global parameters again through these updated target edge device parameters, and obtains a brand new updated global model through the target global parameters, until the test accuracy corresponding to the updated global model is less than or equal to the preset accuracy threshold, the target global model is obtained. After obtaining the target global model, the target global model can also be written into the blockchain network and broadcast to all nodes of the blockchain network, so that the nodes in the blockchain network can directly download the target global model from the blockchain network.
[0080] In an embodiment of the present application, optionally, the step 205 of "when the test accuracy is greater than the preset accuracy threshold, redetermining the target global parameters" specifically includes: when the test accuracy is greater than the preset accuracy threshold, writing the second target address corresponding to the target global parameters into the blockchain network, and broadcasting the second target address to the target edge device node, so that the target edge device node obtains the target global parameters based on the second target address, and updates the target edge device parameters based on the target global parameters; obtains the updated target edge device parameters, and redetermines the target global parameters.
[0081] In this embodiment, when the test accuracy is greater than the preset accuracy threshold, the aggregation node can write the second target address corresponding to the target global parameter into the blockchain network. Here, the second target address may include the local address corresponding to the aggregation node and the storage location of the target global parameter in the aggregation node. In addition, the aggregation node can also broadcast the second target address to the target edge device node. After the target edge device node listens to the second target address broadcast by the aggregation node, it can obtain the target global parameter from the aggregation node according to the second target address. Then, based on the target global parameter, the preset global parameter in the preset global model is updated, and the updated preset global model is trained again using the preset local data to obtain the updated target edge device parameter. After that, the aggregation node can re-obtain the updated target edge device parameter from these target edge device nodes and redetermine the target global parameter.
[0082] In this embodiment, a global model determination method based on blockchain is provided, which is applied to a target edge device node, such as Figure 3 As shown, the method includes:
[0083] Step 301, receiving a local training instruction sent by an aggregation node, and downloading a preset global model from the blockchain network;
[0084] A global model determination method based on blockchain provided by an embodiment of the present application can effectively solve the problem in the prior art that the local data in each terminal device node obeys non-independent and identically distributed conditions, and the local data of each terminal device node is used to locally train the preset global model, and the final training model obtained after aggregating the training results is affected by the skewness of the data. First, the target edge device node in the blockchain network can receive the local training instruction sent by the aggregation node, and after receiving the local training instruction, the preset global model can be downloaded from the blockchain network. Here, the preset global model in the blockchain network can be uploaded by the aggregation node, and specifically can be the initial global model generated by the aggregation node through a random number generation algorithm.
[0085] Step 302: training the preset global model based on preset local data, obtaining target edge device parameters after the training is completed, and generating a first target address corresponding to the target edge device parameters;
[0086] In this embodiment, after the target edge device node downloads the preset global model from the blockchain network, it can train the preset global model based on the preset local data through the preset local data. When the number of training times reaches a preset threshold, or when the model error corresponding to the model obtained after training is less than a preset error threshold, the corresponding target edge device parameters are determined, and a first target address corresponding to the target edge device parameters is generated. Here, the first target address may include the local address corresponding to the target edge device node and the storage location of the target edge device parameters in the target edge device node.
[0087] Step 303, write the first target address into the blockchain network, so that the aggregation node obtains the target edge device parameters according to the first target address, obtains the target mean vector and the target variance vector based on the target edge device parameters, determines the target global parameters according to the target mean vector and the target variance vector, obtains the target global model based on the target global parameters, writes the target global model into the blockchain network, and broadcasts it to the nodes in the blockchain network.
[0088] In this embodiment, the target edge device node can write the generated first target address into the blockchain network, so that the aggregation node can obtain the target edge device parameters corresponding to the first target address from the target edge device node according to the first target address, and calculate the target mean vector and the target variance vector based on the target edge device parameters, and then obtain the target global parameters based on the target mean vector and the target variance vector. After that, the aggregation node can obtain the target global model according to the target global parameters, write the target global model into the blockchain network, and broadcast it to the nodes in the blockchain network.
[0089] In this embodiment, optionally, the method also includes: monitoring the aggregation node in real time, and when the aggregation node is monitored broadcasting a second target address, obtaining the target global parameters from the aggregation node based on the second target address; updating the preset global parameters corresponding to the preset global model in the target edge device node according to the target global parameters, and training the updated preset global model according to the preset local data, and updating the target edge device parameters after the training is completed.
[0090] In this embodiment, the target edge device node can also monitor the aggregation node in real time. After the aggregation node obtains the target global model according to the target edge device parameters of the target edge device node, the test accuracy corresponding to the target global model can be calculated. When the test accuracy is greater than the preset accuracy threshold, the aggregation node can write the second target address corresponding to the target global parameter into the blockchain network and broadcast the second target address to the target edge device node. After the target edge device node monitors the second target address broadcast by the aggregation node, it can find the target global parameter from the aggregation node according to the second target address and obtain the target global parameter. Afterwards, the preset global parameters corresponding to the preset global model in the target edge device node can be updated based on the target global parameters. Then, the preset local data in the target edge device node is used to train the updated preset global model, and when the training is completed, the target edge device parameters obtained last time can be updated.
[0091] In this embodiment, optionally, after “obtaining the target edge device parameters after training is completed”, the method further includes: signing the target edge device parameters.
[0092] In this embodiment, after obtaining the target edge device parameters, the target edge device parameters are signed, which can indicate that the target edge device parameters are obtained through training of the target edge device node, rather than uploaded by other malicious devices, and can indirectly reflect the availability of the target edge device parameters.
[0093] Further, as Figure 1 The specific implementation of the method, the embodiment of the present application provides a global model determination device based on blockchain, which is applied to aggregation nodes, such as Figure 4 As shown, the device comprises:
[0094] A node determination module, used to determine multiple target edge device nodes participating in local training, and send local training instructions to the target edge device nodes, so that the target edge device nodes obtain target edge device parameters according to the local training instructions, and write a first target address corresponding to the target edge device parameters into the blockchain network;
[0095] A parameter acquisition module, configured to acquire the target edge device parameters from the target edge device node based on each of the first target addresses, and obtain a target mean vector and a target variance vector according to the target edge device parameters;
[0096] The model determination module is used to determine the target global parameters according to the target mean vector and the target variance vector, and obtain the target global model based on the target global parameters, write the target global model into the blockchain network, and broadcast it to the nodes in the blockchain network.
[0097] Optionally, the parameter acquisition module is specifically used to:
[0098] According to the target edge device parameters, determine the target matrix corresponding to the target edge device nodes, wherein the number of columns of the target matrix is consistent with the number of the target edge device nodes, the number of rows of the target matrix is consistent with the dimension of any of the target edge device parameters, and the dimensions corresponding to any of the target edge device parameters are the same; based on the target matrix, determine the row mean corresponding to any row element in the target matrix; subtract the corresponding row mean from any row element in the target matrix to obtain a target distance matrix, and based on the target distance matrix, obtain a target mean vector and a target variance vector.
[0099] Optionally, the model determination module is specifically used to:
[0100] Based on the target mean vector and the target variance vector, a target random number vector is obtained through a preset random algorithm, and based on the target random number vector and the target mean vector, a target global parameter is determined.
[0101] Optionally, the model determination module is further configured to:
[0102] The preset global parameters corresponding to the preset global model in the aggregation node are updated through the target global parameters to obtain an updated global model; the updated global model is tested through a preset test set, and the test accuracy is counted; when the test accuracy is less than or equal to a preset accuracy threshold, the updated global model is used as the target global model; when the test accuracy is greater than the preset accuracy threshold, the target global parameters are re-determined.
[0103] Optionally, the model determination module is further configured to:
[0104] When the test accuracy is greater than the preset accuracy threshold, the second target address corresponding to the target global parameter is written into the blockchain network, and the second target address is broadcast to the target edge device node, so that the target edge device node obtains the target global parameter based on the second target address, and updates the target edge device parameter based on the target global parameter; obtains the updated target edge device parameter, and re-determines the target global parameter.
[0105] Further, as Figure 3 The specific implementation of the method, the embodiment of the present application provides a global model determination device based on blockchain, which is applied to the target edge device node, such as Figure 5 As shown, the device comprises:
[0106] The model download module is used to receive local training instructions sent by the aggregation node and download the preset global model from the blockchain network;
[0107] A parameter generation module, used to train the preset global model based on preset local data, obtain target edge device parameters after the training is completed, and generate a first target address corresponding to the target edge device parameters;
[0108] An address writing module is used to write the first target address into the blockchain network, so that the aggregation node obtains the target edge device parameters according to the first target address, obtains the target mean vector and the target variance vector based on the target edge device parameters, determines the target global parameters according to the target mean vector and the target variance vector, obtains the target global model based on the target global parameters, writes the target global model into the blockchain network, and broadcasts it to the nodes in the blockchain network.
[0109] Optionally, the device further comprises:
[0110] A monitoring module, configured to monitor the aggregation node in real time, and when the aggregation node broadcasts a second target address, obtain the target global parameter from the aggregation node based on the second target address;
[0111] A parameter updating module is used to update the preset global parameters corresponding to the preset global model in the target edge device node according to the target global parameters, and to train the updated preset global model according to the preset local data, and to update the target edge device parameters after the training is completed.
[0112] It should be noted that for other corresponding descriptions of the functional units involved in the global model determination device based on blockchain provided in the embodiment of the present application, please refer to Figures 1 to 3 The corresponding description in the method will not be repeated here.
[0113] Based on the above Figures 1 to 3 The method shown in the embodiment of the present application accordingly provides a storage medium on which a computer program is stored, and when the computer program is executed by a processor, the above-mentioned Figures 1 to 3 The blockchain-based global model determination method shown.
[0114] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.
[0115] Based on the above Figures 1 to 3 The method shown, and Figures 4 to 5 In order to achieve the above-mentioned purpose, the embodiment of the present application further provides a computer device, which can be a personal computer, a server, a network device, etc. The computer device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figures 1 to 3 The blockchain-based global model determination method shown.
[0116] Optionally, the computer device may further include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a Bluetooth interface, a WI-FI interface), etc.
[0117] Those skilled in the art will appreciate that the computer device structure provided in this embodiment does not limit the computer device, and may include more or fewer components, or a combination of certain components, or different component arrangements.
[0118] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages and saves the hardware and software resources of the computer device, and supports the operation of information processing programs and other software and / or programs. The network communication module is used to realize communication between the components inside the storage medium, and communication with other hardware and software in the physical device.
[0119] Through the description of the above implementation methods, the technicians in this field can clearly understand that the present application can be implemented by means of software plus the necessary general hardware platform, or by hardware. First, the aggregation node in the blockchain network can randomly determine the target edge device node participating in the local training from multiple edge device nodes. After determining the target edge device node, the aggregation node sends the local training instructions to these target edge device nodes respectively, so that each target edge device node can be based on the local training instruction after receiving the local training instruction. The corresponding target edge device parameters can be finally determined according to the local training instruction, and the first target address corresponding to the target edge device parameter is written into the blockchain network. Then, the aggregation node can find the stored target edge device parameters from the target edge device node according to the first target address corresponding to each target edge device parameter, and then the aggregation node can calculate the target mean vector and the target variance vector based on all the target edge device parameters corresponding to different target edge device nodes. After obtaining the target mean vector and the target variance vector, the target mean vector and the target variance vector can be further used as the basis to determine the target global parameters, and the target global model can be obtained through the target global parameters. After obtaining the target global model, the target global model can also be written into the blockchain network and broadcast to all nodes of the blockchain network. The embodiment of the present application calculates the training results corresponding to different target edge device nodes through the aggregation node to obtain the target mean vector and the target variance vector, and obtains the target global parameters through the target mean vector and the target variance vector, and obtains the target global model through the target global parameters, which can reduce the influence of data skewness on the target global parameters corresponding to the target global model when the local data of each target edge device node is not independent and identically distributed, and improve the accuracy of the target global model.
[0120] Those skilled in the art will appreciate that the accompanying drawings are only schematic diagrams of a preferred implementation scenario, and the modules or processes in the accompanying drawings are not necessarily necessary for implementing the present application. Those skilled in the art will appreciate that the modules in the devices in the implementation scenario can be distributed in the devices of the implementation scenario according to the description of the implementation scenario, or can be changed accordingly and located in one or more devices different from the present implementation scenario. The modules of the above-mentioned implementation scenario can be combined into one module, or can be further split into multiple submodules.
[0121] The above serial numbers of this application are only for description and do not represent the advantages and disadvantages of the implementation scenarios. The above disclosure is only a few specific implementation scenarios of this application, but this application is not limited to them, and any changes that can be thought of by technicians in this field should fall within the scope of protection of this application.
Claims
1. A global model determination method based on blockchain, applied to aggregation nodes, characterized in that: include: Determine multiple target edge device nodes participating in local training, and send local training instructions to the target edge device nodes, so that the target edge device nodes obtain target edge device parameters according to the local training instructions, and write a first target address corresponding to the target edge device parameters into the blockchain network; Based on each of the first target addresses, obtaining the target edge device parameters from the target edge device node, and obtaining a target mean vector and a target variance vector according to the target edge device parameters; Determine target global parameters according to the target mean vector and the target variance vector, obtain a target global model based on the target global parameters, write the target global model into the blockchain network, and broadcast it to the nodes in the blockchain network; Determining the target global parameter according to the target mean vector and the target variance vector specifically includes: Based on the target mean vector and the target variance vector, a target random number vector is obtained by a preset random algorithm, the target random number vector is added to the target mean vector to obtain a vector corresponding to a target global parameter, and each element in the vector corresponding to the target global parameter is used as the target global parameter.
2. The method according to claim 1, characterized in that: The step of obtaining a target mean vector and a target variance vector based on the target edge device parameters specifically includes: According to the target edge device parameters, determine a target matrix corresponding to the target edge device node, wherein the number of columns of the target matrix is consistent with the number of the target edge device nodes, the number of rows of the target matrix is consistent with the dimension of any of the target edge device parameters, the dimensions corresponding to any of the target edge device parameters are the same, and the row elements of each row of the target matrix are target edge device parameters corresponding to a target edge device node; Based on the target matrix, determining a row mean corresponding to any row element in the target matrix; Subtract the corresponding row mean from any row element in the target matrix to obtain a target distance matrix, add the elements of each row of the target distance matrix and divide them by the number of elements in each row to obtain a target mean vector, and square the elements of each row of the target distance matrix, add them and divide them by the number of elements in each row to obtain a target variance vector, wherein the target mean vector and the target variance vector are both column vectors.
3. The method according to claim 1, characterized in that The obtaining of a target global model based on the target global parameters specifically includes: By using the target global parameters, the preset global parameters corresponding to the preset global model in the aggregation node are updated to obtain an updated global model; Testing the updated global model using a preset test set and calculating the test accuracy; When the test accuracy is greater than a preset accuracy threshold, taking the updated global model as the target global model; When the test accuracy is less than or equal to the preset accuracy threshold, the target global parameter is re-determined.
4. The method according to claim 3, characterized in that: When the test accuracy is less than or equal to the preset accuracy threshold, re-determining the target global parameter specifically includes: When the test accuracy is less than or equal to the preset accuracy threshold, the second target address corresponding to the target global parameter is written into the blockchain network, and the second target address is broadcast to the target edge device node, so that the target edge device node obtains the target global parameter based on the second target address, and updates the target edge device parameter based on the target global parameter; The updated target edge device parameters are obtained, and the target global parameters are re-determined.
5. A global model determination method based on blockchain, applied to a target edge device node, characterized in that: include: Receive local training instructions sent by the aggregation node and download the preset global model from the blockchain network; Based on the preset local data, the preset global model is trained, and after the training is completed, the target edge device parameters are obtained, and a first target address corresponding to the target edge device parameters is generated; Writing the first target address into the blockchain network, so that the aggregation node obtains the target edge device parameters according to the first target address, obtains the target mean vector and the target variance vector based on the target edge device parameters, determines the target global parameters according to the target mean vector and the target variance vector, obtains the target global model based on the target global parameters, writes the target global model into the blockchain network, and broadcasts it to the nodes in the blockchain network; Determining the target global parameter according to the target mean vector and the target variance vector specifically includes: Based on the target mean vector and the target variance vector, a target random number vector is obtained by a preset random algorithm, the target random number vector is added to the target mean vector to obtain a vector corresponding to a target global parameter, and each element in the vector corresponding to the target global parameter is used as the target global parameter.
6. The method according to claim 5, characterized in that The method further comprises: monitoring the aggregation node in real time, and upon monitoring the aggregation node broadcasting a second target address, acquiring the target global parameter from the aggregation node based on the second target address; The preset global parameters corresponding to the preset global model in the target edge device node are updated according to the target global parameters, and the updated preset global model is trained according to the preset local data. When the training is completed, the target edge device parameters are updated.
7. A global model determination device based on blockchain, applied to an aggregation node, characterized in that: include: A node determination module, used to determine multiple target edge device nodes participating in local training, and send local training instructions to the target edge device nodes, so that the target edge device nodes obtain target edge device parameters according to the local training instructions, and write a first target address corresponding to the target edge device parameters into the blockchain network; A parameter acquisition module, configured to acquire the target edge device parameters from the target edge device node based on each of the first target addresses, and obtain a target mean vector and a target variance vector according to the target edge device parameters; A model determination module, used to determine target global parameters according to the target mean vector and the target variance vector, and obtain a target global model based on the target global parameters, write the target global model into the blockchain network, and broadcast it to the nodes in the blockchain network; The model determination module is specifically used for: Based on the target mean vector and the target variance vector, a target random number vector is obtained by a preset random algorithm, the target random number vector is added to the target mean vector to obtain a vector corresponding to a target global parameter, and each element in the vector corresponding to the target global parameter is used as the target global parameter.
8. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
9. A computer device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Federation learning defense method and device, electronic equipment and storage medium
CN112446025A
Federal model training method and device, electronic equipment and storage medium
CN113011602A