Automatic reversible synthesis method, device, equipment and medium for deep learning model
By analyzing the abstract syntax tree and directed acyclic graph of the deep learning model, the reversible structure is automatically identified and optimized, which solves the problem of low backpropagation calculation efficiency in the existing technology and achieves efficient optimization of the deep learning model.
Patent Information
- Application Number
- CN202410789229.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-06-19
AI Technical Summary
When optimizing the backpropagation calculation of a deep learning model, the existing technology relies on manual identification of reversible patterns, which is inefficient and cannot traverse the global optimal strategy, resulting in high computing resource and storage requirements.
By obtaining the abstract syntax tree of the deep learning model, generate a directed acyclic graph, analyze node dependencies, determine reversible candidate structures, filter out illegal structures, build a reversible reconstruction model, and dynamically program the global optimal based on the cost model Reversible strategy to achieve automated identification and optimization.
All reversible structures and strategies in deep learning models can be identified without manual participation, reducing labor costs, significantly improving backpropagation calculation efficiency, and optimizing model training.
Smart Images

Figure CN118364890B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an automatic reversible synthesis method, device, equipment and medium for a deep learning model. Background Art
[0002] As deep learning (DL) models rapidly evolve in size and complexity, the requirements for overall system performance are increasing. The training of deep learning models involves forward computation for inference and backpropagation computation for gradient computation, which is critical for updating parameters. Backpropagation computation accounts for about 2 / 3 of the total computational load and introduces a large amount of additional storage requirements to cache intermediate activation values. Therefore, backpropagation computation is not only a bottleneck for computing resources in deep learning model training, but also a bottleneck for storage and bandwidth resources.
[0003] In the prior art, reversible patterns can be used to optimize the back propagation calculation of deep learning models. By converting certain local structures (also called reversible structures) in deep learning models into reversible patterns, the need for accumulated storage activations can be effectively eliminated. Figure 1 A schematic diagram of a reversible mode in the prior art is shown in FIG. Figure 1 As shown, in the reversible mode, when performing forward calculation, Y1 and Y2 can be obtained by normal calculation of X1 and X2. At the same time, when performing back propagation calculation, the gradients of X1 and X2 can also be obtained by calculating the gradients of Y1 and Y2 without the need for assistance from other calculation results.
[0004] However, when using reversible modes to optimize deep learning models, existing technologies often rely on developers to visually identify one or more reversible structures in the deep learning model that can perform reversible mode conversion. This implementation method is very dependent on the actual experience of developers and has very high labor costs. At the same time, this manual identification method cannot effectively traverse all reversible structures in the deep learning model, and it is also impossible to search for the globally optimal reversible strategy to fully optimize the backpropagation calculation. Summary of the invention
[0005] The present invention provides a method, device, equipment and medium for automatic reversible synthesis of a deep learning model, so as to provide an implementation method for automatically determining the optimal reversible strategy of the deep learning model after automatically identifying all available reversible structures in the deep learning model.
[0006] According to one aspect of an embodiment of the present invention, there is provided an automatic reversible synthesis of a deep learning model, including:
[0007] Obtain an abstract syntax tree corresponding to the target deep learning model, and generate a directed acyclic graph according to the abstract syntax tree, wherein nodes in the abstract syntax tree correspond to operators in the target deep learning model;
[0008] Performing structural analysis on the directed acyclic graph to determine the dependency relationship between nodes, and determining a reversible candidate structure corresponding to each node based on the dependency relationship; wherein the reversible candidate structure is a branchless structure containing at least one node;
[0009] Among all the reversible candidate structures, the reversible candidate structures that do not meet the legality detection conditions are filtered out to obtain legal reversible candidate structures, and the reversible transformation pattern sets corresponding to each legal reversible candidate structure are determined according to the black and white lists;
[0010] According to the reversible transformation pattern set corresponding to each legal reversible candidate structure, multiple first-class reversible reconstruction models corresponding to the target deep learning model are constructed;
[0011] Load each first-class reversible reconstruction model into the back-end system for trial operation, and screen out each target reversible structure that can be measured and the target reversible conversion pattern set corresponding to the target reversible structure according to the trial operation result;
[0012] Traverse the nodes according to the tree structure of the abstract syntax tree, and dynamically plan the target reversible strategy corresponding to the target deep learning model in each reversible strategy based on the cost model during the traversal process;
[0013] Among them, each target reversible structure and a target reversible transformation pattern set corresponding to the target reversible structure are used to form a reversible strategy for target deep learning model adaptation;
[0014] According to the target reversible strategy, a target reversible reconstruction model corresponding to the target deep learning model is constructed, and the target reversible reconstruction model is loaded into the back-end system for actual operation to perform model training operations.
[0015] According to another aspect of an embodiment of the present invention, there is also provided an automatic reversible synthesis device for a deep learning model, comprising:
[0016] A directed acyclic graph generation module, used to obtain an abstract syntax tree corresponding to a target deep learning model, and generate a directed acyclic graph according to the abstract syntax tree, wherein nodes in the abstract syntax tree correspond to operators in the target deep learning model;
[0017] A reversible candidate structure determination module is used to perform structural analysis on the directed acyclic graph, determine the dependency relationship between each node, and determine the reversible candidate structure corresponding to each node according to the dependency relationship; wherein the reversible candidate structure is a branchless structure containing at least one node;
[0018] A reversible conversion pattern set determination module is used to filter out reversible candidate structures that do not meet the legality detection conditions from all reversible candidate structures, obtain legal reversible candidate structures, and determine the reversible conversion pattern set corresponding to each legal reversible candidate structure according to the black and white lists;
[0019] A first-class model building module is used to build multiple first-class reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern set corresponding to each legal reversible candidate structure;
[0020] An available mode screening module is used to load each first-class reversible reconstruction model into the back-end system for trial operation, and screen out each target reversible structure that is actually available and a target reversible conversion mode set corresponding to the target reversible structure according to the trial operation result;
[0021] The target reversible strategy planning module is used to traverse the nodes according to the tree structure of the abstract syntax tree, and dynamically plan the target reversible strategy corresponding to the target deep learning model in each reversible strategy based on the cost model during the traversal process;
[0022] Among them, each target reversible structure and a target reversible transformation pattern set corresponding to the target reversible structure are used to form a reversible strategy for target deep learning model adaptation;
[0023] The target reversible reconstruction model construction module is used to construct a target reversible reconstruction model corresponding to the target deep learning model according to the target reversible strategy, and load the target reversible reconstruction model into the back-end system for actual operation to perform model training operations.
[0024] According to another aspect of an embodiment of the present invention, an electronic device is provided, the electronic device comprising:
[0025] at least one processor; and
[0026] a memory communicatively connected to the at least one processor; wherein,
[0027] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the automatic reversible synthesis method of the deep learning model described in any embodiment of the present invention.
[0028] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the automatic reversible synthesis method of the deep learning model described in any embodiment of the present invention when executed.
[0029] The technical solution of the embodiment of the present invention determines all reversible candidate structures by analyzing the dependencies between each node in the target deep learning model; filters out the reversible candidate structures that do not meet the legitimacy detection conditions to obtain legal reversible candidate structures, and determines the reversible transformation pattern set corresponding to each legal reversible candidate structure according to the black and white lists; constructs multiple reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern set corresponding to each legal reversible candidate structure, and runs them in the back-end system for trial operation, and screens out the target reversible structures and the target reversible transformation pattern set corresponding to the target reversible structures according to the trial operation results, performs node traversal according to the tree structure of the abstract syntax tree, and dynamically plans the reversible transformation pattern set corresponding to each reversible strategy in the traversal process based on the cost model. The implementation method of the target reversible strategy corresponding to the target deep learning model innovatively proposes a tree-structured dynamic programming scheme to search for the global optimal implementation method of the target reversible strategy. Without any manual operation, it can realize the automatic identification of legal and effective reversible structures in the deep learning model, and can maximize the mining of all available reversible structures in the deep learning model, as well as the reversible transformation pattern set corresponding to the reversible structure. In addition, the search process of the target reversible strategy does not require the participation of developers, which greatly reduces the labor cost. At the same time, by using the globally optimal target reversible strategy to reversibly process the target deep learning model, it is possible to fully optimize the target deep learning model and maximize the efficiency of the back-propagation calculation.
[0030] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0032] Figure 1 It is a structural schematic diagram of a reversible mode in the prior art;
[0033] Figure 2 This is a flow chart of an automatic reversible synthesis method of a deep learning model provided according to Embodiment 1 of the present invention;
[0034] Figure 3 is a flowchart of another automatic reversible synthesis method of a deep learning model provided in Embodiment 2 of the present invention;
[0035] Figure 4 It is a schematic diagram of conversion from a directed acyclic graph to a post-dominator tree applicable to an embodiment of the present invention;
[0036] Figure 5 It is a flowchart of an implementation method applicable to an embodiment of the present invention, which performs node traversal according to a tree structure of an abstract syntax tree, and dynamically plans a target reversible strategy corresponding to a target deep learning model in each reversible strategy based on a cost model during the traversal process;
[0037] Figure 6 A flowchart of a method for obtaining a first cost value corresponding to an optimal reversible strategy for a current node applicable to an embodiment of the present invention;
[0038] Figure 7 is a schematic diagram of a specific global optimization application scenario applicable to an embodiment of the present invention;
[0039] Figure 8 It is a flow chart of a non-invasive reversible conversion method of a deep learning model applicable to an embodiment of the present invention;
[0040] Fig. 9 is a flow chart of another non-invasive reversible conversion method of a deep learning model applicable to an embodiment of the present invention;
[0041] Fig.10 is a flow chart of another non-invasive reversible conversion method of a deep learning model applicable to an embodiment of the present invention;
[0042] Fig.11 It is a flow chart of a dynamic storage management method during task execution applicable to an embodiment of the present invention;
[0043] Fig.12 is a flow chart of another dynamic storage management method during task execution applicable to an embodiment of the present invention;
[0044] Fig.13 It is a flowchart of a method for realizing a method of searching step by step in a frequency reduction direction to obtain a target frequency with the goal of minimizing runtime time overhead, which is applicable to an embodiment of the present invention;
[0045] Fig.14 is a schematic diagram of a dynamic storage management scenario applicable to an embodiment of the present invention;
[0046] Fig.15 2 is a schematic diagram of the structure of an automatic reversible synthesis device of a deep learning model provided in Embodiment 3 of the present invention;
[0047] Fig.16It is a schematic diagram of the structure of an electronic device that implements the automatic reversible synthesis method of the deep learning model of an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only 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 should fall within the scope of protection of the present invention.
[0049] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0050] Embodiment 1
[0051] Figure 2 A flow chart of a method for automatic reversible synthesis of a deep learning model provided in Example 1 of the present invention. This embodiment is applicable to the situation where, after all available reversible structures are automatically identified in the deep learning model, the optimal reversible strategy of the deep learning model is automatically determined based on the above reversible structures. The method can be executed by an automatic reversible synthesis device for the deep learning model, which can be implemented in the form of hardware and / or software and can generally be configured in an electronic device with data processing capabilities.
[0052] like Figure 2 As shown, the method includes:
[0053] S210. Obtain an abstract syntax tree corresponding to the target deep learning model, and generate a directed acyclic graph based on the abstract syntax tree, wherein nodes in the abstract syntax tree correspond to operators in the target deep learning model.
[0054] In this embodiment, the target deep learning model refers to a machine learning model that needs to use one or more reversible modes to replace the set local structure in order to efficiently perform back propagation calculations, wherein the above-mentioned replacement process is called a reversible transformation. The reversible mode refers to a specific subnet architecture that can use the gradient tensor of the output position and the accompanying tensor transmitted through its own structure to synthesize the gradient to eliminate the accumulated storage activation. At present, reversible modes of various network structures have been developed, such as additive reversible mode, affine reversible mode, or momentum reversible mode, etc., which are not limited in this embodiment.
[0055] Specifically, in the target deep learning model, the local structure that is used to be reversibly transformed by the reversible mode of the set structure is called a reversible structure.
[0056] The Abstract Syntax Tree (AST) is a tree representation of the abstract syntax structure of the source code. Each node in the tree represents a structure in the source code. In the field of machine learning, we can use AST to represent the structure of the machine learning model, and then build or parse the machine learning model by traversing the AST. When using AST to represent the target deep learning model, each node in the AST represents each operator in the target deep learning model.
[0057] Accordingly, after obtaining the abstract syntax tree corresponding to the target deep learning model, a directed acyclic graph (DAG) corresponding to the target deep learning model can be generated based on the abstract syntax tree. A directed acyclic graph refers to a graph in which there are directional edge links (directed edges) between the nodes of the graph, and there are no multiple edges linked to form a ring in the form of a cycle.
[0058] Among them, the directed acyclic graph contains multiple nodes, and each node is connected by a directed edge. Each node in the directed acyclic graph also corresponds to each operator in the target deep learning model.
[0059] S220, performing structural analysis on the directed acyclic graph to determine the dependency relationship between the nodes, and determining a reversible candidate structure corresponding to each node based on the dependency relationship; wherein the reversible candidate structure is a branchless structure including at least one node.
[0060] As mentioned above, the edge links connecting two nodes in a directed acyclic graph are directional, that is, two nodes are connected by a directed edge with an arrow, where the node in the direction where the arrow ends depends on the node in the direction where the arrow starts. For example, if in the target deep learning model, a convolution calculation is first performed on the input data x and y to obtain the calculation result z, and then the calculation result z is normalized to obtain the calculation result k. It can be seen that the execution of the normalization operator depends on the execution result of the convolution operator. Therefore, in the directed acyclic graph corresponding to the target deep learning model, in the directed edge composed of node A corresponding to the convolution operator and node B corresponding to the normalization operator, the arrow points from node A to node B.
[0061] Correspondingly, after obtaining the directed acyclic graph corresponding to the target deep learning model, the dependency relationship between the nodes can be determined by analyzing the directionality of each directed edge between the nodes in the directed acyclic graph.
[0062] The inventors have found through research that if a local structure in the target deep learning model can be used as a reversible structure, then the subgraph corresponding to this local structure in the directed acyclic graph should be a branchless structure from the perspective of data topology. That is, this local structure contains multiple nodes, and after taking this local structure as a whole, this local structure has no directed edges flowing into the local structure or out of the local structure except the initial input edge (which may be one or more) and the final output edge (which may be one or more), that is, the local structure as a whole is a branchless structure.
[0063] It is understandable that a branchless structure is a necessary condition for a local structure to be a final reversible structure. Therefore, firstly, based on the dependency relationship between the nodes defined in the directed acyclic graph, all candidate structures that can be used as the final reversible structure corresponding to the target deep learning model, that is, reversible candidate structures, can be determined.
[0064] S230, among all reversible candidate structures, filter out reversible candidate structures that do not meet the legality detection conditions to obtain legal reversible candidate structures, and determine the reversible conversion pattern set corresponding to each legal reversible candidate structure according to the black and white lists.
[0065] The inventors further discovered that the reversible structure that can be reversibly converted using the reversible mode also needs to meet certain necessary conditions in terms of data capacity, data size or mathematical properties. Accordingly, in the embodiments of the invention, corresponding legality detection conditions can be constructed based on one or more of the necessary conditions that need to be met.
[0066] Furthermore, all reversible candidate structures can be screened once based on the above-mentioned legality detection conditions to obtain legal reversible candidate structures that meet each legality detection condition.
[0067] The reversible conversion mode set includes one or more reversible conversion modes, and one reversible conversion mode set corresponds to one legal reversible candidate structure. The reversible conversion mode can be understood as a reversible mode that can reversibly convert the adapted legal reversible candidate structure.
[0068] In this embodiment, the black and white list can be a pre-established reversible conversion mode white list and a pre-established reversible conversion mode black list. In the reversible conversion mode white list, all reversible modes corresponding to each reversible structure under the broadest conditions are defined, that is, all reversible modes that can be used to reversibly convert a reversible structure without considering other limiting conditions; in the reversible conversion mode black list, invalid reversible modes that cannot be effectively reversibly converted under each algorithm model scenario are defined.
[0069] Specifically, the algorithm model scenario may include: a Transformers model scenario, a TorchVision model scenario, or a Pytorch model scenario, etc., which is not limited in this embodiment.
[0070] By combining the target algorithm model scenario using the target deep learning model, and the black and white lists, it is possible to determine the reversible transformation pattern set corresponding to each legal reversible candidate structure under the target algorithm model scenario, that is, to determine all reversible transformation patterns that can theoretically reversibly transform the legal reversible candidate structures.
[0071] S240. Construct multiple first-class reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern sets corresponding to each legal reversible candidate structure.
[0072] It can be understood that the reversible transformation pattern set corresponding to each legal reversible candidate structure determined by the above operation is a set of theoretically available reversible transformation patterns, but the availability of such reversible transformation cannot be guaranteed in the actual operation of the model. Therefore, in an embodiment of the present invention, a first type of reversible reconstruction model after the target deep learning model is reversibly transformed can be constructed according to the reversible transformation pattern set corresponding to each legal reversible candidate structure. By trial running these first type of reversible reconstruction models, those target reversible structures that are actually available can be screened out, as well as one or more target reversible transformation patterns corresponding to each target reversible structure.
[0073] In a specific example, after determining a legal reversible candidate structure A and a reversible transformation pattern set {reversible transformation pattern B1, reversible transformation pattern B2} corresponding to the legal reversible candidate structure A, the reversible candidate structure A in the target deep learning model can be reversibly transformed using the reversible transformation pattern B1 to obtain a first type of reversible reconstruction model C1. At the same time, the reversible candidate structure A in the target deep learning model can also be reversibly transformed using the reversible transformation pattern B2 to obtain a first type of reversible reconstruction model C2. It can be understood that the total number of first type reversible reconstruction models finally constructed is the cumulative sum of the number of reversible transformation patterns contained in each reversible transformation pattern set corresponding to each legal reversible candidate structure.
[0074] In this embodiment, after obtaining a specific legal reversible candidate structure and a specific reversible transformation pattern corresponding to the specific legal reversible candidate structure, an invasive transformation method can be used to construct a corresponding first-class reversible reconstruction model, or a non-invasive transformation method can be used to construct the first-class reversible reconstruction model. This embodiment does not limit this.
[0075] Specifically, the intrusive conversion method can be understood as a method of modifying the source code of the target deep learning model to achieve the construction of the first-class reversible reconstruction model, while the non-intrusive conversion method can be understood as the need to modify the source code of the target deep learning model. By using compiler technology, the corresponding first-class reversible reconstruction model is automatically generated after the source code of the target deep learning model is input.
[0076] S250, loading each first-class reversible reconstruction model into the back-end system for trial operation, and screening out each target reversible structure that is actually available and a target reversible conversion pattern set corresponding to the target reversible structure according to the trial operation result.
[0077] Among them, the backend system can be understood as a physical execution device for loading and executing the set machine learning model. The trial run can be understood as loading the set first-class reversible reconstruction model to the actual execution device, and controlling the execution device to execute the set time (for example, 10 minutes, 20 minutes or 1 hour, etc.) or controlling the execution device to reach the set calculation target (for example, one round of model training). At the same time, it is necessary to detect whether the set first-class reversible reconstruction model can be executed normally during the execution process based on the set time or the set calculation target. For example, check whether there are abnormal errors during the test run.
[0078] Specifically, the trial operation result may be normal operation or abnormal operation. Assuming that the trial operation result of the first type of reversible reconstruction model A is abnormal operation, after extracting the legal reversible candidate structure a1 corresponding to the first type of reversible reconstruction model A and the corresponding reversible transformation mode a2, the reversible transformation mode a2 is deleted from the reversible transformation mode set corresponding to the legal reversible candidate structure a1. When the reversible transformation mode set corresponding to a legal reversible candidate structure X does not contain any reversible transformation mode, the legal reversible candidate structure X can be directly filtered out accordingly.
[0079] After completing the trial run of the first type of reversible reconstruction model, the legal reversible candidate structures remaining after screening based on the trial run results can be determined as target reversible structures, and the reversible transformation modes remaining after screening of each target reversible structure can be combined and added to the matching target reversible transformation mode set.
[0080] S260, traversing nodes according to the tree structure of the abstract syntax tree, and dynamically planning a target reversible strategy corresponding to the target deep learning model in each reversible strategy based on the cost model during the traversal process.
[0081] Among them, each target reversible structure and the target reversible transformation pattern set corresponding to the target reversible structure are used to constitute a reversible strategy for target deep learning model adaptation.
[0082] It can be understood that by using each target reversible structure and a target reversible conversion mode set corresponding to the target reversible structure, a plurality of reversibility strategies can be formed. In one reversibility strategy, a single target reversible structure and a unique target reversible conversion mode corresponding to the single target reversible structure can be defined. In one reversibility strategy, multiple target reversible structures that do not affect each other and unique target reversible conversion modes corresponding to each of the above target reversible structures can also be defined.
[0083] Among them, non-influence means that after a target reversible structure is reversibly transformed using a matching target reversible transformation mode, it will not affect other target reversible structures that use matching target reversible transformation modes to perform corresponding reversible transformations. In other words, the target reversible structures that do not influence each other do not have any identical (overlapping) nodes.
[0084] In a specific example, if the target deep learning model has two target reversible structures, where the target reversible transformation mode set corresponding to the target reversible structure A is {target reversible transformation mode 1, target reversible transformation mode 2}, and the target reversible transformation mode set corresponding to the target reversible structure B is {target reversible transformation mode 3}, and the target reversible structure A and the target reversible structure B do not affect each other, then the reversibility strategy corresponding to the target deep learning model may include:
[0085] Reversible strategy 1 for reversibly converting the target reversible structure A using only the target reversible conversion mode 1, reversible strategy 2 for reversibly converting the target reversible structure A using only the target reversible conversion mode 2, reversible strategy 3 for reversibly converting the target reversible structure B using only the target reversible conversion mode 3, reversible strategy 4 for reversibly converting the target reversible structure B using the target reversible conversion mode 3 while reversibly converting the target reversible structure A using the target reversible conversion mode 1, and reversible strategy 5 for reversibly converting the target reversible structure B using the target reversible conversion mode 3 while reversibly converting the target reversible structure A using the target reversible conversion mode 2.
[0086] It can be understood that after determining multiple reversible strategies based on the target reversible structure and the target reversible transformation pattern set corresponding to the target reversible structure, the cost value of each reversible strategy can be calculated based on a preset cost model, and the target reversible strategy corresponding to the minimum cost value can be selected.
[0087] In this embodiment, in order to further improve the efficiency of determining the target reversible strategy, a dynamic programming algorithm can be applied to the abstract syntax tree of the target deep learning model to efficiently obtain the final required target reversible strategy.
[0088] The input of the cost model is one or more model performance measurement parameters, and the output is the cost value. In a simple example, the cost model can be a simple linear calculation formula. For example, the model performance measurement parameters can be the calculation time and memory usage, then the linear calculation formula can be: C=AX+BY.
[0089] Among them, C is the cost value, A and B are preset proportional coefficients, X is the calculation time, and Y is the memory usage. Specifically, A and B can be preset fixed empirical values, or variable values dynamically updated as the cost model is used, and this embodiment does not limit this.
[0090] Accordingly, in an optional implementation of this embodiment, node traversal is performed according to the tree structure of the abstract syntax tree, and a target reversible strategy corresponding to the target deep learning model is dynamically planned in each reversible strategy based on the cost model during the traversal process, which may include:
[0091] Obtain the current processing node in the abstract syntax tree in a post-order traversal manner; determine the local optimal reversible strategy corresponding to the current processing node among all reversible strategies associated with the current processing node based on a preset cost model; wherein the reversible strategies associated with the current processing node include: a strategy for reversibly converting the current processing node, and a strategy for not reversibly converting the current processing node; return to execute the operation of obtaining the current processing node in the abstract syntax tree in a post-order traversal manner until the local optimal reversible strategy corresponding to the root node of the abstract syntax tree is traversed; determine the local optimal reversible strategy corresponding to the root node of the abstract syntax tree as the target reversible strategy.
[0092] In this optional implementation, the local optimal reversible strategy corresponding to each tree node in the abstract syntax tree is determined step by step by post-order traversal, wherein the local optimal reversible strategy may include a reversible strategy for performing a reversible transformation on the tree node, and may also include a reversible strategy for not performing a reversible transformation on the tree node. Furthermore, when the local optimal reversible strategy corresponding to the root node of the abstract syntax tree is traversed, it is equivalent to traversing the target reversible strategy corresponding to the target deep learning model.
[0093] S270. According to the target reversible strategy, a target reversible reconstruction model corresponding to the target deep learning model is constructed, and the target reversible reconstruction model is loaded into the back-end system for actual operation to perform the model training operation.
[0094] It can be understood that the target reversible reconstruction model can be understood as the final model obtained after reconstructing the target deep learning model using the target reversible strategy. By running the target reversible reconstruction model for actual model training, the back propagation calculation in the model training process can be effectively optimized.
[0095] It is understandable that the above-mentioned target deep learning model can be a machine learning model applied in various fields such as computer vision (for example, image classification, target detection or face recognition, etc.), natural language processing (for example, text classification, sentiment analysis, machine translation, speech recognition or speech-to-text, etc.), medical field or autonomous driving field.
[0096] Among them, first, based on the abstract syntax tree of the target deep learning model and the target reversibility strategy, an updated abstract syntax tree can be generated by an intrusive modification method or a non-intrusive modification method. Then, an intermediate representation of a computational graph corresponding to the updated abstract syntax tree is generated by a deep learning compiler, and an intermediate computational graph hierarchy corresponding to the intermediate representation of the computational graph is determined by an optimization pipeline inside the deep learning compiler. Then, an executable machine code or bytecode is generated for the intermediate representation of the computational graph and the intermediate computational graph hierarchy as the target reversible reconstruction model through the deep learning encoder backend.
[0097] The technical solution of the embodiment of the present invention determines all reversible candidate structures by analyzing the dependencies between each node in the target deep learning model; filters out the reversible candidate structures that do not meet the legitimacy detection conditions to obtain legal reversible candidate structures, and determines the reversible transformation pattern set corresponding to each legal reversible candidate structure according to the black and white lists; constructs multiple reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern set corresponding to each legal reversible candidate structure, and runs them in the back-end system for trial operation, and screens out the target reversible structures and the target reversible transformation pattern set corresponding to the target reversible structures according to the trial operation results, performs node traversal according to the tree structure of the abstract syntax tree, and dynamically plans the reversible transformation pattern set corresponding to each reversible strategy in the traversal process based on the cost model. The implementation method of the target reversible strategy corresponding to the target deep learning model innovatively proposes a tree-structured dynamic programming scheme to search for the global optimal implementation method of the target reversible strategy. Without any manual operation, it can realize the automatic identification of legal and effective reversible structures in the deep learning model, and can maximize the mining of all available reversible structures in the deep learning model, as well as the reversible transformation pattern set corresponding to the reversible structure. In addition, the search process of the target reversible strategy does not require the participation of developers, which greatly reduces the labor cost. At the same time, by using the globally optimal target reversible strategy to reversibly process the target deep learning model, it is possible to fully optimize the target deep learning model and maximize the efficiency of the back-propagation calculation.
[0098] Embodiment 2
[0099] Figure 3 A flowchart of another method for identifying a reversible structure in a deep learning model provided in Example 2 of the present invention. This embodiment is refined on the basis of the above-mentioned embodiment, and specifically refines the operations of determining the reversible candidate structure corresponding to each node, filtering out the reversible candidate structures that do not meet the legality detection conditions among all reversible candidate structures, and determining the reversible conversion pattern set corresponding to each legal reversible candidate structure according to the black and white lists.
[0100] Correspondingly, such as Figure 3As shown, the method includes:
[0101] S310. Obtain an abstract syntax tree corresponding to the target deep learning model, and generate a directed acyclic graph based on the abstract syntax tree.
[0102] In graph theory, if a directed graph cannot return to any vertex through several edges, then the graph is a directed acyclic graph. Any directed tree is a directed acyclic graph.
[0103] S320 , performing structural analysis on the directed acyclic graph to generate a dominator tree corresponding to the directed acyclic graph, and generating a post-dominator tree corresponding to the directed acyclic graph based on the dominator tree.
[0104] In a directed acyclic graph, for a node n, all paths from the initial node s to n pass through a node m, then m is the dominating point of n. The dominating point closest to n is called the immediate dominating point. With r as the root, all the immediate dominating points are connected according to the dominating relationship to form a dominating tree. The immediate post-dominant point is the closest node passed by all paths from a point n to the terminal node. The dominating tree formed using the immediate post-dominant point is the post-dominant tree.
[0105] Accordingly, a directed acyclic graph can be transformed into a matching post-dominator tree by using the dominator tree as an intermediary. Figure 4 A schematic diagram of a conversion from a directed acyclic graph to a post-dominant tree applicable to an embodiment of the present invention is shown in FIG. The post-dominant tree is determined based on post-dominant node information. The post-dominant node refers to a node A (for example, Figure 4 The outgoing edge of node 5 in must pass through a node B (such as Figure 4 6), then node A is the post-dominant node of node B. For example, Figure 4 Node 2, node 4 and node 5 in are all post-dominant nodes of node 6. That is, in the post-dominant tree, the post-dominant node is the parent node or ancestor node of the node being dominated.
[0106] S330, perform a pre-order traversal on the directed acyclic graph to obtain a sorted node list.
[0107] In this embodiment, according to the mutual dependence relationship between nodes defined in the directed acyclic graph, each node can be traversed in the direction from the dependent node to the dependent node to obtain a sorted node list.
[0108] Accordingly, for Figure 4 The directed acyclic graph shown can construct a sorted node list of the form: {1, 2, 3, 4, 5, 6, 7}.
[0109] S340 , sequentially obtain a node in the sorting node list as the current processing node.
[0110] S350 , query the post-dominant tree, and obtain all subgraphs starting from the current processing node and ending at the post-dominant node of the current processing node as reversible candidate structures corresponding to the current processing node.
[0111] Continuing with the previous example, further, Figure 4 As shown, nodes 1 to 5 have no post-dominant nodes. When traversing to node 6, node 6 and one, two or all of its three post-dominant nodes (i.e., node 2, node 4 and node 5) can be used to try to construct a reversible candidate structure without a branching structure.
[0112] A simple analysis shows that the subgraph composed of nodes 4 and 6, and the subgraph composed of nodes 5 and 6 are not branchless structures, and only the subgraph composed of nodes 2, 4, 5 and 6 is a branchless structure. Therefore, the subgraph composed of the above four nodes can be determined as a reversible candidate structure.
[0113] S360, determine whether to obtain reversible candidate structures corresponding to each node respectively: if so, execute S370; otherwise, return to execute S340.
[0114] S370. Among all reversible candidate structures, filter out reversible candidate structures that do not meet the legality detection conditions to obtain legal reversible candidate structures.
[0115] In an optional implementation of this embodiment, filtering out reversible candidate structures that do not meet the legality detection condition from all reversible candidate structures may include:
[0116] Identify the in-degree and out-degree of the candidate structure that is currently being processed;
[0117] If it is determined that any one of the in-degree and the out-degree is greater than 2, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
[0118] In graph theory, the degree of a node refers to the number of edges associated with the node. In a directed graph, the degree is divided into in-degree and out-degree. In-degree refers to the number of arcs that end at a certain node, while out-degree refers to the number of arcs that start at a certain node and end at the vertex.
[0119] Similarly, the inventors discovered through research that the data capacity of various reversible structures that can be reversibly converted using existing reversible patterns have a common feature, namely, the in-degree or out-degree of each reversible structure can only be 1 or 2. When the in-degree or out-degree of a subnet structure is greater than 2, this subnet structure has no applicable reversible pattern.
[0120] Based on this, the in-degree and out-degree of each reversible candidate structure can be identified, and the reversible candidate structures with in-degree or out-degree greater than 2 can be directly filtered out.
[0121] On the basis of the above embodiments, filtering out reversible candidate structures that do not meet the legality detection condition from all reversible candidate structures may also include:
[0122] Identify the total number of elements in the two input tensors and the two output tensors currently processing the reversible candidate structure;
[0123] If it is determined that the total number of elements in the two input tensors or the two output tensors is inconsistent, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
[0124] Furthermore, the inventors also discovered that when the in-degree of a reversible candidate structure is 2, the reversible candidate structure can only be reversibly transformed using the reversible mode when the total number of elements in the two input tensors of the reversible candidate structure is consistent; similarly, when the out-degree of a reversible candidate structure is 2, the reversible candidate structure can only be reversibly transformed using the reversible mode when the total number of elements in the two output tensors of the reversible candidate structure is consistent. Based on this, the capacity constraints of the input and output tensors can be used to construct matching legitimacy detection conditions.
[0125] The total number of elements in a tensor is usually called the "number of elements", "volume" or "cardinality" of the tensor, which can be obtained by calculating the product of the sizes of each dimension of the tensor. For example, tensor A can be expressed as <3*4*5,f32>, then the total number of elements in tensor A is 3*4*5=60, and the data type of each element in tensor A is float32, that is, single-precision floating point.
[0126] On the basis of the above embodiments, filtering out reversible candidate structures that do not meet the legality detection condition from all reversible candidate structures may also include:
[0127] Obtaining a transfer function matrix corresponding to the currently processed reversible candidate structure; and calculating the determinant of the transfer function matrix;
[0128] If it is determined that the determinant is less than or equal to zero, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
[0129] Furthermore, the inventors conducted further research and found that another necessary condition for a reversible candidate structure to be reversibly transformed using a reversible mode is that the determinant of the transformation function matrix of the reversible candidate structure itself needs to be greater than 0. Therefore, based on this mathematical property, a matching legitimacy detection condition can be constructed accordingly.
[0130] Generally speaking, the determinant of the transfer function matrix of a reversible candidate structure can be determined by the determinants of each node (operator) contained in the reversible candidate structure. Generally speaking, the determinants of some commonly used operators are known a priori, so the determinant calculation method of some operators can be pre-encoded to achieve fast calculation of the determinant of the transfer function matrix.
[0131] The embodiment of the present invention fully explores the common features of reversible structures that cannot be reversibly transformed. On the basis of fully acquiring all reversible candidate structures, the legitimacy detection conditions constructed based on these common features can effectively screen out reversible candidate structures that are obviously unusable among all reversible candidate structures, greatly reducing the workload of subsequent operations and effectively improving the efficiency of automatic recognition of reversible structures.
[0132] S380: Obtain a set of reversible conversion candidate patterns that match each legal reversible candidate structure by querying a pre-established reversible conversion pattern whitelist.
[0133] At present, a large number of reversible structures and various reversible modes available for these reversible structures have been published in various existing academic papers. By aggregating this information, a whitelist of reversible conversion modes can be constructed accordingly.
[0134] That is, in the reversible conversion pattern whitelist, multiple reversible structures and reversible pattern sets corresponding to each reversible structure are recorded. By matching the legal reversible candidate structure with each reversible structure in the reversible conversion pattern whitelist, the reversible pattern set corresponding to the successfully matched reversible structure can be used as the reversible conversion candidate pattern set corresponding to the legal reversible candidate structure.
[0135] S390. Obtain a target algorithm model scenario that matches the target deep learning model, and obtain at least one invalid reversible conversion pattern that matches the target algorithm model scenario by querying a pre-established reversible conversion pattern blacklist.
[0136] As mentioned above, in the reversible conversion mode blacklist, various invalid reversible modes that cannot be effectively reversible converted are defined in each algorithm model scenario. Furthermore, after obtaining the target algorithm model scenario that matches the target deep learning model, by matching the target algorithm model scenario with each algorithm model scenario in the reversible conversion mode blacklist, the invalid reversible modes corresponding to the successfully matched algorithm model scenario can be used as at least one invalid reversible conversion mode that matches the target algorithm model scenario.
[0137] S3100, filtering out invalid reversible conversion patterns in each reversible conversion candidate pattern set, and obtaining a reversible conversion pattern set corresponding to each legal reversible candidate structure.
[0138] In a specific example, assuming that the target algorithm model scenario is the Transformers model scenario, and the legal reversible candidate structure currently being processed is the legal reversible candidate structure A, by querying the reversible transformation pattern whitelist, the reversible transformation pattern B1, reversible transformation pattern B2 and reversible transformation pattern B3 corresponding to the legal reversible candidate structure A can be obtained, and by querying the reversible transformation pattern blacklist, the invalid reversible mode B2 and invalid reversible mode B4 corresponding to the Transformers model scenario can be obtained.
[0139] Furthermore, by filtering out the invalid reversible mode B2 from the reversible mode B1, the reversible mode B2 and the reversible mode B3, the reversible mode set corresponding to the legal reversible candidate structure A can be obtained as {reversible mode B1, reversible mode B3}.
[0140] The advantage of this setting is that by directly using black and white lists to self-define the acquisition of known valid, or self-define the filtering of known invalid reversible conversion modes, the effect of automatic recognition of reversible structures can be effectively improved, and the recognition efficiency of reversible structures can be effectively improved.
[0141] It needs to be emphasized again that by combining the use of legitimacy detection conditions and black and white lists, the theoretical availability of each reversible candidate structure can be effectively constrained while retaining all reversible candidate structures as much as possible.
[0142] S3110. Construct multiple first-class reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern sets corresponding to each legal reversible candidate structure.
[0143] In an optional implementation of this embodiment, constructing multiple first-class reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern sets corresponding to each legal reversible candidate structure may include:
[0144] Constructing a plurality of reversible conversion forms according to each reversible candidate structure and each reversible conversion mode corresponding to each reversible candidate structure;
[0145] Input the abstract syntax tree of the target deep learning model and each reversible transformation form into the non-intrusive reversible converter respectively;
[0146] Outputting updated abstract syntax trees obtained by reversibly transforming the target deep learning model according to each reversible transformation form through a non-intrusive reversible converter as first-type updated abstract syntax trees;
[0147] According to each first-category updated abstract syntax tree, multiple first-category reversible reconstruction models corresponding to the target deep learning model are constructed.
[0148] Specifically, continuing with the previous example, assuming that the reversible transformation pattern set corresponding to the legal reversible candidate structure A is {reversible transformation pattern B1, reversible transformation pattern B2}, the legal reversible candidate structure A and the reversible transformation pattern B1 can be used together as a reversible transformation form 1, indicating that the reversible transformation pattern B1 is used to perform a reversible transformation on the legal reversible candidate structure A in the target deep learning model; at the same time, the legal reversible candidate structure A and the reversible transformation pattern B2 can also be used together as a reversible transformation form 2, indicating that the reversible transformation pattern B2 is used to perform a reversible transformation on the legal reversible candidate structure A in the target deep learning model.
[0149] In this embodiment, a pre-built non-intrusive reversible converter can be used. Based on the abstract syntax tree of the target deep learning model and each reversible transformation form, a first-class updated abstract syntax tree corresponding to each reversible transformation form can be generated, and then a first-class reversible reconstruction model corresponding to each reversible transformation form can be generated according to each first-class updated abstract syntax tree.
[0150] S3120, loading each first-class reversible reconstruction model into the back-end system for trial operation, and screening out each target reversible structure that is actually available and a target reversible conversion pattern set corresponding to the target reversible structure according to the trial operation result.
[0151] S3130. Perform node traversal according to the tree structure of the abstract syntax tree, and dynamically plan a target reversible strategy corresponding to the target deep learning model in each reversible strategy based on the cost model during the traversal process.
[0152] Among them, each target reversible structure and the target reversible transformation pattern set corresponding to the target reversible structure are used to constitute a reversible strategy for target deep learning model adaptation.
[0153] S3140. According to the target reversible strategy, a target reversible reconstruction model corresponding to the target deep learning model is constructed, and the target reversible reconstruction model is loaded into the back-end system for actual operation to perform the model training operation.
[0154] The technical solution of the disclosed embodiment can realize the automatic identification of legal and effective reversible structures in deep learning models without any manual operation, and can maximize the mining of all available reversible structures in the deep learning model, as well as the reversible transformation pattern set corresponding to the reversible structures. Furthermore, it can provide accurate and effective data preparation for ultimately obtaining the optimal reversible transformation form for a specific deep learning model.
[0155] Figure 5 It is a flowchart of an implementation method applicable to an embodiment of the present invention, which performs node traversal according to the tree structure of an abstract syntax tree, and dynamically plans a target reversible strategy corresponding to a target deep learning model in each reversible strategy based on a cost model during the traversal process.
[0156] like Figure 5 As shown, the method may specifically include:
[0157] S510, obtaining each target reversible structure that can be used in actual measurement of the target deep learning model and a target reversible transformation pattern set corresponding to the target reversible structure.
[0158] S520: Obtain an abstract syntax tree corresponding to the target deep learning model.
[0159] S530 , obtaining a current processing node in the abstract syntax tree in a post-order traversal manner.
[0160] In a specific example, assuming that the abstract syntax tree includes a root node A, first-level tree nodes B and C pointed to by the root node A, and a second-level tree node D pointed to by the first-level tree node B, the corresponding post-order traversal order can be: {D, B, C, A}.
[0161] S540: In the abstract syntax tree, obtain a current subtree structure with the current processing node as the root node, and identify, among all reversibility strategies, candidate reversibility strategies that only include nodes in the current subtree structure.
[0162] S550 . From among the candidate reversible strategies, obtain a current node candidate reversible strategy that includes reversible conversion of the current processing node.
[0163] In this embodiment, the core principle of the dynamic programming algorithm is to determine the local optimal reversible strategy corresponding to each tree node in the abstract syntax tree from the bottom up. It can be understood that the local optimal reversible strategy of a tree node may include not only a strategy for performing a corresponding reversible transformation (that is, a reversible transformation) on the tree node, but also a strategy for not performing a reversible transformation on the tree node, but performing a reversible transformation on all child nodes under the tree node using the local optimal reversible strategy of the child nodes.
[0164] Accordingly, in this embodiment, an optimal reversible implementation method is found under these two possible strategies.
[0165] Accordingly, we first need to obtain the alternative reversible strategies that only include the nodes in the current subtree structure. Such alternative reversible strategies may or may not include strategies for reversible transformation of the current processing node. We must first select an optimal strategy from the strategies that include reversible transformation of the current processing node (that is, the alternative reversible strategies for the current node) as the optimal strategy for reversible transformation of the current processing node.
[0166] S560. Identify the optimal reversible strategy for the current node from among the candidate reversible strategies for the current node using a preset cost model, and obtain a first-generation value corresponding to the optimal reversible strategy for the current node.
[0167] Specifically, in Figure 6 , a specific implementation method is shown in which a preset cost model is used to identify the optimal reversible strategy of the current node among the alternative reversible strategies of the current node, and obtain the first-generation value corresponding to the optimal reversible strategy of the current node.
[0168] Correspondingly, such as Figure 6 As shown, the calculation method of the first cost value includes:
[0169] S6100. Reconstruct the target deep learning model according to the alternative reversible strategies of each current node to obtain the second type of reversible reconstruction model corresponding to the alternative reversible strategies of each current node.
[0170] In an optional implementation of this embodiment, the target deep learning model is reconstructed according to the alternative reversible strategies of each current node to obtain the second type of reversible reconstruction model corresponding to each alternative reversible strategy of the current node, which may include:
[0171] Reversible transformation forms defined in the alternative reversible transformation strategies for each current node are identified respectively; the abstract syntax tree of the target deep learning model and the reversible transformation forms are input into the non-intrusive reversible converter respectively; the updated abstract syntax trees obtained after reversible transformation of the target deep learning model according to the reversible transformation forms are outputted through the non-intrusive reversible converter respectively as the second-type updated abstract syntax trees; according to the second-type updated abstract syntax trees, the second-type reversible reconstruction models corresponding to the alternative reversible strategies for each current node are obtained respectively.
[0172] Among them, the reversible transformation form is similar to the definition of the reversibility strategy, which is used to describe which one or several target reversible transformation modes need to be used to reversibly transform the target reversible structure matching in the target deep learning model.
[0173] For example, assuming a reversible transformation form is: target reversible structure A and target reversible transformation mode B1, it means that the target reversible transformation mode B1 is used to perform a reversible transformation on the target reversible structure A in the target deep learning model.
[0174] In this embodiment, a pre-built non-intrusive reversible converter can be used. Based on the abstract syntax tree of the target deep learning model and each reversible transformation form, a second type of updated abstract syntax tree corresponding to each reversible transformation form can be generated, and then according to each second type of updated abstract syntax tree, a second type of reversible reconstruction model corresponding to each reversible transformation form can be generated.
[0175] S6200: Load each second-type reversible reconstruction model into a back-end system for trial operation, and obtain operation performance parameters corresponding to each second-type reversible reconstruction model.
[0176] Optionally, the operating performance parameters may include: calculation time information, and / or memory usage information during the calculation process.
[0177] In this optional implementation, during the process of executing each second-type reversible reconstruction model by the backend system, the operation performance description information corresponding to each second-type reversible reconstruction model can be recorded accordingly. The operation performance description information includes: one or more of the calculation time information or the memory usage information during the calculation process.
[0178] The computing time information can be understood as the time required to complete the set computing target (for example, one round of back-propagation calculation), and the memory usage information can be understood as the average usage of the back-end system memory during the model running process.
[0179] Obviously, the smaller the values of the computation time information and the memory usage information of a second-type reversible reconstruction model are, the better the reconstruction effect of the second-type reversible reconstruction model is.
[0180] S6300: Input the operating performance parameters corresponding to each second-type reversible reconstruction model into the cost model to obtain the cost values corresponding to each current node alternative reversible strategy.
[0181] In an optional implementation of this embodiment, inputting the operating performance parameters corresponding to each second-type reversible reconstruction model into the cost model to obtain the cost values corresponding to each current node candidate reversible strategy may include:
[0182] The current operating performance parameters corresponding to the current second-class reversible reconstruction model are input into the cost model; through the cost model, the cost value corresponding to the current second-class reversible reconstruction model is calculated according to the historically stored historical operating performance parameters and current operating performance parameters that match the current second-class reversible reconstruction model, and the current operating performance parameters are used to update the historical operating performance parameters that match the current second-class reversible reconstruction model.
[0183] S6400. Determine the current node alternative reversible strategy corresponding to the minimum cost value as the current node optimal reversible strategy, and use the minimum cost value as the first cost value.
[0184] S570. In the current subtree structure, obtain all child nodes corresponding to the current processing node, and obtain the subnode local optimal reversible strategy corresponding to each child node, and the second generation value corresponding to the local optimal reversible strategy of each child node.
[0185] S580. Accumulate and sum the second-generation values to obtain the third-generation value when the current processing node is not processed and all child nodes are reversibly processed according to the local optimal reversibility strategy for the child nodes.
[0186] S590. Determine the local optimal reversibility strategy corresponding to the current processing node based on the first-generation value and the third-generation value.
[0187] Specifically, if the first-generation value is less than the third-generation value, the optimal reversible strategy of the current node is determined as the local optimal reversible strategy corresponding to the current processing node; if the first-generation value is greater than or equal to the third-generation value, the combination of the local optimal reversible strategies of the sub-nodes corresponding to all the sub-nodes corresponding to the current processing node is determined as the local optimal reversible strategy corresponding to the current processing node.
[0188] S5100, determine whether the local optimal reversible strategy corresponding to the root node of the abstract syntax tree is traversed: if so, execute S5110; otherwise, return to execute S530.
[0189] S5110. Determine the local optimal reversibility strategy corresponding to the root node of the abstract syntax tree as the target reversibility strategy.
[0190] Through the above settings, an innovative tree-structured dynamic programming scheme is proposed to search for the implementation of the global optimal target reversible strategy. The entire search process does not require the participation of developers, which greatly reduces labor costs. At the same time, by using the global optimal target reversible strategy to reversibly process the target deep learning model, the target deep learning model can be fully optimized and the efficiency of the back-propagation calculation can be maximized.
[0191] Specific global optimization application scenarios
[0192] Figure 7 A schematic diagram showing a specific application scenario to which the technical solution of an embodiment of the present invention is applicable. Figure 7 As shown in the figure, there are four main implementation steps in the global optimization process to achieve the reversibility of the deep learning model.
[0193] Step 1: Post-order traversal of the abstract syntax tree and start dynamic programming based on the tree structure. The reason for using post-order traversal here is that when you need to select the optimal reversible strategy for any node (or subtree), you need to obtain the optimal reversible strategy for the subtree corresponding to its child node in advance. And select the best solution from the following two solution branches.
[0194] Solution 1: Only perform reversible transformation on each child node of the current node, while the current node is not reversible transformed;
[0195] Solution 2: The entire subtree with the current node as the root node (the subtree containing all the child nodes of the current node) is reversibly converted as a whole. These two solutions conflict with each other, so it is necessary to select a more optimized solution overall.
[0196] Step 2: Call the non-intrusive reversible converter to obtain the corresponding second-class reversible reconstruction model for each specific replacement form in the dynamic programming process, and then call the cost model to estimate the cost after execution through the back-end system. The cost model will store the collected data to avoid repeated sampling of the same cost.
[0197] Step 3: Find the optimal cost when performing a reversible transformation on each child node of the current node instead of directly transforming the subtree corresponding to the current node (step 3.1). At the same time, find the optimal cost when performing a reversible transformation on the entire tree with the current node as the root node (step 3.2).
[0198] Step 4: Among the two types of optimal costs mentioned above, select the reversible conversion scheme with the minimum cost value as the optimal reversible strategy corresponding to the current node. In addition, the condition for the termination of the entire dynamic programming is that the root node of the global model is processed and the global optimal target reversible strategy is obtained. And it is output to the subsequent compilation and execution process.
[0199] On the basis of the above-mentioned embodiments, the operation of "respectively outputting updated abstract syntax trees obtained by reversibly converting the target deep learning model according to each reversible conversion form through a non-intrusive reversible converter" is further refined.
[0200] Accordingly, in Figure 8 A flowchart of a non-invasive reversible conversion method of a deep learning model applicable to an embodiment of the present invention is shown in FIG. Figure 8 As shown, the method specifically includes:
[0201] S810, obtaining an abstract syntax tree of a target deep learning model and a set reversible conversion form through a non-intrusive reversible converter.
[0202] The reversible conversion form includes: at least one conversion reversible structure, and a unique conversion reversible conversion mode corresponding to each conversion reversible structure.
[0203] S820. Generate target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern according to the reversible conversion form through a non-intrusive reversible converter.
[0204] As mentioned above, the abstract syntax tree is a tree representation of the abstract syntax structure of the source code. The goal of each embodiment of the present invention is to update the abstract syntax tree of the target deep learning model to an updated abstract syntax tree corresponding to the reversible transformation form based on the set reversible transformation form.
[0205] Among them, based on the updated abstract syntax tree, a reversible reconstruction model can be obtained after reversibly transforming the transformation reversible structure in the target deep learning model using the transformation reversible transformation pattern in the reversible transformation form.
[0206] In order to achieve the above objectives, the embodiments of the present invention consider first converting each conversion reversible structure in the reversible conversion form and the corresponding conversion reversible conversion pattern into a code form (that is, the target injection code), and then generating a subtree structure corresponding to each segment of the target injection code in a manner of generating an abstract syntax tree. Then, in the target deep learning model, the subtree structure corresponding to the conversion reversible structure in the reversible conversion form is converted into the newly generated subtree structure to obtain an updated abstract syntax tree.
[0207] As mentioned above, the reversible conversion form may include only a conversion reversible structure A, and a conversion reversible conversion mode B corresponding to the conversion reversible structure A, then a target injection code C for converting the conversion reversible structure A into the conversion reversible conversion mode B may be generated; or, the reversible conversion form may include a conversion reversible structure A1 and a conversion reversible structure A2 at the same time, a conversion reversible conversion mode B1 corresponding to the conversion reversible structure A1, and a conversion reversible conversion mode B2 corresponding to the conversion reversible structure A2, then a target injection code C1 for converting the conversion reversible structure A1 into the conversion reversible conversion mode B1 may be generated, and at the same time a target injection code C2 for converting the conversion reversible structure A2 into the conversion reversible conversion mode B2 may be generated.
[0208] In an optional implementation of this embodiment, multiple reversible conversion code templates can be pre-constructed, each reversible conversion code template matches the set conversion reversible structure and the set conversion reversible conversion mode. Furthermore, the matching target injection code can be constructed by using the appropriate reversible conversion code template.
[0209] In another optional implementation of this embodiment, one or more reversible conversion rules may be pre-constructed, each reversible conversion rule matching the set conversion reversible structure and the set conversion reversible conversion mode. Furthermore, the matching target injection code may be constructed by using appropriate reversible conversion rules.
[0210] Alternatively, the reversible conversion code template and the reversible conversion rule may be used together to construct the target injection code, which is not limited in this embodiment.
[0211] S830, generating a conversion subtree corresponding to each target injection code through a non-intrusive reversible converter, and updating the abstract syntax tree of the target deep learning model according to each conversion subtree, obtaining an updated abstract syntax tree corresponding to the reversible conversion form and outputting it. Optionally, generating a conversion subtree corresponding to each target injection code may include:
[0212] Call the pre-built code injector to generate a transformation subtree corresponding to each target injection code.
[0213] Specifically, after obtaining the target injection code, the target injection code can be used as the source code to generate the corresponding abstract syntax tree. Compared with the scale of the abstract syntax tree of the target injection code and the abstract syntax tree of the target deep learning model, the abstract syntax tree of the target injection code is only equivalent to a part of the abstract syntax tree of the target deep learning model. Therefore, the abstract syntax tree generated based on the target injection code is called a conversion subtree. It can be understood that the conversion subtree is used to convert the conversion reversible structure in the abstract syntax tree of the target deep learning model.
[0214] Correspondingly, by updating the abstract syntax tree of the target deep learning model according to each conversion subtree, an updated abstract syntax tree corresponding to the reversible conversion form can be obtained.
[0215] Through the above settings, a new technology is provided to automatically realize reversible conversion in a non-invasive manner without the need for human intervention, completely avoiding all kinds of errors caused by manual operation. The implementation method is simple and flexible, and can be effectively generalized and expanded to more machine learning models or application scenarios.
[0216] On the basis of the above embodiments, after obtaining the updated abstract syntax tree corresponding to the reversible conversion form, the following steps may also be included:
[0217] A compiler is used through a non-intrusive reversible converter to perform a validity check on the updated abstract syntax tree, and when it is determined that the updated abstract syntax tree passes the check, a reversible reconstruction model corresponding to the target deep learning model is generated based on the updated abstract syntax tree; the reversible reconstruction model is loaded into a back-end system for trial operation through the non-intrusive reversible converter to obtain a trial operation result that matches the reversible conversion form.
[0218] On the basis of the above embodiments, after the compiler is used to perform a validity check on the updated abstract syntax tree through the non-intrusive reversible converter, it can also include: when the non-intrusive reversible converter determines that the updated abstract syntax tree fails the check, a prompt message prohibiting reversible conversion is generated for the conversion reversible structure in the reversible conversion form and the matching conversion reversible conversion pattern.
[0219] It is understandable that the abstract syntax tree needs to meet certain syntax format requirements, for example, it cannot have nodes with the same name, and the static type of each node (for example, constant, variable, hash key-value pair or structure field, etc.) needs to be set correctly, etc. Based on this, a structure checker for the abstract syntax tree can be constructed based on compiler technology, and the legality of the automatically constructed updated abstract syntax tree can be verified through the structure checker.
[0220] When it is determined that the updated abstract syntax tree passes the legality check, a reversible reconstruction model corresponding to the target deep learning model can be directly generated, and the reversible reconstruction model can be loaded into the back-end system for trial operation; when it is determined that the updated abstract syntax tree fails to pass the legality check, it is determined that the input reversible conversion form cannot be reversibly converted by the method of the embodiment of the present invention. At this time, a prompt message prohibiting reversible conversion corresponding to the reversible conversion form can be generated accordingly.
[0221] Through the above settings, some invalid reversible transformation forms can be filtered out in a simple and convenient way before the abstract syntax tree is updated to generate a reversible reconstruction model, so as to effectively reduce the invalid workload introduced when generating unusable reversible reconstruction models for such reversible transformation forms, thereby improving the efficiency of reversible transformation.
[0222] Further, in Fig. 9 A flowchart of another non-invasive reversible conversion method of a deep learning model applicable to an embodiment of the present invention is shown in FIG.
[0223] Correspondingly, such as Fig. 9 As shown, the method may specifically include:
[0224] S910, obtaining an abstract syntax tree of a target deep learning model and a set reversible conversion form through a non-intrusive reversible converter.
[0225] S920, obtaining a current conversion reversible structure and a current conversion reversible conversion mode matching the current conversion reversible structure through a non-intrusive reversible converter.
[0226] As mentioned above, a reversible switching form may include multiple switching reversible structures and a unique switching reversible switching mode corresponding to each switching reversible structure.
[0227] Therefore, a matching transformation subtree can be generated for each transformation reversible structure respectively, and the abstract syntax tree of the target deep learning model can be updated by using all the transformation subtrees to obtain an updated abstract syntax tree.
[0228] In this embodiment, taking a conversion reversible structure in a reversible conversion form (that is, a current conversion reversible structure) and a unique conversion reversible conversion pattern corresponding to the conversion reversible structure (that is, a current conversion reversible conversion pattern) as an example, the specific generation process of the target injection code corresponding to the current conversion reversible structure and the current conversion reversible conversion pattern is described in detail.
[0229] In this embodiment, considering that the use of reversible conversion code templates to generate target injection codes is more targeted and more accurate, the reversible conversion code templates are preferentially used to generate target injection codes. However, considering that the customization requirements of reversible conversion code templates are relatively high, when there are no available reversible conversion code templates, the reversible conversion rules are considered to generate target injection codes.
[0230] S930. Detect, through the non-intrusive reversible converter, in a preset reversible conversion code template library whether there is a target reversible conversion code template for converting the current conversion reversible structure into the current conversion reversible conversion mode: if so, execute S940; otherwise, execute S950.
[0231] In this embodiment, a variety of reversible conversion code templates may be pre-constructed and added to a reversible conversion code template library, and a reversible structure and a reversible conversion mode corresponding to each reversible conversion code template may be established.
[0232] For example, a reversible conversion code template X1 for reversibly converting the reversible structure A into the reversible conversion pattern B1 and a reversible conversion code template X2 for reversibly converting the reversible structure B into the reversible conversion pattern B2 are established in advance.
[0233] Accordingly, by performing a joint search using the current conversion reversible structure and the current conversion reversible conversion pattern, it can be detected whether there is a target reversible conversion code template for converting the current conversion reversible structure into the current conversion reversible conversion pattern.
[0234] If so, the corresponding target injection code can be generated directly based on the target reversible conversion code template.
[0235] S940. Generate a target injection code corresponding to the current conversion reversible structure according to the target reversible conversion code template through a non-intrusive reversible converter, and execute S970.
[0236] Specifically, when the target reversible conversion code template is highly targeted, the target reversible conversion code template can be directly used as the target injection code corresponding to the current conversion reversible structure. Alternatively, if the target reversible conversion code template is a general template constructed for the same type of reversible structure, the target reversible conversion code template may have one or more parameters to be filled in, such as the number of layers, in-degree, out-degree, or dimensional information of the input and output tensors of the reversible structure; the level, in-degree, out-degree, or dimensional information of the input and output tensors of the reversible conversion mode, etc. At this time, it is necessary to clarify the specific values of the above parameters to be filled in based on the specific current conversion reversible structure and the current conversion reversible conversion mode, and fill the above specific values into the target reversible conversion code template accordingly to obtain the target injection code.
[0237] S950. Obtain, through the non-intrusive reversible converter, a target reversible conversion rule for converting the current conversion reversible structure into the current conversion reversible conversion mode from a preset reversible conversion rule library, and execute S960.
[0238] In this embodiment, if the reversible conversion code template corresponding to the current conversion reversible structure and the current conversion reversible conversion mode is not pre-customized, the reversible conversion rule library can be further queried to obtain the target reversible conversion rule corresponding to the current conversion reversible structure and the current conversion reversible conversion mode.
[0239] Correspondingly, it is also necessary to establish in advance a reversible structure and a reversible conversion mode corresponding to each reversible conversion rule.
[0240] For example, a reversible conversion rule Y1 for reversibly converting the reversible structure A into the reversible conversion mode B1 and a reversible conversion rule Y2 for reversibly converting the reversible structure B into the reversible conversion mode B2 are established in advance.
[0241] It is understandable that the difficulty of constructing a reversible conversion rule is generally much lower than that of constructing a reversible conversion code template. Compared with a reversible conversion code template, a reversible conversion rule is more versatile but less accurate.
[0242] Generally speaking, each reversible transformation rule can be understood as a code generator, which needs to input various parameters corresponding to the transformation reversible structure and the transformation reversible transformation mode, and outputs the corresponding target injection code.
[0243] Of course, it is understandable that there may be a situation where the target reversible conversion rule cannot be found in the reversible conversion rule library. At this time, a prompt message prohibiting reversible conversion can be generated directly for the conversion reversible structure in the reversible conversion form and the matching conversion reversible conversion pattern.
[0244] S960. Generate a target injection code corresponding to the current conversion reversible structure according to the target reversible conversion rule through the non-intrusive reversible converter, and execute S970.
[0245] S970. Generate a conversion subtree corresponding to each target injection code through a non-intrusive reversible converter, and update the abstract syntax tree of the target deep learning model according to each conversion subtree to obtain an updated abstract syntax tree corresponding to the reversible conversion form.
[0246] By comprehensively using the reversible transformation code template library and the reversible transformation rule library to generate the implementation method of the target injection code, the transformation subtree of the abstract syntax tree used to update the target deep learning model can be constructed more accurately, which can effectively improve the generation effectiveness and accuracy of the updated abstract syntax tree.
[0247] Further, in Fig.10 A flowchart of another non-invasive reversible conversion method of a deep learning model applicable to an embodiment of the present invention is shown in FIG.
[0248] Correspondingly, such as Fig.10 The method may specifically include:
[0249] S1010. Obtain the abstract syntax tree of the target deep learning model and the set reversible conversion form through a non-intrusive reversible converter.
[0250] S1020. Generate target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern through a non-intrusive reversible converter according to the reversible conversion form, and generate conversion subtrees corresponding to each target injection code.
[0251] S1030, sequentially obtaining the current conversion subtree and the conversion reversible structure to be replaced that matches the current conversion subtree through the non-intrusive reversible converter, and obtaining the original identification symbol corresponding to the conversion reversible structure to be replaced.
[0252] If there are multiple conversion reversible structures, multiple target injection codes can be generated, and multiple conversion subtrees can be generated accordingly. Then, the abstract syntax tree of the target deep learning model can be updated for each conversion subtree.
[0253] After obtaining a current conversion subtree from all conversion subtrees, a conversion reversible structure corresponding to the current conversion subtree can be obtained accordingly. Furthermore, the conversion reversible structure located in the abstract syntax tree of the target deep learning model can be directly used as the conversion reversible structure to be replaced.
[0254] In the syntax structure of the abstract syntax tree, each node and subtree has a unique identifier (also called symbol) to describe the dependencies between different nodes and subtrees. Accordingly, after locating the reversible structure to be replaced, the identifier corresponding to the reversible structure to be replaced, that is, the original identifier, can be obtained in the abstract syntax tree of the target deep learning model.
[0255] S1040. Add the current conversion subtree to the current abstract syntax tree of the target deep learning model through a non-intrusive reversible converter, and set a replacement identifier corresponding to the current conversion subtree.
[0256] When there are multiple conversion subtrees, multiple rounds of abstract syntax tree updates are required. The abstract syntax tree obtained after each update is called the current abstract syntax tree of the target deep learning model. Correspondingly, when performing the first round of updates, the current abstract syntax tree used is the original abstract syntax tree of the target deep learning model without any update processing. After the update is completed using all conversion subtrees, the current abstract syntax tree obtained is the final updated abstract syntax tree.
[0257] Since the data structure of the current conversion subtree is consistent with the grammatical structure of the abstract syntax tree, the current conversion subtree can be directly added to the current abstract syntax tree of the target deep learning model, and a unique identifier in the current abstract syntax tree can be set for the current conversion subtree, that is, the identifier is replaced.
[0258] S1050, using a non-intrusive reversible converter, replace all nodes that the to-be-replaced conversion reversible structure depends on to correspondingly position the parameters that match the current conversion subtree.
[0259] In the syntax structure of the abstract syntax tree, the nodes that each subtree depends on are written into the set parameter position inside the subtree to describe the dependency relationship between the subtree and other nodes. Since the conversion reversible structure to be replaced needs to be converted to the current conversion subtree, the current conversion subtree needs to inherit all the nodes that the conversion reversible structure to be replaced depends on.
[0260] Correspondingly, all the nodes on which the conversion reversible structure to be replaced depends can be obtained at the parameter position for recording dependent nodes in the conversion reversible structure to be replaced, and the node information of all the above nodes can be written into the parameter position for recording dependent nodes in the current conversion subtree to realize the inheritance of dependent nodes.
[0261] S1060, identifying each user node using the original identifier in the current abstract syntax tree through a non-intrusive reversible converter, and after modifying the original identifier used by each user node to a replacement identifier, deleting the reversible structure to be replaced.
[0262] Furthermore, other nodes in the current abstract syntax tree may record their dependency on the reversible structure of the transformation to be replaced, so the above dependency relationship needs to be redirected to the current transformation subtree. Then, each user node using the original identifier can be identified, that is, the node that depends on the reversible structure of the transformation to be replaced, and the original identifier used by each user node is modified to a replacement identifier.
[0263] After completing the above operations, it is equivalent to completely stripping off the dependency between the conversion reversible structure to be replaced and the remaining nodes in the current abstract syntax tree. At this time, the conversion reversible structure to be replaced in the current abstract syntax tree can be directly deleted to obtain a new current abstract syntax tree corresponding to the target deep learning model, so as to use the new current conversion subtree to update the new current abstract syntax tree.
[0264] S1070 , using the non-intrusive reversible converter to detect whether the processing of all conversion subtrees is completed: if so, execute S1080 ; otherwise, return to execute S1030 .
[0265] S1080. Obtain an updated abstract syntax tree corresponding to the reversible conversion form.
[0266] After it is determined that the processing of all the conversion subtrees is completed, the most recently generated current abstract syntax tree is used as an updated abstract syntax tree corresponding to the reversible conversion form.
[0267] Through the above settings, a new technology is provided to automatically realize reversible conversion in a non-invasive manner without the need for human intervention, completely avoiding all kinds of errors caused by manual operation. The implementation method is simple and flexible, and can be effectively generalized and expanded to more machine learning models or application scenarios.
[0268] Based on the above embodiments, Fig.11 A flowchart of a dynamic storage management method during task execution applicable to an embodiment of the present invention is shown. Specifically, Fig.11 As shown, the method may specifically include:
[0269] S1110. In the process of using the backend system to execute a reversible computing task, whenever a memory release request is detected, a first buffer object in the memory release request is identified, and the first buffer object is added to a set first-in-first-out queue.
[0270] Among them, the reversible computing tasks include: trial operation tasks of the first type of reversible reconstruction model, trial operation tasks of the second type of reversible reconstruction model, or actual operation tasks of the target reversible reconstruction model.
[0271] Specifically, during the process of the backend system executing a reversible computing task, a resource party (for example, a computing thread started in a computing unit) applies for a piece of memory (also called a buffer object) through a memory application request, and after completing the set computing task by using the memory, it can send a memory release request to release the continued occupation of the memory. Among them, the buffer object can be understood as a memory space of a set size.
[0272] In the prior art, when the memory management service receives the memory release request, it first detects whether the memory is being reused by other resource parties. If so, the memory continues to be occupied until all reused resource parties release the memory. If not, the data stored in this memory needs to be refreshed and reset, and released to the memory pool to be provided to the resource party for subsequent application.
[0273] However, the inventors have discovered through research that during the execution of reversible computing tasks, because the introduction of the reversible mode eliminates the need for cumulative storage activation, the life cycle of the buffer object is short, and a large number of allocated buffer objects will be quickly released. In addition, due to the special form of the reversible mode, the sizes of buffer objects in reversible computing are usually very similar. Therefore, over a period of time, the application and release of buffer objects of the same or similar size will occur intensively.
[0274] In view of this, in each embodiment of the present invention, a new type of dynamic storage management strategy is proposed. Whenever a memory release request is detected, the first buffer object to be released is first identified in the memory release request. At this time, instead of executing the memory release process for the first buffer object according to the prior art, the first buffer object is directly added to a first-in-first-out (FIFO) queue.
[0275] That is, different from the prior art, when the resource release conditions are met, the first buffer object of the embodiment of the present invention no longer performs operations of refreshing and resetting data and releasing it to the memory pool, but can be directly added to the first-in-first-out queue for cache to wait for application by other resource parties.
[0276] In this embodiment, considering that during the execution of a reversible computing task, multiple resource parties may apply for the same buffer object for common use, the multiple resource parties will send corresponding memory release requests after finishing using the buffer object.
[0277] Based on this, adding the first buffer object to the set first-in-first-out queue can be specifically as follows: if the first buffer object is not stored in the first-in-first-out queue, directly adding the first buffer object to the first-in-first-out queue; if the first buffer object is already stored in the first-in-first-out queue, giving up adding the first buffer object to the first-in-first-out queue.
[0278] The FIFO queue may be a pre-configured storage queue for storing buffer objects to be released for direct application by other resource parties. The storage space size of the FIFO queue may be preset according to actual conditions, and this embodiment does not limit this.
[0279] Correspondingly, before adding the first buffer object to the set first-in-first-out queue, the method may further include: reducing a reference count of the first buffer object.
[0280] Each buffer object applied for use has a one-to-one reference count, which is used to describe how many resource parties reuse the buffer object. Accordingly, each time a buffer object is applied for use by a resource party, the reference count of the buffer object is increased by one; each time a buffer object is released by a resource party, the reference count of the buffer object is decreased by one.
[0281] It is understandable that before adding the first buffer object to the set first-in-first-out queue, if the first-in-first-out queue is full, the first buffer object stored in the first-in-first-out queue can be directly replaced. Further, if it is detected that the above storage replacement operation is frequently performed, it can be considered to expand the storage space of the first-in-first-out queue according to a certain ratio.
[0282] S1120. Whenever a memory application request is detected, sequentially scan the first-in-first-out queue, obtain the first second buffer object in the first-in-first-out queue that satisfies the memory application request, and provide the second buffer object to the requester of the memory application request.
[0283] In this embodiment, whenever a memory application request is detected, a first-in-first-out queue is first searched for a second buffer object that can satisfy the memory application request in a first-in-first-out order. If the second buffer object can be found, the second buffer object can be directly provided to the requester of the memory application request without performing an operation of applying for memory in the memory pool.
[0284] Combined with the data storage characteristics of reversible computing described above, the buffer objects stored in the first-in-first-out queue that are released first are more likely to be seen by memory application requests first. This time feature is consistent with the rule that the buffer objects in reversible computing have a short life cycle. In addition, the first-in-first-out queue skips the data refresh, reset, and merging actions of the conventional memory pool buffer objects, and the released buffer objects are stored at the same size. This feature is consistent with the feature that the sizes are usually similar or the same in reversible computing, and the data space utilization rate is high.
[0285] Accordingly, in an optional implementation of this embodiment, sequentially scanning the first-in-first-out queue to obtain the first second buffer object in the first-in-first-out queue that satisfies the memory application request may include:
[0286] Obtain a buffer object to be selected in the first-in-first-out queue in turn, and detect whether the buffer object to be selected meets the memory requirement of the memory application request; if so, continue to detect whether the reference count of the buffer object to be selected meets the reusability condition; if not, return to execute the operation of obtaining a buffer object to be selected in the first-in-first-out queue in turn; if it is determined that the reusability condition is met, determine the buffer object to be selected as the second buffer object, and increase the reference count of the buffer object to be selected; if it is determined that the reusability condition is not met, return to execute the operation of obtaining a buffer object to be selected in the first-in-first-out queue in turn.
[0287] In this embodiment, a candidate buffer object can be obtained in sequence according to the first-in-first-out order defined in the first-in-first-out queue to perform two tests. The first test is to detect whether the memory size of the candidate buffer object meets the memory requirement of the memory application request. If it does, the second test is performed to detect whether the candidate buffer object can be reused. Generally speaking, when the reference count of the candidate buffer object is 0, it means that all resource parties using the candidate buffer object have completed the release of its resources. At this time, the candidate buffer object can be determined as the second buffer object.
[0288] Correspondingly, after the to-be-selected buffer object is determined as the second buffer object, the reference count of the to-be-selected buffer object can be increased accordingly. The specific increase amount is matched by the number of requesting parties defined in the memory application request. If the number of requesting parties is 2, the reference count of the to-be-selected buffer object is increased by 2, and if the number of requesting parties is 3, the reference count of the to-be-selected buffer object is increased by 3.
[0289] Of course, it is understandable that if no second buffer object satisfying the memory application request is obtained by traversing the FIFO queue, then the solution of the prior art can be used to apply for the required second buffer object from the memory pool.
[0290] Further, providing the second buffer object to the requester of the memory application request may specifically include:
[0291] After skipping the data refresh and reset operation on the second buffer object and marking the second buffer object as a data ineffective state, the second buffer object is provided to the requester of the memory application request.
[0292] As mentioned above, since the embodiments of the present invention do not actually release the buffer object to the memory pool, the data refresh and reset operations on the second buffer object can be directly skipped to further improve the efficiency of memory management and simplify the memory management implementation process. However, it should be noted that although the data refresh and reset operations on the second buffer object are skipped, it is necessary to mark the second buffer object as being in an invalid data state in the second buffer object.
[0293] The data ineffective state is used to describe that the data currently stored in the second buffer object is invalid data, so as to avoid data calculation errors caused by the requester of the memory application request directly using the data stored in the second buffer object.
[0294] Through the above settings, we fully utilize the storage usage characteristics of reversible deep learning models, such as short storage life cycle and frequent storage reuse, the rule that the input and output tensor capacities of a single reversible structure are usually consistent, and the total storage capacity during model training tends to be consistent. We innovatively propose a new dynamic storage management strategy that can effectively adapt to reversible computing tasks, so as to further improve the advantages of reversible deep learning models in computing, bandwidth and storage resource utilization.
[0295] Further, in Fig.12 FIG. 4 is a flowchart of another method for dynamic storage management during task execution applicable to an embodiment of the present invention. Fig.12 As shown, the method may specifically include:
[0296] S1210 , starting from the standard execution frequency and aiming at minimizing the runtime time overhead, searching step by step in the frequency reduction direction to obtain the target frequency.
[0297] The target frequency is less than a standard execution frequency of a memory defragmentation operation and a storage compression operation.
[0298] Compared with conventional computing requirements, the reversible mode contained in the reversible deep learning model has the same input and output tensor capacity and shape due to the reversible transformation. Therefore, defragmentation and storage compaction are time-consuming and inefficient tasks in the operation of the reversible deep learning model. The reason is that a large number of fragments will frequently be merged and sorted to reallocate small-sized storage requirements, resulting in a large amount of runtime overhead.
[0299] In view of this, the embodiments of the present invention no longer follow the standard execution frequency (a preset empirical value) of memory defragmentation operations and storage compression operations commonly used in the prior art, but choose to design a more reasonable target frequency that is generally much smaller than the standard execution frequency.
[0300] Among them, the target frequency refers to the frequency of executing memory defragmentation operations and storage compression operations in the process of using the back-end system to perform reversible computing tasks. For example, the frequency can be the number of executions per unit time, such as 3 times per second or 5 times per second.
[0301] Accordingly, in the reversible computing process, when the current system time reaches the execution time point that matches the target frequency, the backend system generally interrupts the execution of the reversible computing task, and instead performs the memory defragmentation operation and the storage compression operation first. Of course, it is understandable that the smaller the above target frequency is set, the less time is spent on the memory defragmentation operation and the storage compression operation in the execution of the reversible computing task. However, when the target frequency is too low, the backend system may have excessive memory fragmentation, which may significantly deteriorate the computing performance. Therefore, it is necessary to search for an optimal value of the target frequency with the goal of minimizing the runtime time overhead.
[0302] The runtime time overhead can be understood as the total time span required for the backend system to fully execute the reversible computing task. The above runtime time overhead includes the time taken by the backend system to execute the actual reversible computing task, as well as the time taken by the interrupt task to perform one or more memory defragmentation operations and storage compression operations before the reversible computing task is completed.
[0303] It can be understood that by executing the dynamic storage management method of each embodiment of the present invention, the demand for memory defragmentation operations and storage compression operations can be greatly reduced. Therefore, starting from the standard execution frequency, the most suitable target frequency can be found in the direction of reducing the frequency.
[0304] Specifically, in Fig.13 , which takes the standard execution frequency as the starting point, minimizes the runtime time overhead, and searches step by step in the frequency reduction direction to obtain the target frequency. Fig.13 As shown, the implementation method specifically includes:
[0305] S13100: Perform frequency reduction processing on the current frequency according to the target ratio to obtain a reduced frequency, wherein the current frequency is initialized as a standard execution frequency.
[0306] Specifically, the target ratio may be preset according to actual conditions, for example, 0.5 times, 0.6 times or 0.7 times, etc., and this embodiment does not limit this.
[0307] S13200: During the execution of the test task, perform a memory defragmentation operation and a storage compression operation at a reduced frequency, and after the execution is completed, obtain the current task execution time. The test task is consistent with the task type of the reversible computing task.
[0308] In this embodiment, a test task that is consistent with the task type of the reversible computing task but has a computational scale much smaller than that of the reversible computing task can be pre-constructed. The reason for this setting is that the current task execution time calculated for the test task can accurately describe the actual task execution time of the reversible computing task from the numerical change trend.
[0309] S13300, check whether the current task execution time is less than the currently stored optimized execution time: if so, execute S13400; otherwise, execute S13800.
[0310] The optimized execution time is initialized to the task execution time when the memory defragmentation operation and the storage compression operation are performed according to the standard execution frequency.
[0311] It can be understood that when the execution frequency of memory defragmentation operations and storage compression operations is reduced, when the current task execution time obtained is less than the optimized execution time, it means that the application effect of the reduced frequency is better than the current frequency. At this time, the reduced frequency can be used as the new current frequency, and the current task execution time can be used as the new optimized execution time.
[0312] Similarly, after reducing the execution frequency of memory defragmentation operations and storage compression operations, the current task execution time obtained is greater than or equal to the optimized execution time, indicating that the application effect of the current reduced frequency is worse than the current frequency, indicating that the newly selected search frequency cannot be lower than the current reduced frequency. At this time, the reduced frequency can be determined as the current limit search frequency, and between the current frequency and the current limit search frequency, it is searched whether there is a new frequency that is lower than the current frequency and has a better application effect than the current frequency.
[0313] S13400. Set the reduced frequency as the new current frequency, and set the current task execution time as the new optimized execution time, and execute S13500.
[0314] S13500, check whether there is a current limit search frequency: if not, return to execute S13100; if so, execute S13600.
[0315] If there is no limit search frequency currently, it means that the current frequency can be continuously reduced without restriction to find the optimal frequency; if there is a limit search frequency currently, the optimal frequency must be found between the current frequency and the current limit search frequency.
[0316] S13600. Detect whether the search process is completed based on the numerical difference between the current frequency and the limit search frequency: if so, execute S13900; otherwise, execute S13700.
[0317] Specifically, when the numerical difference between the current frequency and the limit search frequency is small, for example, when the difference value is less than or equal to 1 or less than or equal to 2, the search may not be continued and the search result may be obtained directly.
[0318] S13700. After selecting a frequency between the current frequency and the limit search frequency as a new reduction frequency, return to execute S13200.
[0319] Specifically, a median frequency between the current frequency and the limit search frequency may be obtained as a new reduction frequency.
[0320] S13800. After determining the reduced frequency as the current limit search frequency, execute S13600.
[0321] S13900. Use the frequency corresponding to the optimized execution time stored when the search is completed as the target frequency.
[0322] In a specific example, assuming that the standard execution frequency is 100 times / second, and the task execution time corresponding to the standard execution frequency is 5 seconds, then, the standard execution frequency can be first used as the current frequency, and 5 seconds can be initialized and stored as the optimized execution time. First, the frequency is determined to be reduced to 50 times / second, and the corresponding task execution time corresponding to 50 times / second is obtained as 4.5 seconds. At this time, 50 times / second can be determined as the new current frequency, and 4.5 seconds can be updated and stored as the new optimized execution time. Afterwards, it is determined that the reduced frequency is 25 times / second, and the corresponding task execution time corresponding to 25 times / second is 4.8 seconds. Since 4.8 seconds is greater than 4.5 seconds, 25 times / second is required to be used as the limit search frequency, and a new reduced frequency is searched again between 25 times / second and 50 times / second, for example, 37 times / second, and the corresponding task execution time corresponding to 37 times / second is obtained as 4 seconds. At this time, 37 times / second can be used as the new previous frequency, and 4 seconds can be updated and stored as the new optimized execution time, and then, the new reduced frequency is searched again between 25 times / second and 37 times / second, and so on, until the entire search process is completed to find the optimal target frequency.
[0323] S1220. In the process of using the backend system to execute the reversible computing task, perform memory defragmentation operations and storage compression operations according to the target frequency.
[0324] S1230, in the process of using the back-end system to execute the reversible computing task, whenever a memory release request is detected, identifying the first buffer object in the memory release request, and adding the first buffer object to a set first-in-first-out queue;
[0325] S1240. Whenever a memory application request is detected, sequentially scan the first-in-first-out queue, obtain the first second buffer object in the first-in-first-out queue that satisfies the memory application request, and provide the second buffer object to the requester of the memory application request.
[0326] Through the above settings, a new low-frequency defragmentation and compression strategy is proposed. By searching for the optimal low-frequency execution of memory defragmentation operations and storage compression operations, the runtime overhead of reversible computing tasks can be greatly reduced, and the operating efficiency of reversible deep learning models during model training can be significantly improved.
[0327] Specific dynamic storage management application scenarios
[0328] Fig.14 FIG. 1 is a schematic diagram of a dynamic storage management scenario applicable to an embodiment of the present invention. Fig.14 As shown, the entire dynamic storage management scenario is divided into two parts: system resources and runtime system through the dotted line.
[0329] Specifically, at the system resource level, a mapping relationship between physical addresses and virtual address spaces needs to be established. First, a unified address space needs to be built on the physical layer to manage the host machine and the acceleration device. This step is the basis for ensuring that all storage resources can be effectively managed. In this way, data from different physical storage media can be seamlessly processed, whether internal storage or externally connected devices. Next, at the virtual address layer, physical storage needs to be mapped to virtual addresses. The implementation of this layer is critical because it provides an abstract way for upper-level applications (i.e., runtime systems) to access storage resources without having to worry about specific physical storage details. The design of the virtual address layer can also enhance the flexibility and scalability of storage management.
[0330] In the embodiments of the present invention, by combining the memory pool with the buffer object FIFO queue, fast memory allocation and recovery management can be performed. Specifically, based on the traditional memory pool management, the embodiments of the present invention introduce a layer of FIFO queue description for buffer objects (Buffer objects). Compared with the traditional memory pool, this combined use method is more suitable for processing storage usage requirements with short life cycle and high reuse frequency. The implementation of this step is crucial to improving the efficiency of memory management. Specifically, the module responds to requests for memory allocation and release in the following manner:
[0331] Memory allocation: When there is a storage allocation request, the FIFO queue is scanned sequentially. For the buffer object with the same capacity or larger capacity at the head of the queue, its reference count is checked to determine whether it can be reused. If it can be reused, the data refresh and reset steps are skipped and the buffer object is reused directly.
[0332] Memory release and reuse: When a temporary variable is used up, such as an activation value in the model, the reference count of the buffer object is reduced, but the storage is not immediately recycled or the object is destroyed. Instead, it is placed at the end of the FIFO queue and waits for storage application requirements of appropriate size.
[0333] This design is also based on the characteristics of the short storage life cycle of the reversible deep learning model, and the characteristics of the overall storage of the reversible deep learning model is constant complexity and relatively stable. After the model completes the training warm-up, the memory utilization is quite stable, and there is a large number of tensor storage requirements of the same size. Therefore, canceling frequent storage recycling and replacing it with high-frequency direct reuse is a key implementation focus of each embodiment of the present invention.
[0334] Memory release and recycling: Destroy buffer objects and recycle system resources at a low frequency in the order of the FIFO queue. This solution is based on the consideration that the life cycle is generally short in the reversible model (the buffer object at the head of the FIFO queue is highly likely no longer needed). Recycling directly according to the FIFO queue avoids the high cost of program termination in the conventional memory recycling garbage collection process, and avoids the complex logic of coloring and changing the state of buffer objects in common memory garbage collection technologies. It greatly speeds up processing efficiency.
[0335] In general, this design can greatly improve the efficiency of memory allocation and release: it uses the characteristics of the FIFO queue to quickly recycle and reallocate memory. When a storage object is no longer needed, it is placed at the end of the FIFO queue and waits for the next allocation. When there is a new storage demand, the FIFO queue is checked first, and the free memory at the head of the queue is quickly allocated, which greatly speeds up the memory allocation and release process.
[0336] Specialized low-frequency defragmentation and storage compression strategies: Compared with conventional computing requirements, the reversible mode in the reversible deep learning model has the same input and output tensor capacity and shape due to the reversible conversion. Therefore, defragmentation and storage compression are relatively time-consuming and inefficient tasks in the operation of the reversible model. It will cause a large number of fragments to be merged and sorted and then reallocated to a small size of storage requirements. This will cause a lot of runtime overhead. The embodiments of the present invention adopt specialized low-frequency defragmentation and compression strategies. It is used to greatly reduce runtime overhead and significantly improve model operation efficiency.
[0337] Embodiment 3
[0338] Fig.15 This is a schematic diagram of the structure of an automatic reversible synthesis device for a deep learning model provided in the third embodiment of the present invention. Fig.15 As shown, the device comprises:
[0339] A directed acyclic graph generation module 1510 is used to obtain an abstract syntax tree corresponding to a target deep learning model, and generate a directed acyclic graph according to the abstract syntax tree, wherein nodes in the abstract syntax tree correspond to operators in the target deep learning model;
[0340] The reversible candidate structure determination module 1520 is used to perform structural analysis on the directed acyclic graph, determine the dependency relationship between the nodes, and determine the reversible candidate structure corresponding to each node according to the dependency relationship; wherein the reversible candidate structure is a branchless structure including at least one node;
[0341] The reversible conversion pattern set determination module 1530 is used to filter out the reversible candidate structures that do not meet the legality detection conditions from all the reversible candidate structures, obtain legal reversible candidate structures, and determine the reversible conversion pattern set corresponding to each legal reversible candidate structure according to the black and white lists;
[0342] The first type model construction module 1540 is used to construct a plurality of first type reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern set corresponding to each legal reversible candidate structure;
[0343] The available mode screening module 1550 is used to load each first-class reversible reconstruction model into the back-end system for trial operation, and screen out each target reversible structure that is actually available and a target reversible conversion mode set corresponding to the target reversible structure according to the trial operation result;
[0344] A target reversible strategy planning module 1560 is used to perform node traversal according to the tree structure of the abstract syntax tree, and dynamically plan a target reversible strategy corresponding to the target deep learning model in each reversible strategy based on the cost model during the traversal process;
[0345] Among them, each target reversible structure and a target reversible transformation pattern set corresponding to the target reversible structure are used to form a reversible strategy for target deep learning model adaptation;
[0346] The target reversible reconstruction model construction module 1570 is used to construct a target reversible reconstruction model corresponding to the target deep learning model according to the target reversible strategy, and load the target reversible reconstruction model into the back-end system for actual operation to perform model training operations.
[0347] The technical solution of the embodiment of the present invention determines all reversible candidate structures by analyzing the dependencies between each node in the target deep learning model; filters out the reversible candidate structures that do not meet the legitimacy detection conditions to obtain legal reversible candidate structures, and determines the reversible transformation pattern set corresponding to each legal reversible candidate structure according to the black and white lists; constructs multiple reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern set corresponding to each legal reversible candidate structure, and runs them in the back-end system for trial operation, and screens out the target reversible structures and the target reversible transformation pattern set corresponding to the target reversible structures according to the trial operation results, performs node traversal according to the tree structure of the abstract syntax tree, and dynamically plans the reversible transformation pattern set corresponding to each reversible strategy in the traversal process based on the cost model. The implementation method of the target reversible strategy corresponding to the target deep learning model innovatively proposes a tree-structured dynamic programming scheme to search for the global optimal implementation method of the target reversible strategy. Without any manual operation, it can realize the automatic identification of legal and effective reversible structures in the deep learning model, and can maximize the mining of all available reversible structures in the deep learning model, as well as the reversible transformation pattern set corresponding to the reversible structure. In addition, the search process of the target reversible strategy does not require the participation of developers, which greatly reduces the labor cost. At the same time, by using the globally optimal target reversible strategy to reversibly process the target deep learning model, it is possible to fully optimize the target deep learning model and maximize the efficiency of the back-propagation calculation.
[0348] Based on the above embodiments, the reversible candidate structure determination module 1520 can be specifically used to:
[0349] Performing structural analysis on the directed acyclic graph, generating a dominator tree corresponding to the directed acyclic graph, and generating a post-dominator tree corresponding to the directed acyclic graph based on the dominator tree;
[0350] Perform a pre-order traversal of the directed acyclic graph to obtain a sorted node list;
[0351] Sequentially obtain a node in the sorting node list as the current processing node;
[0352] Query the post-dominator tree to obtain all subgraphs starting from the current processing node and ending at the post-dominator node of the current processing node as the reversible candidate structure corresponding to the current processing node;
[0353] Return to the operation of obtaining a node in the sorted node list in execution order as the current processing node until the reversible candidate structure corresponding to each node is obtained.
[0354] Based on the above embodiments, the reversible conversion mode set determination module 1530 can be specifically used to:
[0355] Identify the in-degree and out-degree of the candidate structure that is currently being processed;
[0356] If it is determined that any one of the in-degree and the out-degree is greater than 2, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
[0357] Based on the above embodiments, the reversible conversion mode set determination module 1530 can be specifically used to:
[0358] Identify the total number of elements in the two input tensors and the two output tensors currently processing the reversible candidate structure;
[0359] If it is determined that the total number of elements in the two input tensors or the two output tensors is inconsistent, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
[0360] Based on the above embodiments, the reversible conversion mode set determination module 1530 can be specifically used to:
[0361] Obtaining a transfer function matrix corresponding to the currently processed reversible candidate structure; and calculating the determinant of the transfer function matrix;
[0362] If it is determined that the determinant is less than or equal to zero, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
[0363] Based on the above embodiments, the reversible conversion mode set determination module 1530 may be further specifically used for:
[0364] By querying a pre-established reversible transformation pattern whitelist, a set of reversible transformation candidate patterns that match each legal reversible candidate structure is obtained;
[0365] Obtain a target algorithm model scenario that matches the target deep learning model, and obtain at least one invalid reversible conversion mode that matches the target algorithm model scenario by querying a pre-established reversible conversion mode blacklist;
[0366] In each reversible transformation candidate pattern set, invalid reversible transformation patterns are filtered out respectively to obtain a reversible transformation pattern set corresponding to each legal reversible candidate structure.
[0367] Based on the above embodiments, the first type of model building module 1540 can be specifically used for:
[0368] Constructing a plurality of reversible conversion forms according to each reversible candidate structure and each reversible conversion mode corresponding to each reversible candidate structure;
[0369] Input the abstract syntax tree of the target deep learning model and each reversible transformation form into the non-intrusive reversible converter respectively;
[0370] Outputting updated abstract syntax trees obtained by reversibly transforming the target deep learning model according to each reversible transformation form through a non-intrusive reversible converter as first-type updated abstract syntax trees;
[0371] According to each first-category updated abstract syntax tree, multiple first-category reversible reconstruction models corresponding to the target deep learning model are constructed.
[0372] Based on the above embodiments, the target reversible strategy planning module 1560 can be specifically used for:
[0373] Obtain the current processing node in the abstract syntax tree in a post-order traversal manner;
[0374] Based on a preset cost model, determining a local optimal reversible strategy corresponding to the current processing node among all reversible strategies associated with the current processing node;
[0375] The reversibility strategy associated with the current processing node includes: a strategy for performing a reversible conversion on the current processing node, and a strategy for not performing a reversible conversion on the current processing node;
[0376] Return to execute the operation of obtaining the current processing node in the abstract syntax tree by post-order traversal, until the local optimal reversible strategy corresponding to the root node of the abstract syntax tree is traversed;
[0377] The local optimal reversibility strategy corresponding to the root node of the abstract syntax tree is determined as the target reversibility strategy.
[0378] Based on the above embodiments, the target reversibility strategy planning module 1560 can be further specifically used for:
[0379] In the abstract syntax tree, a current subtree structure with the current processing node as the root node is obtained, and among all reversible strategies, each candidate reversible strategy that only includes each node in the current subtree structure is identified;
[0380] Among the candidate reversible strategies, obtaining a current node candidate reversible strategy that includes reversible transformation of the current processing node;
[0381] Through the preset cost model, the optimal reversible strategy of the current node is identified from the candidate reversible strategies of each current node, and the first-generation value corresponding to the optimal reversible strategy of the current node is obtained;
[0382] In the current subtree structure, all child nodes corresponding to the current processing node are obtained, and the local optimal reversible strategy of the child nodes corresponding to each child node is obtained, as well as the second generation value corresponding to the local optimal reversible strategy of each child node;
[0383] The second-generation values are accumulated and summed to obtain the third-generation value when the current processing node is not processed and all child nodes are reversibly processed according to the local optimal reversibility strategy of the child nodes;
[0384] According to the first-generation value and the third-generation value, the local optimal reversibility strategy corresponding to the current processing node is determined.
[0385] Based on the above embodiments, the target reversibility strategy planning module 1560 can be further specifically used for:
[0386] Reconstruct the target deep learning model according to the alternative reversible strategies of each current node, and obtain the second type of reversible reconstruction model corresponding to the alternative reversible strategies of each current node;
[0387] Loading each second-type reversible reconstruction model into the back-end system for trial operation, and obtaining operation performance parameters corresponding to each second-type reversible reconstruction model;
[0388] Inputting the operating performance parameters corresponding to each second-type reversible reconstruction model into the cost model, and obtaining the cost values corresponding to each current node alternative reversible strategy;
[0389] The current node alternative reversible strategy corresponding to the minimum cost value is determined as the optimal reversible strategy for the current node, and the minimum cost value is used as the first generation value.
[0390] Based on the above embodiments, the operating performance parameters include: calculation time information, and / or memory usage information during the calculation process.
[0391] Based on the above embodiments, the target reversibility strategy planning module 1560 can be further specifically used for:
[0392] Inputting the current operating performance parameters corresponding to the current second-type reversible reconstruction model into the cost model;
[0393] Through the cost model, the cost value corresponding to the current second-class reversible reconstruction model is calculated based on the historical operating performance parameters and current operating performance parameters that are historically stored and match the current second-class reversible reconstruction model, and the current operating performance parameters are used to update the historical operating performance parameters that match the current second-class reversible reconstruction model.
[0394] Based on the above embodiments, the target reversibility strategy planning module 1560 can be further specifically used for:
[0395] Identify the reversible transformation forms defined in the alternative reversibility strategy for each current node respectively;
[0396] Inputting the abstract syntax tree of the target deep learning model and each reversible transformation form into the non-intrusive reversible transformer respectively;
[0397] Outputting updated abstract syntax trees obtained by reversibly transforming the target deep learning model according to each reversible transformation form through a non-intrusive reversible converter as the second type of updated abstract syntax trees;
[0398] According to each second-type updated abstract syntax tree, a second-type reversible reconstruction model corresponding to each current node candidate reversible strategy is obtained.
[0399] Based on the above embodiments, the target reversible strategy planning module 1560 or the first type model building module 1540 may specifically include:
[0400] A reversible conversion form acquisition unit, used to acquire an abstract syntax tree of a target deep learning model and a set reversible conversion form through a non-intrusive reversible converter;
[0401] Wherein, the reversible conversion form includes: at least one conversion reversible structure, and a unique conversion reversible conversion mode corresponding to each conversion reversible structure;
[0402] a target injection code generating unit, for respectively generating target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern according to the reversible conversion form through a non-intrusive reversible converter;
[0403] The updated abstract syntax tree generation unit is used to generate a conversion subtree corresponding to each target injection code through a non-intrusive reversible converter, and update the abstract syntax tree of the target deep learning model according to each conversion subtree, to obtain and output an updated abstract syntax tree corresponding to the reversible conversion form.
[0404] Based on the above embodiments, the target injection code generation unit can be specifically used for:
[0405] obtaining a current conversion reversible structure and a current conversion reversible conversion pattern matching the current conversion reversible structure through a non-intrusive reversible converter;
[0406] By means of a non-intrusive reversible converter, detecting whether there is a target reversible conversion code template for converting a current conversion reversible structure into a current conversion reversible conversion mode in a preset reversible conversion code template library;
[0407] When the non-intrusive reversible converter detects the existence of a target reversible conversion code template, a target injection code corresponding to the current conversion reversible structure is generated according to the target reversible conversion code template.
[0408] Based on the above embodiments, the target injection code generation unit can be further specifically used for:
[0409] After detecting whether there is a target reversible conversion code template for converting a current conversion reversible structure into a current conversion reversible conversion mode in a preset reversible conversion code template library by the non-intrusive reversible converter, when detecting that there is no target reversible conversion code template, the non-intrusive reversible converter obtains a target reversible conversion rule for converting the current conversion reversible structure into the current conversion reversible conversion mode in a preset reversible conversion rule library;
[0410] The target injection code corresponding to the current conversion reversible structure is generated by a non-intrusive reversible converter according to the target reversible conversion rule.
[0411] Based on the above embodiments, the updating abstract syntax tree generation unit may be specifically used for:
[0412] The pre-built code injector is called through a non-intrusive reversible transformer to generate transformation subtrees corresponding to each target injection code.
[0413] Based on the above embodiments, the updating abstract syntax tree generation unit may be specifically used for:
[0414] The current conversion subtree and the conversion reversible structure to be replaced matching the current conversion subtree are sequentially obtained through the non-intrusive reversible converter, and the original identification symbol corresponding to the conversion reversible structure to be replaced is obtained;
[0415] Add the current transformation subtree to the current abstract syntax tree of the target deep learning model through a non-intrusive reversible transformer, and set a replacement identifier corresponding to the current transformation subtree;
[0416] All nodes that the reversible structure of the to-be-replaced conversion depends on are replaced to the parameter positions matched by the current conversion subtree through a non-intrusive reversible converter;
[0417] Identify each user node using the original identifier in the current abstract syntax tree through a non-intrusive reversible converter, modify the original identifier used by each user node to a replacement identifier, and then delete the reversible structure to be replaced;
[0418] The operation of sequentially acquiring the current conversion subtree is executed by returning through the non-intrusive reversible converter until all conversion subtrees are processed to obtain an updated abstract syntax tree corresponding to the reversible conversion form.
[0419] In the above-mentioned embodiments, the technology may further include a reversible reconstruction model generation module, which is used to:
[0420] After obtaining an updated abstract syntax tree corresponding to the reversible conversion form through the non-intrusive reversible converter, a compiler is used to perform a legality check on the updated abstract syntax tree through the non-intrusive reversible converter, and when it is determined that the updated abstract syntax tree passes the check, a reversible reconstruction model corresponding to the target deep learning model is generated according to the updated abstract syntax tree;
[0421] The reversible reconstruction model is loaded into a back-end system for trial operation through a non-intrusive reversible converter to obtain a trial operation result matching the reversible conversion form.
[0422] Based on the techniques of the above embodiments, the reversible reconstruction model generation module can be further used to:
[0423] After the non-intrusive reversible converter uses a compiler to perform a validity check on the updated abstract syntax tree, when the non-intrusive reversible converter determines that the updated abstract syntax tree fails the check, a prompt message prohibiting reversible conversion is generated for the target reversible structure in the reversible conversion form and the matching target reversible conversion pattern.
[0424] On the basis of the above embodiments, the following may also be included:
[0425] A first buffer object identification module is used to, in the process of using the backend system to execute the reversible computing task, whenever a memory release request is detected, identify the first buffer object in the memory release request and add the first buffer object to a set first-in-first-out queue;
[0426] The reversible computing tasks include: a trial operation task of a first type of reversible reconstruction model, a trial operation task of a second type of reversible reconstruction model, or an actual operation task of a target reversible reconstruction model;
[0427] The second buffer object providing module is used to sequentially scan the first-in-first-out queue whenever a memory application request is detected, obtain the first second buffer object in the first-in-first-out queue that meets the memory application request, and provide the second buffer object to the requester of the memory application request.
[0428] Based on the above embodiments, it further includes a reference count update module, which is used to:
[0429] Before adding the first buffer object to the set first-in-first-out queue, reducing the reference count of the first buffer object;
[0430] Accordingly, the memory application processing module 520 may be specifically used for:
[0431] Obtaining a buffer object to be selected from the first-in-first-out queue in turn, and detecting whether the buffer object to be selected meets the memory requirement of the memory application request;
[0432] If the condition is satisfied, then continue to check whether the reference count of the candidate buffer object meets the reusability condition; if not, return to execute the operation of obtaining a candidate buffer object in the first-in-first-out queue in sequence;
[0433] If it is determined that the reusable condition is met, the to-be-selected buffer object is determined as the second buffer object, and a reference count of the to-be-selected buffer object is increased;
[0434] If it is determined that the reusability condition is not met, the operation of sequentially acquiring a buffer object to be selected from the first-in-first-out queue is returned to be executed.
[0435] Based on the above embodiments, the memory application processing module 520 can be further used to:
[0436] After skipping the data refresh and reset operation on the second buffer object and marking the second buffer object as a data ineffective state, the second buffer object is provided to the requester of the memory application request.
[0437] Based on the above embodiments, a storage compression module may be further included, which is used to:
[0438] In the process of performing the reversible computing task using the backend system, performing the memory defragmentation operation and the storage compression operation according to the target frequency;
[0439] The target frequency is less than a standard execution frequency of a memory defragmentation operation and a storage compression operation.
[0440] On the basis of the above embodiments, a target frequency search module may also be included, which is used to:
[0441] Before performing the memory defragmentation operation and the storage compression operation according to the target frequency, starting from the standard execution frequency and aiming at minimizing the runtime time overhead, the target frequency is acquired by searching step by step along the frequency reduction direction.
[0442] Based on the above embodiments, the target frequency search module can be specifically used for:
[0443] According to the target ratio, the current frequency is subjected to frequency reduction processing to obtain a reduced frequency; wherein the current frequency is initialized as a standard execution frequency;
[0444] During the execution of the test task, the memory defragmentation operation and the storage compression operation are performed at a reduced frequency, and after the execution is completed, the current task execution time is obtained;
[0445] Comparing the current task execution time with the currently stored optimized execution time; wherein the optimized execution time is initialized to the task execution time when the memory defragmentation operation and the storage compression operation are performed according to the standard execution frequency;
[0446] If the current task execution time is less than the optimized execution time, the reduced frequency is used as the new current frequency, and the current task execution time is used as the new optimized execution time;
[0447] Check whether there is a limit search frequency at present. If not, return to execute and perform frequency reduction processing on the current frequency according to the target ratio; if so, select a frequency between the current frequency and the limit search frequency as a new reduction frequency, return to execute during the execution of the test task, perform memory defragmentation operation and storage compression operation according to the reduction frequency until the search process is completed;
[0448] If the current task execution time is greater than or equal to the optimized execution time, after determining the reduced frequency as the current limit search frequency, returning to execute, after selecting a frequency between the current frequency and the limit search frequency as a new reduced frequency, returning to execute during the execution of the test task, performing a memory defragmentation operation and a storage compression operation according to the reduced frequency until the search process is completed;
[0449] Using the frequency corresponding to the optimized execution time stored when the search is completed as the target frequency;
[0450] The test task is consistent with the task type of the reversible computing task.
[0451] The automatic reversible synthesis device of the deep learning model provided in the embodiment of the present invention can execute the automatic reversible synthesis method of the deep learning model provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0452] Embodiment 4
[0453] Fig.16 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0454] like Fig.16 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.
[0455] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0456] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as executing the automatic reversible synthesis method of the deep learning model as described in any embodiment of the present invention.
[0457] That is: obtain an abstract syntax tree corresponding to the target deep learning model, and generate a directed acyclic graph based on the abstract syntax tree, wherein the nodes in the abstract syntax tree correspond to the operators in the target deep learning model; perform structural analysis on the directed acyclic graph to determine the dependencies between the nodes, and determine the reversible candidate structures corresponding to the nodes based on the dependencies; wherein the reversible candidate structure is a branchless structure containing at least one node; among all reversible candidate structures, filter out the reversible candidate structures that do not meet the legality detection conditions to obtain legal reversible candidate structures, and determine the reversible transformation pattern sets corresponding to each legal reversible candidate structure based on the black and white lists; construct multiple first-class reversible candidate structures corresponding to the target deep learning model based on the reversible transformation pattern sets corresponding to each legal reversible candidate structure. Reversible reconstruction model; loading each first-class reversible reconstruction model into the back-end system for trial operation, and screening out each target reversible structure that can be measured and the target reversible transformation pattern set corresponding to the target reversible structure according to the trial operation results; performing node traversal according to the tree structure of the abstract syntax tree, and dynamically planning a target reversible strategy corresponding to the target deep learning model in each reversible strategy based on the cost model during the traversal process; wherein each target reversible structure and the target reversible transformation pattern set corresponding to the target reversible structure are used to constitute a reversible strategy adapted to the target deep learning model; according to the target reversible strategy, construct a target reversible reconstruction model corresponding to the target deep learning model, and load the target reversible reconstruction model into the back-end system for actual operation to perform the model training operation.
[0458] In some embodiments, the automatic reversible synthesis method of the deep learning model as described in any embodiment of the present invention may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the automatic reversible synthesis method of the deep learning model as described in any embodiment of the present invention described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the automatic reversible synthesis method of the deep learning model as described in any embodiment of the present invention by any other appropriate means (e.g., by means of firmware).
[0459] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0460] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0461] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0462] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0463] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0464] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0465] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0466] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for automatic reversible synthesis of a deep learning model, characterized in that: include: Obtain an abstract syntax tree corresponding to a target deep learning model, and generate a directed acyclic graph according to the abstract syntax tree, wherein nodes in the abstract syntax tree correspond to operators in the target deep learning model; the target deep learning model is applied in the fields of computer vision, natural language processing, medical treatment, or autonomous driving; the computer vision field includes image classification, target detection, or face recognition; the natural language processing field includes text classification, machine translation, or speech recognition; Performing structural analysis on the directed acyclic graph to determine the dependency relationship between each node, and determining the reversible candidate structure corresponding to each node based on the dependency relationship; wherein the reversible candidate structure is a branchless structure containing at least one node; wherein, when a local structure in the target deep learning model has no directed edge flowing into the local structure or directed edge flowing out of the local structure except for the initial input edge and the final output edge, the local structure as a whole is a branchless structure; Among all the reversible candidate structures, the reversible candidate structures that do not meet the legality detection conditions are filtered out to obtain legal reversible candidate structures, and the reversible transformation pattern sets corresponding to each legal reversible candidate structure are determined according to the black and white lists; According to the reversible transformation pattern set corresponding to each legal reversible candidate structure, multiple first-class reversible reconstruction models corresponding to the target deep learning model are constructed; Load each first-class reversible reconstruction model into the back-end system for trial operation, and screen out each target reversible structure that can be measured and the target reversible conversion pattern set corresponding to the target reversible structure according to the trial operation result; The back-end system is a physical execution device, and the trial operation refers to loading the set first reversible reconstruction model into the execution device, and controlling the execution device to execute the set time or controlling the execution device to achieve the set calculation target, detecting whether the set first reversible reconstruction model can be executed normally, and the trial operation result includes normal operation or abnormal operation; Traverse the nodes according to the tree structure of the abstract syntax tree, and dynamically plan the target reversible strategy corresponding to the target deep learning model in each reversible strategy based on the cost model during the traversal process; Among them, based on the cost model, the cost value of each reversible strategy can be calculated, and the target reversible strategy corresponding to the minimum cost value can be selected, the input of the cost model is one or more model performance measurement parameters, and the output is the cost value, and the model performance measurement parameters include calculation time and memory usage; Among them, each target reversible structure and a target reversible transformation pattern set corresponding to the target reversible structure are used to form a reversible strategy for target deep learning model adaptation; According to the target reversibility strategy, a target reversible reconstruction model corresponding to the target deep learning model is constructed, and the target reversible reconstruction model is loaded into the back-end system for actual operation to perform a model training operation; Among them, the nodes are traversed according to the tree structure of the abstract syntax tree, and during the traversal process, a target reversible strategy corresponding to the target deep learning model is dynamically planned in each reversible strategy based on the cost model, including: Obtain the current processing node in the abstract syntax tree in a post-order traversal manner; Based on a preset cost model, determining a local optimal reversible strategy corresponding to the current processing node among all reversible strategies associated with the current processing node; The reversibility strategy associated with the current processing node includes: a strategy for performing a reversible conversion on the current processing node, and a strategy for not performing a reversible conversion on the current processing node; Return to execute the operation of obtaining the current processing node in the abstract syntax tree by post-order traversal, until the local optimal reversible strategy corresponding to the root node of the abstract syntax tree is traversed; The local optimal reversibility strategy corresponding to the root node of the abstract syntax tree is determined as the target reversibility strategy.
2. The method according to claim 1, characterized in that Perform structural analysis on the directed acyclic graph to determine the dependencies between nodes, and based on the dependencies, determine the reversible candidate structures corresponding to each node, including: Performing structural analysis on the directed acyclic graph, generating a dominator tree corresponding to the directed acyclic graph, and generating a post-dominator tree corresponding to the directed acyclic graph based on the dominator tree; Perform a pre-order traversal of the directed acyclic graph to obtain a sorted node list; Sequentially obtain a node in the sorting node list as the current processing node; Query the post-dominator tree to obtain all subgraphs starting from the current processing node and ending at the post-dominator node of the current processing node as the reversible candidate structure corresponding to the current processing node; Return to the operation of obtaining a node in the sorted node list in execution order as the current processing node until the reversible candidate structure corresponding to each node is obtained.
3. The method according to claim 1, characterized in that: Among all reversible candidate structures, filter out those that do not meet the legality detection conditions, including: Identify the in-degree and out-degree of the candidate structure that is currently being processed; If it is determined that any one of the in-degree and the out-degree is greater than 2, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
4. The method according to claim 1, characterized in that: Among all reversible candidate structures, filter out those that do not meet the legality detection conditions, including: Identify the total number of elements in the two input tensors and the two output tensors currently processing the reversible candidate structure; If it is determined that the total number of elements in the two input tensors or the two output tensors is inconsistent, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
5. The method according to claim 1, characterized in that Among all reversible candidate structures, filter out those that do not meet the legality detection conditions, including: Obtaining a transfer function matrix corresponding to the currently processed reversible candidate structure; and calculating the determinant of the transfer function matrix; If it is determined that the determinant is less than or equal to zero, the currently processed reversible candidate structure is determined to be a reversible candidate structure that does not meet the legality detection condition, and the currently processed reversible candidate structure is filtered out.
6. The method according to claim 1, characterized in that The reversible conversion pattern set corresponding to each legal reversible candidate structure is determined according to the black and white lists, including: By querying a pre-established reversible transformation pattern whitelist, a set of reversible transformation candidate patterns that match each legal reversible candidate structure is obtained; Obtain a target algorithm model scenario that matches the target deep learning model, and obtain at least one invalid reversible conversion mode that matches the target algorithm model scenario by querying a pre-established reversible conversion mode blacklist; In each reversible transformation candidate pattern set, invalid reversible transformation patterns are filtered out respectively to obtain a reversible transformation pattern set corresponding to each legal reversible candidate structure.
7. The method according to claim 1, characterized in that According to the reversible transformation pattern set corresponding to each legal reversible candidate structure, multiple first-class reversible reconstruction models corresponding to the target deep learning model are constructed, including: Constructing a plurality of reversible conversion forms according to each reversible candidate structure and each reversible conversion mode corresponding to each reversible candidate structure; Input the abstract syntax tree of the target deep learning model and each reversible transformation form into the non-intrusive reversible converter respectively; Outputting updated abstract syntax trees obtained by reversibly transforming the target deep learning model according to each reversible transformation form through a non-intrusive reversible converter as first-type updated abstract syntax trees; According to each first-category updated abstract syntax tree, multiple first-category reversible reconstruction models corresponding to the target deep learning model are constructed.
8. The method according to claim 1, characterized in that Based on the preset cost model, a local optimal reversible strategy corresponding to the current processing node is determined among all reversible strategies associated with the current processing node, including: In the abstract syntax tree, a current subtree structure with the current processing node as the root node is obtained, and among all reversible strategies, each candidate reversible strategy that only includes each node in the current subtree structure is identified; Among the candidate reversible strategies, obtaining a current node candidate reversible strategy that includes reversible transformation of the current processing node; Through the preset cost model, the optimal reversible strategy of the current node is identified from the candidate reversible strategies of each current node, and the first-generation value corresponding to the optimal reversible strategy of the current node is obtained; In the current subtree structure, all child nodes corresponding to the current processing node are obtained, and the local optimal reversible strategy of the child nodes corresponding to each child node is obtained, as well as the second generation value corresponding to the local optimal reversible strategy of each child node; The second-generation values are accumulated and summed to obtain the third-generation value when the current processing node is not processed and all child nodes are reversibly processed according to the local optimal reversibility strategy of the child nodes; According to the first-generation value and the third-generation value, the local optimal reversibility strategy corresponding to the current processing node is determined.
9. The method according to claim 8, characterized in that Through the preset cost model, the optimal reversible strategy of the current node is identified among the candidate reversible strategies of each current node, and the first-generation value corresponding to the optimal reversible strategy of the current node is obtained, including: Reconstruct the target deep learning model according to the alternative reversible strategies of each current node, and obtain the second type of reversible reconstruction model corresponding to the alternative reversible strategies of each current node; Loading each second-type reversible reconstruction model into the back-end system for trial operation, and obtaining operation performance parameters corresponding to each second-type reversible reconstruction model; Inputting the operating performance parameters corresponding to each second-type reversible reconstruction model into the cost model, and obtaining the cost values corresponding to each current node alternative reversible strategy; The current node alternative reversible strategy corresponding to the minimum cost value is determined as the optimal reversible strategy for the current node, and the minimum cost value is used as the first generation value.
10. The method according to claim 9, characterized in that The operating performance parameters include: calculation time information, and / or memory usage information during the calculation process.
11. The method according to claim 9, characterized in that The operating performance parameters corresponding to each second-class reversible reconstruction model are input into the cost model to obtain the cost values corresponding to each current node alternative reversible strategy, including: Inputting the current operating performance parameters corresponding to the current second-type reversible reconstruction model into the cost model; Through the cost model, the cost value corresponding to the current second-class reversible reconstruction model is calculated based on the historical operating performance parameters and current operating performance parameters that are historically stored and match the current second-class reversible reconstruction model, and the current operating performance parameters are used to update the historical operating performance parameters that match the current second-class reversible reconstruction model.
12. The method according to claim 9, characterized in that The target deep learning model is reconstructed according to the alternative reversible strategies of each current node, and the second type of reversible reconstruction model corresponding to the alternative reversible strategies of each current node is obtained, including: Identify the reversible transformation forms defined in the alternative reversibility strategy for each current node respectively; Inputting the abstract syntax tree of the target deep learning model and each reversible transformation form into the non-intrusive reversible transformer respectively; Outputting updated abstract syntax trees obtained by reversibly transforming the target deep learning model according to each reversible transformation form through a non-intrusive reversible converter as the second type of updated abstract syntax trees; According to each second-type updated abstract syntax tree, a second-type reversible reconstruction model corresponding to each current node candidate reversible strategy is obtained.
13. The method according to claim 7 or 12, characterized in that: The updated abstract syntax trees obtained by reversibly transforming the target deep learning model according to each reversible transformation form are outputted through a non-intrusive reversible converter, including: Obtain the abstract syntax tree of the target deep learning model and the set reversible transformation form through a non-intrusive reversible transformer; Wherein, the reversible conversion form includes: at least one conversion reversible structure, and a unique conversion reversible conversion mode corresponding to each conversion reversible structure; Generating target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern respectively according to the reversible conversion form by a non-intrusive reversible converter; A non-intrusive reversible converter is used to generate conversion subtrees corresponding to each target injection code, and the abstract syntax tree of the target deep learning model is updated according to each conversion subtree to obtain an updated abstract syntax tree corresponding to the reversible conversion form and output it.
14. The method according to claim 13, characterized in that Generate target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern according to the reversible conversion form through a non-intrusive reversible converter, including: obtaining a current conversion reversible structure and a current conversion reversible conversion pattern matching the current conversion reversible structure through a non-intrusive reversible converter; By means of a non-intrusive reversible converter, detecting whether there is a target reversible conversion code template for converting a current conversion reversible structure into a current conversion reversible conversion mode in a preset reversible conversion code template library; When the non-intrusive reversible converter detects the existence of a target reversible conversion code template, a target injection code corresponding to the current conversion reversible structure is generated according to the target reversible conversion code template.
15. The method according to claim 14, characterized in that After detecting whether there is a target reversible conversion code template for converting the current conversion reversible structure into the current conversion reversible conversion mode in a preset reversible conversion code template library through the non-intrusive reversible converter, the method further includes: When the non-intrusive reversible converter detects that there is no target reversible conversion code template, obtaining a target reversible conversion rule for converting a current conversion reversible structure into a current conversion reversible conversion mode from a preset reversible conversion rule library; The target injection code corresponding to the current conversion reversible structure is generated by a non-intrusive reversible converter according to the target reversible conversion rule.
16. The method according to claim 13, characterized in that The non-intrusive reversible converter generates a transformation subtree corresponding to each target injection code, including: The pre-built code injector is called through a non-intrusive reversible transformer to generate transformation subtrees corresponding to each target injection code.
17. The method according to claim 13, characterized in that The abstract syntax tree of the target deep learning model is updated according to each conversion subtree through a non-intrusive reversible converter to obtain an updated abstract syntax tree corresponding to the reversible conversion form, including: The current conversion subtree and the conversion reversible structure to be replaced matching the current conversion subtree are sequentially obtained through the non-intrusive reversible converter, and the original identification symbol corresponding to the conversion reversible structure to be replaced is obtained; Add the current transformation subtree to the current abstract syntax tree of the target deep learning model through a non-intrusive reversible transformer, and set a replacement identifier corresponding to the current transformation subtree; All nodes that the reversible structure of the to-be-replaced conversion depends on are replaced to the parameter positions matched by the current conversion subtree through a non-intrusive reversible converter; Identify each user node using the original identifier in the current abstract syntax tree through a non-intrusive reversible converter, modify the original identifier used by each user node to a replacement identifier, and then delete the reversible structure to be replaced; The operation of sequentially acquiring the current conversion subtree is executed by returning through the non-intrusive reversible converter until all conversion subtrees are processed to obtain an updated abstract syntax tree corresponding to the reversible conversion form.
18. The method according to claim 13, characterized in that After obtaining the updated abstract syntax tree corresponding to the reversible conversion form through the non-intrusive reversible converter, the method further includes: A compiler is used to perform a legality check on the updated abstract syntax tree through a non-intrusive reversible converter, and when it is determined that the updated abstract syntax tree passes the check, a reversible reconstruction model corresponding to the target deep learning model is generated according to the updated abstract syntax tree; The reversible reconstruction model is loaded into a back-end system for trial operation through a non-intrusive reversible converter to obtain a trial operation result matching the reversible conversion form.
19. The method according to claim 18, characterized in that After the compiler is used to check the legality of the updated abstract syntax tree through the non-intrusive reversible transformer, it also includes: When the non-intrusive reversible converter determines that the update of the abstract syntax tree fails to pass the detection, a prompt message prohibiting the reversible conversion is generated for the target reversible structure in the reversible conversion form and the matching target reversible conversion pattern.
20. The method according to any one of claims 1 to 9, characterized in that: The method further comprises: In the process of using the back-end system to execute the reversible computing task, whenever a memory release request is detected, a first buffer object in the memory release request is identified, and the first buffer object is added to a set first-in-first-out queue; The reversible computing tasks include: a trial operation task of a first type of reversible reconstruction model, a trial operation task of a second type of reversible reconstruction model, or an actual operation task of a target reversible reconstruction model; Whenever a memory application request is detected, the first-in-first-out queue is sequentially scanned to obtain the first second buffer object in the first-in-first-out queue that satisfies the memory application request, and the second buffer object is provided to the requester of the memory application request.
21. The method according to claim 20, characterized in that Before adding the first buffer object to the set first-in-first-out queue, the method further includes: Decrementing a reference count to the first buffer object; Sequentially scanning the first-in-first-out queue to obtain the first second buffer object in the first-in-first-out queue that satisfies the memory application request includes: Obtaining a buffer object to be selected from the first-in-first-out queue in turn, and detecting whether the buffer object to be selected meets the memory requirement of the memory application request; If the condition is satisfied, then continue to check whether the reference count of the candidate buffer object meets the reusability condition; if not, return to execute the operation of obtaining a candidate buffer object in the first-in-first-out queue in sequence; If it is determined that the reusable condition is met, the to-be-selected buffer object is determined as the second buffer object, and a reference count of the to-be-selected buffer object is increased; If it is determined that the reusability condition is not met, the operation of sequentially acquiring a buffer object to be selected from the first-in-first-out queue is returned to be executed.
22. The method according to claim 20, characterized in that Providing the second buffer object to the requester of the memory application request includes: After skipping the data refresh and reset operation on the second buffer object and marking the second buffer object as a data ineffective state, the second buffer object is provided to the requester of the memory application request.
23. The method according to claim 20, characterized in that The method further comprises: In the process of performing the reversible computing task using the backend system, performing the memory defragmentation operation and the storage compression operation according to the target frequency; The target frequency is less than a standard execution frequency of a memory defragmentation operation and a storage compression operation.
24. The method according to claim 23, characterized in that Before performing memory defragmentation and storage compression operations at the target frequency, it also includes: Taking the standard execution frequency as a starting point and minimizing the runtime time overhead as a goal, the target frequency is acquired by searching step by step along the frequency reduction direction.
25. The method according to claim 24, characterized in that Starting from the standard execution frequency and aiming at minimizing the runtime time overhead, searching step by step in the frequency reduction direction to obtain the target frequency includes: According to the target ratio, the current frequency is subjected to frequency reduction processing to obtain a reduced frequency; wherein the current frequency is initialized as a standard execution frequency; During the execution of the test task, the memory defragmentation operation and the storage compression operation are performed at a reduced frequency, and after the execution is completed, the current task execution time is obtained; Comparing the current task execution time with the currently stored optimized execution time; wherein the optimized execution time is initialized to the task execution time when the memory defragmentation operation and the storage compression operation are performed according to the standard execution frequency; If the current task execution time is less than the optimized execution time, the reduced frequency is used as the new current frequency, and the current task execution time is used as the new optimized execution time; Detect whether there is a limit search frequency at present. If not, return to execute and perform frequency reduction processing on the current frequency according to the target ratio; if so, select a frequency between the current frequency and the limit search frequency as a new reduction frequency, return to execute during the execution of the test task, perform memory defragmentation operation and storage compression operation according to the reduction frequency until the search process is completed; If the current task execution time is greater than or equal to the optimized execution time, after determining the reduced frequency as the current limit search frequency, returning to execute, after selecting a frequency between the current frequency and the limit search frequency as a new reduced frequency, returning to execute during the execution of the test task, performing a memory defragmentation operation and a storage compression operation according to the reduced frequency until the search process is completed; Using the frequency corresponding to the optimized execution time stored when the search is completed as the target frequency; The test task is consistent with the task type of the reversible computing task.
26. An automatic reversible synthesis device for a deep learning model, characterized in that: include: A directed acyclic graph generation module, used to obtain an abstract syntax tree corresponding to a target deep learning model, and generate a directed acyclic graph according to the abstract syntax tree, wherein nodes in the abstract syntax tree correspond to operators in the target deep learning model; the target deep learning model is applied in the fields of computer vision, natural language processing, medical treatment or autonomous driving; the computer vision field includes image classification, target detection or face recognition; the natural language processing field includes text classification, machine translation or speech recognition; A reversible candidate structure determination module is used to perform structural analysis on a directed acyclic graph, determine the dependency relationship between nodes, and determine the reversible candidate structure corresponding to each node based on the dependency relationship; wherein the reversible candidate structure is a branchless structure containing at least one node; wherein, when a local structure in a target deep learning model has no directed edge flowing into the local structure or directed edge flowing out of the local structure except for the initial input edge and the final output edge, the local structure as a whole is a branchless structure; A reversible conversion pattern set determination module is used to filter out reversible candidate structures that do not meet the legality detection conditions from all reversible candidate structures, obtain legal reversible candidate structures, and determine the reversible conversion pattern set corresponding to each legal reversible candidate structure according to the black and white lists; A first-class model building module is used to build multiple first-class reversible reconstruction models corresponding to the target deep learning model according to the reversible transformation pattern set corresponding to each legal reversible candidate structure; An available mode screening module is used to load each first-class reversible reconstruction model into the back-end system for trial operation, and screen out each target reversible structure that is actually available and a target reversible conversion mode set corresponding to the target reversible structure according to the trial operation result; The back-end system is a physical execution device, and the trial operation refers to loading the set first reversible reconstruction model into the execution device, and controlling the execution device to execute the set time or controlling the execution device to achieve the set calculation target, detecting whether the set first reversible reconstruction model can be executed normally, and the trial operation result includes normal operation or abnormal operation; The target reversible strategy planning module is used to traverse the nodes according to the tree structure of the abstract syntax tree, and dynamically plan the target reversible strategy corresponding to the target deep learning model in each reversible strategy based on the cost model during the traversal process; Among them, based on the cost model, the cost value of each reversible strategy can be calculated, and the target reversible strategy corresponding to the minimum cost value can be selected, the input of the cost model is one or more model performance measurement parameters, and the output is the cost value, and the model performance measurement parameters include calculation time and memory usage; Among them, each target reversible structure and a target reversible transformation pattern set corresponding to the target reversible structure are used to form a reversible strategy for target deep learning model adaptation; A target reversible reconstruction model construction module is used to construct a target reversible reconstruction model corresponding to the target deep learning model according to the target reversible strategy, and load the target reversible reconstruction model into the backend system for actual operation to perform model training operations; The target reversibility strategy planning module is specifically used for: Obtain the current processing node in the abstract syntax tree in a post-order traversal manner; Based on a preset cost model, determining a local optimal reversible strategy corresponding to the current processing node among all reversible strategies associated with the current processing node; The reversibility strategy associated with the current processing node includes: a strategy for performing a reversible conversion on the current processing node, and a strategy for not performing a reversible conversion on the current processing node; Return to execute the operation of obtaining the current processing node in the abstract syntax tree by post-order traversal, until the local optimal reversible strategy corresponding to the root node of the abstract syntax tree is traversed; The local optimal reversibility strategy corresponding to the root node of the abstract syntax tree is determined as the target reversibility strategy.
27. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the automatic reversible synthesis method of the deep learning model described in any one of claims 1-25.
28. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, which are used to enable a processor to implement the automatic reversible synthesis method of the deep learning model described in any one of claims 1-25 when executed.
