Defect detection method and device for deep learning library based on fuzzy test, and medium
By generating a deep learning model with high diversity based on the directed acyclic graph and the multi-armed bandit algorithm, and combining the detection methods in the forward, loss, and reverse calculation stages, the problem of insufficient defect detection capabilities of the deep learning library in the existing technology is solved. , achieving comprehensive exploration and efficient detection of library code.
Patent Information
- Application Number
- CN202410529849.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-29
- Publication Date
- 2024-08-27
AI Technical Summary
Existing deep learning library defect detection methods are insufficient in detecting defects under different model structures, and are mainly concentrated in the model prediction stage, ignoring the model training stage, and have limited exploration capabilities, which can easily lead to missed defects.
The model structure is generated based on the directed acyclic graph, and the multi-armed bandit and Thompson sampling algorithms are used to generate a model with high diversity, which is divided into forward calculation, loss calculation and reverse calculation stages. The mutation strategy is used to detect library defects and increase the number of pairs of libraries. Code exploration capabilities.
It improves the defect detection capability of the deep learning library and can detect defects in the model training and prediction stages. The generated model has rich structure and high diversity of parameters and weights, reducing the possibility of missing defects.
Smart Images

Figure CN118550817A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning, and in particular to a deep learning library defect detection method, device and medium based on fuzzy testing. Background Art
[0002] Existing research on defect detection of deep learning libraries based on fuzz testing can be divided into two categories: interface level and model level. Interface level methods use library interfaces as the test subject. Such methods usually obtain interface seed samples through crawlers or constraint extraction, and then generate more test cases through search or optimization algorithms, and use test prediction schemes to determine whether there are abnormalities in the output of the interface on the test cases. Model level methods use models as test cases and generate more models by mutating seed models. These models are implemented in multiple deep learning libraries, and the output results of the same model in multiple libraries are compared to determine whether there are inconsistencies, so as to determine whether there are defects in the deep learning library.
[0003] Take Comet and Muffin as examples. Comet proposes three coverage indicators and multiple layer parameter mutation strategies. It generates new models by changing existing popular models, and proposes a heuristic strategy to guide the model generation in the direction of amplifying errors, and detects library defects in the model prediction stage. Muffin generates model structures based on directed acyclic graphs, and designs a layer selection method to generate models by selecting previously rarely used layers, and records the errors of each model in the training stage to detect deep learning library defects. Both Comet and Muffin methods have achieved good results, but they have the following disadvantages: The Comet method uses a layer mutation strategy to mutate existing models to generate new models. Since the mutation strategy can only add, delete, and modify existing models, the newly generated model structure is similar to the existing model structure. The model structure is too single and it is difficult to detect library defects under different structures. The Comet method can only detect defects in the model prediction stage, but does not consider the model training stage. Muffin considers the diversity of model structures, but ignores the diversity of model parameters, input shapes, etc., and has limited exploration capabilities for library codes. In addition, although Muffin can detect defects during model training, its detection method is not perfect, which will lead to defect omissions.
[0004] Most existing deep learning library testing methods detect defects by comparing whether the prediction results of the same model in different libraries are consistent. This method relies on the prediction stage of the model, only involves part of the library code, and cannot fully execute the library code. Summary of the invention
[0005] In view of this, the present invention provides a deep learning library defect detection method, device and medium based on fuzzy testing, which can increase the ability to explore deep learning library codes and improve the ability of library defect detection.
[0006] To achieve the above purpose, the technical solution of the present invention is as follows:
[0007] A deep learning library defect detection method based on fuzz testing, comprising:
[0008] Generate model structure based on directed acyclic graph;
[0009] Determine the candidate layer pool of the model; the layer that is about to select the model layer type is called the candidate layer, the layer that can be used as a potential option for the candidate layer is called the candidate layer, and the option pool composed of the candidate layers is called the candidate layer pool;
[0010] The model layer selection is formulated as a multi-armed bandit problem. A candidate layer is selected to be added to the generated model fragments. Then, the diversity of the generated model fragments is calculated. The candidate layers are sorted according to the model diversity. Model generation is achieved based on the multi-armed bandit and Thompson sampling algorithms.
[0011] Compare model calculation results based on multiple libraries, and detect library defects based on differential calculations in deep learning libraries, as follows:
[0012] The training process of the model includes: the forward calculation stage, in which the input data is propagated through the calculation graph, and the calculation is performed from the input layer through each layer to obtain the output of the model; the loss calculation stage, in which the output of the model is compared with the expected output, and the value of the loss function is calculated at the same time; the reverse calculation stage, by using the chain rule, the gradient of the loss function with respect to the model parameters is passed back to each layer of the model, and the model weights are updated; indicators are designed to determine whether there is inconsistency between the calculation results of the same model in different libraries.
[0013] Wherein, a mutation strategy is defined to mutate the generated model; the mutation strategy includes a parameter value mutation strategy and a weight mutation strategy; the parameter value mutation strategy includes value mutation, boundary value mutation and input type mutation; the weight mutation strategy includes noise fuzzification, weight scaling and weight rotation;
[0014] Define an evaluation method for model diversity, using edge space, layer space, and input shape space to measure model diversity.
[0015] In the forward calculation stage, the comparison layer l and the next layer l s The difference in output results, if layer l or the next layer l s When the output results of running in two libraries differ greatly, it is considered to be inconsistent;
[0016] During the loss calculation phase, if layer l or the next layer l s When the loss values and loss gradient calculation results of the two libraries are significantly different, it is considered that there is an inconsistency; or when the calculation results of layer l in the two libraries are consistent, but the loss or loss function output is significantly different, it is considered that there is an inconsistency;
[0017] In the reverse calculation phase, compare layer l with the next layer l s The difference in gradient calculation results, if layer l or the next layer l s When the gradient calculation results in the two libraries differ significantly, an inconsistency is considered to exist.
[0018] Among them, a suitable model layer is selected for the candidate layer to construct a candidate layer pool. Each candidate layer in the candidate layer pool must satisfy the output constraints of the previous layer, including:
[0019] Constraint on the number of layer inputs: Model layers are divided into single-input and multi-input layers according to the number of layer inputs required; when the number of in-degrees of a node in a directed acyclic graph exceeds 1, it is considered that the candidate layer of the node must be a multi-input layer, otherwise it is a single-input layer; model layers are divided into single-input and multi-input layers, and suitable layers are selected to construct a candidate layer pool;
[0020] Layer input dimension constraint: A hash function is constructed, the key of which is all model layer categories, and the value is the input dimension corresponding to the layer. According to the hash function, the candidate layer with the specified input dimension can be selected;
[0021] Layer input shape constraint: If the candidate layer is a multi-input layer and its multiple input shapes do not conform to the input shape constraint of the candidate layer interface, use the reshape layer unique to the deep learning library to transform all inputs into a consistent shape.
[0022] Among them, in the model structure generated based on the directed acyclic graph, a random value is first generated. If the random value is less than 0.5, a chain structure model is generated, otherwise a unit structure model is generated; if a chain structure model is generated, nodes and edges are randomly generated and stacked into a chain structure model; if a unit structure model is generated, each unit in the unit structure is traversed, the number of unit nodes is randomly generated, and the unit nodes and the edges between the unit nodes are randomly generated; the directed acyclic graph composed of these nodes and edges is used as the structural information of the model.
[0023] The present invention also provides an electronic device, comprising a processor and a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the deep learning library defect detection method based on fuzzy testing described in the present invention.
[0024] The present invention also provides a computer-readable storage medium, which stores a computer program, and the computer program is used to execute the deep learning library defect detection method based on fuzzy testing described in the present invention.
[0025] Beneficial effects:
[0026] 1. The method of the present invention generates a highly diverse model, specifically a model with rich structure, rich parameter values, and rich weight values as much as possible, thereby increasing the ability to explore the deep learning library code; detects deep learning library defects in the model training and prediction stages, and improves the ability to detect library defects.
[0027] 2. The model generation method based on the multi-armed bandit and Thompson sampling algorithms of the present invention is used to generate models with rich structures, rich parameter values and rich weight values. The present invention is based on the deep learning model generation of directed acyclic graphs and multi-armed bandit algorithms, wherein the deep learning model structure is generated based on the directed acyclic graph, and at the same time, the multi-armed bandit and Thompson sampling algorithms are used to select a suitable model layer from the candidate layer pool to generate the model, so that the library defect detection process can be carried out without relying on the existing popular model, and the edge space, layer space and input shape space of the generated model have strong diversity, which can not only increase the coverage of the defect detection method for the deep learning library, but also improve the defect detection capability of the deep learning library.
[0028] 3. The present invention divides the model training process into three stages: forward calculation, loss calculation and reverse calculation, and proposes a deep learning library defect detection method based on multi-library collaboration and gradient according to the calculation characteristics of each stage. It can not only detect defects in the deep learning library during the model training and prediction stages, but also play a role in the scenario where only one deep learning library is tested.
[0029] 4. The method of the present invention has a finer granularity and is less likely to miss defects.
[0030] 5. The device of the present invention is based on the method of the present invention, and increases the ability to explore deep learning library codes by generating models with high diversity, specifically generating models with rich structures, rich parameter values, and rich weight values as much as possible; detects deep learning library defects in the model training and prediction stages, and improves the ability to detect library defects. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 It is a schematic diagram of the process of the present invention.
[0032] Figure 2 Schematic diagram of the chain structure in the Muffin method.
[0033] Figure 3 Schematic diagram of the unit structure in the Muffin method.
[0034] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0035] The present invention is described in detail below with reference to the accompanying drawings and embodiments.
[0036] The present invention provides a deep learning library defect detection method based on fuzzy testing, such as Figure 1 As shown, the following steps are included:
[0037] Step 1: Generate a model structure based on a directed acyclic graph, as follows:
[0038] The deep learning model receives input data and obtains output results through layer-by-layer calculation. This process can be abstracted into a directed acyclic graph, where each node represents a transformation in the model, such as convolution and pooling transformation, and the edges represent the dependencies between model layers. The Muffin method summarizes two common model structures: chain structure and unit structure, such as Figure 2 and Figure 3 The following are schematic diagrams of these two structures. Based on these two model structures, a directed acyclic graph can be generated as the basic structure of the model.
[0039] Specifically, first generate a random value. If the random value is less than 0.5, a chain structure model is generated, otherwise a unit structure model is generated. If a chain structure model is generated, nodes and edges are randomly generated and stacked into a chain structure model. If a unit structure model is generated, each unit in the unit structure is traversed, the number of unit nodes is randomly generated, and unit nodes and edges between unit nodes are randomly generated. The directed acyclic graph composed of these nodes and edges is used as the structural information of the model.
[0040] Step 2: Define the evaluation method of model diversity, as follows:
[0041] The generation space of models is infinite, and it is impossible to generate all models to carry out testing. We can only generate models with high diversity as much as possible to trigger more deep learning library codes. The present invention proposes to use edge space, layer space and input shape space to measure the diversity of models.
[0042] The edge space is used to define the order in which the internal layers of the model are executed, that is, the set of edge pairs contained in the model. <layer i ,layer j > represents an edge pair, which indicates that the input data is input into the i-th layer of the model and the output is obtained. i , and then output i As the input of layer j, the output is obtainedj ; The layer space is used to define the type of model layer, that is, the set of model layer types; the input shape space is used to define the shape set of model layer input. The input of the model is usually a tensor. A tensor has three attributes: type, shape, and dimension. The model input type is usually float16, float32, double, bfloat, and half. The layer dimension is relatively fixed. For example, the input dimensions of common convolutional layers are usually three-dimensional, four-dimensional, and five-dimensional. Therefore, the model input type and dimension can be relatively exhaustive, while the input shape is usually not fixed. Therefore, only the model input shape space is captured here as one of the model diversity measurement methods.
[0043] Step 3: Determine the candidate layer pool of the model.
[0044] In order to generate a model that can run, it is necessary to determine the type and parameters of each layer in the model structure. In the present invention, the layer for which the model layer type selection is about to be performed is called the candidate layer, the layer that can be a potential option for the candidate layer is called the candidate layer, and the option pool composed of candidate layers is called the candidate layer pool. When building a model, there can be many options for the type of candidate layers in the candidate layer pool, such as convolution, pooling, and full connection, but each candidate layer in the candidate layer pool must meet the output constraints of the previous layer, otherwise the failure to process the output of the previous layer will cause the built model to fail. The following are three constraints to select a suitable model layer for the candidate layer to construct the candidate layer pool:
[0045] Constraint on the number of layer inputs: Model layers can be divided into single-input and multi-input layers according to the number of layer inputs required. A single-input model layer only requires one input to make the layer interface run, while a multi-input model layer requires multiple inputs to make the layer interface run. If a node in a directed acyclic graph requires multiple inputs, but there is only a single-input layer in the candidate layer pool of the node, the constructed model will fail. The edges in a directed acyclic graph represent the dependencies between model layers, and can also be used to represent the direction of data flow in the model. Therefore, when the number of in-degrees of a node in a directed acyclic graph exceeds 1, it can be considered that the candidate layer of the node must be a multi-input layer, otherwise it is a single-input layer. Based on this constraint, the present invention divides the model layers into single-input and multi-input layers, and screens out suitable layers to construct a candidate layer pool.
[0046] Layer input dimension constraint: The dimension of model layer input is usually fixed. If the output dimension of the previous layer of the model candidate layer is five-dimensional, and the candidate layer in the model candidate layer pool can only process two-dimensional tensors, the model will also fail. Therefore, a hash function is constructed in the present invention, the key of which is all model layer categories, and the value is the input dimension corresponding to the layer. According to the hash function, the candidate layer with the specified input dimension can be selected.
[0047] Layer input shape constraints: The multi-input layers in the model usually have constraints on the shapes of multiple inputs. If there is a shape mismatch between the inputs, the shape cannot be broadcasted, causing the model to fail. Therefore, if the candidate layer is a multi-input layer and its multiple input shapes do not meet the input shape constraints of the candidate layer interface, the reshape layer unique to the deep learning library will be used to transform all inputs into a consistent shape.
[0048] According to the above three constraints, combined with the input and output of the model layer, we can select a suitable model layer for the candidate layer to construct the candidate layer pool. However, since the model generation process is progressive, we can only get the input information of the candidate layer based on the output of the previous layer, such as input dimension, shape, etc., and cannot directly obtain the output information of the candidate layer for the next layer. To this end, we need to query all model layer interface documents and calculate the layer output according to the calculation formula in the interface document.
[0049] Step 4: Generate the model based on the multi-armed bandit and Thompson sampling algorithms.
[0050] Among them, model layer selection is actually to select the most suitable layer from the candidate layer pool to generate the model. This problem can be expressed as a multi-armed bandit problem. Specifically, the best way to select a suitable candidate layer is to adaptively learn the effectiveness of each layer in the model layer selection process. Intuitively, you can select a candidate layer to add to the generated model fragments, and then calculate the diversity of the generated model fragments, and sort the candidate layers according to the model diversity.
[0051] Therefore, the present invention models the model layer selection problem as a multi-armed bandit problem:
[0052] Definition 1, Multi-armed Bandit: Assume there are K arms, K∈[1,n]. Each arm corresponds to a potential action, and the goal is to select the arm in T rounds of experiments to maximize the cumulative reward.
[0053] In the present invention, each candidate layer can be regarded as an arm associated with an unknown expected success probability. The essence of selecting an arm is to select a candidate layer to add to the model fragment and verify whether the candidate layer can increase the model diversity. According to the measurement method of model diversity in step 2, Formula 1 is proposed here to determine whether the candidate layer can increase the model diversity.
[0054]
[0055] In formula 1, the edge space Se, layer space Sl, and input shape space Si of the generated model segment M are first analyzed; then a candidate layer is selected to be added to M to obtain M'; then the edge space Se', layer space Sl', and input shape space Si' of M' are calculated. As long as M' contains new edge pairs, layer types, or input shapes, this candidate layer is considered to increase the model diversity.
[0056] In the present invention, one arm is equivalent to one candidate layer. Since one candidate layer can only increase the diversity of the model or keep it unchanged, the reward of each arm follows the Bernoulli distribution. Since there are only two cases of rewards, the Thompson sampling algorithm specific to the Bernoulli distribution is used here to solve the multi-armed bandit problem.
[0057] Definition 2, Thompson sampling: For each arm, the Beta distribution is introduced as the prior distribution. The probability density function f of the Beta distribution is shown in Equation 2, which includes two parameters α and β, which represent the prior information of success and failure respectively. Γ represents the Gamma function.
[0058]
[0059] To select a suitable model layer for the model, first update the initial success prior information and failure prior information of each arm, both set to 1; then, for each arm, the number of successes is α, the number of failures is β, calculate and save the posterior distribution Beta(α, β) of each arm; then select the layer corresponding to the arm with the highest posterior distribution score in the candidate layer pool as the final result of the candidate layer; finally, use the function shown in Formula 1 to calculate whether the layer with the highest score can increase the model diversity, and update the posterior distribution value of the layer.
[0060] Step 5: Define the mutation strategy.
[0061] In order to make the generated model explore as much deep learning library code as possible, the present invention proposes three parameter value mutation strategies and three weight mutation strategies to mutate the generated model, thereby increasing the diversity of the model.
[0062] Among them, value mutation (parameter value mutation strategy), for some parameters with only fixed values in the model layer interface, value mutation will select a value from the parameter list for assignment, and in the model layer parameter value mutation, the least used value in the value list will be selected as the parameter as much as possible, so as to increase the model's ability to explore the library code; boundary value mutation (parameter value mutation strategy), inspired by traditional software boundary testing, collects the boundary values of integer and floating point types, which are [2 n ,2 n -1,2 n +1,-(2 n ),-(2n -1),-(2 n +1)] and [2.0 n ,2.0 n -1,2.0 n +1,-(2.0 n ),-(2.0 n -1),-(2.0 n +1)], where n∈[0,64]. If the parameter value is an integer or floating point type, one of these boundary values is taken and assigned to the parameter; input type mutation (parameter value mutation strategy), the input types of the model are usually float16, half, float32, double and bfloat, and the input type mutation rule can transform the type of input data into one of these five common input types.
[0063] Noise blurring (weight mutation strategy), adding Laplace noise, exponential noise or sine noise to the model weights; weight scaling (weight mutation strategy). Use regularization methods to scale weights to limit the size of weights; weight rotation (weight mutation strategy). Multiply the weights by a rotation matrix, such as an orthogonal matrix, to change the direction of the weights.
[0064] Step six, since a large amount of library code is used in the model training phase, the present invention not only detects inconsistencies in model output in the prediction phase, but also detects whether there are inconsistencies in the output of the model in different libraries in the training phase. The present invention detects defects by comparing whether the prediction results of the same model in multiple different libraries are consistent, but in fact these deep learning libraries may have the same defects, resulting in the same calculation results of the same model in multiple libraries. In this case, the defects generated will be missed. Therefore, in addition to comparing the model calculation results based on multiple libraries, the present invention also proposes a method for detecting library defects without multiple libraries based on the differential calculation method in the deep learning library, as follows:
[0065] The training process of the model can be divided into three stages: forward calculation, loss calculation and reverse calculation. In the forward calculation stage, the input data is propagated through the calculation graph, and the calculation is performed from the input layer through each layer to finally obtain the output of the model; in the loss calculation stage, the output of the model will be compared with the expected output, and the value of the loss function will be calculated at the same time; in the reverse calculation stage, by using the chain rule, the gradient of the loss function with respect to the model parameters is passed back to each layer of the model, and the model weights are updated. According to the characteristics of these three stages, the present invention designs a set of indicators to determine whether there is inconsistency between the calculation results of the same model in different libraries.
[0066] The present invention uses Formula 3 to measure the distance between two tensors in the model:
[0067] D(X,Y)=max m (|x m -y m |) Formula 3
[0068] In Formula 3, X and Y represent the tensors calculated by a certain layer of the two deep learning libraries, respectively. m and m Represent the elements in two tensors respectively. This formula defines that the distance between two tensors is the maximum value of the difference in any dimension of the two tensors.
[0069] In the forward calculation phase, compare layer l with the next layer l s The difference in output results. If layer l or the next layer l s When the output results of running in the two libraries differ greatly, it is considered that there is inconsistency. The method for determining inconsistency in the forward calculation stage is shown in Equation 4.
[0070]
[0071] In Formula 4, Xl and Yl represent the output of layer l in the two libraries respectively, Xl s andYl s Respectively represent layer l s Output in two libraries.
[0072] In the loss calculation stage, the present invention first uses Formula 5 to compare layer l with the next layer l s The difference between the loss values is then compared using Equation 6 between layer l and the next layer l s The difference between the loss gradients is calculated, and finally Equation 7 is used to compare the difference between the loss of layer l and the loss function. If layer l or the subsequent layer l s When the loss values and loss gradient calculation results of the two libraries are significantly different, it is considered that there is an inconsistency. Or when the calculation results of layer l in the two libraries are consistent, but the loss or loss function output is significantly different, it is considered that there is an inconsistency.
[0073]
[0074]
[0075]
[0076] In formula 5-7, Xloss and Yloss represent the loss of layer l in the two libraries respectively. s and Yloss s Respectively represent layer l s Loss in both libraries, Xloss grad and Yloss gradRespectively represent the loss gradient of layer l in the two libraries, Xsloss grad and Ysloss grad Respectively represent layer l s Gradients of the loss in both libraries.
[0077] In the reverse calculation phase, compare layer l with the next layer l s The difference in gradient calculation results. If layer l or the next layer l s When the gradient calculation results in the two libraries differ greatly, it is considered that there is inconsistency. The method for detecting model inconsistency in the reverse calculation stage is shown in Equation 8.
[0078]
[0079] In formula 8, Xlgrad and Ylgrad represent the gradients of layer l in the two libraries, Xlsgrad and Ylsgrad represent the gradients of layer l in the two libraries, s Gradients in both libraries.
[0080] During the training phase, the deep learning model calculates the output and gradient under different inputs. To facilitate gradient calculation, the deep learning library provides an automatic differentiation calculation component, which is one of the core components of the library. Automatic differentiation in the library is implemented through computational graphs and back-propagation algorithms. In mathematics, differentiation is a tool for studying the local rate of change of a function near a certain point, also known as numerical differentiation, which is usually solved using the finite difference approximation method. The basic idea of numerical differentiation is to calculate the derivative by adding a small perturbation to the input and observing the change in the output. Therefore, for any layer in the model, its numerical differentiation and the library automatic differentiation should be consistent for the same input, otherwise it means that there is a defect in the library.
[0081] The embodiment of the present application also provides an electronic device, Figure 4The structure of the electronic device provided by the embodiment of the present invention is shown. For example, the electronic device 40 may include a processor 41, a memory 42 and a transmission device 43. The processor is used to execute the deep learning library defect detection method based on fuzzy testing mentioned in the above embodiment, wherein the processor and the memory may be connected by a bus or other means, taking the bus connection as an example. The transmission device may be connected to the processor and the memory by wire or wirelessly. The memory, as a non-transient computer-readable storage medium, may be used to store non-transient software programs, non-transient computer executable programs and modules, such as program instructions or modules corresponding to the deep learning library defect detection method based on fuzzy testing in the embodiment of the present application. The processor executes various functional applications and data processing of the processor by running the non-transient software programs, instructions and modules stored in the memory, that is, the deep learning library defect detection method based on fuzzy testing in the above method embodiment is realized. The memory may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required by at least one function; the storage data area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The one or more modules are stored in the memory, and when executed by the processor, the deep learning library defect detection method based on fuzzy testing in the embodiment is executed.
[0082] As another aspect, the present application also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the device described in the above embodiment; or it may be a computer-readable storage medium that exists independently and is not assembled into the device. The computer-readable storage medium may be a tangible storage medium, such as a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a floppy disk, a hard disk, a removable storage disk, a CD-ROM, or any other form of storage medium known in the technical field. The computer-readable storage medium stores one or more programs, and the programs are used by one or more processors to execute the deep learning library defect detection method based on fuzzy testing described in the present application.
[0083] In summary, the above are only preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A deep learning library defect detection method based on fuzz testing, characterized in that: include: Generate model structure based on directed acyclic graph; Determine the candidate layer pool of the model; the layer that is about to select the model layer type is called the candidate layer, the layer that can be used as a potential option for the candidate layer is called the candidate layer, and the option pool composed of the candidate layers is called the candidate layer pool; The model layer selection is formulated as a multi-armed bandit problem. A candidate layer is selected to be added to the generated model fragments. Then, the diversity of the generated model fragments is calculated. The candidate layers are sorted according to the model diversity. Model generation is achieved based on the multi-armed bandit and Thompson sampling algorithms. Compare model calculation results based on multiple libraries, and detect library defects based on differential calculations in deep learning libraries, as follows: The training process of the model includes: the forward calculation stage, in which the input data is propagated through the calculation graph, and the calculation is performed from the input layer through each layer to obtain the output of the model; the loss calculation stage, in which the output of the model is compared with the expected output, and the value of the loss function is calculated at the same time; the reverse calculation stage, by using the chain rule, the gradient of the loss function with respect to the model parameters is passed back to each layer of the model, and the model weights are updated; indicators are designed to determine whether there is inconsistency between the calculation results of the same model in different libraries.
2. The method according to claim 1, characterized in that Defining mutation strategies to mutate the generated model; the mutation strategies include parameter value mutation strategies and weight mutation strategies; the parameter value mutation strategies include value mutation, boundary value mutation and input type mutation; the weight mutation strategies include noise blurring, weight scaling and weight rotation; Define an evaluation method for model diversity, using edge space, layer space, and input shape space to measure model diversity.
3. The method according to claim 1 or 2, characterized in that ,In the forward calculation phase, compare layer l with the next layer l s The difference in output results, if layer l or the next layer l s When the output results of running in two libraries differ greatly, it is considered to be inconsistent; During the loss calculation phase, if layer l or the next layer l s When the loss values and loss gradient calculation results of the two libraries are significantly different, it is considered that there is an inconsistency; or when the calculation results of layer l in the two libraries are consistent, but the loss or loss function output is significantly different, it is considered that there is an inconsistency; In the reverse calculation phase, compare layer l with the next layer l s The difference in gradient calculation results, if layer l or the next layer l s When the gradient calculation results in the two libraries differ significantly, an inconsistency is considered to exist.
4. The method according to claim 1 or 2, characterized in that , select a suitable model layer for the candidate layer to construct a candidate layer pool. Each candidate layer in the candidate layer pool must satisfy the output constraints of the previous layer, including: Constraint on the number of layer inputs: Model layers are divided into single-input and multi-input layers according to the number of layer inputs required; when the number of in-degrees of a node in a directed acyclic graph exceeds 1, it is considered that the candidate layer of the node must be a multi-input layer, otherwise it is a single-input layer; model layers are divided into single-input and multi-input layers, and suitable layers are selected to construct a candidate layer pool; Layer input dimension constraint: A hash function is constructed, the key of which is all model layer categories, and the value is the input dimension corresponding to the layer. According to the hash function, the candidate layer with the specified input dimension can be selected; Layer input shape constraint: If the candidate layer is a multi-input layer and its multiple input shapes do not conform to the input shape constraint of the candidate layer interface, use the reshape layer unique to the deep learning library to transform all inputs into a consistent shape.
5. The method according to claim 1 or 2, characterized in that: In the model structure generated based on the directed acyclic graph, a random value is first generated. If the random value is less than 0.5, a chain structure model is generated, otherwise a unit structure model is generated; if a chain structure model is generated, nodes and edges are randomly generated and stacked into a chain structure model; if a unit structure model is generated, each unit in the unit structure is traversed, the number of unit nodes is randomly generated, and unit nodes and edges between unit nodes are randomly generated; the directed acyclic graph composed of these nodes and edges is used as the structural information of the model.
6. An electronic device, characterized in that: The electronic device includes a processor and a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the deep learning library defect detection method based on fuzzy testing as described in any one of claims 1 to 5.
7. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and the computer program is used to execute the deep learning library defect detection method based on fuzzy testing as described in any one of claims 1 to 5.
