Deep learning model non-intrusive reversible conversion method and device, equipment and medium
By generating and updating the abstract syntax tree of the deep learning model, the non-invasive reversible conversion of the deep learning model is realized, solving the problems of low efficiency and poor scalability caused by manual operations in the existing technology, and realizing automation and flexibility. promote.
Patent Information
- Application Number
- CN202410791071.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-06-19
AI Technical Summary
The reversible transformation of existing deep learning models relies on manual operations, resulting in low resource utilization efficiency, high cost, error-prone, and difficulty in generalization and expansion.
By obtaining the abstract syntax tree of the target deep learning model and the set reversible transformation form, the injected code for the transformation is generated, and the abstract syntax tree is updated to achieve non-invasive reversible transformation.
It realizes automated reversible conversion, avoids errors caused by manual operations, simplifies the process, improves flexibility and scalability, and is suitable for more machine learning models and application scenarios.
Smart Images

Figure CN118569346A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method, device, equipment and medium for non-invasive reversible conversion of a deep learning model. Background Art
[0002] The reversibility technology of deep learning models is a technical solution that can effectively optimize the utilization efficiency of computing, bandwidth and storage resources during model training. The specific implementation method is to convert certain local structures (also called reversible structures) in the deep learning model into specific reversible modes.
[0003] In the prior art, developers with rich knowledge and experience manually analyze the model structure to identify the reversible structure and the corresponding reversible mode that can be reversibly transformed. After that, the deep learning model source code is manually modified in an intrusive way to achieve the above reversible transformation process. For example, the two cutting-edge research in the academic field of RevNet and Reformer both achieve reversible transformation by directly modifying the Pytorch model source code.
[0004] Obviously, such an implementation method relies heavily on the actual experience of developers, which is labor-intensive, cumbersome and error-prone. At the same time, this manual implementation method that relies on experience is difficult to generalize and expand to more models and application scenarios. Summary of the invention
[0005] The present invention provides a method, device, equipment and medium for non-invasive reversible conversion of a deep learning model to achieve the technical effect of non-invasively realizing reversible conversion.
[0006] According to one aspect of an embodiment of the present invention, a method for non-invasive reversible conversion of a deep learning model is provided, comprising:
[0007] Obtain the abstract syntax tree of the target deep learning model and the set reversible transformation form;
[0008] The nodes in the abstract syntax tree correspond to operators in the target deep learning model, and the reversible transformation form includes: at least one transformation reversible structure in the target deep learning model, and a unique transformation reversible transformation pattern corresponding to each transformation reversible structure; the transformation reversible structure is a branchless structure containing at least one node;
[0009] According to the reversible conversion form, respectively generating target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern;
[0010] Generate a conversion subtree corresponding to each target injection code, 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.
[0011] According to another aspect of an embodiment of the present invention, a non-invasive reversible conversion device for a deep learning model is also provided, comprising:
[0012] A reversible transformation form acquisition module is used to obtain the abstract syntax tree of the target deep learning model and the set reversible transformation form;
[0013] The nodes in the abstract syntax tree correspond to operators in the target deep learning model, and the reversible transformation form includes: at least one transformation reversible structure in the target deep learning model, and a unique transformation reversible transformation pattern corresponding to each transformation reversible structure; the transformation reversible structure is a branchless structure containing at least one node;
[0014] A target injection code generation module, for generating target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern according to the reversible conversion form;
[0015] The updated abstract syntax tree generation module is used to generate a conversion subtree corresponding to each target injection code, 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.
[0016] According to another aspect of an embodiment of the present invention, an electronic device is provided, the electronic device comprising:
[0017] at least one processor; and
[0018] a memory communicatively connected to the at least one processor; wherein,
[0019] 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 non-invasive reversible conversion method of the deep learning model described in any embodiment of the present invention.
[0020] 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 non-invasive reversible conversion method of a deep learning model described in any embodiment of the present invention when executed.
[0021] The technical solution of the embodiment of the present invention obtains the abstract syntax tree of the target deep learning model and the set reversible conversion form; according to the reversible conversion form, generates target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern; generates conversion subtrees corresponding to each target injection code, and updates the abstract syntax tree of the target deep learning model according to each conversion subtree, and obtains a technical means for updating the abstract syntax tree corresponding to the reversible conversion form. A new technology for automatically realizing reversible conversion in a non-invasive manner is provided, without the need for human intervention, and completely avoids various errors caused by manual operations. The implementation method is simple and flexible, and can be effectively generalized and expanded to more machine learning models or application scenarios.
[0022] 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
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. 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.
[0024] Figure 1 This is a flowchart of a method for non-invasive reversible conversion of a deep learning model provided in accordance with Embodiment 1 of the present invention;
[0025] Figure 2 is a flowchart of another non-invasive reversible conversion method of a deep learning model provided in Embodiment 2 of the present invention;
[0026] Figure 3 is a flowchart of another non-invasive reversible conversion method of a deep learning model provided in Embodiment 3 of the present invention;
[0027] Figure 4 It is a structural schematic diagram of a non-invasive reversible conversion device of a deep learning model provided according to a fourth embodiment of the present invention;
[0028] Figure 5 It is a structural schematic diagram of an electronic device that implements the non-invasive reversible conversion method of a deep learning model according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] 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.
[0030] 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.
[0031] Embodiment 1
[0032] Figure 1 A flowchart of a method for non-invasive reversible conversion of a deep learning model provided in Example 1 of the present invention. This embodiment can be applied to the case where a new abstract syntax tree corresponding to the reversible conversion form is generated in a non-invasive manner based on the abstract syntax tree of the target deep learning model and the set reversible conversion form. The method can be executed by a deep learning model non-invasive reversible conversion device, 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.
[0033] Correspondingly, such as Figure 1 As shown, the method may include:
[0034] S110, obtaining an abstract syntax tree of a target deep learning model and a set reversible conversion form.
[0035] Among them, the nodes in the abstract syntax tree correspond to the operators in the target deep learning model, and the reversible transformation form includes: at least one transformation reversible structure in the target deep learning model, and a unique transformation reversible transformation pattern corresponding to each transformation reversible structure; the transformation reversible structure is a branchless structure containing at least one node.
[0036] 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.
[0037] Specifically, in the target deep learning model, the local structure used to perform reversible transformation of the reversible mode of the set structure is called a reversible structure.
[0038] The reversible transformation form is used to describe which reversible transformation mode or modes (i.e., transformation reversible transformation modes) need to be used to reversibly transform the matching reversible structure (i.e., transformation reversible structure) in the target deep learning model. In the reversible transformation form, a transformation reversible structure has a unique transformation reversible transformation mode that matches it.
[0039] For example, assuming that a reversible transformation form is: transformation reversible structure A and transformation reversible transformation mode B1, it means that the transformation reversible transformation mode B1 is used to perform a reversible transformation on the transformation reversible structure A in the target deep learning model. For another example, assuming that a reversible transformation form is: transformation reversible structure C and transformation reversible transformation mode D1, and transformation reversible structure E and transformation reversible transformation mode F1, it means that while the transformation reversible transformation mode D1 is used to perform a reversible transformation on the transformation reversible structure C in the target deep learning model, the transformation reversible transformation mode F1 is used to perform a reversible transformation on the transformation reversible structure E in the target deep learning model.
[0040] In this embodiment, the dependency relationship between nodes in the abstract syntax tree corresponding to the target deep learning model can be analyzed, and the theoretically usable legal reversible structures and the reversible transformation pattern set corresponding to each legal reversible structure can be determined based on the legality detection conditions and the black and white lists to generate a conversion reversible structure and a corresponding conversion reversible transformation pattern;
[0041] Alternatively, the conversion reversible structure and the corresponding conversion reversible conversion mode may be generated by using the actually measured available target reversible structures determined by the actual trial operation and the target reversible conversion mode set corresponding to each target reversible structure, which is not limited in this embodiment.
[0042] In an optional implementation of this embodiment, the manner of determining the reversible conversion pattern set corresponding to each legal reversible candidate structure may include:
[0043] An abstract syntax tree corresponding to the target deep learning model is obtained, and a directed acyclic graph is generated based on the abstract syntax tree; a structural analysis is performed on the directed acyclic graph to determine the dependency relationship between the nodes, and based on the dependency relationship, a reversible candidate structure corresponding to each node is determined; wherein the reversible candidate structure is a branchless structure containing at least one node; among all the reversible candidate structures, reversible candidate structures that do not meet the legitimacy detection conditions are filtered out to obtain legal reversible candidate structures, and a reversible conversion pattern set corresponding to each legal reversible candidate structure is determined based on the black and white lists.
[0044] The Abstract Syntax Tree (AST) is a tree representation of the abstract syntax structure of the source code, and each node on 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.
[0045] 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 edge links (directed edges) with a certain direction between the nodes, and there are no multiple edges linked to form a ring in the form of a cycle.
[0046] 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.
[0047] 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.
[0048] 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.
[0049] 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.
[0050] 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.
[0051] The inventors further discovered that the reversible structure that can be reversibly transformed using the reversible mode also needs to meet certain necessary conditions in terms of data capacity (the total number of elements contained in the tensor), in-degree and out-degree, or mathematical properties (determinant value). 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.
[0052] 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.
[0053] 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.
[0054] 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.
[0055] 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.
[0056] 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.
[0057] Further, the directed acyclic graph is structurally analyzed to determine the dependency relationship between the nodes, and based on the dependency relationship, the reversible candidate structures corresponding to the nodes are determined, which may include:
[0058] Perform structural analysis on the directed acyclic graph to generate a dominator tree corresponding to the directed acyclic graph, and generate a post-dominator tree corresponding to the directed acyclic graph based on the dominator tree; perform a pre-order traversal on the directed acyclic graph to obtain a sorted node list; sequentially obtain a node in the sorted node list as the current processing node; query the post-dominator tree to obtain all subgraphs with the current processing node as the starting point and the post-dominator node of the current processing node as the end point, as the reversible candidate structure corresponding to the current processing node; return to execute the operation of sequentially obtaining a node in the sorted node list as the current processing node, until the reversible candidate structure corresponding to each node is obtained.
[0059] Furthermore, filtering out reversible candidate structures that do not meet the legality detection conditions from among all reversible candidate structures may include:
[0060] Identify the in-degree and out-degree of the currently processed reversible candidate structure; if it is determined that any one of the in-degree and the out-degree is greater than 2, determine that the currently processed reversible candidate structure is a reversible candidate structure that does not meet the legality detection condition, and filter out the currently processed reversible candidate structure.
[0061] Furthermore, filtering out reversible candidate structures that do not meet the legality detection conditions from among all reversible candidate structures may include:
[0062] Identify the total number of elements in the two input tensors and the two output tensors of the currently processed reversible candidate structure; if it is determined that the total number of elements in the two input tensors or the two output tensors are inconsistent, determine that the currently processed reversible candidate structure is a reversible candidate structure that does not meet the legality detection conditions, and filter out the currently processed reversible candidate structure.
[0063] Furthermore, filtering out reversible candidate structures that do not meet the legality detection conditions from among all reversible candidate structures may include:
[0064] Obtain a transfer function matrix corresponding to the currently processed reversible candidate structure; and calculate the determinant of the transfer function matrix; if it is determined that the determinant is less than or equal to zero, determine that the currently processed reversible candidate structure is a reversible candidate structure that does not meet the legality detection conditions, and filter out the currently processed reversible candidate structure.
[0065] Furthermore, determining the reversible conversion pattern set corresponding to each legal reversible candidate structure according to the black and white lists may include:
[0066] By querying a pre-established reversible conversion pattern whitelist, a set of reversible conversion alternative patterns that match each legal reversible candidate structure is obtained; a target algorithm model scenario that matches the target deep learning model is obtained, and by querying a pre-established reversible conversion pattern blacklist, at least one invalid reversible conversion pattern that matches the target algorithm model scenario is obtained; in each reversible conversion alternative pattern set, each invalid reversible conversion pattern is filtered out respectively to obtain a reversible conversion pattern set corresponding to each legal reversible candidate structure.
[0067] In a specific 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.
[0068] Furthermore, in a reversible form, a single conversion reversible structure and a unique conversion reversible conversion mode corresponding to the single conversion reversible structure can be defined; in a reversible form, multiple conversion reversible structures that do not affect each other can also be defined, as well as unique conversion reversible conversion modes corresponding to each of the above conversion reversible structures.
[0069] The term "non-influence" means that after a conversion reversible structure is reversibly converted using a matching conversion reversible conversion mode, it will not affect other conversion reversible structures that are reversibly converted using a matching conversion reversible conversion mode. That is, the conversion reversible structures that do not influence each other do not have any identical (overlapping) nodes.
[0070] S120. According to the reversible conversion form, respectively generate target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern.
[0071] 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.
[0072] 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.
[0073] 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.
[0074] 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.
[0075] 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.
[0076] 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.
[0077] 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.
[0078] S130. Generate a conversion subtree corresponding to each target injection code, 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.
[0079] Optionally, generating a transformation subtree corresponding to each target injection code may include:
[0080] Call the pre-built code injector to generate a transformation subtree corresponding to each target injection code.
[0081] In this embodiment, 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.
[0082] 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.
[0083] Furthermore, after obtaining the updated abstract syntax tree, a reversible reconstruction model corresponding to the target deep neural network can be generated based on the updated abstract syntax tree. The specific generation method may include:
[0084] An intermediate representation of a computational graph corresponding to the updated abstract syntax tree is generated through a deep learning compiler, and an intermediate computational graph hierarchy corresponding to the intermediate representation of the computational graph is determined through an optimization pipeline inside the deep learning compiler. Then, an executable machine code or bytecode is generated as the reversible reconstruction model for the intermediate representation of the computational graph and the intermediate computational graph hierarchy through a deep learning encoder backend.
[0085] Furthermore, after obtaining the reversible reconstruction model, the reversible reconstruction model can be loaded into the back-end system for trial operation, and whether the reversible conversion form is available is verified based on the trial operation results. Alternatively, after verifying that the reversible conversion form is available based on the trial operation results, it is also possible to determine whether the reversible reconstruction model can be used to replace the target deep learning model based on the operating performance description information of the back-end system when executing the reversible reconstruction model. If so, the reversible reconstruction model is loaded into the back-end system for actual operation to perform equivalent model training operations.
[0086] 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 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 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.
[0087] The operating performance description information includes: one or more of the calculation time information or the memory usage information during the calculation process.
[0088] The computation time information can be understood as the time required to complete the set computation target (for example, one round of back-propagation computation), and the memory usage information can be understood as the average amount of memory used by the back-end system during model operation.
[0089] Obviously, the smaller the values of the computation time information and memory usage information of a reversible reconstruction model are, the better the reconstruction effect of the reversible reconstruction model is.
[0090] It can be understood that if the reconstruction effect of the reversible reconstruction model is good, after the reversible reconstruction model is used to replace the target deep neural network and loaded into the back-end system for actual operation, the back-propagation calculation in the model training process can be effectively optimized.
[0091] It can be understood 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.
[0092] The technical solution of the embodiment of the present invention obtains the abstract syntax tree of the target deep learning model and the set reversible conversion form; according to the reversible conversion form, generates target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern; generates conversion subtrees corresponding to each target injection code, and updates the abstract syntax tree of the target deep learning model according to each conversion subtree, and obtains a technical means for updating the abstract syntax tree corresponding to the reversible conversion form. A new technology for automatically realizing reversible conversion in a non-invasive manner is provided, without the need for human intervention, and completely avoids various errors caused by manual operations. The implementation method is simple and flexible, and can be effectively generalized and expanded to more machine learning models or application scenarios.
[0093] 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:
[0094] A compiler is used 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, and a trial operation result matching the reversible conversion form is obtained.
[0095] On the basis of the above embodiments, after using the compiler to perform a validity check on the updated abstract syntax tree, it can also include: when it is determined that the updated abstract syntax tree fails the check, generating a prompt message prohibiting reversible conversion for the conversion reversible structure in the reversible conversion form and the matching conversion reversible conversion pattern.
[0096] It is understandable that the abstract syntax tree needs to meet certain syntax format requirements, for example, there cannot be 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 checked through the structure checker.
[0097] 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.
[0098] 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.
[0099] Embodiment 2
[0100] Figure 2 A flowchart of another non-invasive reversible conversion method for a deep learning model provided in Example 2 of the present invention. This embodiment is optimized based on the above embodiments. In this embodiment, the operation of "generating target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern according to the reversible conversion form" is concretized.
[0101] Correspondingly, such as Figure 2 As shown, the method may include:
[0102] S210, obtaining an abstract syntax tree of a target deep learning model and a set reversible conversion form.
[0103] Among them, the nodes in the abstract syntax tree correspond to the operators in the target deep learning model, and the reversible transformation form includes: at least one transformation reversible structure in the target deep learning model, and a unique transformation reversible transformation pattern corresponding to each transformation reversible structure; the transformation reversible structure is a branchless structure containing at least one node.
[0104] S220: Obtain a current conversion reversible structure and a current conversion reversible conversion mode matching the current conversion reversible structure.
[0105] 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.
[0106] 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.
[0107] 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.
[0108] 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.
[0109] S230. In a preset reversible conversion code template library, check 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 S240; otherwise, execute S250.
[0110] 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.
[0111] 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.
[0112] 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.
[0113] If so, the corresponding target injection code can be generated directly based on the target reversible conversion code template.
[0114] S240. Generate a target injection code corresponding to the current conversion reversible structure according to the target reversible conversion code template, and execute S270.
[0115] 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.
[0116] S250. Obtain 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, and execute S260.
[0117] 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.
[0118] Correspondingly, it is also necessary to establish in advance a reversible structure and a reversible conversion mode corresponding to each reversible conversion rule.
[0119] 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.
[0120] 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.
[0121] 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.
[0122] 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.
[0123] S260. Generate a target injection code corresponding to the current conversion reversible structure according to the target reversible conversion rule, and execute S270.
[0124] S270. Generate a conversion subtree corresponding to each target injection code, 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.
[0125] The technical solution of the embodiment of the present invention generates the target injection code by comprehensively using a reversible conversion code template library and a reversible conversion rule library, which can more accurately construct a conversion subtree for updating the abstract syntax tree of the target deep learning model, and can effectively improve the generation validity and accuracy of the updated abstract syntax tree.
[0126] Embodiment 3
[0127] Figure 3 A flowchart of another method for non-invasive reversible conversion of a deep learning model provided in Example 3 of the present invention. This embodiment is optimized based on the above embodiments. In this embodiment, the operation of "updating 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" is concretized.
[0128] Correspondingly, such as Figure 3 As shown, the method may include:
[0129] S310, obtaining an abstract syntax tree of a target deep learning model and a set reversible conversion form.
[0130] Among them, the nodes in the abstract syntax tree correspond to the operators in the target deep learning model, and the reversible transformation form includes: at least one transformation reversible structure in the target deep learning model, and a unique transformation reversible transformation pattern corresponding to each transformation reversible structure; the transformation reversible structure is a branchless structure containing at least one node.
[0131] S320. According to the reversible conversion form, respectively generate target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern, and generate conversion subtrees corresponding to each target injection code.
[0132] S330: sequentially obtain the current conversion subtree and the conversion reversible structure to be replaced that matches the current conversion subtree, and obtain the original identification symbol corresponding to the conversion reversible structure to be replaced.
[0133] In this embodiment, if there are multiple conversion reversible structures, multiple target injection codes can be generated, and then 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.
[0134] 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.
[0135] 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.
[0136] S340. Add the current conversion subtree to the current abstract syntax tree of the target deep learning model, and set a replacement identifier corresponding to the current conversion subtree.
[0137] In this embodiment, when there are multiple conversion subtrees, multiple rounds of abstract syntax tree updates are required, and 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.
[0138] 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.
[0139] S350: Replace all nodes that the to-be-replaced conversion reversible structure depends on with corresponding positions of parameters matched by the current conversion subtree.
[0140] 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.
[0141] 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.
[0142] S360: In the current abstract syntax tree, identify each user node that uses the original identifier, modify the original identifier used by each user node to a replacement identifier, and then delete the reversible conversion structure to be replaced.
[0143] 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.
[0144] 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.
[0145] S370, check whether the processing of all conversion subtrees is completed: if so, execute S380; otherwise, return to execute S330.
[0146] S380. Obtain an updated abstract syntax tree corresponding to the reversible conversion form.
[0147] 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.
[0148] The technical solution of the embodiment of the present invention obtains the abstract syntax tree of the target deep learning model and the set reversible conversion form; according to the reversible conversion form, generates target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern; generates conversion subtrees corresponding to each target injection code, and updates the abstract syntax tree of the target deep learning model according to each conversion subtree, and obtains a technical means for updating the abstract syntax tree corresponding to the reversible conversion form. A new technology for automatically realizing reversible conversion in a non-invasive manner is provided, without the need for human intervention, and completely avoids various errors caused by manual operations. The implementation method is simple and flexible, and can be effectively generalized and expanded to more machine learning models or application scenarios.
[0149] Embodiment 4
[0150] Figure 4 This is a schematic diagram of the structure of a non-invasive reversible conversion device for a deep learning model provided in the fourth embodiment of the present invention. Figure 4 As shown, the device includes: a reversible conversion form acquisition module 410, a target injection code generation module 420 and an updated abstract syntax tree generation module 430, wherein:
[0151] A reversible conversion form acquisition module 410 is used to obtain an abstract syntax tree of a target deep learning model and a set reversible conversion form;
[0152] The nodes in the abstract syntax tree correspond to operators in the target deep learning model, and the reversible transformation form includes: at least one transformation reversible structure in the target deep learning model, and a unique transformation reversible transformation pattern corresponding to each transformation reversible structure; the transformation reversible structure is a branchless structure containing at least one node;
[0153] A target injection code generation module 420 is used to generate target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern according to the reversible conversion form;
[0154] The updated abstract syntax tree generation module 430 is used to generate a conversion subtree corresponding to each target injection code, 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.
[0155] The technical solution of the embodiment of the present invention obtains the abstract syntax tree of the target deep learning model and the set reversible conversion form; according to the reversible conversion form, generates target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern; generates conversion subtrees corresponding to each target injection code, and updates the abstract syntax tree of the target deep learning model according to each conversion subtree, and obtains a technical means for updating the abstract syntax tree corresponding to the reversible conversion form. A new technology for automatically realizing reversible conversion in a non-invasive manner is provided, without the need for human intervention, and completely avoids various errors caused by manual operations. The implementation method is simple and flexible, and can be effectively generalized and expanded to more machine learning models or application scenarios.
[0156] Based on the above embodiments, the target injection code generation module 420 can be specifically used for:
[0157] Obtaining a current conversion reversible structure and a current conversion reversible conversion mode matching the current conversion reversible structure;
[0158] In a preset reversible conversion code template library, detecting whether there is a target reversible conversion code template for converting a current conversion reversible structure into a current conversion reversible conversion mode;
[0159] If it is determined to exist, a target injection code corresponding to the current conversion reversible structure is generated according to the target reversible conversion code template.
[0160] Based on the above embodiments, the target injection code generation module 420 can be further specifically used for:
[0161] 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, if it is determined that there is no target reversible conversion code template, then obtaining 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;
[0162] According to the target reversible transformation rule, the target injection code corresponding to the current transformation reversible structure is generated.
[0163] Based on the above embodiments, the abstract syntax tree generation module 430 can be updated to:
[0164] Call the pre-built code injector to generate a transformation subtree corresponding to each target injection code.
[0165] Based on the above embodiments, the abstract syntax tree generation module 430 can be further specifically used for:
[0166] Sequentially obtain the current conversion subtree and the conversion reversible structure to be replaced that matches the current conversion subtree, and obtain the original identification symbol corresponding to the conversion reversible structure to be replaced;
[0167] Add the current transformation subtree to the current abstract syntax tree of the target deep learning model, and set the replacement identifier corresponding to the current transformation subtree;
[0168] Replace all nodes that the reversible structure of the transformation to be replaced depends on to the parameter positions matched by the current transformation subtree;
[0169] In the current abstract syntax tree, each user node using the original identifier is identified, and after the original identifier used by each user node is modified to a replacement identifier, the reversible conversion structure to be replaced is deleted;
[0170] Return to execute the operation of obtaining the current conversion subtree in sequence until all conversion subtrees are processed to obtain an updated abstract syntax tree corresponding to the reversible conversion form.
[0171] On the basis of the above embodiments, a legality detection module may also be included, which is used to:
[0172] After obtaining the updated abstract syntax tree corresponding to the reversible conversion form, a compiler is used to perform a legality 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;
[0173] The reversible reconstruction model is loaded into a back-end system for trial operation to obtain a trial operation result matching the reversible conversion form.
[0174] Based on the above embodiments, the legitimacy detection module may be further used for:
[0175] After the compiler is used to perform a legality check on the updated abstract syntax tree, when it is determined 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.
[0176] The non-invasive reversible conversion device of the deep learning model provided in the embodiment of the present invention can execute the non-invasive reversible conversion 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.
[0177] Embodiment 5
[0178] Figure 5 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.
[0179] like Figure 5 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. An input / output (I / O) interface 15 is also connected to the bus 14.
[0180] 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.
[0181] 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 dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as executing a non-invasive reversible conversion method for a deep learning model as described in any embodiment of the present invention. That is:
[0182] Obtain an abstract syntax tree of a target deep learning model and a set reversible conversion form; wherein the nodes in the abstract syntax tree correspond to operators in the target deep learning model, and the reversible conversion form includes: at least one conversion reversible structure in the target deep learning model, and a unique conversion reversible conversion pattern corresponding to each conversion reversible structure; the conversion reversible structure is a branchless structure containing at least one node; according to the reversible conversion form, respectively generate target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern; generate conversion subtrees corresponding to each target injection code, 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.
[0183] In some embodiments, a non-invasive reversible conversion method of a 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 non-invasive reversible conversion method of a 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 a non-invasive reversible conversion method of a deep learning model as described in any embodiment of the present invention in any other appropriate manner (e.g., by means of firmware).
[0184] 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.
[0185] 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.
[0186] 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 combination 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.
[0187] 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).
[0188] 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.
[0189] 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.
[0190] 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.
[0191] 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 non-invasive reversible conversion method for a deep learning model, characterized in that: include: Obtain the abstract syntax tree of the target deep learning model and the set reversible transformation form; The nodes in the abstract syntax tree correspond to operators in the target deep learning model, and the reversible transformation form includes: at least one transformation reversible structure in the target deep learning model, and a unique transformation reversible transformation pattern corresponding to each transformation reversible structure; the transformation reversible structure is a branchless structure containing at least one node; According to the reversible conversion form, respectively generating target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern; Generate a conversion subtree corresponding to each target injection code, 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.
2. The method according to claim 1, characterized in that According to the reversible conversion form, target injection codes are generated for converting each conversion reversible structure into a matching conversion reversible conversion pattern, including: Obtaining a current conversion reversible structure and a current conversion reversible conversion mode matching the current conversion reversible structure; In a preset reversible conversion code template library, detecting whether there is a target reversible conversion code template for converting a current conversion reversible structure into a current conversion reversible conversion mode; If so, a target injection code corresponding to the current conversion reversible structure is generated according to the target reversible conversion code template.
3. The method according to claim 2, 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 the preset reversible conversion code template library, the method further includes: If not, then obtaining 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; According to the target reversible transformation rule, the target injection code corresponding to the current transformation reversible structure is generated.
4. The method according to any one of claims 1 to 3, characterized in that: Generates a transformation subtree corresponding to each target injection code, including: Call the pre-built code injector to generate a transformation subtree corresponding to each target injection code.
5. The method according to any one of claims 1 to 3, characterized in that: 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, including: Sequentially obtain the current conversion subtree and the conversion reversible structure to be replaced that matches the current conversion subtree, and obtain the original identification symbol corresponding to the conversion reversible structure to be replaced; Add the current transformation subtree to the current abstract syntax tree of the target deep learning model, and set the replacement identifier corresponding to the current transformation subtree; Replace all nodes that the reversible structure of the transformation to be replaced depends on to the parameter positions matched by the current transformation subtree; In the current abstract syntax tree, each user node using the original identifier is identified, and after the original identifier used by each user node is modified to a replacement identifier, the reversible conversion structure to be replaced is deleted; Return to execute the operation of obtaining the current conversion subtree in sequence until all conversion subtrees are processed to obtain an updated abstract syntax tree corresponding to the reversible conversion form.
6. The method according to claim 1, characterized in that After obtaining the updated abstract syntax tree corresponding to the reversible conversion form, it also includes: A compiler is used 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 to obtain a trial operation result matching the reversible conversion form.
7. The method according to claim 6, characterized in that After the compiler is used to check the legality of the updated abstract syntax tree, it also includes: When it is determined that the update of the abstract syntax tree fails the detection, a prompt message prohibiting the reversible conversion is generated for the conversion reversible structure in the reversible conversion form and the matching conversion reversible conversion pattern.
8. A non-invasive reversible conversion device for a deep learning model, characterized in that: include: A reversible transformation form acquisition module is used to obtain the abstract syntax tree of the target deep learning model and the set reversible transformation form; The nodes in the abstract syntax tree correspond to operators in the target deep learning model, and the reversible transformation form includes: at least one transformation reversible structure in the target deep learning model, and a unique transformation reversible transformation pattern corresponding to each transformation reversible structure; the transformation reversible structure is a branchless structure containing at least one node; A target injection code generation module, for generating target injection codes for converting each conversion reversible structure into a matching conversion reversible conversion pattern according to the reversible conversion form; The updated abstract syntax tree generation module is used to generate a conversion subtree corresponding to each target injection code, 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.
9. 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 non-invasive reversible conversion method of the deep learning model described in any one of claims 1-7.
10. 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 non-invasive reversible conversion method of a deep learning model as described in any one of claims 1 to 7 when executed.
Citation Information
Patent Citations
Transplantation method and source to source compiler
CN103631632A
Smart contract processing method and device, medium and electronic equipment
CN112104709A
Model code conversion method and device, equipment and storage medium
CN117251164A
Computer security based on artificial intelligence
US20170214701A1
Model reasoning acceleration method and apparatus, and electronic device and storage medium
WO2023197554A1
