Memory management method and device for deep learning model training on end-side devices

By graphical representation of the DNN model and collection of basic information, training plans are generated, memory usage is optimized, and memory allocation problems in end-side devices are solved, DNN model training with low latency and low memory overhead is achieved, and training speed and efficiency are improved. , protecting user privacy.

CN118519786BActive Publication Date: 2024-10-18HEFEI HUANWEI BIOTECHNOLOGY CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410979092.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2024-10-18
Estimated Expiration
2044-07-22

AI Technical Summary

Technical Problem

End-side devices face memory allocation and optimization problems when training deep learning models, resulting in insufficient transmission capabilities, limited computing resources, and high memory peaks, which cannot effectively improve training speed and efficiency, and there are user data privacy issues.

Method used

By representing the DNN model to be trained as a graph G=(V, E), we obtain the basic information of the layer nodes, generate a training plan, determine the intermediate output data that needs to be swapped out to external memory, and recalculate according to the memory pool allocation rules. Rules optimize memory usage, divide low-value areas and high-value areas, and store and discard corresponding data to achieve reasonable memory allocation and recalculation.

Benefits of technology

It realizes DNN model training with low latency and low memory overhead, meets the direct training needs of end-side devices, protects user privacy, improves training speed and efficiency, and solves the problems of memory fragmentation and high peak values.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118519786B_ABST
    Figure CN118519786B_ABST
Patent Text Reader

Abstract

The present invention discloses a memory management method and device during deep learning model training on an end-side device, and belongs to the field of artificial intelligence technology. The above method includes: representing the DNN model to be trained as a graph; the layer node information collector obtains the basic information of each layer node of the DNN model to be trained; the training plan generator determines the intermediate output data of the layer nodes that need to be swapped out to the external memory based on the basic information of each layer node; the intermediate output data of the layer nodes that need to be recalculated are determined according to the memory pool allocation rules and the recalculation rules, and the intermediate output data of the layer nodes that need to be recalculated are the intermediate output data of the layer nodes that are not stored during the training process of the DNN model to be trained. The present invention realizes low latency and low memory overhead in DNN model training, and meets the needs of direct training of DNN models by end-side devices.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a memory management method and device during deep learning model training on a terminal device. Background Art

[0002] With the continuous development of deep learning technology, deep learning models (Deep Neural Networks, DNN) are widely deployed on end devices such as smartphones and embedded platforms for reasoning.

[0003] End-side devices usually refer to mobile terminals such as mobile phones. Due to the diversity of end-side device usage and the different user habits and scenarios, the pre-trained DNN model cannot meet the needs of all users well, and it is necessary to fine-tune the DNN model, that is, to retrain the DNN model. The method adopted in the prior art is usually to upload the data on the end-side device and the DNN model that needs to be retrained to the cloud server, and return the retrained DNN model to the end-side device after the training is completed. However, this method requires moving the user data on the end-side device to the cloud, which involves user data privacy issues and incurs additional data movement costs. Therefore, it is necessary to train the DNN model directly on the end-side device.

[0004] Training DNN models directly on the end-side device faces the following difficulties: The end-side device does not have high-speed transmission capabilities, that is, the end-side device has limited external memory transmission capabilities. The end-side device has limited computing resources. In the existing technology, deep learning training frameworks usually use the principle of first-come-first-served allocation of memory. Therefore, additional computing time is required to ensure continuous memory capacity requirements, and it is impossible to increase the training batch size of the DNN model, resulting in a high memory peak when training the DNN model. Summary of the invention

[0005] The present invention provides a memory management method and device for deep learning model training on an end-side device, aiming to solve the technical problem of memory allocation and optimization when deep neural network training is performed on an end-side device.

[0006] A first aspect of the present invention provides a memory management method for deep learning model training on a terminal device, the method comprising:

[0007] Step S1: Represent the DNN model to be trained as a graph G=(V, E);

[0008] Wherein, V is a set of layer nodes, including multiple layer nodes; each layer node corresponds to a network layer of the DNN model to be trained; E is an edge, indicating the connection relationship between layer nodes; the DNN model is a deep learning model;

[0009] Step S2: The layer node information collector obtains basic information of each layer node of the DNN model to be trained;

[0010] The basic information includes: the memory usage of the intermediate output data of the layer node, the time for the layer node to calculate the intermediate output data of the layer node, the swap-out time of the intermediate output data of the layer node from the memory to the external memory, and the swap-in time of the intermediate output data of the layer node from the external memory to the memory;

[0011] The intermediate output data of the layer node is the output data generated by the corresponding layer node during the training process of the DNN model to be trained in the computing device independent of the end-side device; the basic information is pre-calculated by the computing device independent of the end-side device according to the model of the end-side device and the structure of the DNN model to be trained;

[0012] Step S3: The training plan generator determines the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained based on the basic information of each layer node; generates a training plan based on the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained;

[0013] Wherein, determining the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained includes:

[0014] Determine the intermediate output data of the layer nodes that need to be swapped out to the external memory, and store the intermediate output data of the layer nodes that need to be swapped out to the external memory in the external memory;

[0015] Determine the intermediate output data of the layer nodes that need to be recalculated according to the memory pool allocation rule and the recalculation rule, wherein the intermediate output data of the layer nodes that need to be recalculated are the intermediate output data of the layer nodes that are not stored;

[0016] The intermediate output data of other layer nodes of the DNN model to be trained are stored in the memory.

[0017] According to the method of the first aspect of the present invention, in step S3: determining the intermediate output data of the layer node that needs to be swapped out to the external memory specifically includes:

[0018] The training plan generator obtains basic information of each layer node, calculates the k value, and uses the intermediate output data of the layer nodes corresponding to the 1st layer to the kth layer of the DNN model to be trained as the intermediate output data of the layer nodes that need to be swapped out to the external memory;

[0019] The calculation method of k value is:

[0020]

[0021] Among them, vk is the kth layer node, i is a variable, j is a variable, n is the total number of layers of the DNN model to be trained, and v i is the i-th layer node, v j is the j-th layer node, Bwd(i) is the earliest dependency v when performing back propagation during the training process of the DNN model to be trained i The corresponding layer node outputs data in the middle of the layer node; is the computation time of the j-th layer node, is the swap-out time of the intermediate output data of the layer node corresponding to the j-th layer node from the memory to the external memory, It is the swapping time of the intermediate output data of the layer node corresponding to the j-th layer node from the external memory to the internal memory.

[0022] According to the method of the first aspect of the present invention, in step S3: the intermediate output data of the layer node that needs to be recalculated is determined according to the memory pool allocation rule and the recalculation rule, wherein:

[0023] The memory pool allocation rule is: divide the memory pool into a low-value area and a high-value area; wherein:

[0024] The memory cost is calculated for each layer node from the k+1th layer node to the nth layer node;

[0025] The layer nodes whose memory cost is higher than the preset threshold are regarded as high-value layer nodes, and the layer nodes whose memory cost is equal to or lower than the preset threshold are regarded as low-value layer nodes;

[0026] The intermediate output data of the layer nodes corresponding to the low-value layer nodes are stored in the low-value area, and the intermediate output data of the layer nodes corresponding to the high-value layer nodes are stored in the high-value area;

[0027] The low-value area is the memory pool area for storing low-value layer nodes, and the high-value area is the memory pool area for storing high-value layer nodes;

[0028] The calculation formula of the memory cost is:

[0029]

[0030] Among them, v r is the r-th layer node, is the memory cost of the r-th layer node, is the memory usage of the intermediate output data of the layer node of the rth layer node, Calculate the layer node intermediate output data time for the layer node of the rth layer node.

[0031] According to the method of the first aspect of the present invention, the recalculation rule is: based on the actual storage situation of the memory pool, the intermediate output data of the layer nodes are selected from the high-value area for discarding, and the discarded intermediate output data of the layer nodes are the intermediate output data of the layer nodes that need to be recalculated; wherein:

[0032] The formula for selecting the intermediate output data of the layer node from the high value area is:

[0033]

[0034] in, Indicates the amount of memory required for training on the client device, E r is the first identification information, E r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node is not in the high-value area; E r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node is in the high-value area; is the maximum value, S r is the second identification information, S r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node does not need to be recalculated; S r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node needs to be recalculated.

[0035] A second aspect of the present invention provides a memory management device for deep learning model training on a terminal device, the device comprising:

[0036] Topology module: configured to represent the DNN model to be trained as a graph G=(V, E);

[0037] Wherein, V is a set of layer nodes, including multiple layer nodes; each layer node corresponds to a network layer of the DNN model to be trained; E is an edge, indicating the connection relationship between layer nodes; the DNN model is a deep learning model;

[0038] Basic information determination module: configured as a layer node information collector to obtain basic information of each layer node of the DNN model to be trained;

[0039] The basic information includes: the memory usage of the intermediate output data of the layer node, the time for the layer node to calculate the intermediate output data of the layer node, the swap-out time of the intermediate output data of the layer node from the memory to the external memory, and the swap-in time of the intermediate output data of the layer node from the external memory to the memory;

[0040] The intermediate output data of the layer node is the output data generated by the corresponding layer node during the training process of the DNN model to be trained in the computing device independent of the end-side device; the basic information is pre-calculated by the computing device independent of the end-side device according to the model of the end-side device and the structure of the DNN model to be trained;

[0041] The training plan generation module is configured as a training plan generator, which determines the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained based on the basic information of each layer node; generates a training plan based on the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained;

[0042] Wherein, determining the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained includes:

[0043] Determine the intermediate output data of the layer nodes that need to be swapped out to the external memory, and store the intermediate output data of the layer nodes that need to be swapped out to the external memory in the external memory;

[0044] Determine the intermediate output data of the layer nodes that need to be recalculated according to the memory pool allocation rule and the recalculation rule, wherein the intermediate output data of the layer nodes that need to be recalculated are the intermediate output data of the layer nodes that are not stored;

[0045] The intermediate output data of other layer nodes of the DNN model to be trained are stored in the memory.

[0046] According to the device of the second aspect of the present invention, the determining of the intermediate output data of the layer node that needs to be swapped out to the external memory specifically includes:

[0047] The training plan generator obtains basic information of each layer node, calculates the k value, and uses the intermediate output data of the layer nodes corresponding to the 1st layer to the kth layer of the DNN model to be trained as the intermediate output data of the layer nodes that need to be swapped out to the external memory;

[0048] The calculation method of k value is:

[0049]

[0050] Among them, v k is the kth layer node, i is a variable, j is a variable, n is the total number of layers of the DNN model to be trained, and v i is the i-th layer node, v j is the j-th layer node, Bwd(i) is the earliest dependency v when performing back propagation during the training process of the DNN model to be trained i The corresponding layer node outputs data in the middle of the layer node; is the computation time of the j-th layer node, is the swap-out time of the intermediate output data of the layer node corresponding to the j-th layer node from the memory to the external memory, It is the swapping time of the intermediate output data of the layer node corresponding to the j-th layer node from the external memory to the internal memory.

[0051] According to the device of the second aspect of the present invention, the intermediate output data of the layer node that needs to be recalculated is determined according to the memory pool allocation rule and the recalculation rule, wherein:

[0052] The memory pool allocation rule is: divide the memory pool into a low-value area and a high-value area; wherein:

[0053] The memory cost is calculated for each layer node from the k+1th layer node to the nth layer node;

[0054] The layer nodes whose memory cost is higher than the preset threshold are regarded as high-value layer nodes, and the layer nodes whose memory cost is equal to or lower than the preset threshold are regarded as low-value layer nodes;

[0055] The intermediate output data of the layer nodes corresponding to the low-value layer nodes are stored in the low-value area, and the intermediate output data of the layer nodes corresponding to the high-value layer nodes are stored in the high-value area;

[0056] The low-value area is the memory pool area for storing low-value layer nodes, and the high-value area is the memory pool area for storing high-value layer nodes;

[0057] The calculation formula of the memory cost is:

[0058]

[0059] Among them, v r is the r-th layer node, is the memory cost of the r-th layer node, is the memory usage of the intermediate output data of the layer node of the rth layer node, Calculate the layer node intermediate output data time for the layer node of the rth layer node.

[0060] According to the device of the second aspect of the present invention, the recalculation rule is: based on the actual storage situation of the memory pool, the intermediate output data of the layer nodes are selected from the high-value area for discarding, and the discarded intermediate output data of the layer nodes are the intermediate output data of the layer nodes that need to be recalculated; wherein:

[0061] The formula for selecting the intermediate output data of the layer node from the high value area is:

[0062]

[0063] in, Indicates the amount of memory required for training on the client device, E r is the first identification information, E r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node is not in the high-value area; E r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node is in the high-value area; is the maximum value, S r is the second identification information, S r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node does not need to be recalculated; S r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node needs to be recalculated.

[0064] The present invention provides a computer-readable storage medium, wherein a plurality of instructions are stored in the computer-readable storage medium; the plurality of instructions are used for a processor to load and execute the method described in the first aspect of the present invention.

[0065] An electronic device provided by the present invention is characterized in that the electronic device comprises:

[0066] A processor, which is used to execute multiple instructions;

[0067] A memory for storing a plurality of instructions;

[0068] The plurality of instructions are used to be stored by the memory, and loaded and executed by the processor according to the method described in the first aspect of the present invention.

[0069] The beneficial technical effects brought by the present invention include:

[0070] (1) The present invention takes into account the transmission capacity and memory fragmentation issues of the end-side device, achieves low latency and low memory overhead for DNN model training, and meets the needs of directly training the DNN model on the end-side device.

[0071] (2) The present invention solves the problem that DNN model training in the end-side device requires a large amount of memory resources while the end-side device has insufficient memory resources. The training plan generated by the present invention can directly train the entire DNN model on the end-side device, and can protect user privacy.

[0072] (3) The present invention fully considers the calculation time and swap-in and swap-out time of intermediate output data, does not introduce additional transmission time cost, and improves the training speed of the end-side device.

[0073] (4) The present invention fully considers the node information of the DNN model layer and performs more reasonable memory allocation. Combined with recalculation, it can solve the problems of memory fragmentation and high memory peak during training in the prior art.

[0074] (5) The present invention allocates memory based on cost arrangement, which can ensure that the DNN model training is not interrupted and the training is completed efficiently. BRIEF DESCRIPTION OF THE DRAWINGS

[0075] Figure 1 A flowchart of a method for memory management during deep learning model training on a terminal device according to an embodiment of the present invention;

[0076] Figure 2 A schematic diagram of the architecture of a memory management method during deep learning model training on a terminal device according to an embodiment of the present invention;

[0077] Figure 3 This is a structural block diagram of a memory management device during deep learning model training on a terminal device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0078] The present invention is described in detail below in conjunction with the accompanying drawings and embodiments.

[0079] like Figure 1-2 As shown, the present invention proposes a memory management method for deep learning model training on a terminal device, including:

[0080] Step S1: Represent the DNN model to be trained as a graph G=(V, E);

[0081] Wherein, V is a set of layer nodes, including multiple layer nodes; each layer node corresponds to a network layer of the DNN model to be trained; E is an edge, indicating the connection relationship between layer nodes; the DNN model is a deep learning model;

[0082] Step S2: The layer node information collector obtains basic information of each layer node of the DNN model to be trained;

[0083] The basic information includes: the memory usage of the intermediate output data of the layer node, the time for the layer node to calculate the intermediate output data of the layer node, the swap-out time of the intermediate output data of the layer node from the memory to the external memory, and the swap-in time of the intermediate output data of the layer node from the external memory to the memory;

[0084] The intermediate output data of the layer node is the output data generated by the corresponding layer node during the training process of the DNN model to be trained in the computing device independent of the end-side device; the basic information is pre-calculated by the computing device independent of the end-side device according to the model of the end-side device and the structure of the DNN model to be trained;

[0085] Step S3: The training plan generator determines the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained based on the basic information of each layer node; generates a training plan based on the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained;

[0086] Wherein, determining the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained includes:

[0087] Determine the intermediate output data of the layer nodes that need to be swapped out to the external memory, and store the intermediate output data of the layer nodes that need to be swapped out to the external memory in the external memory;

[0088] Determine the intermediate output data of the layer nodes that need to be recalculated according to the memory pool allocation rule and the recalculation rule, wherein the intermediate output data of the layer nodes that need to be recalculated are the intermediate output data of the layer nodes that are not stored;

[0089] The intermediate output data of other layer nodes of the DNN model to be trained are stored in the memory.

[0090] In the present invention, the DNN model is essentially a directed acyclic graph, and the DNN model is represented by a directed acyclic graph, that is, G=(V, E), where V represents the set of layer nodes in the model, including multiple layer nodes, and E represents whether the layer nodes are connected. After topological sorting, it can be simplified by numbering to further clarify the layer nodes.

[0091] Since the parameters and structure of the DNN model are known, the connections and information of the nodes in each layer can be clearly identified, and the specific information of each layer of the DNN model can be simply and clearly known, such as the amount of computation and the amount of memory required for the output data in the middle of the layer. On this basis, as long as the device model and the specific DNN model on the end are determined, the computation time required for each layer can be known. , Swap-in time , swap out time ,in Represents the ith network layer, that is, the ith layer node. Considering that DNN model training is divided into two steps, the first step is forward propagation to calculate the intermediate output data; the second step is back propagation, which automatically updates the layer node parameters based on automatic differentiation. Since back propagation starts from the last layer node and forward propagation starts from the first layer node, the back propagation process accesses the intermediate output data in accordance with the stack characteristics. Based on the above findings and the detailed information of the layer nodes obtained, the exchange method proposed in the present invention is a time-aware exchange technology, which can be calculated in one calculation. , that is, including this layer node and all layer nodes before this layer node should be regarded as layer nodes that need to swap out intermediate output data to external memory.

[0092] In step S3: determining the intermediate output data of the layer node that needs to be swapped out to the external memory specifically includes:

[0093] The training plan generator obtains basic information of each layer node, calculates the k value, and uses the intermediate output data of the layer nodes corresponding to the 1st layer to the kth layer of the DNN model to be trained as the intermediate output data of the layer nodes that need to be swapped out to the external memory;

[0094] The calculation method of k value is:

[0095]

[0096] Among them, v k is the kth layer node, i is a variable, j is a variable, n is the total number of layers of the DNN model to be trained, and v i is the i-th layer node, v j is the j-th layer node, Bwd(i) is the earliest dependency v when performing back propagation during the training process of the DNN model to be trained i The corresponding layer node outputs data in the middle of the layer node; is the computation time of the j-th layer node, is the swap-out time of the intermediate output data of the layer node corresponding to the j-th layer node from the memory to the external memory, It is the swapping time of the intermediate output data of the layer node corresponding to the j-th layer node from the external memory to the internal memory.

[0097] In the present invention, it is necessary to perform an exchange operation on the intermediate output data of the layer nodes corresponding to several layer nodes. These layer nodes are the first type of layer nodes, that is, the intermediate output data of the layer nodes corresponding to the first type of layer nodes are swapped out to the external memory, and when they need to be loaded into the internal memory, the corresponding intermediate output data of the layer nodes are swapped into the internal memory. It is necessary to perform a discard operation on the intermediate output data of the layer nodes of several layer nodes. These layer nodes are the second type of layer nodes, that is, when the intermediate output data of the layer nodes of the second type of layer nodes are needed later, the intermediate output data of the layer nodes of the second type of layer nodes are determined according to the input of the second type of layer nodes. Among all the layer nodes, the layer nodes other than the first type of layer nodes and the second type of layer nodes are regarded as the third type of layer nodes, and the intermediate output data of the layer nodes corresponding to the third type of layer nodes are stored in the internal memory.

[0098] In the present invention, as long as the calculation time of the layer node is greater than the swap-in / swap-out time, the node can make full use of the calculation time to offset the time required for swap-in / swap-out. At the same time, the calculation time of the node and the swap-in / swap-out time difference are accumulated to quickly locate which node is the best position.

[0099] The intermediate output data of the layer nodes that need to be recalculated are determined according to the memory pool allocation rules and recalculation rules, where:

[0100] The memory pool allocation rule is: divide the memory pool into a low-value area and a high-value area; wherein:

[0101] The memory cost is calculated for each layer node from the k+1th layer node to the nth layer node;

[0102] The layer nodes whose memory cost is higher than the preset threshold are regarded as high-value layer nodes, and the layer nodes whose memory cost is equal to or lower than the preset threshold are regarded as low-value layer nodes;

[0103] The intermediate output data of the layer nodes corresponding to the low-value layer nodes are stored in the low-value area, and the intermediate output data of the layer nodes corresponding to the high-value layer nodes are stored in the high-value area;

[0104] The low-value area is the memory pool area for storing low-value layer nodes, and the high-value area is the memory pool area for storing high-value layer nodes;

[0105] The calculation formula of the memory cost is:

[0106]

[0107] Among them, v r is the r-th layer node, is the memory cost of the r-th layer node, is the memory usage of the intermediate output data of the layer node of the rth layer node, Calculate the layer node intermediate output data time for the layer node of the rth layer node.

[0108] The recalculation rule is: based on the actual storage situation of the memory pool, the intermediate output data of the layer nodes are selected from the high-value area for discarding, and the discarded intermediate output data of the layer nodes are the intermediate output data of the layer nodes that need to be recalculated; wherein:

[0109] The formula for selecting the intermediate output data of the layer node from the high value area is:

[0110]

[0111] in, Indicates the amount of memory required for training on the client device, E r is the first identification information, E r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node is not in the high-value area; E r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node is in the high-value area; is the maximum value, S r is the second identification information, Sr The value is 0, indicating that the intermediate output data of the layer node of the rth layer node does not need to be recalculated; S r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node needs to be recalculated.

[0112] The present invention divides the memory pool into two parts, one is a low-value area and the other is a high-value area, and distributes the intermediate output data of the layer nodes to different areas according to the memory cost value to perform recalculation operations.

[0113] like Figure 2 As shown, the training plan generator includes a switching layer node determination module, a memory pool allocation module, a recalculation layer node determination module, and a training plan generation module. The switching layer node determination module determines the intermediate output data of the layer nodes that need to be swapped out to the external memory based on the basic information of each layer node; the memory pool allocation module determines the memory cost of the layer node, and the recalculation determination module determines the intermediate output data of the layer nodes that need to be recalculated. The training plan generation module generates a training plan, and the training plan includes the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained. The DNN model to be trained is trained based on the training plan.

[0114] The present invention also provides a memory management device for deep learning model training on a terminal device, such as Figure 3 As shown, the device comprises:

[0115] Topology module: configured to represent the DNN model to be trained as a graph G=(V, E);

[0116] Wherein, V is a set of layer nodes, including multiple layer nodes; each layer node corresponds to a network layer of the DNN model to be trained; E is an edge, indicating the connection relationship between layer nodes; the DNN model is a deep learning model;

[0117] Basic information determination module: configured as a layer node information collector to obtain basic information of each layer node of the DNN model to be trained;

[0118] The basic information includes: the memory usage of the intermediate output data of the layer node, the time for the layer node to calculate the intermediate output data of the layer node, the swap-out time of the intermediate output data of the layer node from the memory to the external memory, and the swap-in time of the intermediate output data of the layer node from the external memory to the memory;

[0119] The intermediate output data of the layer node is the output data generated by the corresponding layer node during the training process of the DNN model to be trained in the computing device independent of the end-side device; the basic information is pre-calculated by the computing device independent of the end-side device according to the model of the end-side device and the structure of the DNN model to be trained;

[0120] The training plan generation module is configured as a training plan generator, which determines the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained based on the basic information of each layer node; generates a training plan based on the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained;

[0121] Wherein, determining the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained includes:

[0122] Determine the intermediate output data of the layer nodes that need to be swapped out to the external memory, and store the intermediate output data of the layer nodes that need to be swapped out to the external memory in the external memory;

[0123] Determine the intermediate output data of the layer nodes that need to be recalculated according to the memory pool allocation rule and the recalculation rule, wherein the intermediate output data of the layer nodes that need to be recalculated are the intermediate output data of the layer nodes that are not stored;

[0124] The intermediate output data of other layer nodes of the DNN model to be trained are stored in the memory.

[0125] The above specific embodiments only describe the design principle of the present invention. The shapes and names of the components in the description may be different and are not limited. Therefore, those skilled in the art in the field of the present invention may modify or replace the technical solutions recorded in the above embodiments; and these modifications and replacements do not deviate from the creative purpose and technical solutions of the present invention and should all fall within the protection scope of the present invention.

Claims

1. A memory management method for deep learning model training on a terminal device, characterized in that: The method comprises: Step S1: Represent the DNN model to be trained as a graph G=(V, E); Wherein, V is a set of layer nodes, including multiple layer nodes; each layer node corresponds to a network layer of the DNN model to be trained; E is an edge, indicating the connection relationship between layer nodes; the DNN model is a deep learning model; Step S2: The layer node information collector obtains basic information of each layer node of the DNN model to be trained; The basic information includes: the memory usage of the intermediate output data of the layer node, the time for the layer node to calculate the intermediate output data of the layer node, the swap-out time of the intermediate output data of the layer node from the memory to the external memory, and the swap-in time of the intermediate output data of the layer node from the external memory to the memory; The intermediate output data of the layer node is the output data generated by the corresponding layer node during the training process of the DNN model to be trained in the computing device independent of the end-side device; the basic information is pre-calculated by the computing device independent of the end-side device according to the model of the end-side device and the structure of the DNN model to be trained; Step S3: The training plan generator determines the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained based on the basic information of each layer node; generates a training plan based on the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained; Wherein, determining the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained includes: Determine the intermediate output data of the layer nodes that need to be swapped out to the external memory, and store the intermediate output data of the layer nodes that need to be swapped out to the external memory in the external memory; Determine the intermediate output data of the layer nodes that need to be recalculated according to the memory pool allocation rule and the recalculation rule, wherein the intermediate output data of the layer nodes that need to be recalculated are the intermediate output data of the layer nodes that are not stored; Storing intermediate output data of other layer nodes of the DNN model to be trained into the memory; In step S3: determining the intermediate output data of the layer node that needs to be swapped out to the external memory specifically includes: The training plan generator obtains basic information of each layer node, calculates the k value, and uses the intermediate output data of the layer nodes corresponding to the 1st layer to the kth layer of the DNN model to be trained as the intermediate output data of the layer nodes that need to be swapped out to the external memory; The calculation method of k value is: Among them, v k is the kth layer node, i is a variable, j is a variable, n is the total number of layers of the DNN model to be trained, and v i is the i-th layer node, v j is the j-th layer node, Bwd(i) is the earliest dependency v when performing back propagation during the training process of the DNN model to be trained i The corresponding layer node outputs data in the middle of the layer node; is the computation time of the j-th layer node, is the swap-out time of the intermediate output data of the layer node corresponding to the j-th layer node from the memory to the external memory, is the swapping time of the intermediate output data of the layer node corresponding to the j-th layer node from the external memory to the internal memory; In step S3: the intermediate output data of the layer nodes that need to be recalculated is determined according to the memory pool allocation rule and the recalculation rule, wherein: The memory pool allocation rule is: divide the memory pool into a low-value area and a high-value area; wherein: The memory cost is calculated for each layer node from the k+1th layer node to the nth layer node; The layer nodes whose memory cost is higher than the preset threshold are regarded as high-value layer nodes, and the layer nodes whose memory cost is equal to or lower than the preset threshold are regarded as low-value layer nodes; The intermediate output data of the layer nodes corresponding to the low-value layer nodes are stored in the low-value area, and the intermediate output data of the layer nodes corresponding to the high-value layer nodes are stored in the high-value area; The low-value area is the memory pool area for storing low-value layer nodes, and the high-value area is the memory pool area for storing high-value layer nodes; The calculation formula of the memory cost is: Among them, v r is the rth layer node, is the memory cost of the r-th layer node, is the memory usage of the intermediate output data of the layer node of the rth layer node, Calculate the intermediate output data time of the layer node for the layer node of the rth layer node; The recalculation rule is: based on the actual storage situation of the memory pool, the intermediate output data of the layer nodes are selected from the high-value area for discarding, and the discarded intermediate output data of the layer nodes are the intermediate output data of the layer nodes that need to be recalculated; wherein: The formula for selecting the intermediate output data of the layer node from the high value area is: in, Indicates the amount of memory required for training on the client device, E r is the first identification information, E r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node is not in the high-value area; E r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node is in the high-value area; is the maximum value, S r is the second identification information, S r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node does not need to be recalculated; S r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node needs to be recalculated.

2. A memory management device for deep learning model training on a terminal device, characterized in that: include: Topology module: configured to represent the DNN model to be trained as a graph G=(V, E); Wherein, V is a set of layer nodes, including multiple layer nodes; each layer node corresponds to a network layer of the DNN model to be trained; E is an edge, indicating the connection relationship between layer nodes; the DNN model is a deep learning model; Basic information determination module: configured as a layer node information collector to obtain basic information of each layer node of the DNN model to be trained; The basic information includes: the memory usage of the intermediate output data of the layer node, the time for the layer node to calculate the intermediate output data of the layer node, the swap-out time of the intermediate output data of the layer node from the memory to the external memory, and the swap-in time of the intermediate output data of the layer node from the external memory to the memory; The intermediate output data of the layer node is the output data generated by the corresponding layer node during the training process of the DNN model to be trained in the computing device independent of the end-side device; the basic information is pre-calculated by the computing device independent of the end-side device according to the model of the end-side device and the structure of the DNN model to be trained; The training plan generation module is configured as a training plan generator, which determines the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained based on the basic information of each layer node; generates a training plan based on the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained; Wherein, determining the storage method of the intermediate output data of the layer nodes corresponding to each layer node of the DNN model to be trained includes: Determine the intermediate output data of the layer nodes that need to be swapped out to the external memory, and store the intermediate output data of the layer nodes that need to be swapped out to the external memory in the external memory; Determine the intermediate output data of the layer nodes that need to be recalculated according to the memory pool allocation rule and the recalculation rule, wherein the intermediate output data of the layer nodes that need to be recalculated are the intermediate output data of the layer nodes that are not stored; Storing intermediate output data of other layer nodes of the DNN model to be trained into the memory; Determine the intermediate output data of the layer nodes that need to be swapped out to external memory, including: The training plan generator obtains basic information of each layer node, calculates the k value, and uses the intermediate output data of the layer nodes corresponding to the 1st layer to the kth layer of the DNN model to be trained as the intermediate output data of the layer nodes that need to be swapped out to the external memory; The calculation method of k value is: Among them, v k is the kth layer node, i is a variable, j is a variable, n is the total number of layers of the DNN model to be trained, and v i is the i-th layer node, v j is the j-th layer node, Bwd(i) is the earliest dependency v when performing back propagation during the training process of the DNN model to be trained i The corresponding layer node outputs data in the middle of the layer node; is the computation time of the j-th layer node, is the swap-out time of the intermediate output data of the layer node corresponding to the j-th layer node from the memory to the external memory, is the swapping time of the intermediate output data of the layer node corresponding to the j-th layer node from the external memory to the internal memory; The intermediate output data of the layer nodes that need to be recalculated are determined according to the memory pool allocation rules and recalculation rules, where: The memory pool allocation rule is: divide the memory pool into a low-value area and a high-value area; wherein: The memory cost is calculated for each layer node from the k+1th layer node to the nth layer node; The layer nodes whose memory cost is higher than the preset threshold are regarded as high-value layer nodes, and the layer nodes whose memory cost is equal to or lower than the preset threshold are regarded as low-value layer nodes; The intermediate output data of the layer nodes corresponding to the low-value layer nodes are stored in the low-value area, and the intermediate output data of the layer nodes corresponding to the high-value layer nodes are stored in the high-value area; The low-value area is the memory pool area for storing low-value layer nodes, and the high-value area is the memory pool area for storing high-value layer nodes; The calculation formula of the memory cost is: Among them, v r is the rth layer node, is the memory cost of the r-th layer node, is the memory usage of the intermediate output data of the layer node of the rth layer node, Calculate the intermediate output data time of the layer node for the layer node of the rth layer node; The recalculation rule is: based on the actual storage situation of the memory pool, the intermediate output data of the layer nodes are selected from the high-value area for discarding, and the discarded intermediate output data of the layer nodes are the intermediate output data of the layer nodes that need to be recalculated; wherein: The formula for selecting the intermediate output data of the layer node from the high value area is: in, Indicates the amount of memory required for training on the client device, E r is the first identification information, E r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node is not in the high-value area; E r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node is in the high-value area; is the maximum value, S r is the second identification information, S r The value is 0, indicating that the intermediate output data of the layer node of the rth layer node does not need to be recalculated; S r The value is 1, indicating that the intermediate output data of the layer node of the rth layer node needs to be recalculated.

3. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions; the plurality of instructions are used for a processor to load and execute the method as claimed in claim 1.

4. An electronic device, characterized in that: The electronic device comprises: A processor, which is used to execute multiple instructions; A memory for storing a plurality of instructions; Wherein, the plurality of instructions are used to be stored by the memory, and loaded and executed by the processor according to the method as claimed in claim 1.

Citation Information

Patent Citations

  • GPU memory optimization method and system for a deep learning training task

    CN109919310A

  • Method, system and equipment for breaking through memory limitation in parallel training and storage medium

    CN114880130A

  • Memory management method and system for deep neural network

    CN116107754A

  • Method for realizing AI model training memory optimization by adopting reinforcement learning

    CN117234710A

  • Memory optimization method and device based on tensor version control

    CN118245207A