Model training method, device, electronic device and storage medium
By adopting a master-slave structure of training node clusters and shared memory technology in AI model training, the problem of large training data and cumbersome encrypted transmission is solved, and the efficiency and security of model training are improved.
Patent Information
- Application Number
- CN202211441517.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-17
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2042-11-17
AI Technical Summary
Existing AI model training methods reduce the start-up and operating efficiency of the trusted execution environment due to the large training data, and the process of encrypting the training data and transferring it to the TEE is cumbersome, which affects the model training efficiency.
A training node cluster with a master-slave structure is used to divide the training data into multiple sub-training data, and encrypt and store it in the shared memory through the host process. The master node and the worker node train collaboratively in a trusted execution environment, using the shared memory and The queue mechanism reduces data copying and transmission overhead.
It improves the startup and operating efficiency of each training node, reduces data transmission overhead, improves the overall efficiency and integrity of model training, and ensures data security.
Smart Images

Figure CN115756846B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence (AI) technology, and in particular to a model training method, device, electronic device and storage medium. Background Art
[0002] Machine learning (Artificial Intelligence, AI) uses large amounts of data for training, and then uses the learning results for subsequent data decision-making / prediction. It has been widely used in various scenarios, such as computer vision, autonomous driving, etc.
[0003] In actual AI applications, in order to ensure security (such as model security, privacy security, etc.), the training data needs to be encrypted and passed to the Trusted Execution Environment (TEE), and the model training is completed in the TEE. However, the current training method requires a large amount of trusted memory space due to the large amount of training data, which reduces the startup and operation efficiency of the TEE. In addition, the process of encrypting the training data and passing it to the TEE is also cumbersome, which in turn affects the efficiency of model training. Summary of the invention
[0004] The embodiments of the present disclosure at least provide a model training method, device, electronic device and storage medium, which can reduce data transmission overhead and improve startup efficiency while ensuring the privacy of training data, thereby improving the training efficiency of the model.
[0005] The present disclosure provides a model training method, including:
[0006] The training data is obtained through a host process, and the training data is divided into a plurality of sub-training data for a training node cluster adopting a master-slave structure; the training node cluster includes a master node and a plurality of working nodes, and the master node and the plurality of working nodes are used to collaboratively perform model training; wherein the host process runs in a non-trusted execution environment, and the training node cluster runs in a trusted execution environment;
[0007] Encrypting each sub-training data through the host process, and storing the encrypted sub-training data in the shared memory of the host process; the shared memory of the host process is used for sharing by the host process and the training node cluster;
[0008] Recording the data storage address of each encrypted sub-training data in the shared memory through the host process, and sending each data storage address to the corresponding master node and working node respectively; wherein each data storage address corresponds to a training node;
[0009] Control the master node and each of the working nodes to obtain corresponding encrypted sub-training data from the shared memory according to corresponding data storage addresses, and decrypt the encrypted sub-training data to obtain decrypted sub-training data;
[0010] The master node and each of the working nodes are controlled to use their corresponding decrypted sub-training data to train the preset model respectively to obtain a trained model; during the training process, the master node is used to send training tasks to each of the working nodes and summarize the sub-training results sent by each of the working nodes.
[0011] In the disclosed embodiment, by using a distributed master-slave structured training node cluster to collaboratively train the model, the original large training data can be divided into multiple smaller training data, so that the startup and operation efficiency of each training node can be improved. In addition, the encrypted training data is stored in a shared memory area through the host process, and different training nodes can read and write the shared memory area. That is, each training node can directly perform decryption operations on the shared memory, and the decryption results are placed in the training node, thereby eliminating the original encrypted data copy overhead and ecall overhead, thereby further improving the training efficiency of the model.
[0012] In a possible implementation manner, after obtaining a plurality of sub-training data corresponding to the number of training nodes, the method further includes:
[0013] The master node and each of the working nodes are started through the host process, and the master node and each of the working nodes are controlled to generate a trusted memory matching the data volume according to the data volume of the corresponding sub-training data, and the trusted memory is used to store the sub-training data.
[0014] In the disclosed embodiment, corresponding trusted memory can be adaptively generated according to the data volume of sub-training data, thereby improving the startup efficiency of each training node.
[0015] In a possible implementation manner, the master node and each working node are respectively configured with the preset model; and the controlling the master node and each working node to respectively train the preset model using the corresponding decrypted sub-training data to obtain the trained model includes:
[0016] Control the master node to assign corresponding training tasks to each working node based on the decrypted sub-training data corresponding to each working node, and control the master node to send each training task to the corresponding working node;
[0017] Control each working node to train the preset model according to the corresponding training task and the corresponding decrypted sub-training data to obtain the corresponding sub-training result;
[0018] Control each working node to send the corresponding sub-training result to the master node;
[0019] Control the master node to aggregate the sub-training results of the master node and the sub-training results of each working node to obtain a total training result;
[0020] Repeat the above steps until the total training result meets the preset conditions.
[0021] In the disclosed embodiment, since the multiple training node clusters include a master node and multiple working nodes, and the master node synchronously participates in the training while being responsible for the overall training logic, the integrity of the model training can be improved while ensuring the training efficiency.
[0022] In a possible implementation, the method further includes:
[0023] A target number of queues is created by the host process based on the number of the working nodes, where the target number is twice the number of the working nodes; the target number of queues is used for two-way communication between the master node and the multiple working nodes.
[0024] In the disclosed embodiment, since the host process runs in a non-trusted environment, the efficiency of queue creation can be improved by creating a queue through the host process. In addition, the master node and each working node communicate through the queue, which can improve communication efficiency.
[0025] In a possible implementation, the target number of queues is a pair of two queues, and each pair of queues is used for bidirectional communication between the master node and one of the working nodes; after creating the target number of queues based on the number of working nodes by the host process, the method further includes:
[0026] The target number of queues are stored in a shared memory through the host process, and a queue storage address of each queue is generated;
[0027] The queue storage address of each queue in the target number of queues is sent to the master node through the host process, and the queue storage address of each pair of queues is sent to the corresponding working node; the master node communicates with each working node based on the corresponding queue storage address.
[0028] In the disclosed embodiment, by placing the queue into the shared content, the copying overhead and ecall overhead of the original encrypted data can be omitted, thereby further improving the efficiency of data transmission.
[0029] In a possible implementation, each pair of queues includes a first queue and a second queue, and the communication process between the master node and any one of the working nodes includes the following:
[0030] After controlling the master node to encrypt the first target data, the encrypted first target data is written into the queue storage address of the first queue; and, controlling the working node to obtain the encrypted first target data according to the queue storage address of the first queue; and / or,
[0031] After controlling the working node to encrypt the second target data, the encrypted second target data is written into the queue storage address of the second queue; and controlling the master node to obtain the encrypted second target data according to the queue storage address of the second queue.
[0032] In the disclosed embodiment, for the communication between the master node and any working node, encryption technology and shared memory are used to not only ensure data security but also improve data transmission efficiency.
[0033] In a possible implementation, the method further includes:
[0034] Creating thread pools for the master node and each of the working nodes respectively through the host process, each thread pool including a preset number of threads;
[0035] The controlling the master node and each of the working nodes to respectively train the preset model using the decrypted sub-training data corresponding to each of them to obtain the trained model includes:
[0036] The master node and each of the working nodes are controlled to train the preset model based on the threads in their corresponding thread pools to obtain the trained model.
[0037] In the disclosed embodiment, since the host process runs in a non-trusted execution environment, the host process creates thread pools for each training node, which can improve the efficiency of thread creation. In addition, the efficiency of training can be further improved by running multiple threads in parallel.
[0038] In a possible implementation manner, a process in which the host process encrypts each sub-training data and a process in which each training node decrypts the encrypted sub-training data share a symmetric key.
[0039] In a possible implementation, the master node and at least some of the working nodes are distributed on different physical machines; and the step of creating a target number of queues based on the number of the working nodes by a host process, where the target number is twice the number of the working nodes, includes:
[0040] For the target physical machine on which the master node is distributed, a target number of queues is created based on the number of working nodes on the target physical machine by a host machine process on the target physical machine, and the target number of queues is twice the number of working nodes on the target physical machine; the target number of queues is used for two-way communication between the master node on the target physical machine and multiple working nodes on the target physical machine. In this way, the expansion of multiple physical machines can be achieved, and the security and efficiency of data transmission on the target physical machine can be guaranteed.
[0041] In a possible implementation, for other physical machines not having the master node, the working nodes distributed on the other physical machines use the transmission control protocol TCP to perform bidirectional communication with the master node on the target physical machine. In this way, communication between the working nodes distributed on different physical machines and the master node can be achieved.
[0042] The present disclosure provides a model training device, including:
[0043] A data acquisition module, used to acquire training data through a host process, and divide the training data into multiple sub-training data for a training node cluster adopting a master-slave structure; the training node cluster includes a master node and multiple working nodes, and the master node and the multiple working nodes are used to collaborate in model training; wherein the host process runs in a non-trusted execution environment, and the training node cluster runs in a trusted execution environment;
[0044] A data encryption module, used to encrypt each sub-training data through the host process, and store the encrypted sub-training data in the shared memory of the host process; the shared memory of the host process is used to be shared by the host process and the training node cluster;
[0045] A data transmission module, used to record the data storage address of each encrypted sub-training data in the shared memory through the host process, and send each data storage address to the corresponding master node and working node respectively; wherein each data storage address corresponds to a training node;
[0046] A data decryption module, used to control the master node and each of the working nodes to obtain the corresponding encrypted sub-training data from the shared memory according to the corresponding data storage address, and decrypt the encrypted sub-training data to obtain decrypted sub-training data;
[0047] The model training module is used to control the master node and each of the working nodes to use their corresponding decrypted sub-training data to train the preset model respectively to obtain a trained model; during the training process, the master node is used to send training tasks to each of the working nodes and summarize the sub-training results sent by each of the working nodes.
[0048] In a possible implementation, the device also includes an object creation module, which is used to: start the master node and each of the working nodes through the host process, and control the master node and each of the working nodes to generate a trusted memory matching the data volume according to the data volume of the corresponding sub-training data, and the trusted memory is used to store the sub-training data.
[0049] In a possible implementation manner, the master node and each of the working nodes respectively store the preset model; and the model training module is specifically used for:
[0050] Control the master node to assign corresponding training tasks to each working node based on the decrypted sub-training data corresponding to each working node, and control the master node to send each training task to the corresponding working node;
[0051] Control each working node to train the preset model according to the corresponding training task and the corresponding decrypted sub-training data to obtain the corresponding sub-training result;
[0052] Control each working node to send the corresponding sub-training result to the master node;
[0053] Control the master node to aggregate the sub-training results of the master node and the sub-training results of each working node to obtain a total training result;
[0054] Repeat the above steps until the total training result meets the preset conditions.
[0055] In one possible implementation, the object creation module is also used to: create a target number of queues based on the number of working nodes through the host process, where the target number is twice the number of working nodes; the target number of queues is used for two-way communication between the master node and the multiple working nodes.
[0056] In a possible implementation manner, the target number of queues is formed into a pair of two queues, and each pair of the queues is used for bidirectional communication between the master node and one of the working nodes; the data transmission module is further used for:
[0057] The target number of queues are stored in a shared memory by the host process, and a queue storage address of each queue is generated;
[0058] The queue storage address of each queue in the target number of queues is sent to the master node through the host process, and the queue storage address of each pair of queues is sent to the corresponding working node; the master node communicates with each working node based on the corresponding queue storage address.
[0059] In a possible implementation manner, each pair of queues includes a first queue and a second queue, and the data encryption module is further used for:
[0060] After controlling the master node to encrypt the first target data, the encrypted first target data is written into the queue storage address of the first queue; and, controlling the working node to obtain the encrypted first target data according to the queue storage address of the first queue; and / or,
[0061] After controlling the working node to encrypt the second target data, the encrypted second target data is written into the queue storage address of the second queue; and controlling the master node to obtain the encrypted second target data according to the queue storage address of the second queue.
[0062] In a possible implementation manner, the object creation module is further used to: create thread pools for the master node and each of the working nodes respectively through the host process, and each thread pool includes a preset number of threads;
[0063] The model training module is specifically used to control the master node and each of the working nodes to train the preset model based on the threads in their corresponding thread pools to obtain the trained model.
[0064] In a possible implementation manner, a process in which the host process encrypts each sub-training data and a process in which each training node decrypts the encrypted sub-training data share a symmetric key.
[0065] In a possible implementation manner, the master node and at least some of the working nodes are distributed on different physical machines; and the object creation module is specifically used to:
[0066] For the target physical machine on which the master node is distributed, a target number of queues is created based on the number of working nodes on the target physical machine through the host machine process on the target physical machine, and the target number of queues is twice the number of working nodes on the target physical machine; the target number of queues is used for two-way communication between the master node on the target physical machine and multiple working nodes on the target physical machine.
[0067] An embodiment of the present disclosure provides an electronic device, including: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the model training method described in any of the above embodiments is performed.
[0068] An embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the model training method described in any of the above embodiments is executed.
[0069] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0071] Figure 1 A schematic diagram showing an execution process of a model training method provided by some embodiments of the present disclosure;
[0072] Figure 2 A flow chart of a model training method provided by some embodiments of the present disclosure is shown;
[0073] Figure 3 A schematic diagram showing the execution process of another model training method provided in some embodiments of the present disclosure;
[0074] Figure 4 A schematic diagram showing the execution process of another model training method provided in some embodiments of the present disclosure;
[0075] Figure 5 A schematic diagram of a communication process between a master node and each working node provided in some embodiments of the present disclosure is shown;
[0076] Figure 6 A schematic diagram showing the distribution of training nodes on multiple physical machines provided by some embodiments of the present disclosure is shown;
[0077] Figure 7 A schematic diagram showing the structure of a model training device provided in some embodiments of the present disclosure is shown;
[0078] Figure 8 A schematic diagram showing the structure of another model training device provided in some embodiments of the present disclosure is shown;
[0079] Fig. 9 A schematic diagram of an electronic device provided by some embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0080] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0081] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0082] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0083] Trusted execution environments (TEEs) ensure that sensitive data is stored, processed, and protected in an isolated, trusted environment through hardware isolation. They are widely used in various security applications, such as payment, fingerprint, and digital rights management (DRM). With the development of computer technology, AI technology has been applied to various scenarios, such as computer vision and autonomous driving. In actual AI applications, in order to ensure security (such as model security and privacy security), the training data needs to be encrypted and transferred to the trusted execution environment, and the model training is completed in the trusted execution environment.
[0084] Specifically, see Figure 1 As shown, in the process of training the model, the training data is first obtained from the database, and then the training data is encrypted and sent to the TEE. In the TEE, the encrypted training data is first decrypted, and then the model is trained based on the decrypted training data to obtain a trained model. Finally, the trained model is encrypted and sent to the user end. After the user end obtains the encrypted trained model, it can decrypt it to obtain the trained model.
[0085] Research has found that although the above model training method can ensure the privacy of training data and the security of model training, due to the large amount of training data, it requires a large amount of trusted memory space, resulting in reduced TEE startup and operation efficiency. In addition, the process of encrypting the training data and transferring it to TEE is also relatively cumbersome, which in turn affects the efficiency of model training.
[0086] Based on the above research, the present disclosure provides a model training method, which can obtain training data through a host process, and divide the training data into multiple sub-training data for a training node cluster using a master-slave structure; the training node cluster includes a master node and multiple working nodes, and the master node and the multiple working nodes are used to collaborate in model training; wherein the host process runs in a non-trusted execution environment, and the training node cluster runs in a trusted execution environment; then each sub-training data is encrypted through the host process, and the encrypted sub-training data is stored in the shared memory of the host process; the shared memory of the host process is used for sharing by the host process and the training node cluster; then each sub-training data is recorded through the host process The encrypted sub-training data has a data storage address in the shared memory, and each data storage address is sent to the corresponding master node and working node respectively; wherein each data storage address corresponds to a training node; secondly, the master node and each working node are controlled to obtain the corresponding encrypted sub-training data from the shared memory according to the corresponding data storage address, and the encrypted sub-training data is decrypted to obtain the decrypted sub-training data; finally, the master node and each working node are controlled to use their respective corresponding decrypted sub-training data to train the preset model respectively to obtain a trained model; during the training process, the master node is used to send training tasks to each working node, and summarize the sub-training results sent by each working node.
[0087] The model training method provided by the embodiment of the present disclosure can divide the original large training data into multiple smaller training data by using a distributed master-slave structure training node cluster to collaboratively train the model, so that the startup and operation efficiency of each training node can be improved. In addition, the encrypted training data is stored in a shared memory area through the host process, and different training nodes can read and write the shared memory area. That is, each training node can directly perform decryption operations on the shared memory, and the decryption results are placed in the training node, thereby eliminating the original encrypted data copy overhead and ecall overhead, thereby further improving the training efficiency of the model.
[0088] To facilitate understanding of this embodiment, the execution subject of the model training method provided by the embodiment of the present disclosure is first introduced in detail. Specifically, the execution subject of the model training method provided by the embodiment of the present disclosure is an electronic device configured with TEE. In this embodiment, the electronic device is a server, which can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, big data and artificial intelligence platforms. In other embodiments, the electronic device can also be a terminal device, which can also be a mobile device, a user terminal, a terminal, a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. Optionally, the model training method can also be implemented by a processor calling computer-readable instructions stored in a memory.
[0089] The model training method provided in the embodiment of the present application is described in detail below with reference to the accompanying drawings. Figure 2 As shown, it is a flow chart of a model training method provided by an embodiment of the present disclosure, and the model training method includes the following S101 to S105:
[0090] S101, obtaining training data through a host process, and dividing the training data into a plurality of sub-training data for a training node cluster adopting a master-slave structure; the training node cluster comprises a master node and a plurality of working nodes, and the master node and the plurality of working nodes are used to collaboratively perform model training; wherein the host process runs in a non-trusted execution environment, and the training node cluster runs in a trusted execution environment.
[0091] See also Figure 3 As shown, in some embodiments, the model training method is applied to a physical machine, which is an electronic device, such as the aforementioned server. The physical machine is configured with TEE and non-TEE, which run in parallel, and TEE is more secure than non-TEE.
[0092] Specifically, TEE can be a secure area separated from the central processing unit (CPU) or a TEE chip independent of the central processing unit. TEE provides security services to the outside world and can ensure that the code and data loaded in it are protected in terms of confidentiality and integrity. Trusted applications running in TEE can access all functions of the device's main processor and memory, while hardware isolation protects these trusted applications from user-installed applications running in the main operating system. Non-TEE can be a rich execution environment (REE) or a normal execution environment.
[0093] For example, a training node cluster with a master-slave structure can be used to train the model. The training node cluster includes a master node and multiple working nodes. The multiple working nodes can be Figure 3 In the working nodes 1 to 4 shown in FIG, the master node and the multiple working nodes are used to collaborate in model training. In the disclosed embodiment, the master node and the working nodes are both referred to as training nodes.
[0094] It should be understood that both the host process and the training node are program processes on the physical machine. The difference is that the host process runs in a non-trusted execution environment, and the training node cluster runs in a trusted execution environment.
[0095] Training data refers to the sample data required for model training, which includes sample images. It is understood that the fields of training data vary depending on the application of the training model. For example, if the training model is applied to the field of automatic driving, the training data includes sample images of the vehicle driving environment; and if the training model is applied to the field of object classification, the training data includes sample images of various types of objects. Before model training, the training data needs to be collected and stored in the database so that multiple training nodes can train the model later.
[0096] Specifically, after the training data is obtained from the database through the host process, in order to facilitate each training node to train the preset model, the host process can divide the training data for the training node cluster using a master-slave structure to obtain multiple sub-training data. Specifically, the training data can be divided according to the number of training nodes that need to be started, wherein the number of training nodes that need to be started can be determined by the resources owned by the user. In some embodiments, in order to enable multiple training nodes to obtain training results synchronously to improve training efficiency, the training data can be divided equally based on the number of training nodes that need to be started. For example, taking 5 training nodes as an example, the training data M can be divided into five equal parts to obtain 5 sub-training data, which are M / 5 respectively. Of course, in other embodiments, the training data may not be divided equally when it is divided. It can be determined according to actual needs and is not limited here.
[0097] In some possible implementations, after obtaining a plurality of sub-training data corresponding to the number of training nodes, the method further includes: starting the master node and each working node through a host process, and controlling the master node and each working node to generate a trusted memory matching the data volume according to the data volume of the corresponding sub-training data, and the trusted memory is used to store the sub-training data. That is, after dividing the data, the corresponding trusted memory space can be adaptively generated according to the data volume of the sub-training data. In addition to storing the sub-training data, the trusted memory space is also used to store intermediate variables of the training node running program.
[0098] Exemplarily, the trusted memory space of each training node can be twice the size of the corresponding sub-training data. Of course, it can also be more (such as 3 times) or less (such as 1.8 times), without specific limitation. It can be understood that in TEE, each training node corresponds to an independent enclave, that is, the training node runs on the corresponding enclave, and the size of the trusted memory of the training node is also the size of the trusted memory of the corresponding enclave.
[0099] S102, encrypt each sub-training data through the host process, and store the encrypted sub-training data in the shared memory of the host process; the shared memory of the host process is used for sharing by the host process and the training node cluster.
[0100] For example, after obtaining a plurality of sub-training data corresponding to the number of training nodes, each sub-training data can be encrypted by the host process, and the encrypted sub-training data can be stored in the shared memory of the host, so that the master node and the working node can obtain the sub-training data from the shared memory. Figure 3 As shown, the encrypted sub-training data 1, the encrypted sub-training data 2, the encrypted sub-training data 3, the encrypted sub-training data 4 and the encrypted sub-training data 5 are all stored in the shared memory.
[0101] S103, recording the data storage address of each encrypted sub-training data in the shared memory through the host process, and sending each data storage address to the corresponding master node and working node respectively; wherein each data storage address corresponds to a training node.
[0102] Specifically, after the encrypted sub-training data is stored in the shared memory of the host machine, the data storage address of each encrypted sub-training data in the shared memory can be recorded by the host machine process. For example, the data storage addresses corresponding to the five encrypted sub-training data are dp1-dp5, and then each data storage address is sent to the corresponding training node. For example, the data storage address dp1 is sent to the master node, the data storage address dp2 is sent to the working node 1, the data storage address dp3 is sent to the working node 2, the data storage address dp4 is sent to the working node 3, and the data storage address dp5 is sent to the working node 4, that is, each data storage address corresponds to a training node.
[0103] S104, controlling the master node and each of the working nodes to obtain corresponding encrypted sub-training data from the shared memory according to corresponding data storage addresses, and decrypting the encrypted sub-training data to obtain decrypted sub-training data.
[0104] After sending each data storage address to the corresponding training node, the master node and each working node can be controlled to obtain the corresponding encrypted sub-training data from the shared memory according to the corresponding data storage address, and decrypt the encrypted sub-training data to obtain the decrypted sub-training data. Specifically, the master node can obtain the encrypted sub-training data 1 according to the data storage address dp1, and decrypt the encrypted sub-training data 1 to obtain the decrypted sub-training data 1 (that is, the original sub-training data 1). The process of each working node obtaining data is similar to that of the master node, and will not be repeated here.
[0105] It should be noted that, in order to improve the efficiency of the encryption and decryption process, the process of encrypting each sub-training data by the host process and the process of decrypting the encrypted sub-training data by each training node use a symmetric key, that is, the host process and each node share a symmetric key. The symmetric key can be pre-set, or a key obtained through remote authentication (RA), or other key negotiation methods, which are not limited here.
[0106] S105, controlling the master node and each of the working nodes to use their corresponding decrypted sub-training data to train the preset model respectively to obtain a trained model; during the training process, the master node is used to send training tasks to each of the working nodes, and summarize the sub-training results sent by each of the working nodes.
[0107] It can be understood that since the same preset model is stored on the master node and each working node, after the master node and each working node respectively obtain the corresponding decrypted sub-training data, the master node and each working node can be controlled to use their corresponding decrypted sub-training data to train the preset model respectively to obtain a trained model. During the training process, the master node is used to send training tasks to each working node and summarize the sub-training results sent by each working node. That is, the master node synchronously participates in the training under the premise of being responsible for the overall training logic, and aggregates the model parameters obtained from each working node.
[0108] The specific type of the preset model is not limited, and may be Convolutional Neural Networks (CNN), Generative Adversarial Networks (GAN), linear regression, k-mean (clustering), etc. In addition, the functions implemented by the preset model vary depending on the application scenario. For example, the preset model may be a model for target detection or a model for object classification, which is not specifically limited here.
[0109] In the disclosed embodiment, the model training method provided can divide the original large training data into multiple smaller training data because it uses a training node cluster with a master-slave structure to collaboratively train the model. In this way, the startup and operation efficiency of each training node can be improved. In addition, since the host process and the training node cluster share the shared memory of the host process, the encrypted training data is stored in the shared memory area through the host process, and different training nodes can read and write the shared memory area. That is, each training node can perform decryption operations directly on the shared memory, and the decryption results are placed in the training node, thereby eliminating the original encryption data copy overhead and ecall overhead, thereby further improving the training efficiency of the model.
[0110] It should be noted that if there is no shared memory, the host process will pass the encrypted sub-training data to the enclave in the form of ecall, the encrypted sub-training data will be copied into the enclave, and the enclave thread will decrypt the encrypted sub-training data. The overhead in this process is that the encrypted sub-training data has been copied once and the host process has an ecall to transmit the data. Therefore, the use of shared memory technology can save the copying overhead and ecall overhead of encrypted data, thereby further improving the efficiency of model training.
[0111] Among them, the ecall method is the only channel for the outside of the enclave to access the inside of the enclave, but its execution process is protected by the trusted environment. All methods not declared as ecall cannot be called outside the enclave. ocall is the type of method that the enclave calls outside the enclave.
[0112] Please refer again Figure 3 In some embodiments, step S105, when the control master node and each working node use their corresponding decrypted sub-training data to train the preset model respectively, may include the following (1) to (5):
[0113] (1) Control the master node to assign corresponding training tasks to each working node based on the decrypted sub-training data corresponding to each working node, and control the master node to send each training task to the corresponding working node;
[0114] (2) Control each working node to train the preset model according to the corresponding training task and the corresponding decrypted sub-training data to obtain the corresponding sub-training result;
[0115] (3) Control each working node to send the corresponding sub-training results to the master node;
[0116] (4) The control master node aggregates the sub-training results of the master node and the sub-training results of each working node to obtain the overall training result;
[0117] (5) Repeat the above steps until the overall training results meet the preset conditions.
[0118] In the above training process, the master node is responsible for the overall logic of model training. It will assign corresponding training tasks to each working node based on the decrypted sub-training data corresponding to each working node, send each training task to each corresponding working node, and synchronously train the preset model with each working node.
[0119] In each round of training, the master node obtains the sub-training results (also called model parameters) of each working node, and then aggregates the sub-training results of the master node and each working node to obtain the total training results (total model parameters) of the preset model; then the master node re-sends the model parameters corresponding to each working node to the corresponding working node based on the sub-training data corresponding to each working node, and each working node performs another round of training on the preset model based on the corresponding sub-training data and the current model parameters, and so on, until the total training result meets the preset conditions.
[0120] Among them, the overall training result meets the preset conditions if the number of training times reaches the preset number, or the loss function of the model is less than the preset threshold, that is, the model converges to a preset degree.
[0121] See also Figure 4 In some embodiments, in order to improve communication efficiency, the method further includes: creating a target number of queues based on the number of working nodes through a host process, where the target number is twice the number of working nodes. The target number of queues is used for two-way communication between the master node and multiple working nodes. For example, if there are 5 training nodes, including 1 master node and 4 working nodes, then 8 queues need to be created for two-way communication between 1 master node and 4 working nodes.
[0122] Exemplarily, during the model training process, the master node and the worker node can send information through the created queue. Specifically, the master node can be controlled to send each training task to the corresponding worker node through the queue, and each worker node can be controlled to send the corresponding sub-training result to the master node through the queue.
[0123] Optionally, the target number of queues is a pair of two queues, and each pair of queues is used for two-way communication between the master node and one of the working nodes; after creating the target number of queues based on the number of working nodes by the host process, the method further includes the following:
[0124] The host process stores the target number of queues in the shared memory and generates the queue storage address of each queue;
[0125] The queue storage address of each queue in the target number of queues is sent to the master node through the host process, and the queue storage address of each pair of queues is sent to the corresponding working node; the master node communicates with each working node based on the corresponding queue storage address.
[0126] The following takes 4 working nodes as an example. Specifically, after the 8 queues are stored in the shared memory through the host process, the queue storage addresses qp1-qp8 of the 8 queues can be generated; then the queue storage addresses qp1-qp8 of the 8 queues are sent to the master node through the host process, and the queue storage address qp is sent to the working node i. 2i-1 And the queue storage address qp 2i For example, if it is working node 1, the queue storage address qp1 is sent to working node 1 ( Figure 4 The address of queue 1 in ) and the queue storage address qp2 ( Figure 4 The address of queue 2 in ).
[0127] Optionally, each pair of queues includes a first queue and a second queue, and the communication process between the master node and any one of the working nodes includes the following:
[0128] After the master node encrypts the first target data, the encrypted first target data is written into the queue storage address of the first queue; and, the working node is controlled to obtain the encrypted first target data according to the queue storage address of the first queue; and / or,
[0129] After the control working node encrypts the second target data, the encrypted second target data is written into the queue storage address of the second queue; and the control main node obtains the encrypted second target data according to the queue storage address of the second queue.
[0130] It can be understood that data transmission between the master node and the working node needs to use encryption technology and shared memory to ensure security and efficiency. For example, the master node wants to send data A to the working node 1. At this time, the master node needs to first encrypt A with the key k, and then write the corresponding encrypted data to the address qp1. The working node 1 can directly obtain the encrypted data by reading the address of qp1, thereby realizing the process of sending data from the master node to the working node.
[0131] See also Figure 5 As shown, the above model training process is used as an example to illustrate that in each round of training, the master node can be controlled to encrypt the training task and write the encrypted training task into the queue storage address of the corresponding first queue (such as queue 1); then the corresponding working node (such as working node 1) is controlled to obtain the encrypted training task according to the queue storage address of the first queue, thereby realizing the communication process of controlling the master node to send the training task to the corresponding working node. In addition, the working node (working node 1) can also be controlled to encrypt the corresponding sub-training result and write the encrypted sub-training result into the queue storage address of the corresponding second queue (queue 2); then the master node is controlled to obtain the encrypted sub-training result according to the queue storage address of the second queue, thereby realizing the communication process of controlling the working node to send the sub-training result to the master node.
[0132] Please refer again Figure 4 In some embodiments, the method further includes: creating thread pools for the master node and each worker node respectively through the host process, each thread pool including a preset number of threads. The preset number of threads in each thread pool is determined by the size of resources owned by the user. It is understood that the resources owned by the user may be resources pre-allocated to the user, for example, the resources may be obtained through purchase.
[0133] like Figure 5As shown, since a thread pool is created for each training node in advance through the host process, the control master node and each working node use the corresponding decrypted sub-training data to train the preset model respectively to obtain the trained model, which may include: controlling the master node and each working node to train the preset model based on the threads in the corresponding thread pool respectively to obtain the trained model, thereby further improving the training efficiency of the model. Specifically, for any thread in each thread pool, when the thread has no computing task, it can poll the task queue, and when a new task is found, it performs the computing; when the task is completed, it polls the queue again.
[0134] It can be understood that without using a thread pool, when an enclave main thread (assuming the thread ID is 1) needs an additional thread to help perform computing tasks, it needs to go through the following process:
[0135] ocall to the host process, a conversion from a trusted environment to an untrusted environment is performed, which is costly. The pthread_create function is called to create a new thread (assuming that the thread ID is 2). After thread 2 is created, thread 1 returns to the enclave through ecall (ecall has a large cost), and thread 2 also enters the enclave through ecall to perform calculations (ecall has a large cost). After thread 2 finishes calculating, ocall exits the enclave and destroys the thread (ocall has a large cost). Therefore, without pre-creating a thread pool through the host process, each time a new thread is created for calculation, it will go through four trusted environment-untrusted environment conversions, which is very costly. Among them, pthread_create is a function for creating threads in Unix-like operating systems (Unix, Linux, Mac OS X, etc.). Its function is to create a thread (actually, it is to determine the entry point for calling the thread function). After the thread is created, the related thread function starts to run.
[0136] When the thread pool is created in advance by the host process, all threads enter the enclave thread pool through ecall when the program starts and wait for computing tasks. When an enclave main thread needs an additional thread to help perform computing tasks, it only needs to find an idle thread from the thread pool to help with the calculation. This process does not involve the conversion of trusted environment to non-trusted environment. Therefore, by creating a thread pool for each training node in advance through the host process, communication overhead can be saved and training efficiency can be further improved.
[0137] It should be understood that the above-mentioned embodiments are described for the case of one physical machine, that is, the master node and each working node are distributed on one physical machine. However, the model training method can also be extended to multiple physical machines, that is, the master node and each working node are distributed on different physical machines.
[0138] The following is an explanation of the situation where the master node and multiple working nodes are distributed on two physical machines. Figure 6 As shown, each physical machine is configured with TEE and non-TEE, and each physical machine is provided with a host process. Therefore, the host process of each physical machine can be controlled to obtain training data separately. In this embodiment, the host process on each physical machine obtains the same training data, and then controls one of the host processes to divide the training data according to the total number of nodes (the number of nodes distributed on all physical machines), and sends the division result to other host processes. For example, if the training data is divided by host process 1, the division result is sent (informed) to host process 2; then each host process performs data encryption processing based on the number of training nodes on the physical machine where it is located. The subsequent process is similar to the methods in the aforementioned implementations and will not be repeated here.
[0139] It should be noted that, unlike the aforementioned embodiments, the master node communicates with the working nodes distributed on the same physical machine using the aforementioned technology of creating queues and storing the created queues in shared memory, while communicating with the working nodes distributed on different physical machines using the Transmission Control Protocol (TCP).
[0140] Specifically, for the target physical machine 1 with a master node, the host process 1 on the target physical machine 1 creates a target number of queues based on the number of working nodes on the target physical machine 1. The target number of queues is twice the number of working nodes on the target physical machine, that is, 4 queues need to be created, which are used for two-way communication between the master node on the target physical machine 1 and multiple working nodes (working node 1 and working node 2) on the target physical machine. For other physical machines 2 without a master node, the working nodes (working node 3 and working node 4) distributed on the other physical machines 2 use TCP to communicate with the master node on the target physical machine 1.
[0141] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0142] Based on the same technical concept, a model training device corresponding to the model training method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned model training method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0143] Reference Figure 7 FIG. 7 is a schematic diagram of a model training device 700 provided in an embodiment of the present disclosure, wherein the device includes:
[0144] The data acquisition module 701 is used to acquire training data through a host process, and divide the training data into multiple sub-training data for a training node cluster adopting a master-slave structure; the training node cluster includes a master node and multiple working nodes, and the master node and the multiple working nodes are used to collaborate in model training; wherein the host process runs in a non-trusted execution environment, and the training node cluster runs in a trusted execution environment;
[0145] A data encryption module 702 is used to encrypt each sub-training data through the host process, and store the encrypted sub-training data in the shared memory of the host process; the shared memory of the host process is used to be shared by the host process and the training node cluster;
[0146] The data transmission module 703 is used to record the data storage address of each encrypted sub-training data in the shared memory through the host process, and send each data storage address to the corresponding master node and working node respectively; wherein each data storage address corresponds to a training node;
[0147] The data decryption module 704 is used to control the master node and each of the working nodes to obtain the corresponding encrypted sub-training data from the shared memory according to the corresponding data storage address, and decrypt the encrypted sub-training data to obtain decrypted sub-training data;
[0148] The model training module 705 is used to control the master node and each of the working nodes to use their corresponding decrypted sub-training data to train the preset model respectively to obtain a trained model; during the training process, the master node is used to send training tasks to each of the working nodes and summarize the sub-training results sent by each of the working nodes.
[0149] In one possible implementation, see Figure 8 As shown, the device further includes an object creation module 706, and the object creation module 706 is used to:
[0150] The master node and each of the working nodes are started through the host process, and the master node and each of the working nodes are controlled to generate a trusted memory matching the data volume according to the data volume of the corresponding sub-training data, and the trusted memory is used to store the sub-training data.
[0151] In a possible implementation, the multiple training nodes include a master node and multiple working nodes, and the master node and each working node respectively store the preset model; the model training module 705 is specifically used to:
[0152] Control the master node to assign corresponding training tasks to each working node based on the decrypted sub-training data corresponding to each working node, and control the master node to send each training task to the corresponding working node;
[0153] Control each working node to train the preset model according to the corresponding training task and the corresponding decrypted sub-training data to obtain the corresponding sub-training result;
[0154] Control each working node to send the corresponding sub-training result to the master node;
[0155] Control the master node to aggregate the sub-training results of the master node and the sub-training results of each working node to obtain a total training result;
[0156] Repeat the above steps until the total training result meets the preset conditions.
[0157] In a possible implementation, the object creation module 706 is also used to: create a target number of queues based on the number of working nodes through the host process, where the target number is twice the number of working nodes; the target number of queues is used for two-way communication between the master node and the multiple working nodes.
[0158] In a possible implementation manner, the target number of queues is formed into a pair of two queues, and each pair of the queues is used for bidirectional communication between the master node and one of the working nodes; the data transmission module 703 is further used to:
[0159] The target number of queues are stored in a shared memory through the host process, and a queue storage address of each queue is generated;
[0160] The queue storage address of each queue in the target number of queues is sent to the master node through the host process, and the queue storage address of each pair of queues is sent to the corresponding working node; the master node communicates with each working node based on the corresponding queue storage address.
[0161] In a possible implementation manner, each pair of queues includes a first queue and a second queue, and the data encryption module 702 is further configured to:
[0162] After controlling the master node to encrypt the first target data, the encrypted first target data is written into the queue storage address of the first queue; and, controlling the working node to obtain the encrypted first target data according to the queue storage address of the first queue; and / or,
[0163] After controlling the working node to encrypt the second target data, the encrypted second target data is written into the queue storage address of the second queue; and controlling the master node to obtain the encrypted second target data according to the queue storage address of the second queue.
[0164] In a possible implementation, the object creation module 706 is further used to: create thread pools for the master node and each of the working nodes respectively through the host process, and each thread pool includes a preset number of threads;
[0165] The model training module 705 is specifically used to control the master node and each working node to train the preset model based on the threads in their respective corresponding thread pools to obtain the trained model.
[0166] In a possible implementation manner, a process in which the host process encrypts each sub-training data and a process in which each training node decrypts the encrypted sub-training data share a symmetric key.
[0167] In a possible implementation manner, the master node and at least some of the working nodes are distributed on different physical machines; the object creation module 706 is specifically used to:
[0168] For the target physical machine on which the master node is distributed, a target number of queues is created based on the number of working nodes on the target physical machine through the host machine process on the target physical machine, and the target number of queues is twice the number of working nodes on the target physical machine; the target number of queues is used for two-way communication between the master node on the target physical machine and multiple working nodes on the target physical machine.
[0169] In a possible implementation manner, the data transmission module 703 is further configured to:
[0170] For other physical machines where the master node is not distributed, the working nodes distributed on the other physical machines are controlled to perform two-way communication with the master node on the target physical machine using the transmission control protocol TCP.
[0171] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0172] Based on the same technical concept, the embodiment of the present disclosure also provides an electronic device. Fig. 9 , which is a schematic diagram of the structure of an electronic device 900 provided in an embodiment of the present disclosure, including a processor 901, a memory 902, and a bus 903. The memory 902 is used to store execution instructions, including a memory 9021 and an external memory 9022; the memory 9021 is also called an internal memory, which is used to temporarily store the operation data in the processor 901 and the data exchanged with the external memory 9022 such as a hard disk. The processor 901 exchanges data with the external memory 9022 through the memory 9021.
[0173] In the embodiment of the present application, the memory 902 is specifically used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 901. That is, when the electronic device 900 is running, the processor 901 communicates with the memory 902 through the bus 903, so that the processor 901 executes the application code stored in the memory 902, and then executes the method described in any of the above embodiments.
[0174] Among them, the memory 902 can be, but is not limited to, random access memory (Random Access Memory, RAM), read only memory (Read Only Memory, ROM), programmable read-only memory (Programmable Read-Only Memory, PROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable read-only memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
[0175] Processor 901 may be an integrated circuit chip with signal processing capabilities. The above-mentioned processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present invention may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0176] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 900. In other embodiments of the present application, the electronic device 900 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0177] The present disclosure also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the model training method in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0178] The embodiments of the present disclosure also provide a computer program product, which carries a program code. The instructions included in the program code can be used to execute the steps of the model training method in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.
[0179] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).
[0180] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.
[0181] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0182] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0183] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk.
[0184] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A model training method, characterized in that: include: Acquire training data through a host process, and for a training node cluster adopting a master-slave structure, divide the training data into a plurality of sub-training data based on the number of training nodes to be started in the training node cluster; The training node cluster includes a master node and a plurality of working nodes, and the master node and the plurality of working nodes are used to collaboratively perform model training; wherein the host machine process runs in a non-trusted execution environment, and the training node cluster runs in a trusted execution environment; Encrypting each sub-training data through the host process, and storing the encrypted sub-training data in the shared memory of the host process; the shared memory of the host process is used for sharing by the host process and the training node cluster; Recording the data storage address of each encrypted sub-training data in the shared memory through the host process, and sending each data storage address to the corresponding master node and working node respectively; wherein each data storage address corresponds to a training node; Control the master node and each of the working nodes to obtain corresponding encrypted sub-training data from the shared memory according to corresponding data storage addresses, and decrypt the encrypted sub-training data to obtain decrypted sub-training data; The master node and each of the working nodes are controlled to use their corresponding decrypted sub-training data to train the preset model respectively to obtain a trained model; during the training process, the master node is used to send training tasks to each of the working nodes and summarize the sub-training results sent by each of the working nodes.
2. The method according to claim 1, characterized in that After obtaining a plurality of sub-training data corresponding to the number of training nodes, the method further includes: The master node and each of the working nodes are started through the host process, and the master node and each of the working nodes are controlled to generate a trusted memory matching the data volume according to the data volume of the corresponding sub-training data, and the trusted memory is used to store the sub-training data.
3. The method according to claim 1, characterized in that The master node and each working node are respectively configured with the preset model; the controlling the master node and each working node to respectively train the preset model using the corresponding decrypted sub-training data to obtain the trained model includes: Control the master node to assign corresponding training tasks to each working node based on the decrypted sub-training data corresponding to each working node, and control the master node to send each training task to the corresponding working node; Control each working node to train the preset model according to the corresponding training task and the corresponding decrypted sub-training data to obtain the corresponding sub-training result; Control each working node to send the corresponding sub-training result to the master node; Control the master node to aggregate the sub-training results of the master node and the sub-training results of each working node to obtain a total training result; Repeat the above steps until the total training result meets the preset conditions.
4. The method according to claim 1, characterized in that The method further comprises: A target number of queues is created by the host process based on the number of the working nodes, where the target number is twice the number of the working nodes; the target number of queues is used for two-way communication between the master node and the multiple working nodes.
5. The method according to claim 4, characterized in that The target number of queues is formed into a pair of two queues, and each pair of queues is used for bidirectional communication between the master node and one of the working nodes; After creating the target number of queues based on the number of working nodes by the host process, the method further includes: The target number of queues are stored in a shared memory through the host process, and a queue storage address of each queue is generated; The queue storage address of each queue in the target number of queues is sent to the master node through the host process, and the queue storage address of each pair of queues is sent to the corresponding working node; the master node communicates with each working node based on the corresponding queue storage address.
6. The method according to claim 5, characterized in that Each pair of queues includes a first queue and a second queue, and the communication process between the master node and any of the working nodes includes the following: After controlling the master node to encrypt the first target data, the encrypted first target data is written into a queue storage address of the first queue; and, controlling the working node to obtain the encrypted first target data according to the queue storage address of the first queue; and / or, After controlling the working node to encrypt the second target data, the encrypted second target data is written into the queue storage address of the second queue; and controlling the master node to obtain the encrypted second target data according to the queue storage address of the second queue.
7. The method according to claim 1, characterized in that The method further comprises: Creating thread pools for the master node and each of the working nodes respectively through the host process, each thread pool including a preset number of threads; The controlling the master node and each of the working nodes to respectively train the preset model using the decrypted sub-training data corresponding to each of them to obtain the trained model includes: The master node and each working node are controlled to train the preset model based on threads in their corresponding thread pools to obtain the trained model.
8. The method according to claim 1, characterized in that The process of encrypting each sub-training data by the host process and the process of decrypting the encrypted sub-training data by each training node share a symmetric key.
9. The method according to claim 4, characterized in that The master node and at least some of the working nodes are distributed on different physical machines; The creating a target number of queues based on the number of the working nodes by the host process, where the target number is twice the number of the working nodes, includes: For the target physical machine on which the master node is distributed, a target number of queues is created based on the number of working nodes on the target physical machine through the host machine process on the target physical machine, and the target number of queues is twice the number of working nodes on the target physical machine; the target number of queues is used for two-way communication between the master node on the target physical machine and multiple working nodes on the target physical machine.
10. The method according to claim 9, characterized in that The method further comprises: For other physical machines where the master node is not distributed, the working nodes distributed on the other physical machines are controlled to perform two-way communication with the master node on the target physical machine using the transmission control protocol TCP.
11. A model training device, characterized in that: include: A data acquisition module is used to acquire training data through a host process, and for a training node cluster adopting a master-slave structure, divide the training data into a plurality of sub-training data based on the number of training nodes that need to be started in the training node cluster; The training node cluster includes a master node and a plurality of working nodes, and the master node and the plurality of working nodes are used to collaboratively perform model training; wherein the host machine process runs in a non-trusted execution environment, and the training node cluster runs in a trusted execution environment; A data encryption module, used to encrypt each sub-training data through the host process, and store the encrypted sub-training data in the shared memory of the host process; the shared memory of the host process is used to be shared by the host process and the training node cluster; A data transmission module, used to record the data storage address of each encrypted sub-training data in the shared memory through the host process, and send each data storage address to the corresponding master node and working node respectively; wherein each data storage address corresponds to a training node; A data decryption module, used to control the master node and each of the working nodes to obtain the corresponding encrypted sub-training data from the shared memory according to the corresponding data storage address, and decrypt the encrypted sub-training data to obtain decrypted sub-training data; The model training module is used to control the master node and each of the working nodes to use their corresponding decrypted sub-training data to train the preset model respectively to obtain a trained model; during the training process, the master node is used to send training tasks to each of the working nodes and summarize the sub-training results sent by each of the working nodes.
12. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the model training method as described in any one of claims 1-10 is performed.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, executes the model training method as described in any one of claims 1 to 10.
