A deep learning library defect detection method based on a weighted directed cyclic graph
By constructing a weighted directed cyclic graph topology and multidimensional oracle execution, the problems of blind mutation and false positives in deep learning library detection are solved, achieving efficient and accurate defect detection that covers the detection needs of the entire training and inference lifecycle.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING INST OF TECH
- Filing Date
- 2026-04-27
- Publication Date
- 2026-07-24
AI Technical Summary
Existing technologies for detecting defects in deep learning libraries suffer from problems such as blind mutation, low testing efficiency, and high false positives in test oracle mechanisms. They cannot effectively detect defects in deep learning libraries, especially those related to handling dynamic computational flows and core state management during training.
We employ a weighted directed cyclic graph (WDCG)-based approach to construct complex temporal control flow topologies. By introducing cyclic edges and weight mapping, we prioritize the topology and operator mutations. Combined with multidimensional oracle execution, we perform cross-framework graph instantiation and anomaly detection to achieve comprehensive detection of deep learning libraries.
It improves the efficiency and accuracy of defect detection in deep learning libraries, effectively triggers deep structural bugs, covers defects throughout the entire training lifecycle, reduces false positives and false negatives, and enhances the utilization of testing resources and the comprehensiveness of defect detection.
Smart Images

Figure CN122450828A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer system testing technology, specifically relating to a method for detecting defects in deep learning libraries based on weighted directed cyclic graphs. Background Technology
[0002] As one of the core technologies for ensuring system reliability in the field of software engineering, testing technology has formed a relatively complete testing technology system in the traditional software testing field. Among them, fuzz testing and metamorphic testing are two mature and widely used testing technologies that have played an important role in many fields such as operating systems and network protocols.
[0003] Deep learning systems are essentially a special type of software system that relies on deep learning libraries (such as PyTorch, TensorFlow, and MXNet) to build, train, and infer neural network models. They have been widely applied in key fields such as autonomous driving, medical image diagnosis, and facial recognition. However, the widespread use of deep learning systems is also accompanied by potential security risks and stability issues. Once defects occur, they may lead to serious safety incidents and economic losses. Therefore, using testing techniques to comprehensively test deep learning systems has become a key research focus in the current intersection of artificial intelligence and software engineering.
[0004] While traditional testing techniques are well-established in software testing, significant differences exist between deep learning systems and traditional software systems, making it difficult to directly transfer these techniques to deep learning scenarios. This is primarily due to two core aspects: First, deep learning systems rely on probabilistic and statistical characteristics to perform computational tasks, while traditional software systems are more deterministic in their computations. Second, deep learning systems are highly dependent on data; the quality of the training data directly determines the reliability of the output results. These characteristics collectively present significant challenges to the transfer and application of traditional testing techniques in deep learning scenarios.
[0005] In recent years, to expose the potential defects and security issues of deep learning systems, academia and industry have conducted extensive research on the application of testing techniques in the field of deep learning, resulting in two main research directions. One part of the research focuses on testing specific data, programs, framework interfaces, or framework models within deep learning systems to specifically uncover their defects and shortcomings. The other part of the research focuses on the properties of deep learning systems, such as security, robustness, fairness, and interpretability, testing the inherent defects of deep learning systems from a holistic perspective.
[0006] Currently, the main testing methods for deep learning libraries include:
[0007] (1) Interface-level testing method Empirical studies of deep learning libraries show that most reported errors reside in the algorithms and their interfaces. Therefore, interface-level testing is a crucial area of focus for researchers. Deep learning libraries expose well-encapsulated interfaces to users; if these interfaces contain defects, then the deep learning systems built using these interfaces will also be flawed. Interface-based methods only require a high-dimensional tensor as input and fixed framework interface parameters. They generate scripts by executing each interface and determine the defects in the generated scripts based on solutions to the proposed test oracle problem. However, this method can only test isolated operator behavior and cannot cover the execution paths of the computation graph formed by operator combinations.
[0008] (2) Model-level testing methods The model building, training, and inference processes are all based on deep learning frameworks, and the model is a crucial component of a deep learning framework. If the same model produces significantly different results on different frameworks, it indicates that some of the frameworks supporting the model have flaws. Model-based testing methods follow this approach, running the model on different deep learning frameworks and analyzing the results to determine if any deep learning frameworks have defects.
[0009] Among them, methods such as Muffin construct a directed acyclic graph model structure composed of multiple operator nodes, execute generative models in different deep learning frameworks, and compare the differences in execution results to detect potential defects.
[0010] Existing technologies for testing solutions based on Directed Acyclic Graphs (DAGs) suffer from two major flaws, which severely restrict the efficiency and accuracy of defect detection in deep learning libraries and fail to meet the actual needs of testing deep learning libraries throughout their entire lifecycle.
[0011] First, the problem of blind mutation is prominent. Existing DAG generation methods mostly employ a completely random combination strategy, simply splicing different types of operators in an unordered manner, lacking targeted attention to high-risk paths and key operator combinations in deep learning libraries. This random generation mode often produces a large number of redundant and worthless computational graphs, not only consuming significant hardware resources and testing time, leading to low testing efficiency, but also failing to trigger hidden deep structural bugs in deep learning libraries. This makes it impossible to effectively detect many potential operator combination interaction defects, significantly reducing the actual value of testing.
[0012] Secondly, the test oracle mechanism suffers from a high false positive rate and a significant lack of verification dimensions. Existing test oracles largely rely on cross-framework lateral difference comparisons, which are not only highly susceptible to interference from differences in the underlying operator implementations, resulting in a massive number of false positives, but also the single feedforward verification mode is insufficient to effectively induce and verify the compiler's underlying cross-graph operator fusion optimization. Furthermore, existing rules completely strip away the concept of "temporal state," lacking equivalence constraints on stateful control flow and backpropagation over time (BPTT), leaving the core state management deficiencies of deep learning libraries in handling dynamic computational flows long in a verification blind spot. Summary of the Invention
[0013] In view of this, the present invention proposes a deep learning library defect detection method based on a weighted directed cyclic graph (WDCG).
[0014] The technical solution for implementing the present invention is as follows: Firstly, this invention provides a method for detecting defects in a deep learning library based on a weighted directed cyclic graph, the specific process of which is as follows: WDCG topology generation: Construct a weighted directed cyclic graph (WDCG) topology to express complex temporal control flow and serialize it into a standardized configuration file; WDCG topology mutation: Priority-guided topology mutation and operator mutation for high-risk transmission paths in the WDCG topology physical graph; Cross-frame graph instantiation: Maps the generated WDCG topology to executable physical models under different deep learning libraries; Multidimensional oracle execution: Concurrently execute multidimensional test oracles on an executable physical model, capturing the output tensor and parameter gradients with given input data; Anomaly assessment and global feedback: Compare the output tensor with the parameter gradient. When defects are found, exclude reasonable underlying calculation errors and determine the real defects of the executable physical model. Perform structured analysis on the execution data collected during the test, identify high-risk transmission paths and feed them back to WDCG topology variations. Save the files required to reproduce the defects and provide feedback to the official team.
[0015] Optionally, the nodes of the WDCG topology described in this invention are provided with cyclic edges: used to represent data feedback "with a unit time step delay".
[0016] Optionally, the specific process for generating the WDCG topology structure according to the present invention is as follows: (1) Node set initialization: Assign a globally unique identifier to each node and determine its running parameters; (2) Spatial edge connectivity: Establish "spatial edges" between nodes, and all spatial edges follow the directed acyclic principle; if the tensor dimensions of adjacent nodes do not match, insert bridging nodes and their operators between adjacent nodes; (3) Cyclic edge injection: In the generated acyclic graph, randomly select node pairs In node pair Inject a cyclic edge between the data points to represent data feedback with a unit time step delay. (4) Edge weight and metadata allocation: Assign a floating-point weight to each edge. Construct a global metadata dictionary (Meta) to store global configuration information independent of specific nodes and edges; randomly generate a time step in the Meta to define the number of loop unrolling times the network will run. (5) Serialization output: Serialize the WDCG topology structure containing node attributes, edge topology relationships and time steps into JSON format.
[0017] Optionally, the present invention describes priority-guided topology mutations and operator mutations for high-risk transmission paths in the WDCG topology physical graph: Topology variation: While maintaining the mathematical validity of WDCG, high-risk nodes are dynamically adjusted based on node weight distribution for high-risk transmission paths; Operator attribute mutation: By intervening in the args parameter dictionary in the WDCG configuration file, we can explore the extreme boundaries of the internal hyperparameters of various deep learning operators in high-risk transmission paths.
[0018] Optionally, the topological variations described in this invention include: Adding, deleting, and modifying nodes and spatial edges: Based on the node weight distribution, a weighted sampling operation is performed on the set of high-risk nodes involved in historical anomalies in the WDCG topology, and spatial edges in the risk subgraph are selected. As the target of structural mutation, a "disconnect and reconnect" operation is performed to mutate it into... ,in For newly randomly instantiated nodes and their onboard operators; Dynamic resetting of cyclic edges: Based on tensor dimension alignment constraints in the graph topology, search for legal node pairs and perform the addition or deletion of cyclic edges.
[0019] Optionally, the operator attribute variation described in this invention includes: Convolution kernel and padding strategy variation: For spatial aggregation operators, the system randomly varies its convolution kernel size, stride and dilation rate, and randomly switches between effective modes and the same padding mode. Activation function equivalent replacement: Perform attribute-level preferential mutation on the nonlinear activation functions attached to operators that participate in anomalous gradient propagation in high-risk propagation paths.
[0020] Optionally, the topology variation of the WDCG in this invention also includes time step variation and edge weight variation: Time step mutation: Performs targeted increments or decrements on the time_steps parameter in the global metadata; Edge weight variation: Fine-tune the floating-point weights W assigned to the edges of WDCG.
[0021] Optionally, after implementing priority-guided topology mutations and operator mutations on high-risk transmission paths in the WDCG topology physical graph, this invention also performs a self-check for the legality of the mutations: If the mutation causes a dimension conflict, it will be resolved through automatic insertion. Forced physical patching is performed using convolutional or adaptive global pooling layers; if the patching is successful, the mutated new WDCG configuration file is transferred to the next step and enters the next test lifecycle; if the patching fails, the mutation is discarded and rolled back to the previous valid seed state.
[0022] Optionally, the specific process of multidimensional oracle execution in this invention is as follows: Input data pre-allocation: Two benchmark input test tensors with identical data shapes but independent numerical distributions are pre-constructed. and As a unified input for subsequent execution of test predictions across various dimensions; Differential test branch execution: Cross-modal differential: Within a single framework, for the physical model under test, it is first passed in Eager mode. Obtaining the basic gradient Then, the just-in-time compiler was started, and the data was passed in again. Obtaining compilation gradients ; Cross-device differential: For the physical model under test, the tensor is... The model weights are migrated to different physical hardware via .to("cpu") and .to("cuda") respectively, and the computational bias generated by the underlying computational math library is run and collected.
[0023] Optionally, the multidimensional oracle execution described in this invention further includes: spatial superposition metamorphic oracle execution and temporal unfolding metamorphic oracle execution; Spatial superposition metamorphic oracle execution: Utilizing the same JIT compilation model for the physical model under test, execute separately get ,implement get In memory, the two tensors are physically added together to form a superimposed input. Input the JIT model and calculate the combined gradient. ; Time Unfolds Metamorphosis Prophecy Execution: Copy each node of the original graph The space edges are copied within the same time step, and the cyclic edges are copied from... Converted to time step The time attribute is removed to obtain the deep feedforward unfolded graph; the deep feedforward unfolded graph is instantiated, and the memory addresses of the weights of the recurrent model are directly cloned to the corresponding values in the unfolded graph using the hierarchical mapping dictionary. Each layer is a separate layer; it executes two computation graphs that are mathematically equivalent in topology but have distinct physical code representations, and captures the full gradients generated by their backpropagation.
[0024] Optionally, when defects exist, the present invention performs structured analysis on the execution data collected during the current test, extracts the node IDs involved in the anomaly, and increases their weight in the distribution table. Specifically, for operator nodes that directly generate NaN, Inf, or numerical mutations, a high contribution value is assigned; for nodes located on the anomaly propagation path that are only responsible for transmitting the damaged tensor, a basic contribution value is assigned; before the end of each round of feedback, Softmax normalization is performed on the weight distribution table so that the sum of the mutation weights of all nodes in the entire graph is always 1, completing the update of the "node risk weight distribution table" and applying it to the next round of WDCG mutation stage, that is, returning to step two to start the next round of mutation operation.
[0025] Beneficial effects: First, WDCG topology modeling: protects a model description method that introduces weight dimension on the basis of DAG. By introducing cyclic edges and shift weight mapping, WDCG can represent complex temporal dependency logic with a very small graph size.
[0026] Second, weight-guided heuristic mutation: protects the strategy of dynamically adjusting operator weights based on execution feedback and selecting mutation targets according to weight distribution.
[0027] Third, the "spatiotemporal dual-dimensional" transformation test: Based on the transformation relationship of rigorous calculus theorems and graph topological physical expansion technology, a dual-dimensional test prediction scheme for deep learning library compilers is constructed by combining spatial superposition invariance and temporal expansion equivalence. Attached Figure Description
[0028] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the embodiments 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.
[0029] Figure 1 This is the overall flowchart of the method. Detailed Implementation
[0030] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0031] It should be noted that, unless otherwise specified, the following embodiments and features can be combined with each other; and, based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0032] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this disclosure, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.
[0033] like Figure 1 As shown in the figure, this application provides a method for detecting defects in a deep learning library based on a weighted directed cyclic graph. This method is mainly completed by a main control process and multiple test subprocesses working together. The specific process is as follows: Step 1, WDCG Topology Generation This step aims to automatically construct a mathematical topology capable of expressing complex temporal control flow and serialize it into a standardized configuration file. The specific implementation process is as follows: (1) Node set initialization: The system first establishes a usable neural network operator library, which includes, but is not limited to, fully connected layers (Dense / Linear), two-dimensional convolutional layers (Conv2D), global average pooling layers (GlobalAvgPool2D), and flattening layers. The system determines the depth of the generated computation graph using a pseudo-random number generator (e.g., setting the maximum number of nodes N=50) and assigns a globally unique identifier (ID) to each node so that the system can accurately identify and operate on specific nodes when building connections or modifying the computation graph later. At the same time, the system sets specific operating parameters for each node (e.g., specifying the node as a fully connected operator or a convolutional operator, and specifically setting its convolution kernel size, stride, and other values).
[0034] (2) Spatial Edge Connectivity: To ensure data reachability during forward propagation, the system employs a restricted random walk algorithm to establish "spatial edges" between nodes. The system enforces that all spatial edges must adhere to the directed acyclic principle, i.e., if an edge exists... Then the node The topological order must be less than the node For each node, the system performs forward tensor shape inference to calculate the shape of the input tensor for that node. If the tensor dimensions of adjacent nodes do not match (e.g., Conv2D outputs a 4D tensor while Dense receives a 2D tensor), the system automatically inserts Flatten or GlobalAvgPool2D as a bridging operator, i.e., a node, between the two nodes. In model-level testing, "node" and "operator" can be considered equivalent concepts. The topology of the computation graph is composed of nodes, and each node physically carries a specific operator.
[0035] (3) Cyclic edge injection: This is the core step to break the limitations of traditional DAG static feedforward. The system randomly selects pairs of nodes from the generated acyclic graph, ensuring that the output and input dimensions match. ,in It can be The successor node can even be The system injects an edge of type RECURRENT between these two nodes, which in physical semantics represents data feedback with a unit time step delay.
[0036] (4) Edge weight and metadata allocation: The system assigns a floating-point weight to each edge. Simultaneously, a global metadata (Meta) dictionary is constructed to store global configuration information independent of specific nodes and edges. A random integer parameter `time_steps` (time step size, e.g., ...) is generated within the Meta dictionary. ), which defines the number of loops to be unrolled during the runtime of the network.
[0037] (5) Serialization output: The system serializes the WDCG topology structure containing node attributes, edge topology relationships and time steps into a JSON format file (such as model_config.json), providing a consistent blueprint across frameworks for subsequent physical instantiation.
[0038] Topology: WDCG; Computational graph: A concretization of the topology, written in JSON; Physical graph: The actual model created in PyTorch / TensorFlow memory after reading the JSON.
[0039] In this embodiment, the WDCG weights are implemented as follows: The weight mechanism of WDCG is not limited to a single implementation form. In addition to the weight settings defined on the operator nodes in the core solution, the weights can also be defined on the "edges" of WDCG to simulate stress tests of different computing paths and achieve precise control over the dependencies of computing paths.
[0040] Step 2: Multidimensional Structure and Operator Mutation of WDCG Based on Heuristic Strategies This step maintains a node risk weight distribution table. During the initial execution of step two, the mutation weights of all nodes are set to an equal and uniform distribution. In subsequent test loops, the mutation weights of all nodes are based on the information fed back in step seven. While maintaining the mathematical validity of the WDCG topology, priority-guided structural and operator mutation operations are implemented on high-risk propagation paths in the computation graph. This transforms the model mutation strategy from random search to an adaptive, directional search process driven by execution behavior. The specific mutation implementation process is as follows: (1) Topological variation: The system dynamically adjusts the connections of its computation graph while maintaining the mathematical validity of WDCG.
[0041] Adding, deleting, and modifying nodes and spatial edges: Based on the node weight distribution, the system performs a weighted sampling operation on the set of high-risk nodes involved in historical anomalies in the WDCG topology, prioritizing the selection of spatial edges in the risk subgraph. As a target for structural mutation, the system can perform a "disconnect and reconnect" operation to mutate it into... ,in For newly randomly instantiated operators (such as additional Conv2D or ReLU). This operation can forcibly change the depth and width of the computation graph, interfering with the active variable analysis and register allocation thresholds of the XLA or Inductor compiler.
[0042] Dynamic resetting of cyclic edges: Based on the unique temporal state mechanism of this invention, the system searches for legal node pairs in the graph topology according to tensor dimension alignment constraints, and adds or deletes cyclic edges. For example, the original shallow state feedback... The mutation is a deep delayed feedback that spans multiple network layers. This mutation strategy is specifically designed to challenge the graph compiler's ability to manage the lifecycle of the global state cache (StateCache) when dealing with complex backpropagation over time.
[0043] (2) Operator attribute level mutation: The system directly intervenes in the args parameter dictionary in the WDCG configuration file to explore the limit boundary of the internal hyperparameters of various deep learning operators.
[0044] Convolution kernel and padding strategy mutation: For spatial aggregation operators such as Conv2D, the system randomly mutates its convolution kernel size (kernel_size, e.g., from the conventional...). Mutation into asymmetric The parameters include strides and dilation rate. It also randomly switches between valid and same-fill patterns.
[0045] Activation function equivalent replacement: Based on the updated node risk weight distribution table, the system performs attribute-level preferential mutation on the nonlinear activation functions attached to the operators participating in abnormal gradient propagation (such as mutating ReLU to Swish, Gelu, or sigmoid).
[0046] (3) Temporal and boundary value variations: Time step parameter variation: The system performs targeted numerical increments or decrements on the time_steps parameter in the global metadata to enhance its ability to perturb the calculation process of deep state feedback paths propagating backward over time.
[0047] Edge weight numerical variation: The system fine-tunes the floating-point weights W assigned to the edges of WDCG. This operation can change the numerical distribution of the data flow during forward propagation without altering the graph topology.
[0048] (4) Self-check for the legality of variations: Before any mutation operation is issued, the system must perform rigorous self-verification to prevent the framework from crashing before compilation due to dimension mismatch (i.e., generating a worthless early error, Reject). The system has a built-in lightweight shape inference engine. After each mutation is executed, the engine recalculates the input / output tensor dimensions of each node along the topological order.
[0049] If the mutation causes a dimensional conflict (e.g., two tensors with different numbers of channels are forcibly added), the system will automatically insert... Convolutional layers (for channel alignment) or adaptive global pooling layers (for spatial dimension alignment) are used to force physical patching.
[0050] If the patch is successful, the mutated new WDCG configuration file will be transferred to the next step and enter the next test lifecycle; if the patch fails, the mutation will be discarded and rolled back to the previous valid seed state.
[0051] Step 3, Cross-frame graph instantiation This step reads the valid computation graph file (generated by the mutation in step two) from the current test lifecycle and maps it in memory as an executable physical model under different deep learning libraries.
[0052] (1) Framework isolation environment construction: Since modern deep learning frameworks (such as Keras3) can only hard-bind one backend in a single Python process, the main process of the system spawns child processes through the subprocess module. By injecting environment variables (such as KERAS_BACKEND="tensorflow" or KERAS_BACKEND="torch") before the child process starts, physical isolation instantiation of the same WDCG structure in different underlying computing libraries is achieved.
[0053] (2) Network layer container mapping: In the PyTorch environment, the system parses the node list in the JSON and uses torch.nn.ModuleDict as the layer container. For the same padding mode of Conv2D, the system automatically derives the padding parameters based on the kernel size to ensure the alignment of the operator parameters. In the TensorFlow environment, the system inherits keras.Model, parses each node into a keras.layers module, disables the built-in activation function, and uses independent keras.activations to ensure the absolute consistency of the backpropagation chain derivative.
[0054] (3) Timing State Buffer Allocation: The system traverses the graph structure, initializing an independent memory block for each node that receives an input edge. At time step... At that time, use torch.zeros or ops.zeros to output the feature dimensions (e.g., ...) based on the node's theoretical output. Allocate a tensor buffer with all values set to 0. This buffer will be used to store the historical gradients and states resulting from the cyclic edges.
[0055] Step 4: Execution of Multidimensional Oracles This step is the core defect detection engine of the present invention. The system receives the cross-framework executable physical model that has been instantiated in step three, and uses them as the basic test objects to concurrently execute multi-dimensional test oracles. The system captures the output tensor and parameter gradients through the given input data.
[0056] (1) Input data pre-allocation: The system pre-constructs two benchmark input test tensors (denoted as ) with consistent data shapes but independent numerical distributions in the CPU or GPU memory, based on the dataset used or using the framework's built-in random function. and This serves as the unified input for subsequent execution of test predictions across various dimensions.
[0057] (2) Differential test branch execution Cross-modal differential: Within a single framework, the system first inputs the instantiated physical model to be tested in Eager mode (dynamic graph interpretation execution). Obtaining the basic gradient Then, the just-in-time compiler was started, and the input was passed in again. Obtaining compilation gradients .
[0058] Cross-device differential: The system performs tensor analysis on the instantiated physical model to be tested. The model weights are migrated to different physical hardware via .to("cpu") and .to("cuda") respectively, and the computational bias generated by the underlying computational math libraries (such as Eigen and cuDNN) is run and collected.
[0059] (3) Spatial superposition metamorphosis prediction execution To detect the cross-graph operator fusion vulnerability in the JIT compiler, the system uses the physical model instantiated in step three and the same JIT compilation model to execute... get ,implement get .
[0060] The system physically adds the two tensors in memory to form a superimposed input. Input the JIT model and calculate the combined gradient. The system uses this step to force the JIT compiler to perform alias analysis and register reallocation in an extremely large overlay graph.
[0061] (4) Time unfolds the metamorphosis prophecy execution To detect the defects in the backward propagation of state over time, the system executes a topology dimensionality reduction algorithm to expand the JSON with loops generated in step one. Specifically, this involves copying each node of the original graph. share( (For time steps), copy spatial edges within the same time step, and change cyclic edges from... Converted to time step And erase the time attribute.
[0062] The system instantiates this deep feedforward unfolded graph and uses a layer mapping dictionary (such as self.layers) to directly clone the memory addresses of the weights of the recurrent model to the corresponding values in the unfolded graph. A clone layer.
[0063] The system executes these two computational graphs (the original graph and the deep feedforward unfolded graph) which are mathematically topologically equivalent but physically distinct, and captures the full gradients generated by their backpropagation.
[0064] Step 5: Anomaly Analysis and Filtering This step receives the data collected in step four and performs automated comparison. By eliminating reasonable underlying computational errors, the system can accurately verify the real defects of deep learning frameworks. The specific process is as follows: (1) Determine the comparison object For differential testing: The system directly extracts the tensor results of the same model output in two different execution environments (such as interpreted execution and compiled execution, or CPU and GPU) as the comparison points.
[0065] For the metamorphosis test: The system extracts two sets of data calculated based on mathematical equivalence formulas. In the "spatial superposition metamorphosis", the comparison is between "the sum of gradients obtained by two independent differentiations" and "the comprehensive gradient obtained by one fused differentiation"; in the "time unfolding metamorphosis", the comparison is between "the gradient calculated by the original cycle graph" and "the result of the cumulative gradient of each time step after unfolding".
[0066] (2) Check the shape of the data After identifying the two sides to be compared, the system first compares the size and dimension (shape) of the tensors on both sides. If even the shapes are inconsistent, it indicates that the framework has experienced a complete logical collapse when performing graph structure fusion or temporal unrolling, and the system directly determines it as a structural anomaly.
[0067] (3) Calculate numerical error If the shapes match, the system begins comparing the specific values within each element. Because the underlying computer hardware naturally produces minute floating-point precision deviations during concurrent accumulation (especially when performing multi-branch merging or loop unrolling), the system calls the underlying matrix comparison interface, based on a set absolute error limit (ATOL, e.g.) ) and relative error limit (RTOL, e.g. Calculate the judgment matrix: If all elements in the matrix satisfy the above inequality, the system determines that the current test round has passed.
[0068] The system calculates the "maximum absolute deviation" (MaxAbsDiff) and "maximum relative error rate" (MaxRelDiff) for the entire matrix. If the maximum relative error rate is lower than a set empirical threshold (e.g., ...), the system will determine the maximum absolute deviation. The system will perform a silent filtering process. If the maximum absolute deviation exceeds ATOL and the relative error rate increases by an order of magnitude (e.g., exceeding...), the system will implement a silent filtering process. The system detected the defect.
[0069] Step 6: Save the files needed to reproduce the defect. In traditional testing, it's often difficult to reproduce errors after they occur. The purpose of this step is to immediately save all relevant data the moment a vulnerability is detected, making it easier for developers to reproduce and fix the issue later. The specific process is as follows: (1) Save current data immediately: Once step five confirms the discovery of a real vulnerability, the system will immediately pause and save the currently used computation graph structure file (JSON), the weight parameters inside the model, and the input test data that caused the error as local files.
[0070] (2) Data archiving and cleaning: The system will put the saved files into a dedicated defect folder and add a timestamp to the file names to prevent them from being overwritten by subsequent files. After completing the current round, regardless of whether any defects are found, the system must clean up unnecessary files in the current process to prevent the computation graph state from affecting the next round.
[0071] Step 7, WDCG Global Feedback Control Mechanism This step is used to construct a closed-loop control system based on historical test results. By dynamically updating the node risk weight distribution table, the mutation process of the WDCG model is transformed from a random search to an adaptive search process guided by execution feedback.
[0072] When a potential defect is detected in step 5, the system does not directly proceed to the next round of WDCG generation. Instead, it performs structured analysis on the execution data collected during this round of testing, extracts the node IDs involved in the anomaly, and increases their weights in the distribution table. Specifically, operator nodes that directly generate NaN, Inf, or numerical mutations are assigned high contribution values; nodes located on the anomaly propagation path and only responsible for transmitting damaged tensors are assigned basic contribution values. Before the end of each round of feedback, the system performs Softmax normalization on the weight distribution table, ensuring that the sum of the mutation weights of all nodes in the entire graph is always 1, thus updating the "Node Risk Weight Distribution Table" and applying it to the next round of WDCG mutation stage, i.e., returning to step 2 to start the next round of mutation operation.
[0073] Compared with the prior art, the present invention has the following advantages: First, the weighting mechanism based on WDCG topology modeling precisely solves the problems of blind mutation and low testing efficiency in existing technologies. As mentioned earlier, existing DAG generation is completely random and cannot focus on high-risk paths. This invention introduces a weight dimension into the traditional DAG, adding cyclic edges and shift weight mapping, which can assign higher weights to complex operators and high-risk computational paths. This allows test resources to be actively concentrated in such key areas, avoiding the waste of resources by redundant and worthless random test cases. This not only improves the triggering efficiency of model-level fuzz testing, but also accurately reaches deep structural bugs, significantly improving the bug detection rate. At the same time, it carries complex temporal dependencies with a very small graph size, further optimizing the utilization of test resources.
[0074] Second, the weight-guided heuristic mutation strategy overcomes the limitation of existing technologies that can only detect inference errors, achieving defect coverage throughout the entire training lifecycle. This invention dynamically adjusts operator weights through execution feedback and selects mutation targets based on weight distribution. It can specifically focus on the back-derivative logic of core operators in deep learning libraries. Through gradient comparison, it effectively tests this crucial step in the training process, compensating for the shortcomings of existing technologies that cannot cover defects in the training stage. This perfectly meets the technical requirement of "covering the entire training lifecycle," achieving comprehensive defect detection in both inference and training stages.
[0075] Third, the constraint checking mechanism in the "spatiotemporal dual-dimensional" test oracle scheme solves the problem of low execution pass rate of traditional random mutation-generated test cases. This invention incorporates constraint checking logic into the test oracle construction process to verify the rationality of generated model test cases, eliminating invalid test cases that do not conform to the deep learning library compiler's operating rules. Compared to the traditional random mutation method that simply blindly splices operators, this significantly improves the execution pass rate of generated test cases, reduces invalid execution during the testing process, and further improves testing efficiency. At the same time, the dual-dimensional oracle system also improves the accuracy of defect detection, avoiding false positives and false negatives.
[0076] This invention is not only applicable to PyTorch and TensorFlow, but can also be implemented by adding a general conversion interface, which can flexibly support defect detection of various domestic deep learning frameworks.
[0077] In summary, the above are merely preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A deep learning library defect detection method based on weighted directed cyclic graphs, characterized in that, The specific process is as follows: WDCG topology generation: Construct a weighted directed cyclic graph (WDCG) topology to express complex temporal control flow and serialize it into a standardized configuration file; WDCG topology mutation: Priority-guided topology mutation and operator mutation for high-risk transmission paths in the WDCG topology physical graph; Cross-frame graph instantiation: Maps the generated WDCG topology to executable physical models under different deep learning libraries; Multidimensional oracle execution: Concurrently execute multidimensional test oracles on an executable physical model, capturing the output tensor and parameter gradients with given input data; Anomaly detection and global feedback: The output tensor is compared with the parameter gradient. When defects are found, reasonable underlying calculation errors are excluded, and the real defects of the executable physical model are determined. The execution data collected during the test is subjected to structured analysis to identify high-risk transmission paths and feedback them to the WDCG topology variation. The files required to reproduce the defects are saved and fed back.
2. The method for detecting defects in a deep learning library based on a weighted directed cyclic graph as described in claim 1, characterized in that, The nodes in the WDCG topology are connected by cyclic edges, which are used to represent data feedback with a unit time step delay.
3. The method for detecting defects in a deep learning library based on a weighted directed cyclic graph as described in claim 2, characterized in that, The specific process for generating the WDCG topology is as follows: (1) Node set initialization: Assign a globally unique identifier to each node and determine its running parameters; (2) Spatial edge connectivity: Establish "spatial edges" between nodes, and all spatial edges follow the directed acyclic principle; if the tensor dimensions of adjacent nodes do not match, insert bridging nodes and their operators between adjacent nodes; (3) Cyclic edge injection: In the generated acyclic graph, randomly select node pairs In node pair Inject a cyclic edge between the data points to represent data feedback with a unit time step delay; (4) Edge weight and metadata allocation: Assign a floating-point weight to each edge. Construct a global metadata dictionary (Meta) to store global configuration information independent of specific nodes and edges; randomly generate a time step in the Meta to define the number of loop unrolling times the network will run. (5) Serialization output: Serialize the WDCG topology structure containing node attributes, edge topology relationships and time steps into JSON format.
4. The deep learning library defect detection method based on weighted directed cyclic graphs according to claim 3, characterized in that, The aforementioned topology mutations and operator mutations that prioritize high-risk transmission paths in the WDCG topology physical graph: Topology variation: While maintaining the mathematical validity of WDCG, for high-risk transmission paths, high-risk nodes are dynamically adjusted based on the node risk weight distribution; Operator attribute mutation: By intervening in the args parameter dictionary in the WDCG configuration file, we can explore the extreme boundaries of the internal hyperparameters of various deep learning operators in high-risk transmission paths.
5. The deep learning library defect detection method based on weighted directed cyclic graphs according to claim 4, characterized in that, The topology variations include: adding, deleting, and modifying nodes and spatial edges, and dynamically resetting cyclic edges; Adding, deleting, and modifying nodes and spatial edges: Based on the node risk weight distribution, a weighted sampling operation is performed on the set of high-risk nodes involved in historical anomalies in the WDCG topology, and spatial edges in the risk subgraph are selected. As the target of structural mutation, the "disconnect and reconnect" operation is performed to mutate it into... ,in For newly randomly instantiated nodes and their onboard operators; Dynamic resetting of cyclic edges: Based on tensor dimension alignment constraints in the graph topology, search for legal node pairs and perform the addition or deletion of cyclic edges; The operator attribute mutations include: convolution kernel and padding strategy mutations and equivalent replacements of activation functions; Convolution kernel and padding strategy variation: For spatial aggregation operators, the system randomly varies its convolution kernel size, stride and dilation rate, and randomly switches between effective modes and the same padding mode. Activation function equivalent replacement: Perform attribute-level preferential mutation on the nonlinear activation functions attached to operators that participate in anomalous gradient propagation in high-risk propagation paths.
6. The deep learning library defect detection method based on weighted directed cyclic graphs according to claim 4, characterized in that, WDCG topology variations also include time step variations and edge weight variations: Time step mutation: Performs targeted increments or decrements on the time_steps parameter in the global metadata; Edge weight variation: Fine-tune the floating-point weights W assigned to the edges of WDCG.
7. The deep learning library defect detection method based on weighted directed cyclic graphs according to claim 4, characterized in that, After implementing priority-guided topology mutations and operator mutations on high-risk transmission paths in the WDCG topology physical graph, a self-check for the legality of the mutations is also performed: If the mutation causes a dimension conflict, it will be resolved through automatic insertion. Forced physical patching is performed using convolutional or adaptive global pooling layers; if the patching is successful, the mutated new WDCG configuration file is transferred to the next step and enters the next test lifecycle; if the patching fails, the mutation is discarded and rolled back to the previous valid seed state.
8. The deep learning library defect detection method based on weighted directed cyclic graphs according to claim 4, characterized in that, The specific process of executing a multidimensional oracle is as follows: Input data pre-assignment: Two benchmark input test tensors with identical data shapes but independent numerical distributions are pre-constructed. and As a unified input for subsequent execution of test predictions across various dimensions; Differential test branch execution: Cross-modal differential: Within a single framework, for the physical model under test, it is first passed in Eager mode. Obtaining the basic gradient ; Then, the just-in-time compiler was started, and the data was passed in again. Obtaining compilation gradients ; Cross-device differential: For the physical model under test, the tensor is... The model weights are migrated to different physical hardware via .to("cpu") and .to("cuda") respectively, and the computational bias generated by the underlying computational math library is run and collected.
9. The deep learning library defect detection method based on weighted directed cyclic graphs according to claim 4, characterized in that, The multidimensional oracle execution also includes: spatial superposition metamorphic oracle execution and temporal unfolding metamorphic oracle execution; Spatial superposition metamorphic oracle execution: Utilizing the same JIT compilation model for the physical model under test, execute separately get ,implement get In memory, the two tensors are physically added together to form a superimposed input. Input the JIT model and calculate the combined gradient. ; Time Unfolds Metamorphosis Prophecy Execution: Copy each node of the original graph The space edges are copied within the same time step, and the cyclic edges are copied from... Converted to time step The time attribute is removed to obtain a deep feedforward unfolded graph; the deep feedforward unfolded graph is instantiated, and the weight memory address of the recurrent model is directly cloned to the corresponding clone layer in the unfolded graph using the hierarchical mapping dictionary; the two computation graphs that are mathematically equivalent but physically distinct are executed respectively, and the full gradients generated by their backpropagation are captured.
10. The deep learning library defect detection method based on weighted directed cyclic graphs according to claim 4, characterized in that, When defects are found, the execution data collected during this round of testing is subjected to structured analysis to extract the node IDs involved in the anomaly and increase their weight in the distribution table. Specifically, operator nodes that directly generate NaN, Inf, or numerical mutations are assigned high contribution values; nodes located on the anomaly propagation path and only responsible for transmitting damaged tensors are assigned basic contribution values. Before the end of each round of feedback, the weight distribution table is subjected to Softmax normalization to ensure that the sum of the mutation weights of all nodes in the entire graph is always 1, thus completing the update of the "Node Risk Weight Distribution Table" and applying it to the next round of WDCG mutation stage, i.e., returning to step two to start the next round of mutation operation.