A model training method and device
By generating and updating target model parameters in deep learning model training, the problem of stopping training when adding new training data is solved, and the training continuity and efficiency are improved.
Patent Information
- Application Number
- CN202111177135.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-09
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2041-10-09
AI Technical Summary
Existing deep learning model training needs to be stopped when new training data is added, resulting in reduced training efficiency.
When new training data is added to the task node device, the target data identification is sent to the parameter node device, the corresponding target model parameters are generated, and the non-continuous storage is used to store it in the memory of the parameter node device. Then, the target model parameters are sent to the task node device through the parameter node device, the target gradient value is calculated, and the target model parameters are updated.
It realizes that when adding new training data, it does not need to stop training, and directly processes the added data, avoiding errors due to the inability to find the associated model parameters, and avoiding feature space overflow, ensuring the normal progress of training.
Smart Images

Figure CN113987004B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning model training, and in particular to a model training method and device. Background Art
[0002] Model training involves a large amount of data and calculations. The whole process is very complicated, which leads to a long training cycle. At present, distributed training is popular for its high efficiency. Among them, the PS (Parameter Server) architecture is the representative, which includes parameter server nodes and task nodes; the main function of the parameter server node is to initialize and save model parameters, accept local gradients calculated by task nodes, summarize and calculate global gradients, and update model parameters. The main function of the task node is to save part of the training data, initialize the model, pull the latest model parameters from the parameter server node, read the model parameters, calculate the local gradient according to the training data, and then upload the local gradient to the parameter server node. The two parts of the node perform their respective duties to avoid the concentration of data and calculation processes in one place.
[0003] In the process of model training using PS architecture in existing deep learning platforms, it is necessary to prepare training data in advance and set model parameters based on the training data. After starting the training, the model is trained based on the prepared training data.
[0004] However, in the above training process, if new training data is added, the training will be terminated, so the training can only be restarted, delaying the training process. Summary of the invention
[0005] In view of the above problems, an embodiment of the present invention provides a model training method and device to solve the problem in the prior art that when new training data is added, training needs to be stopped, which affects the training efficiency.
[0006] In a first aspect of the present invention, a model training method is provided, which is applied to a distributed system including a task node device and a parameter node device, wherein the task node device stores training data required for training the model, and the parameter node device stores a data identifier of each piece of training data and a model parameter corresponding to each data identifier, and the method comprises:
[0007] When the task node device adds new training data, the target data identifier is sent to the parameter node device, wherein the target data identifier is a data identifier in the newly added training data;
[0008] If the parameter node device fails to find the model parameter corresponding to the target data identifier, generating the corresponding target model parameter for the target data identifier, and storing the target data identifier and the target model parameter in the memory of the parameter node device in a non-continuous storage manner;
[0009] The target model parameters are sent to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the training data corresponding to the target data identifier and the target model parameters;
[0010] The target gradient value is sent to the parameter node device through the task node device, so that the parameter node device updates the target model parameter based on the target gradient value.
[0011] Optionally, after the parameter node device updates the target model parameter based on the target gradient value, the method further includes:
[0012] Determining an actual data range value by the parameter node device based on the data identifier and the model parameter in the memory, wherein the actual data range value includes: the number of elements in each dimension of the data identifier and the model parameter in the memory;
[0013] When the actual data range value is different from the preset data range value, the data identifier and model parameters in the memory are stored in the external memory of the parameter node device according to the actual data range value, wherein the preset data range value includes the data identifier determined based on the training data before starting training and the number of elements in each dimension of the model parameters.
[0014] Optionally, storing the data identifier and the model parameter in the memory into the external memory of the parameter node device according to the actual data range value includes:
[0015] Generate an identification tensor and a parameter tensor according to the data identification and model parameters in the memory respectively;
[0016] According to the number of elements in each dimension of the identification tensor and the parameter tensor, the identification tensor and the parameter tensor are respectively stored in the external memory of the parameter node device.
[0017] Optionally, the parameter node device updates the target model parameter based on the target gradient value, including:
[0018] The target model parameters are updated using a target optimizer based on the target gradient value, wherein the target optimizer is an optimizer designed for non-continuously stored variables.
[0019] Optionally, when the newly added training data includes multiple pieces of training data and the number of the parameter node devices is multiple, sending the target data identifier to the parameter node device includes:
[0020] The target data identifiers of the plurality of training data are respectively sent to different parameter node devices.
[0021] In a second aspect of the implementation of the present invention, a model training device is also provided, which is applied to a distributed system including a task node device and a parameter node device, wherein the task node device stores training data required for training the model, and the parameter node device stores a data identifier of each training data and a model parameter corresponding to each data identifier, and the device includes:
[0022] A receiving module, used to receive target information input by a user, wherein the target information includes information required by multiple different applications when querying data in their respective corresponding data sources;
[0023] A sending module, used for sending a target data identifier to a parameter node device when the task node device adds new training data, wherein the target data identifier is a data identifier in the newly added training data;
[0024] A parameter returning module, configured to generate a corresponding target model parameter for the target data identifier if the parameter node device fails to find the model parameter corresponding to the target data identifier, and store the target data identifier and the target model parameter in the memory of the parameter node device in a non-continuous storage manner;
[0025] A gradient module, used for sending the target model parameters to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the training data corresponding to the target data identifier and the target model parameters;
[0026] An updating module is used to send the target gradient value to the parameter node device through the task node device, so that the parameter node device updates the target model parameter based on the target gradient value.
[0027] Optionally, the device further comprises:
[0028] A judgment module, configured to determine an actual data range value based on the data identifier and the model parameter in the memory through the parameter node device, wherein the actual data range value includes: the number of elements in each dimension of the data identifier and the model parameter in the memory;
[0029] A storage module is used to store the data identifier and model parameters in the memory into the external memory of the parameter node device according to the actual data range value when the actual data range value is different from the preset data range value, wherein the preset data range value includes the data identifier determined based on the training data before starting training and the number of elements in each dimension of the model parameter.
[0030] Optionally, the storage module includes:
[0031] A generating unit, used to generate an identification tensor and a parameter tensor according to the data identification and the model parameters in the memory respectively;
[0032] A storage unit is used to store the identification tensor and the parameter tensor in the external memory of the parameter node device according to the number of elements in each dimension of the identification tensor and the parameter tensor.
[0033] Optionally, the updating module is specifically used to update the target model parameters using a target optimizer based on the target gradient value, wherein the target optimizer is an optimizer designed for non-continuously stored variables.
[0034] Optionally, when the newly added training data includes multiple pieces of training data and the number of the parameter node devices is multiple, the sending module is specifically used to send the respective target data identifiers in the multiple pieces of training data to different parameter node devices respectively.
[0035] In a third aspect of the present invention, there is also provided an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0036] Memory, used to store computer programs;
[0037] The processor is used to implement the steps of the above-mentioned model training method when executing the program stored in the memory.
[0038] In the fourth aspect of the implementation of the present invention, a computer-readable storage medium is also provided, on which a computer program is stored. When the computer program is executed by a processor, the training method of the model as described in any one of the first aspects is implemented.
[0039] In the fifth aspect of the implementation of the present invention, there is also provided a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the training method of the above-mentioned model.
[0040] Compared with the prior art, the present invention has the following advantages:
[0041] The training method of the model provided by the present invention is applied to a distributed system including a task node device and a parameter node device, wherein the task node device stores the training data required for the training model, and the parameter node device stores the data identifier of each training data and the model parameters corresponding to each data identifier. The method comprises: when the task node device adds training data, the target data identifier is sent to the parameter node device, wherein the target data identifier is the data identifier in the newly added training data. No need to stop training, and the training data is directly added. When the parameter node device fails to find the model parameter corresponding to the target data identifier, the corresponding target model parameter is generated for the target data identifier, and the target data identifier and the target model parameter are stored in the memory of the parameter node device in a non-continuous storage manner. Even if the model parameter associated with the newly added training data is not found, a corresponding target model parameter can be directly generated to avoid direct error reporting; and storing in a non-continuous storage manner can also avoid feature space overflow. The target model parameter is sent to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the training data corresponding to the target data identifier and the target model parameter. The target gradient value obtained by reverse calculation can be prepared for the update of the target parameter model. The target gradient value is sent to the parameter node device through the task node device, so that the parameter node device updates the target model parameter based on the target gradient value. The target model parameter is updated by the target gradient value, so that the numerical value of the target model parameter is more accurate and effective. In the case of newly added training data, the embodiment of the present invention can process the newly added training data to avoid reporting errors due to failure to find model parameters associated with the newly added training data, and can also avoid feature space overflow, thereby ensuring that the training is carried out normally, so that there is no need to terminate the training. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0043] Figure 1 A flowchart of the steps of the model training method provided by an embodiment of the present invention;
[0044] Figure 2 A schematic diagram of a non-contiguous storage architecture provided by an embodiment of the present invention;
[0045] Figure 3 A schematic diagram of a process for storing data identifiers and model parameters in an external memory provided by an embodiment of the present invention;
[0046] Figure 4 A schematic diagram of a process for restoring data identifiers and model parameters provided by an embodiment of the present invention;
[0047] Figure 5 A schematic diagram of the practical application of the training method of the model provided in the embodiment of the present invention;
[0048] Figure 6 A structural block diagram of a training device for a model provided in an embodiment of the present invention;
[0049] Figure 7 This is a structural block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] It should be understood that the references to "one embodiment" or "an embodiment" throughout the specification mean that the specific features, structures, or characteristics associated with the embodiment are included in at least one embodiment of the present invention. Therefore, the references to "in one embodiment" or "in an embodiment" appearing throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0052] In various embodiments of the present invention, it should be understood that the size of the serial numbers of the following processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0053] See also Figure 1 , an embodiment of the present invention provides a model training method, which is applied to a distributed system including a task node device and a parameter node device, wherein the task node device stores the training data required for training the model, and the parameter node device stores the data identifier of each training data and the model parameters corresponding to each data identifier. The number of training data stored in the task node device is multiple, preferably, it can be tens of thousands, but not limited to this. In order to distinguish different training data, each training data is provided with a unique data identifier. For example, if the training data is user feature data, the data identifier can be a user identifier for distinguishing different users. Each data identifier in the parameter node device corresponds to a part of the model parameters. Here, the data identifier and the model parameter can be stored in the form of a key-value pair structure.
[0054] It is understandable that the model trained by the training method of the model can be a recommendation model in a recommendation scenario of large-scale sparse features, but is not limited thereto. In the case where the training object of the training method is a recommendation model, the training data is large-scale sparse features about user behavior. By inputting sparse features about user behavior into the recommendation model, the user's preferences or the data content of the user's preferences can be output, thereby achieving the purpose of recommendation.
[0055] The method may include:
[0056] Step 101: When the task node device adds new training data, the target data identifier is sent to the parameter node device.
[0057] It should be noted that during the model training process, users can import new training data into the task node device, thereby adding training data to the model training and improving the model training results. For example, during the training of the above recommendation model, users can pre-process the newly collected large amount of user behavior data so that its data format is consistent with the original training data, thereby generating new training data, and importing this part of the new training data into the task node device as new training data.
[0058] The target data identifier is a data identifier in the newly added training data, and the model parameters associated with the newly added training data can be pulled from the parameter node device through the target data identifier.
[0059] Step 102: if the parameter node device fails to find the model parameters corresponding to the target data identifier, a corresponding target model parameter is generated for the target data identifier, and the target data identifier and the target model parameter are stored in the memory of the parameter node device in a non-continuous storage manner.
[0060] It should be noted that the parameter node device stores model parameters associated with training data. The model parameters are usually divided into multiple different parts, each of which corresponds to its associated training data and is processed by its associated training data. Here, the model parameters correspond to the training data associated with them, that is, the model parameters correspond to the data identifiers of the training data associated with them.
[0061] If the model parameter corresponding to the target data identifier is not found in the parameter node device, it means that the training data indicated by the target data identifier is newly added training data. To avoid error reporting, it is necessary to generate a target model parameter corresponding to the target data identifier, that is, initialize a model parameter in the parameter node device as the target model parameter according to the preset algorithm. Thus, the model parameter corresponding to the target data identifier can be found in the parameter node device.
[0062] It is understandable that in order to improve the training speed, the parameter node device usually backs up the pre-stored model parameters to the memory, and directly searches for the model parameters in the memory. Accordingly, after the target model parameters are generated, they are stored in the memory in the form of the original model parameters. That is, they are stored in the memory of the parameter node device in a non-continuous storage manner. Figure 2 As shown, by adopting the form of non-continuous storage, the data you want to store can be freely added to the memory.
[0063] Of course, when the parameter node device finds the model parameters corresponding to the target data identifier, the found model parameters are used as the target model parameters.
[0064] Step 103: Send the target model parameters to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the target data identifier corresponding to the training data and the target model parameters.
[0065] It should be noted that the task node device is used to pull the model parameters on the parameter node device and calculate the gradient value based on the training data for the parameter node device to update the model parameters. Therefore, the target model parameter here is the model parameter associated with the training data indicated by the target data identifier pulled by the task node device. Here, when calculating the target gradient value, it can be calculated according to any gradient algorithm, which will not be repeated here.
[0066] Step 104: Send the target gradient value to the parameter node device via the task node device, so that the parameter node device updates the target model parameters based on the target gradient value.
[0067] It should be noted that the parameter node device is used to update the model parameters based on the gradient value, that is, to update the parameter value of the target model parameter.
[0068] The training method of the model in the embodiment of the present invention is applied to a distributed system including a task node device and a parameter node device, wherein the task node device stores the training data required for the training model, and the parameter node device stores the data identifier of each training data and the model parameters corresponding to each data identifier. The method comprises: when the task node device adds new training data, the target data identifier is sent to the parameter node device, wherein the target data identifier is the data identifier in the newly added training data. There is no need to stop training, and the training data is directly added. When the parameter node device does not find the model parameter corresponding to the target data identifier, the corresponding target model parameter is generated for the target data identifier, and the target data identifier and the target model parameter are stored in the memory of the parameter node device in a non-continuous storage manner. Even if the model parameter associated with the newly added training data is not found, a corresponding target model parameter can be directly generated to avoid direct error reporting; and storing in a non-continuous storage manner can also avoid feature space overflow. The target model parameter is sent to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the training data corresponding to the target data identifier and the target model parameter. The target gradient value obtained by reverse calculation can be prepared for the update of the target parameter model. The target gradient value is sent to the parameter node device through the task node device, so that the parameter node device updates the target model parameter based on the target gradient value. The target model parameter is updated by the target gradient value, so that the numerical value of the target model parameter is more accurate and effective. In the case of newly added training data, the embodiment of the present invention can process the newly added training data to avoid reporting errors due to failure to find model parameters associated with the newly added training data, and can also avoid feature space overflow, thereby ensuring that the training is carried out normally, so that there is no need to terminate the training.
[0069] Optionally, during the training process, the data identifiers and model parameters stored in the memory can be synchronized to the external memory at regular intervals or at a preset number of training times, so as to avoid data loss due to power failure. Specifically, after the parameter node device updates the target model parameters based on the target gradient value, the method further includes:
[0070] The actual data range value is determined by the parameter node device based on the data identifier in the memory and the model parameters, wherein the actual data range value includes: the number of elements in each dimension of the data identifier in the memory and the model parameters.
[0071] It should be noted that the data identifiers and model parameters in the memory are usually multidimensional arrays, for example, a two-dimensional array of 100×10, where the number of elements in the first dimension is 100 and the number of elements in the second dimension is 10. Accordingly, the actual data range value may be (100, 10).
[0072] When the actual data range value is different from the preset data range value, the data identifier and model parameters in the memory are stored in the external memory of the parameter node device according to the actual data range value.
[0073] It should be noted that the preset data range value includes the number of elements in each dimension of the data identifier and model parameters determined based on the training data before starting training. Before starting training, the number of elements in each dimension of the data identifier and model parameters to be stored in the memory is estimated based on all the current training data. For example, if there are currently 100 training data, and the number of parameters of the data identifier and model parameters corresponding to each training data is 10, then the preset data range value can be (100, 10). Here, the preset data range value is similar to the Shape parameter in the machine learning system Tensorflow, which will not be repeated here.
[0074] In an embodiment of the present invention, by synchronously storing the data identifiers and model parameters in the memory into the external memory, data loss after power failure can be avoided; at the same time, even when the actual data range value is different from the preset data range value, the storage of data identifiers and model parameters can be achieved.
[0075] Optionally, storing the data identifier and the model parameters in the memory into the external memory of the parameter node device according to the actual data range value includes:
[0076] Generate identification tensor and parameter tensor according to the data identification and model parameters in memory respectively.
[0077] It should be noted that the data identifiers and model parameters in the memory of the parameter node device are stored together, which makes it convenient to query the data directly. Among them, the data identifier and the model parameter correspond one to one in the form of a key-value pair (KV) structure, that is, the data identifier is the key in the key-value pair, and the corresponding model parameter is the value. Therefore, when it is necessary to generate a key tensor based on all the keys in the memory and a value tensor based on all the values, it is only necessary to generate an identifier tensor based on the data identifier in the memory and generate a parameter tensor based on the model in the memory. The identifier tensor is the key tensor, and the parameter tensor is the value tensor.
[0078] According to the number of elements in each dimension of the identification tensor and the parameter tensor, the identification tensor and the parameter tensor are stored in the external memory of the parameter node device respectively.
[0079] It should be noted that the identification tensor and parameter tensor are stored according to the actual situation to avoid data loss. For example, if the budget tensor is a 100×10 two-dimensional tensor and the actual parameter tensor is a 90×10 two-dimensional tensor, then after being stored in the external memory, the identification tensor is a 90×1 two-dimensional tensor and the parameter tensor is a 90×10 two-dimensional tensor.
[0080] like Figure 3 As shown in the figure, it is a schematic diagram of storing data identifiers and model parameters in external memory, where the data tensor is the data identifier and model parameter in the memory of the parameter node device, and the data identifier and model parameter are represented in the data format of the tensor. For the data identifier in the memory, an identifier tensor is generated; for the parameter model in the memory, a parameter tensor is generated. Then, the logic of shape parameter detection in the existing Tensorflow is borrowed to determine whether the predefined data range value and the actual data range value are the same. And store according to the actual data range value.
[0081] Of course, when restoring the data identifiers and model parameters after the training is terminated, a similar method of storing the data identifiers and model parameters can be used to restore them, such as Figure 4 As shown, the identification tensor and parameter tensor are restored respectively, and it is determined whether the predefined data range value and the actual data range value are the same. In different cases, the data identification and model parameters are obtained according to the actual data range value. This will not be described in detail here.
[0082] In the embodiment of the present invention, the data identifier and the model parameter may be stored separately, thereby facilitating subsequent use.
[0083] Optionally, the parameter node device updates the target model parameter based on the target gradient value, including:
[0084] The target model parameters are updated using a target optimizer based on the target gradient value, wherein the target optimizer is an optimizer designed for non-continuously stored variables.
[0085] It should be noted that after the gradient value is calculated, the parameter matrix (model parameters) needs to be updated according to certain strategies and algorithms, and these algorithms and strategies are called optimizers. It is understandable that there are differences in optimizers for variables in different storage forms. The target optimizer used in the present invention is different from the existing optimizer designed for variables with continuous storage. Among them, before using the optimizer to process the gradient value, it is necessary to construct an optimizer subgraph. Specifically, it is possible to detect whether the storage form of its own variables (data identifiers and model parameters) is a non-continuous storage form. If so, an optimizer designed for variables with non-continuous storage is added to the calculation graph. The optimizer here includes but is not limited to FTRL (Follow-the-regularized-Leader) optimizer and SGD (stochastic gradient descent) optimizer. The calculation graph here is equivalent to the calculation graph in Tensorflow, which will not be repeated here.
[0086] In the embodiment of the present invention, the target gradient value is optimized by an optimizer designed for discontinuously stored variables, so that the updated target model parameters have a better training effect.
[0087] Optionally, when the newly added training data includes multiple pieces of training data and the number of parameter node devices is multiple, sending the target data identifier to the parameter node device includes:
[0088] The target data identifiers of the plurality of training data are respectively sent to different parameter node devices.
[0089] It should be noted that by setting multiple parameter node devices, multiple training data can be processed in parallel. The processing process of each parameter node device is the same. Figure 5 As shown, it is a practical application diagram of the training method of the model provided by the embodiment of the present invention, in which only one task node device and two parameter node devices are used as examples for explanation. The newly added training data includes multiple training data, where the data identifiers of multiple training data are usually connected together to form a string, namely a data identifier string. The data string can be preprocessed to convert the string data into integer data, and then the preprocessed data identifier string can be segmented using a hash algorithm to segment it into individual data identifiers. Figure 5 Only two data identifiers (the first data identifier and the second data identifier) are shown, but not limited to this. Here, the subsequent processing for the first data identifier and the subsequent processing for the second data identifier are similar, and only the subsequent processing of the first data identifier is described here. The task node device sends the first data identifier to the parameter node device 1, and the parameter node device 1 performs return processing, that is, searches for whether the first data identifier exists in the data identifier in the local memory. If it exists, the model parameter corresponding to the first data identifier is determined as the first model parameter. If it does not exist, the model parameter corresponding to the first data identifier is initialized as the first model parameter using a preset algorithm. The first model parameter and the first data identifier are stored in the memory in a non-continuous storage form, and the first model parameter is sent to the task node device at the same time. The task node device reversely calculates the first gradient value and sends the first gradient value to the parameter node device 1. The parameter node device 1 updates the first model parameter based on the received first gradient value, and replaces the parameter value before the update with the updated parameter value to realize the storage of the updated first model parameter.
[0090] In the embodiment of the present invention, a plurality of parameter node devices are used to process different training parameters respectively, thereby improving processing efficiency.
[0091] The above introduces the training method of the model provided by the embodiment of the present invention. The following will introduce the training device of the model provided by the embodiment of the present invention in conjunction with the accompanying drawings.
[0092] See also Figure 6 The embodiment of the present invention further provides a model training device, which is applied to a distributed system including a task node device and a parameter node device, wherein the task node device stores training data required for training the model, and the parameter node device stores a data identifier of each piece of training data and a model parameter corresponding to each data identifier, and the device includes:
[0093] A receiving module is used to receive target information input by a user, wherein the target information includes information required by multiple different applications when querying data in their respective corresponding data sources; the device includes:
[0094] The sending module 61 is used to send the target data identifier to the parameter node device when the task node device adds new training data, wherein the target data identifier is the data identifier in the newly added training data;
[0095] The parameter return module 62 is used to generate the corresponding target model parameters for the target data identifier when the parameter node device fails to find the model parameters corresponding to the target data identifier, and store the target data identifier and the target model parameters in the memory of the parameter node device in a non-continuous storage manner;
[0096] The gradient module 63 is used to send the target model parameters to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the training data corresponding to the target data identifier and the target model parameters;
[0097] The updating module 64 is used to send the target gradient value to the parameter node device through the task node device, so that the parameter node device updates the target model parameter based on the target gradient value.
[0098] Optionally, the device further comprises:
[0099] A judgment module, used to determine the actual data range value based on the data identifier in the memory and the model parameter through the parameter node device, wherein the actual data range value includes: the number of elements in each dimension of the data identifier in the memory and the model parameter;
[0100] A storage module is used to store the data identifier and model parameters in the memory into the external memory of the parameter node device according to the actual data range value when the actual data range value is different from the preset data range value, wherein the preset data range value includes the data identifier determined based on the training data before starting training and the number of elements in each dimension of the model parameter.
[0101] Optionally, the storage module includes:
[0102] A generation unit, used to generate an identification tensor and a parameter tensor according to the data identification and model parameters in the memory respectively;
[0103] The storage unit is used to store the identification tensor and the parameter tensor in the external memory of the parameter node device according to the number of elements of each dimension of the identification tensor and the parameter tensor.
[0104] Optionally, the updating module 64 is specifically configured to update the target model parameters using a target optimizer based on the target gradient value, wherein the target optimizer is an optimizer designed for variables stored discontinuously.
[0105] Optionally, when the newly added training data includes multiple training data and the number of parameter node devices is multiple, the sending module 61 is specifically configured to send the respective target data identifiers in the multiple training data to different parameter node devices respectively.
[0106] The model training device provided by the embodiment of the present invention can achieve Figures 1 to 5 To avoid repetition, the various processes of implementing the training method of the model in the method embodiment will not be repeated here.
[0107] The embodiment of the present invention can process the newly added training data when new training data is added, avoiding errors caused by failure to find model parameters associated with the newly added training data, and also avoiding feature space overflow, thereby ensuring normal training without terminating the training.
[0108] The embodiment of the present invention further provides an electronic device, such as Figure 7 As shown, it includes a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702, and the memory 703 communicate with each other through the communication bus 704;
[0109] Memory 703, used for storing computer programs;
[0110] The processor 701 is used to execute the program stored in the memory 703 to implement the following steps:
[0111] When the task node device adds new training data, the target data identifier is sent to the parameter node device, wherein the target data identifier is the data identifier in the newly added training data;
[0112] In the case that the parameter node device fails to find the model parameters corresponding to the target data identifier, the corresponding target model parameters are generated for the target data identifier, and the target data identifier and the target model parameters are stored in the memory of the parameter node device in a non-continuous storage manner;
[0113] The target model parameters are sent to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the training data corresponding to the target data identifier and the target model parameters;
[0114] The target gradient value is sent to the parameter node device through the task node device, so that the parameter node device updates the target model parameter based on the target gradient value.
[0115] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0116] The communication interface is used for communication between the above terminal and other devices.
[0117] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0118] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0119] In another embodiment provided by the present invention, a computer-readable storage medium is also provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the training method of the model described in any of the above embodiments.
[0120] In another embodiment provided by the present invention, a computer program product containing instructions is also provided, which, when executed on a computer, enables the computer to execute the model training method described in the above embodiment.
[0121] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0122] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0123] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0124] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A model training method, characterized in that: Applied to a distributed system including a task node device and a parameter node device, wherein the task node device stores training data required for training a model, and the parameter node device stores a data identifier of each piece of training data and a model parameter corresponding to each data identifier, the method comprising: When the task node device adds new training data, the target data identifier is sent to the parameter node device, wherein the target data identifier is a data identifier in the newly added training data; If the parameter node device fails to find the model parameter corresponding to the target data identifier, generating the corresponding target model parameter for the target data identifier, and storing the target data identifier and the target model parameter in the memory of the parameter node device in a non-continuous storage manner; The target model parameters are sent to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the training data corresponding to the target data identifier and the target model parameters; Sending the target gradient value to the parameter node device through the task node device, so that the parameter node device updates the target model parameter based on the target gradient value; After the parameter node device updates the target model parameter based on the target gradient value, the method further includes: Determining an actual data range value by the parameter node device based on the data identifier and the model parameter in the memory, wherein the actual data range value includes: the number of elements in each dimension of the data identifier and the model parameter in the memory; When the actual data range value is different from the preset data range value, the data identifier and model parameters in the memory are stored in the external memory of the parameter node device according to the actual data range value, wherein the preset data range value includes the data identifier determined based on the training data before starting training and the number of elements in each dimension of the model parameters.
2. The method according to claim 1, characterized in that The step of storing the data identifier and the model parameter in the memory into the external memory of the parameter node device according to the actual data range value includes: Generate an identification tensor and a parameter tensor according to the data identification and model parameters in the memory respectively; According to the number of elements in each dimension of the identification tensor and the parameter tensor, the identification tensor and the parameter tensor are respectively stored in the external memory of the parameter node device.
3. The method according to claim 1, characterized in that The parameter node device updates the target model parameter based on the target gradient value, including: The target model parameters are updated using a target optimizer based on the target gradient value, wherein the target optimizer is an optimizer designed for non-continuously stored variables.
4. The method according to claim 1, characterized in that: In the case where the newly added training data includes multiple pieces of training data and the number of the parameter node devices is multiple, sending the target data identifier to the parameter node device includes: The target data identifiers of the plurality of training data are respectively sent to different parameter node devices.
5. A model training device, characterized in that: Applied to a distributed system including a task node device and a parameter node device, wherein the task node device stores training data required for training a model, and the parameter node device stores a data identifier of each piece of training data and a model parameter corresponding to each data identifier, the device comprising: A receiving module, used to receive target information input by a user, wherein the target information includes information required by multiple different applications when querying data in their respective corresponding data sources; A sending module, used for sending a target data identifier to a parameter node device when the task node device adds new training data, wherein the target data identifier is a data identifier in the newly added training data; A parameter returning module, configured to generate a corresponding target model parameter for the target data identifier if the parameter node device fails to find the model parameter corresponding to the target data identifier, and store the target data identifier and the target model parameter in the memory of the parameter node device in a non-continuous storage manner; A gradient module, used for sending the target model parameters to the task node device through the parameter node device, so that the task node device calculates the target gradient value according to the training data corresponding to the target data identifier and the target model parameters; An updating module, configured to send the target gradient value to the parameter node device through the task node device, so that the parameter node device updates the target model parameter based on the target gradient value; A judgment module, configured to determine an actual data range value based on the data identifier and the model parameter in the memory through the parameter node device, wherein the actual data range value includes: the number of elements in each dimension of the data identifier and the model parameter in the memory; A storage module is used to store the data identifier and model parameters in the memory into the external memory of the parameter node device according to the actual data range value when the actual data range value is different from the preset data range value, wherein the preset data range value includes the data identifier determined based on the training data before starting training and the number of elements in each dimension of the model parameter.
6. The device according to claim 5, characterized in that The storage module comprises: A generating unit, used to generate an identification tensor and a parameter tensor according to the data identification and the model parameters in the memory respectively; A storage unit is used to store the identification tensor and the parameter tensor in the external memory of the parameter node device according to the number of elements in each dimension of the identification tensor and the parameter tensor.
7. The device according to claim 5, characterized in that The updating module is specifically used to update the target model parameters using a target optimizer based on the target gradient value, wherein the target optimizer is an optimizer designed for variables stored discontinuously.
8. The device according to claim 5, characterized in that In the case that the newly added training data includes multiple pieces of training data, and the number of the parameter node devices is multiple, the sending module is specifically used to send the respective target data identifiers in the multiple pieces of training data to different parameter node devices respectively.
Citation Information
Patent Citations
Online training method, device and system and computer readable storage medium
CN109635948A