A model-oriented generation and mutation method and system for deep learning compilers
By constructing an ONNX operator rule base and constraint analysis mechanism, and combining coverage feedback for targeted generation and mutation, the problems of blind model generation and low coverage in deep learning compiler testing are solved, achieving more efficient test coverage and defect discovery.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- EAST CHINA NORMAL UNIV
- Filing Date
- 2026-03-17
- Publication Date
- 2026-07-10
AI Technical Summary
In existing deep learning compiler testing methods, randomly generated models lack specificity and are difficult to trigger specific optimization paths. Furthermore, simple mutation methods do not incorporate the compiler's internal optimization rules, resulting in highly randomized test samples and limited coverage improvement.
By constructing an ONNX operator rule base, a computational graph DAG that satisfies the constraints is generated. A constraint analysis mechanism is introduced in the model generation and mutation stages, and targeted scheduling is carried out in combination with coverage feedback to ensure the legality and effectiveness of the model.
It improves the coverage efficiency and code coverage of deep learning compiler tests, enhances the ability to discover potential defects, and improves the effectiveness and coverage of tests.
Smart Images

Figure CN122364070A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of deep learning model optimization technology, and in particular to a method and system for targeted generation and mutation of models for deep learning compilers. Background Technology
[0002] Random generation and model mutation are common software testing techniques that automatically construct input data to trigger different execution paths in a program, thereby discovering potential defects. Random generation methods generate test samples by randomly combining structures and parameters in a search space, while model mutation methods generate new test samples by modifying the structure or parameters of existing valid samples. These methods are suitable for testing complex systems and can explore different execution paths within a large input space.
[0003] Deep learning compilers designed for complex optimization processes suffer from multiple optimization stages, complex path branches, and strong input dependencies. The structure of the test input model, the operator combination method, and the tensor shape parameters all influence the compiler's internal optimization path selection. Therefore, constructing diverse and effective input models is a key technique for improving the test coverage of deep learning compilers.
[0004] ONNX (Open Neural Network Exchange) is an open exchange format for neural network models that can represent deep learning model structures in the form of directed acyclic graphs. An ONNX model consists of operator nodes, tensor data, and their topological connections, and it imposes explicit constraints on the input / output types of operators, tensor shapes, and data types. Generating test models based on the ONNX format enables cross-framework and cross-platform model representation and transfer.
[0005] In existing technologies, deep learning compiler testing is typically based on randomly generating ONNX models or performing simple mutation operations on existing models. However, random generation methods often lack specificity, making it difficult for the generated models to trigger specific optimization paths; simple mutation methods are not guided by the compiler's internal optimization rules, resulting in highly randomized test samples. Furthermore, if the generated model does not meet operator constraints or tensor shape matching rules, it cannot pass the compiler front-end parsing stage, reducing testing efficiency.
[0006] Existing model generation and mutation methods typically employ traversal or random selection as the structure construction path, compromising model generation efficiency for structural diversity. Therefore, from the perspective of model generation paths and mutation strategies, existing deep learning compiler testing methods still have room for improvement in terms of test effectiveness and coverage efficiency. Summary of the Invention
[0007] To address the aforementioned problems, the purpose of this invention is to provide a method for targeted model generation and mutation in deep learning compilers, aiming to improve the issues of blind model generation and limited coverage improvement in existing deep learning compiler testing processes. This invention introduces a constraint analysis mechanism during the model generation stage and incorporates targeted scheduling based on coverage feedback during the model mutation stage, thereby improving test coverage efficiency while ensuring model validity.
[0008] The specific technical solution for achieving the objective of this invention is as follows:
[0009] A method for model-oriented generation and mutation in a deep learning compiler includes the following steps:
[0010] Step 1: Build the ONNX operator rule library and perform initialization configuration;
[0011] Step 2: Construct a computational graph DAG based on the operator rule base; specifically including:
[0012] The operators in the operator rule base are traversed and selected, and the computation graph topology is generated according to the directed acyclic graph structure constraints.
[0013] During the generation process, the input and output data types and tensor shape constraints of each newly added node are checked;
[0014] The generated node sequence is stored in a list in topological order, and the completed topological structure is the ONNX computation graph DAG that needs to be generated.
[0015] Step 3: Construct a constraint model based on the generated DAG; specifically including:
[0016] Extract operator type constraints, input / output shape constraints, and data type matching constraints for each node in the computation graph;
[0017] Traverse the list of topological nodes obtained in step 2, and perform constraint consistency checks on each node to establish a complete set of model structure constraints.
[0018] The constraint relationship established for each node is based on the operator input-output mapping rule.
[0019] Step 4: Perform targeted generation and model mutation based on the constraint model constructed in Step 3. Specifically, this includes:
[0020] First, instantiate and generate all initial models that meet the constraints. Then, solve the target structural path for each node that needs to be triggered in a directional manner using a constraint-driven strategy. Finally, perform structural mutation or parameter mutation operations on the model according to the obtained structural path.
[0021] In step 3 of this invention, constraint relationships are established for each node to ultimately obtain the complete constraint model, specifically including:
[0022] If the current node does not have an input node, then only the shape and type constraints of its output tensor are recorded;
[0023] If the current node has input nodes, then perform the following operations on all input nodes:
[0024] The first step is to extract the shape matching constraints between the current node and the first input node according to the operator rules;
[0025] The second step is to extract the type matching constraints between the current node and the next input node according to the operator rules;
[0026] Repeat step two until there is no next input node, and finally obtain the complete set of input and output constraints for the current node;
[0027] Once the constraint relationships of all nodes are established, the complete model structure constraint model can be obtained.
[0028] Step 4 of this invention, which involves solving the target structural path for each node requiring directional triggering using a constraint-driven strategy, specifically includes:
[0029] Initialize the parameters by setting the mutation count to a preset value (e.g., 50), the target coverage function set to the set of nodes to be triggered, and the maximum number of iterations to 1000. These preset parameters are primarily determined based on prior experimental experience and efficiency trade-offs. The mutation count controls the scale of candidate models generated in a single round of search. Too few mutation counts result in insufficient model structural diversity, making it difficult to effectively explore new structural paths; too many mutation counts significantly increase model compilation and execution overhead. Preliminary experiments show that a mutation count of approximately 50 maintains good testing efficiency while ensuring structural diversity; therefore, this is set as the default value.
[0030] The operator structure corresponding to the node to be triggered is regarded as the target structure to be generated, and the structural variation cost is estimated in combination with the current model topology position as the evaluation criterion for the generation path.
[0031] The candidate nodes in the model are replaced or expanded one by one, and the validity of the mutated model is determined based on the constraints of the model.
[0032] Calculate the coverage increment triggered by the model after each mutation, record the optimal structural path for this iteration, and update the mutation strategy based on the coverage feedback results.
[0033] Determine if the maximum number of iterations has been reached. If not, continue with the next round of mutation attempts; otherwise, terminate the calculation and record the optimal model structure path.
[0034] The method of using the estimated structural variation cost based on the current model topology location as an evaluation criterion for the generated path specifically includes:
[0035] Calculate the hierarchical position of the current node in the computation graph;
[0036] Calculate the topological distance between the current node and the target trigger node;
[0037] The priority of structural mutations is adjusted according to the order of the current node in the generation path;
[0038] If the current node is the first in the generated path, then the operator type replacement operation is performed first.
[0039] If the current node is the last one in the generated path, then parameter perturbation operation is performed first.
[0040] Step 4 of this invention, the directed generation and model mutation process, also includes the following steps:
[0041] Step 41: Traverse the list topo_node_list from front to back, and determine whether the currently traversed node belongs to the operator type related to the target trigger function;
[0042] Step 42: If the currently traversed node does not belong to the target trigger operator type, then keep the current structure unchanged;
[0043] Step 43: If the currently traversed node belongs to the target trigger operator type, then add the node to the candidate_list list;
[0044] Step 44: Traverse the candidate_list from front to back, and perform the following operations on the current traversed node:
[0045] Step 441: Initialize parameters. Set the maximum number of mutations to 1000, the target coverage function set to the set of functions to be triggered, the mutation priority factor alpha to 3, and the constraint matching factor beta to 5. The mutation priority factor α and the constraint matching factor β are used to control the trade-off between structure exploration and constraint satisfaction during the search process. α adjusts the influence of the mutation strategy on candidate structure selection; a larger α value indicates that the system is more inclined to prioritize mutation results with greater structural changes to enhance the search space exploration capability. β measures the degree of matching between the generated structure and the target constraint; a larger β value indicates a greater tendency to select candidate models that better meet the target structural constraints. These parameters were determined through preliminary experiments. In tests with multiple parameter combinations, a good balance was achieved between structure exploration capability and constraint satisfaction when α is 3 and β is 5; therefore, these are used as the default settings.
[0046] Step 442: For each mutation method of the currently traversed node, including operator replacement, parameter perturbation and structural expansion operations, calculate the degree of constraint satisfaction and the cost of structural mutation;
[0047] Step 443: Randomly select a mutation method to try, and judge whether the mutated model is valid according to the constraint model. If it is valid, record the mutation result; otherwise, revert to the original structure.
[0048] Step 444: After the model is executed by the compiler, count the number of covered functions and calculate the coverage increment;
[0049] Step 445: Update the priority of the current mutation strategy based on the coverage increment;
[0050] Step 446: Determine if the number of mutations has reached 1000. If not, clear the current mutation record and continue to execute steps 443 to 445. If it has reached 1000, save the model structure with the best coverage effect.
[0051] Step 447: Output the final ONNX model based on the optimal model structure saved in step 446.
[0052] The method described in this invention improves compiler code coverage and defect detection efficiency while ensuring the semantic correctness and structural legality of the model.
[0053] Based on the above, this invention also proposes a model-oriented generation and mutation system for a deep learning compiler, comprising:
[0054] The rule base construction module is used to build the ONNX model operator rule base and operator connection constraint set, and complete the initialization configuration.
[0055] The initial model generation module is used to construct a computation graph topology that satisfies the DAG structure constraints based on the operator rule library. During the topology generation process, the input and output data type constraints and tensor shape constraints are verified for each newly added node, and a valid initial ONNX model is instantiated and generated.
[0056] The constraint model construction module is used to perform static analysis on the compilation process of the target deep learning compiler, extract the path triggering conditions and operator constraint information of the compilation optimization stage, and establish a coverage-driven constraint model in combination with the DAG topology of the initial ONNX model.
[0057] The directional mutation module is used to perform structural mutation and / or parameter mutation on the initial ONNX model based on the coverage-driven constraint model, and generate candidate ONNX models for directional triggering of target optimization paths or uncovered functions;
[0058] The compilation and testing module is used to input the candidate ONNX model into the target deep learning compiler to execute the complete compilation process and collect code coverage information and exception information during the compilation process.
[0059] The feedback iteration module is used to dynamically adjust the model generation and mutation strategies based on the code coverage information and exception information, forming a closed-loop iterative test until the preset termination condition is met.
[0060] Based on the above, the present invention also proposes a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, it implements the steps of the model-oriented generation and mutation method for a deep learning compiler described in the present invention.
[0061] Based on the above, the present invention also proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the model-oriented generation and mutation method for a deep learning compiler described in the present invention.
[0062] This invention also proposes an application of the aforementioned method or system in automated defect mining of deep learning compilers and targeted verification of optimization modules of deep learning compilers.
[0063] The model-directed generation and mutation method for deep learning compilers disclosed in this invention has the following beneficial effects:
[0064] Compared to existing technologies, this invention provides a targeted generation and mutation method for ONNX models used in deep learning compiler testing, which improves upon existing random model generation and simple mutation methods. This invention explores the diversity of model structures based on operator rules and structural constraints when constructing the model generation space. This invention broadens the effective boundary of model mutation through a targeted constraint-driven mechanism, increasing the likelihood of specific optimization paths being triggered. This invention utilizes the optimal generation path for model instantiation and mutation, thereby improving the coverage efficiency of deep learning compiler testing. Attached Figure Description
[0065] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0066] Figure 1 This is an overall flowchart of an embodiment of the present invention;
[0067] Figure 2 This is a visualization structure of the deep learning model in an embodiment of the present invention;
[0068] Figure 3 This is a computational graph (DAG) topology diagram generated by an embodiment of the present invention;
[0069] Figure 4 This is a diagram illustrating the constraint model of an embodiment of the present invention;
[0070] Figure 5 This is a flowchart of the model mutation process according to an embodiment of the present invention. Figure 5 In the Z3 solver, constraint encoding employs Satisfiability Modulo Theories (SMT), a formalized approach that transforms model structural constraints and operator parameter constraints into unified logical constraint formulas. For example, it symbolically encodes shape compatibility relationships, data type consistency, and input-output dimensional relationships between operators, constructing complete constraint expressions using logical connectors. During the solution process, a constraint set is first constructed based on the current target operator and its upstream and downstream dependencies. These constraints are then input into the Z3 solver for satisfiability assessment. If the solution result is satisfiable (SAT), new structural parameters satisfying the constraints are generated based on the solved model. If it is unsatisfiable (UNSAT), the current structure is re-mutated, and the constraint set is reconstructed. This constraint-driven approach based on SMT ensures the legality of the model structure while guiding the mutation process to generate candidate models that meet the target path requirements. Detailed Implementation
[0071] The invention will be further described in detail below with reference to the specific embodiments and accompanying drawings. Except for the contents specifically mentioned below, the processes, conditions, and experimental methods for implementing the invention are all common knowledge and general knowledge in the art, and the invention does not have any particular limitations.
[0072] This invention discloses a method for targeted model generation and mutation in a deep learning compiler, comprising the following steps: constructing an ONNX model operator rule library and an operator connection constraint set; constructing a computational graph satisfying directed acyclic graph structure constraints based on a random topology generation strategy, and instantiating a valid ONNX model according to data type constraints and tensor shape constraints; performing static analysis on the compilation process of the deep learning compiler, extracting path triggering conditions and operator constraint information in the optimization stage, and establishing a coverage-driven constraint model; performing structural mutation and parameter mutation on the generated model based on the constraint model to achieve targeted triggering of specific optimization paths or uncovered functions; inputting the generated or mutated ONNX model into the compiler to execute the complete compilation process, collecting code coverage information and anomaly information; dynamically adjusting the generation and mutation strategy according to the coverage feedback results to form a closed-loop iterative testing mechanism. This invention can improve the compiler's code coverage and defect detection efficiency while ensuring the semantic correctness and structural validity of the model.
[0073] The proposed method for model-oriented generation and mutation in a deep learning compiler includes the following steps:
[0074] Step 1: Build the ONNX operator rule library and perform initialization configuration;
[0075] Step 2: Construct a computational graph DAG based on the operator rule base, specifically as follows:
[0076] The operators in the operator rule base are traversed and selected, and the computation graph topology is generated according to the directed acyclic graph structure constraints.
[0077] During the generation process, the input and output data types and tensor shape constraints of each newly added node are checked;
[0078] The generated node sequence is stored in a list in topological order, and the completed topological structure is the ONNX computation graph DAG that needs to be generated.
[0079] Step 3: Construct a constraint model based on the generated DAG, specifically:
[0080] Extract operator type constraints, input / output shape constraints, and data type matching constraints for each node in the computation graph;
[0081] Traverse the list of topological nodes obtained in step 2, and perform constraint consistency checks on each node to establish a complete set of model structure constraints.
[0082] Among them, the constraint relationship established for each node is based on the operator input-output mapping rule;
[0083] Step 4: Based on the constraint model constructed in Step 3, perform targeted generation and model mutation, specifically as follows:
[0084] First, instantiate and generate all initial models that meet the constraints. Then, solve the target structural path for each node that needs to be triggered in a directional manner using a constraint-driven strategy. Finally, perform structural mutation or parameter mutation operations on the model according to the obtained structural path.
[0085] Step 3 involves establishing constraint relationships for each node to ultimately obtain the complete constraint model, specifically as follows:
[0086] If the current node does not have an input node, then only the shape and type constraints of its output tensor are recorded;
[0087] If the current node has input nodes, then perform the following operations on all input nodes:
[0088] The first step is to extract the shape matching constraints between the current node and the first input node according to the operator rules;
[0089] The second step is to extract the type matching constraints between the current node and the next input node according to the operator rules;
[0090] Repeat step two until there is no next input node, and finally obtain the complete set of input and output constraints for the current node;
[0091] Once the constraint relationships of all nodes are established, the complete model structure constraint model can be obtained.
[0092] Step 4 involves solving the target structural path for each node requiring directional triggering using a constraint-driven strategy.
[0093] Initialize the parameters, set the number of mutations to a preset value (e.g., 50), set the target coverage function set to the set of nodes to be triggered, and set the maximum number of iterations to 1000;
[0094] The operator structure corresponding to the node to be triggered is regarded as the target structure to be generated, and the structural variation cost is estimated in combination with the current model topology position as the evaluation criterion for the generation path.
[0095] The candidate nodes in the model are replaced or expanded one by one, and the validity of the mutated model is determined based on the constraints of the model.
[0096] Calculate the coverage increment triggered by the model after each mutation, record the optimal structural path for this iteration, and update the mutation strategy based on the coverage feedback results.
[0097] Determine if the maximum number of iterations has been reached. If not, continue with the next round of mutation attempts; otherwise, terminate the calculation and record the optimal model structure path.
[0098] The method of using the estimated structural variation cost based on the current model topology location as an evaluation criterion for the generated path is as follows:
[0099] Calculate the hierarchical position of the current node in the computation graph;
[0100] Calculate the topological distance between the current node and the target trigger node;
[0101] The priority of structural mutations is adjusted according to the order of the current node in the generation path;
[0102] If the current node is the first in the generated path, then the operator type replacement operation is performed first.
[0103] If the current node is the last one in the generated path, then parameter perturbation operation is performed first.
[0104] Example
[0105] This embodiment provides a method for model-oriented generation and mutation in a deep learning compiler. The overall process is as follows: Figure 1 As shown, the specific steps are as follows:
[0106] (1) Construct the initial ONNX model and perform preprocessing. First, select the operator type according to the preset operator rule library and generate the corresponding input tensor. Then, match and adjust the shape of the tensor according to the operator input and output requirements to construct a legal computation graph structure. Finally, serialize the computation graph into an ONNX model file and input it into the deep learning compiler for parsing.
[0107] The ONNX model structure generated by the embodiments of the present invention is as follows: Figure 2 As shown, the generated computational graph DAG structure is as follows: Figure 3 As shown.
[0108] (2) Construct a computational graph DAG. Perform topological analysis on the ONNX model imported in (1), that is, treat the output nodes of the ONNX model as root nodes and construct a directed acyclic graph according to the connection relationship between the nodes. This includes the following steps:
[0109] (21) Determine the node type of the currently traversed node. The ONNX model includes different types of nodes, such as Conv nodes, Relu nodes, Add nodes, etc.
[0110] (22) Read the input and output tensor information of the node according to the node type of the currently traversed node, extract the data type and shape attributes, and construct the corresponding DAG node;
[0111] (23) Repeat (21) and (22) using the topological sorting method, and finally record the topological sorting sequence in the list topo_node_list. The generated topological structure is the DAG that needs to be constructed.
[0112] In this embodiment of the invention, the nodes stored in topo_node_list are in the order of conv_0, relu_1, conv_2, add_3, conv_4, add_5.
[0113] (3) Construct a constraint model. Based on the node order in the list topo_node_list obtained in (2), traverse from front to back, and solve the input-output constraint relationship of each node by combining operator rules and tensor matching rules, thereby constructing a complete constraint model, including the following steps:
[0114] (31) Based on the DAG, determine the number of input nodes of the current traversed node;
[0115] (32) If the current traversed node has only one input node, then establish shape matching constraints between the current node and the input node according to the operator rules;
[0116] (33) If the current traversed node has multiple input nodes, then calculate the data type constraints and shape consistency constraints between the current node and each input node according to the operator rules, and finally merge the multiple input constraints;
[0117] In this embodiment of the invention, the output shape of conv_0 is (1,32,28,28), relu_1 inherits the output shape of conv_0, the output shape of conv_2 is (1,32,28,28), the two input nodes of add_3, relu_1 and conv_2, satisfy the shape consistency constraint, and the two input nodes of add_5, add_3 and conv_4, satisfy the shape consistency constraint. Therefore, the final generated complete constrained model is as follows: Figure 4 As shown.
[0118] (4) Based on the constraint model generated in (3), perform model-oriented generation and mutation, including the following steps:
[0119] (41) Traverse the list topo_node_list from front to back and determine whether the currently traversed node belongs to the operator type related to the target trigger function;
[0120] (42) If the currently traversed node does not belong to the target trigger operator type, then keep the current structure unchanged;
[0121] (43) If the currently traversed node belongs to the target trigger operator type, then add the node to the candidate_list list;
[0122] (44) Traverse the candidate_list list from front to back, and perform the following operations on the current traversed node:
[0123] (441) Initialize the parameters, set the maximum number of mutations to 1000, set the target coverage function set to the set of functions to be triggered, set the mutation priority factor alpha to 3, and set the constraint matching factor beta to 5;
[0124] (442) For each mutation method of the currently traversed node, including operator replacement, parameter perturbation and structural expansion operations, calculate the degree of constraint satisfaction and the cost of structural mutation;
[0125] (443) Randomly select a mutation method to try, and judge whether the mutated model is legal according to the constraint model. If it is legal, record the mutation result; otherwise, revert to the original structure.
[0126] (444) After the model is executed by the compiler, count the number of covered functions and calculate the coverage increment;
[0127] (445) Update the priority of the current mutation strategy based on the coverage increment;
[0128] (446) Determine if the number of mutations has reached 1000. If not, clear the current mutation record and continue to execute steps (443) to (445). If it has reached 1000, save the model structure with the best coverage effect.
[0129] (447) Output the final ONNX model based on the best model structure saved in (446).
[0130] In this embodiment of the invention, the original structures of conv_0 and relu_1 are kept unchanged. Since add_3 belongs to the target triggering operator type, parameter perturbation and structure expansion operations are performed on add_3, and a new structure mutate_0 is generated based on the mutation results. According to the coverage statistics, mutate_0 successfully triggers a new optimization function path. Subsequently, a mutation operation is performed on add_5, and according to the constraint judgment, it maintains the shape consistency constraint with conv_4, finally generating a new model mutate_1, which successfully triggers an additional optimization path.
[0131] This embodiment builds a test model based on ONNX opset 13 and verifies it in the TVM 0.21 compiler environment. The test environment is an Ubuntu operating system, using LLVM as the backend compiler, and the gcov tool is used to count the compiler code coverage. During the experiment, the generated ONNX model is compiled and executed sequentially, and the triggered optimization function paths and coverage changes are recorded.
[0132] Experimental results show that, while keeping the structures of conv_0 and relu_1 unchanged, the models mutate_0 and mutate_1 generated by perturbing parameters and expanding the structure of add_3 and add_5 can both trigger new compiler optimization paths. Compared with the base model without targeted mutation, the test model generated in this embodiment shows a significant improvement in code coverage in the relevant optimization modules, and several potential defects were discovered during testing, thus verifying the effectiveness of the proposed method in improving compiler test coverage and defect detection capabilities.
[0133] Unless otherwise defined, all technical and scientific terms used in this invention have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
[0134] As used in this invention, the term "comprising" is an open-ended expression, meaning it includes the contents specified in this invention but does not exclude other aspects.
[0135] As used in this invention, the term "and / or" includes any one or more of the related listed items and all combinations thereof.
[0136] The scope of protection of this invention is not limited to the above embodiments. Any variations and advantages that can be conceived by those skilled in the art without departing from the spirit and scope of the inventive concept are included in this invention and are protected by the appended claims.
Claims
1. A method for model-oriented generation and mutation in a deep learning compiler, characterized in that, Includes the following steps: Step 1: Build the ONNX operator rule library and perform initialization configuration; Step 2: Construct a computational graph DAG based on the operator rule base; Step 3: Construct a constraint model based on the generated DAG; Step 4: Perform targeted generation and model mutation based on the constraint model constructed in Step 3.
2. The model-oriented generation and mutation method for a deep learning compiler according to claim 1, characterized in that, Step 2 includes: The operators in the operator rule base are traversed and selected, and the computation graph topology is generated according to the directed acyclic graph structure constraints. During the generation process, the input and output data types and tensor shape constraints of each newly added node are checked; The generated node sequence is stored in a list in topological order, and the completed topological structure is the ONNX computation graph DAG that needs to be generated.
3. The model-oriented generation and mutation method for a deep learning compiler according to claim 1, characterized in that, Step 3 includes: Extract operator type constraints, input / output shape constraints, and data type matching constraints for each node in the computation graph; Traverse the list of topological nodes obtained in step 2, and perform constraint consistency checks on each node to establish a complete set of model structure constraints. The constraint relationship established for each node is based on the operator input-output mapping rule.
4. The model-oriented generation and mutation method for a deep learning compiler according to claim 3, characterized in that, Constraint relationships are established for each node to ultimately obtain the complete constraint model, specifically: If the current node does not have an input node, then only the shape and type constraints of its output tensor are recorded; If the current node has input nodes, then perform the following operations on all input nodes: The first step is to extract the shape matching constraints between the current node and the first input node according to the operator rules; The second step is to extract the type matching constraints between the current node and the next input node according to the operator rules; Repeat step two until there is no next input node, and finally obtain the complete set of input and output constraints for the current node; Once the constraint relationships of all nodes are established, the complete model structure constraint model can be obtained.
5. The model-oriented generation and mutation method for a deep learning compiler according to claim 1, characterized in that, Step 4 includes: First, instantiate and generate all initial models that meet the constraints. Then, solve the target structural path for each node that needs to be triggered in a directional manner using a constraint-driven strategy. Finally, perform structural mutation or parameter mutation operations on the model according to the obtained structural path.
6. The model-oriented generation and mutation method for a deep learning compiler according to claim 5, characterized in that, In step 4, the step of solving the target structural path for each node requiring directional triggering using a constraint-driven strategy is as follows: Initialize the parameters, setting the number of mutations to a preset value, the target coverage function set to the set of nodes to be triggered, and the maximum number of iterations to 1000; the preset values are determined based on previous experimental experience and the principle of efficiency trade-off; among them, the number of mutations is used to control the scale of candidate models generated in a single round of search; The operator structure corresponding to the node to be triggered is regarded as the target structure to be generated, and the structural variation cost is estimated in combination with the current model topology position as the evaluation criterion for the generation path. The candidate nodes in the model are replaced or expanded one by one, and the validity of the mutated model is determined based on the constraints of the model. Calculate the coverage increment triggered by the model after each mutation, record the optimal structural path for this iteration, and update the mutation strategy based on the coverage feedback results. Determine if the maximum number of iterations has been reached. If not, continue with the next round of mutation attempts; otherwise, terminate the calculation and record the optimal model structure path.
7. The model-oriented generation and mutation method for a deep learning compiler according to claim 6, characterized in that, The method of using the estimated structural variation cost based on the current model topology location as an evaluation criterion for the generated path is as follows: Calculate the hierarchical position of the current node in the computation graph; Calculate the topological distance between the current node and the target trigger node; The priority of structural mutations is adjusted according to the order of the current node in the generation path; If the current node is the first in the generated path, then the operator type replacement operation is performed first. If the current node is the last one in the generated path, then parameter perturbation operation is performed first.
8. The model-oriented generation and mutation method for a deep learning compiler according to claim 1, characterized in that, Step 4, the directed generation and model mutation process, includes the following steps: Step 41: Traverse the list topo_node_list from front to back, and determine whether the currently traversed node belongs to the operator type related to the target trigger function; Step 42: If the currently traversed node does not belong to the target trigger operator type, then keep the current structure unchanged; Step 43: If the currently traversed node belongs to the target trigger operator type, then add the node to the candidate_list list; Step 44: Traverse the candidate_list from front to back, and perform the following operations on the current traversed node: Step 441: Initialize parameters, setting the maximum number of mutations to 1000, the target coverage function set to the set of functions to be triggered, the mutation priority factor alpha to 3, and the constraint matching factor beta to 5. The mutation priority factor α and the constraint matching factor β are used to control the trade-off between structure exploration and constraint satisfaction during the search process. α adjusts the influence of the mutation strategy on candidate structure selection; the larger the α value, the more the system tends to prioritize mutation results with larger structural changes to enhance the search space exploration capability. β measures the degree of matching between the generated structure and the target constraint; the larger the β value, the more it tends to select candidate models that better meet the target structural constraints. These parameters were determined through pre-experimental experience. In tests with multiple parameter combinations, a good balance between structure exploration capability and constraint satisfaction was achieved when α is 3 and β is 5; therefore, these are used as the default settings. Step 442: For each mutation method of the currently traversed node, including operator replacement, parameter perturbation and structural expansion operations, calculate the degree of constraint satisfaction and the cost of structural mutation; Step 443: Randomly select a mutation method to try, and judge whether the mutated model is valid according to the constraint model. If it is valid, record the mutation result; otherwise, revert to the original structure. Step 444: After the model is executed by the compiler, count the number of covered functions and calculate the coverage increment; Step 445: Update the priority of the current mutation strategy based on the coverage increment; Step 446: Determine if the number of mutations has reached 1000. If not, clear the current mutation record and continue to execute steps 443 to 445. If it has reached 1000, save the model structure with the best coverage effect. Step 447: Output the final ONNX model based on the optimal model structure saved in step 446.
9. A model-directed generation and mutation system for a deep learning compiler, characterized in that, The system comprising the method described in any one of claims 1-8, wherein the method is: The rule base construction module is used to build the ONNX model operator rule base and operator connection constraint set, and complete the initialization configuration. The initial model generation module is used to construct a computation graph topology that satisfies the DAG structure constraints based on the operator rule library. During the topology generation process, the input and output data type constraints and tensor shape constraints are verified for each newly added node, and a valid initial ONNX model is instantiated and generated. The constraint model construction module is used to perform static analysis on the compilation process of the target deep learning compiler, extract the path triggering conditions and operator constraint information of the compilation optimization stage, and establish a coverage-driven constraint model in combination with the DAG topology of the initial ONNX model. The directional mutation module is used to perform structural mutation and / or parameter mutation on the initial ONNX model based on the coverage-driven constraint model, and generate candidate ONNX models for directional triggering of target optimization paths or uncovered functions; The compilation and testing module is used to input the candidate ONNX model into the target deep learning compiler to execute the complete compilation process and collect code coverage information and exception information during the compilation process. The feedback iteration module is used to dynamically adjust the model generation and mutation strategies based on the code coverage information and exception information, forming a closed-loop iterative test until the preset termination condition is met.
10. The application of a method as described in any one of claims 1-8, or a system as described in claim 9, in automated defect discovery of deep learning compilers and targeted verification of optimization modules of deep learning compilers.