CN115617693B - Deep learning library interface test method based on particle swarm optimization - Google Patents

Deep learning library interface test method based on particle swarm optimization Download PDF

Info

Publication number
CN115617693B
CN115617693B CN202211462877.3A CN202211462877A CN115617693B CN 115617693 B CN115617693 B CN 115617693B CN 202211462877 A CN202211462877 A CN 202211462877A CN 115617693 B CN115617693 B CN 115617693B
Authority
CN
China
Prior art keywords
particle
mutation
particles
strategy
test sample
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202211462877.3A
Other languages
Chinese (zh)
Other versions
CN115617693A (en
Inventor
单纯
廖书妍
钟晨
闫憬睿
韩瑾锐
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Institute of Technology BIT
Original Assignee
Beijing Institute of Technology BIT
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Institute of Technology BIT filed Critical Beijing Institute of Technology BIT
Priority to CN202211462877.3A priority Critical patent/CN115617693B/en
Publication of CN115617693A publication Critical patent/CN115617693A/en
Application granted granted Critical
Publication of CN115617693B publication Critical patent/CN115617693B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/004Artificial life, i.e. computing arrangements simulating life
    • G06N3/006Artificial life, i.e. computing arrangements simulating life based on simulated virtual individual or collective life forms, e.g. social simulations or particle swarm optimisation [PSO]

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Biomedical Technology (AREA)
  • Evolutionary Computation (AREA)
  • Artificial Intelligence (AREA)
  • Health & Medical Sciences (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

A deep learning library interface test method based on a particle swarm optimization abstracts a process of finding an optimal position by particles in a test sample generation process, and enables the generated test sample to expose the interface defect of the deep learning library as much as possible through selection of the particle advancing direction and the particle advancing distance. The method can effectively reduce the number of test samples required by the test, improves the test efficiency, improves the accuracy of the defect detection of the deep learning library and reduces the false alarm based on the definition of the solution of the test prediction problem.

Description

Deep learning library interface test method based on particle swarm optimization
Technical Field
The invention relates to the technical field of computers, in particular to a deep learning library interface testing method based on a particle swarm algorithm.
Background
Some work has been currently done to test deep learning libraries. These tasks can be broadly divided into two broad categories. One type is test work that is carried out from a model perspective. The building, training and reasoning processes of the model are developed based on the deep learning library, and the model is an important product of the deep learning library. If testing the model reveals defects, it can be concluded that the deep-learning library is defective. The model-based test method needs a series of models and input data of the models, the models are operated in different deep learning libraries, and whether the deep learning libraries have defects or not is indirectly judged according to the operation result. The other type is to carry out test work from an interface of a deep learning library. The deep learning library exposes to the user interfaces that have been packaged well, and if there are defects in these interfaces, the models built using these interfaces may also have defects.
The interface-based test method does not need model assistance, only needs a test sample, and can directly judge whether the deep learning library has defects according to the running result of the test sample. However, the existing interface-based deep learning library test method has low test efficiency, each interface needs a large number of test samples to expose the defects of the deep learning library code, and the judgment on whether the execution result of the interface to be tested in a given test sample meets the expectation is not accurate enough.
Disclosure of Invention
The invention provides a deep learning library interface testing method based on a particle swarm algorithm, which can realize that the generation of a test sample exposes the defect of the deep learning library interface as much as possible on one hand, thereby reducing the number of required test samples and improving the testing efficiency; on the other hand, a new method is provided to solve the problem of test prediction and improve the accuracy of judgment of test results.
The deep learning library interface testing method based on the particle swarm algorithm comprises the following steps:
step S1, defining a mutation strategy, and executing the mutation strategy by randomly selecting a specified number of parameters in a seed sample to generate a new test sample;
s2, defining a solution of a test prediction problem, and judging whether the execution result of the deep learning library interface to be tested in a given test sample meets the expected requirement or not;
s3, initializing a particle swarm, and taking a seed test sample as an initial position of a particle in the particle swarm;
s4, determining the advancing direction and the advancing distance of the particles;
s5, generating a new test sample by mutating particles according to the selected advancing direction and the selected advancing distance;
s6, defining a fitness value calculation method, and evaluating whether the advancing direction and the advancing distance of the particles are correct or not;
step S7, updating particle information;
when the particles meet certain conditions, ending the algorithm, and returning the best fitness value and the optimal variation strategy of the particle swarm; otherwise, the particles will go back to step S4, reselect the forward direction and forward distance, and repeat the following steps to generate a new test sample.
Further, the variation strategy includes random value variation, database value variation, type variation and boundary value variation, wherein the boundary value variation refers to:
if the selected parameter is integer, floating point or character string, then randomly selecting one from the boundary values of the parameter to assign, wherein:
for integer parameters, the range of values for the boundary values includes
Figure SMS_1
,n∈[0,64](ii) a For the floating point type parameter, the value range of the boundary value includes [, ]
Figure SMS_2
],n∈[0, 64](ii) a For the character string type parameters, the value range of the boundary value comprises the values of other interfaces containing the character string type parameters except the interface to be detected in the interface document and the randomly generated character string;
if the selected parameter is a list or tuple type and the elements in the list or tuple are integer, floating point or character string, performing the boundary value mutation on the elements in the parameter;
no changes are made to other types of parameters.
Further, the testing predictive problem solution includes: judging error calculation defects, judging crash defects, judging overtime defects and judging type mismatching defects; wherein:
judging overtime defect, wherein the time for operating a single test sample by the interface exceeds a threshold value and no result is returned;
and judging the type mismatch defect, namely judging that a certain parameter type in the newly generated test sample is inconsistent with the parameter type of the seed test sample generating the test sample, but no error is reported in the test process.
Further, in step S4, the method for determining the particle advancing direction includes:
s41, calculating the score of the mutation strategy according to the iteration stage of the particle swarm:
at the beginning of the iteration, for the specified mutation strategy, to
Figure SMS_3
To calculate its score;
middle iterative stage, using the specified mutation strategy
Figure SMS_4
To calculate its score;
at the later stage of iteration, the specified mutation strategy is applied, so as to
Figure SMS_5
Calculating the score of the variation strategy, wherein the variation strategy with more use times has higher priority;
s42, selecting a variation strategy for the particles based on a Metropolis algorithm: setting the currently selected variation strategy of the particles as stra1, and randomly selecting one variation strategy from the four variation strategies as stra2; the probability of acceptance of a randomly selected mutation strategy is calculated according to equation (1):
Figure SMS_6
(1)
wherein, p represents the probability of selecting one of the four variation strategies, and rank (stra 1) and rank (stra 2) represent the scores of the variation strategies stra1 and stra2 calculated according to the procedure in S41;
s43 at [0,1 ]]Generates a random number alpha therebetween t
If α is t <= α, it indicates that a randomly chosen mutation strategy stra2 is acceptable, which will be taken as the direction of the next advance of the particle;
if α is t >α, the mutation strategy is re-randomly selected and evaluated as described above until an acceptable mutation strategy is generated.
Further, in step S4, the distance traveled by the particle in each variation is determined using the following formula:
Figure SMS_7
(2)
Figure SMS_8
(3)
Figure SMS_9
(4)
wherein distance is the distance of advance in the particle variation, w max Representing the upper bound, w, of the inertial weight min Represents the lower bound of the inertial weight, index represents the current iteration algebra, iter _ num represents the total number of iterations, c min Lower bound representing cognitive factor, c max The upper bound of the cognition factors is represented by particle, particle group is represented by particle group, distance is the distance of the last advance of the particle, and average is the average of the last advance of all the particles in the whole population.
Further, in the step S6, the running result of the defined test prediction solution is used to calculate the fitness value, as shown in equation (5):
Figure SMS_10
(5)
in the formula, fitness represents a fitness value, API represents a deep learning library interface to be tested, and particle represents a particle; the OracleCuda function receives a deep learning library interface and particles to be tested, overtime defect judgment, error calculation defect judgment and type mismatching defect judgment are sequentially executed in the function, if the potential defect of the interface is detected in the running process, 1 is returned, otherwise, 0 is returned;
the OracleCrash function has the same principle, but overtime defect judgment, crash defect judgment and type mismatching defect judgment are sequentially executed in the function.
Further, the algorithm ends when the particles satisfy the following condition: the fitness value of an individual in the particle swarm is equal to 1/3, or the current iteration number exceeds the specified iteration number.
Compared with the prior art, the beneficial effect of this disclosure is: (1) The generation of the test sample is guided by selecting the particle advancing direction and the particle advancing distance, while the test sample is generated by randomly selecting a variation strategy in the prior art, the test sample generated by the method has ambiguous directivity and low test efficiency; (2) The selection strategies of the advancing direction and the advancing distance of the particles enable the generated test samples to expose the interface defects of the deep learning library as far as possible, reduce the number of the required test samples and improve the test efficiency; (3) The method for judging the solution of the test prediction problem in the prior art is related to the hardware condition of a machine, and false alarm is easy to generate; (4) Selection of the next mutation strategy for the particle is based on ongoing evaluation.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be apparent from the following more particular descriptions of exemplary embodiments of the disclosure as illustrated in the accompanying drawings wherein like reference numbers generally represent like parts throughout the exemplary embodiments of the disclosure.
FIG. 1 is a flow chart according to an exemplary embodiment of the present disclosure;
fig. 2 is a schematic diagram of particle optimization in the present disclosure.
Detailed Description
Preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While the preferred embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
The disclosure provides a deep learning library interface testing method based on a particle swarm algorithm, a flow chart of an exemplary embodiment is shown in the attached figure 1, and the method comprises the following steps:
step 1, defining a mutation strategy. Since new test samples need to be generated from seed test samples, some mutation strategies need to be defined to guide the generation of new test samples. There are multiple parameters in each seed test sample, and a new test sample is generated by randomly selecting a specified number of parameters to perform a mutation strategy in the present disclosure.
The preferred mutation strategy in this embodiment mainly includes:
random value variation: aiming at the integer type, the floating point type, the character string type and the Boolean type of the basic data type of python, if the selected parameter value type belongs to one of the basic types, the data of the same type is randomly generated to replace the data in the seed test sample so as to generate a new test sample. If the selected parameter value is a specific type of tensor, such as eight-bit signed integer, sixteen-bit floating point, etc., one of the tensor types is randomly selected to be given to the parameter. If the selected parameter value is a tensor, two random values are taken to respectively cover the original maximum value and the original minimum value of the tensor according to the type of the tensor. And if the selected parameter is the traversable list or tuple type, continuing to carry out random value mutation according to the types of the elements in the list or tuple.
Database value mutation: since many interfaces in the deep learning library have similar functions, the interfaces only differ in the dimension and type of the parameter. That is, in a set of similar interfaces, the parameter value for one interface is likely to be a potentially reasonable value for other similar interfaces in the same set. Based on the idea, in database value variation, for the selected parameter needing variation, one interface is randomly selected from other interfaces in the same group, and the parameter value of the same parameter of the interface is given to the selected parameter.
Type variation: if the selected parameter value is a tensor, randomly selecting the following mode to mutate the dimensionality of the tensor: increasing the dimension, decreasing the dimension, or modifying the value of the dimension. For example, the value of the selected parameter is a tensor with dimension [1,2, 3], and after the type variation is performed on the tensor, the dimension of the tensor may become any one of [1,2, 3, 4], [1, 2] or [1,2, 5 ]. If the selected parameter value is data of other types except tensor, the parameter value is changed into any type except the type.
Boundary value variation: in the traditional software test, the boundary test method is mainly used for testing the running condition of the code when the variable takes the boundary value. Use for reference traditional softThe idea of the piece test, possible boundary values are collected. For integer shapes, the boundary value may take the value [ 2] n ,2 n-1 ,2 n+1 ,-(2 n ),-(2 n-1 ),-(2 n+1 )]Where n ∈ [0, 64 ]]. For the floating point type, the possible value of the boundary value is [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 ]]. For the character string type, firstly, values of other interfaces containing character string type parameters except for the interface to be detected in the interface document are obtained, then, character strings are randomly generated, and the values of the two parts are used as possible values of boundary values. In the boundary value variation, if the selected parameter is integer, floating point or character string, then randomly taking one value from the boundary value of the corresponding type to assign the parameter. If the selected argument is of list or tuple type and the elements in the list or tuple are integer, floating point, or string, then the above boundary value mutation is performed on the elements in the argument. No changes are made to other types of parameters.
And 2, defining a solution of the test prediction problem. During testing, it needs to be determined whether the execution result of the deep learning library interface to be tested under given test input meets the expected requirement, and 4 test prediction problem solutions are defined in this embodiment, where:
and (3) judging the defect through error calculation: and under the same test sample, respectively operating each interface on the CPU and the GPU, and comparing the operation results of the two ends. If the operation results are different, it indicates that the interface is implemented differently on the CPU and the GPU, and there may be a defect.
Judging the breakdown defect: if a legal test sample is input into the interface, but the interface throws an exception, it is considered as a crash defect.
Judging overtime defects: the time for the interface to run a single test sample is extremely short, and the run time under some boundary test samples may be long, but should not exceed a preset threshold. If the running time of the interface exceeds the preset threshold value but no result is returned, the defect of timeout is considered.
Judging the type mismatch defect: and if the program runs without error and the operation result is returned in the test process, judging the type mismatch defect. Specifically, if a certain parameter type of the newly generated test sample is different from the parameter type in the seed test sample generating the test sample, but no error is reported in the test, it indicates that no type check may be performed in the code of the interface, and there may be a defect. For example, for the parameter 'device _ type' of the interface tf.config.list _ local _ devices, it is indicated in the document that it must be a string type, but in the test, it is found that when the parameter takes the value of integer, floating point, list or other types, the result can also be output, the program does not report errors, which is inconsistent with the document description, and there may be defects.
And 3, initializing the particle swarm. In this step, the particle swarm size, the particle swarm iteration number, the inertia weight parameter, the cognitive factor, the particle attribute, the optimal particle variation strategy, the initial value of the optimal particle variation strategy, and the optimal particle swarm fitness value need to be set. In the present disclosure, the attributes of the particle are position, velocity, and fitness value, where the velocity in turn depends on the heading direction and the heading distance. The initial position of the particle is set as a seed test sample, the advancing direction and the advancing distance are initially set as null, and the fitness value is initially set as 1. The process by which the particles reach themselves to a new location using a mutation strategy is the process by which new test samples are generated. In order to facilitate the subsequent step 4, the number of uses and the number of successful mutation times of each mutation strategy are initialized, and the initial values are both 0.
And 4, determining the advancing direction of the particles.
In the present disclosure, in order to obtain a test sample most likely to expose interface defects of the deep learning library through mutation of the seed test sample, a process of finding the test sample most likely to expose the interface defects is abstracted to a process of finding an optimal position through searching of the seed, which is described below with reference to fig. 2. In the figure, a filled circle represents the current position of the particle, and a square represents the optimal position of the particle. During the search, in order to reach the optimal position, multiple directions may be selected to advance, and all directions shown by arrows in fig. 2 are possible search advancing directions. The positions in the particle properties represent the test sample, so the possible advancing directions of the particles can be abstracted into the variation strategy that the test sample can select. In the present disclosure, the Metropolis method is used to determine the direction of travel of the particles. It is not sufficient to determine only the particle advancement direction, and the distance of advancement in this advancement direction is further determined in this disclosure. If the forward distance is too short, the searching process is possibly long, and the optimal position cannot be reached within the iteration times; if the distance of advance is too long, the optimal position of the particle may be skipped directly. To address this issue, the present disclosure dynamically adjusts the distance that the particle has traveled in each iteration according to the distance the particle has traveled the last time and the average of the distance the particle population has traveled the last time. After the advancing direction and the advancing distance of the particles are determined, the test sample can be guided to select a proper mutation strategy to generate a new test sample.
In the present disclosure, the selection of particles for the direction of travel is equivalent to the selection of the test sample for the mutation strategy. Different mutation strategies may have different effects on the extent to which the test specimen exposes interface defects. To select the appropriate mutation strategy for a test sample, the score for each mutation strategy is first calculated. The particle swarm optimization has high convergence speed, but is easy to fall into local extrema, low in search precision and the like, and in order to overcome the problems, the score of the mutation strategy is calculated according to an iteration stage. Specifically, the entire particle swarm iteration is divided into three phases:
the first stage is the initial stage of iteration, and the particles should expand the search range as much as possible to avoid trapping in the local optimal solution. At this stage, the possible directions of particle progression should be tried as much as possible, so that each mutation strategy should be used as much as possible for the whole population. However, at the beginning of the iteration, the particles may not find the optimal positions immediately, so that there is a high possibility that there are no optimal positions for the particles and no optimal positions for the particle group at this time. Thus, for a given mutation strategy, use is made of
Figure SMS_11
To calculate its score forIts priority is evaluated. Those mutation strategies that are used less frequently will be given higher priority to increase the probability of being selected, thereby expanding the search scope.
The second stage is an iterative intermediate stage, belongs to a stable transition period, and can not expand the search range infinitely and can not use a certain variation strategy too intensively. After the first stage of trial, the optimal positions of the particles and the optimal positions of the particle swarms are most likely to occur, so the variation strategy capable of detecting the interface defects should be locked as much as possible, thereby improving the success rate of defect detection. For this, for a given mutation strategy, use is made of
Figure SMS_12
The priority scores are calculated, and the mutation strategies with high mutation success rates are ranked in the top.
The third stage is the later stage of iteration, and the quality of each variation strategy is already highlighted by the communication and selection of the first two stages of individuals in the particle swarm, and at the moment, the strategy for selecting a plurality of particles should be used as much as possible. Therefore, for the given mutation strategy, to
Figure SMS_13
To calculate a score for the mutation strategy. And giving a higher rank to the mutation strategy with a high use ratio.
In the three stages, the sorting result of the variation strategy is obtained according to the history selection of the particles and the history effect of the variation strategy, that is, all particle information and particle swarm information of the particles before a certain iteration are reflected on the current position of the particles, so that the next position of the particles can be predicted based on the current position of the particles, which is equivalent to predicting the next test sample based on the current test sample and conforming to the characteristics of the Markov chain.
Based on the above analysis, the Metropolis algorithm will be used in this step to guide the selection of the mutation strategy for the test sample. To simplify the problem, here the probability distribution follows a geometric distribution. And setting the currently selected variation strategy of the test sample as stra1, and randomly selecting one of the four variation strategies as stra2. The acceptance probability calculation mode for the randomly selected mutation strategy is shown as the formula (1):
Figure SMS_14
(1)
where p represents the probability of selecting one of the four mutation strategies, and rank (stra 1) and rank (stra 2) represent the scores of the mutation strategies stra1 and stra2 calculated in accordance with the procedure in S41.
Then in [0,1 ]]Generates a random number alpha therebetween t If α is t <And = α, this indicates that a randomly selected mutation strategy is acceptable, which will be the direction in which the particle will next advance. If α is t >α, it indicates that the mutation strategy is rejected, and the mutation strategy is re-selected randomly and evaluated according to the above method until an acceptable mutation strategy is generated. Because the selection of the variation strategy is random, the proposed distribution is symmetrical distribution with a simpler form, and the basic requirements of Metropolis sampling are met.
And 5, determining the advancing distance of the particles. The distance the particle traveled in each variation was determined using equations (2) - (4).
Figure SMS_15
(2)/>
Figure SMS_16
(3)
Figure SMS_17
(4)
Wherein, distance is the advancing distance in particle variation, w max Representing the upper bound, w, of the inertial weight min Represents the lower bound of the inertial weight, index represents the current iteration algebra, iter _ num represents the total number of iterations, c min Lower bound representing cognitive factor, c max Represents the upper bound of the recognition factor, particle represents particle, particle _ group represents particle group, and particle distance represents the last time before the particleThe distance of advance, particle _ group.avg _ distance, refers to the average of the distance of last advance of all particles in the entire population. The first term of equation (4) represents the inertial part, which illustrates how much the particle trusts itself to the last distance traveled; the second term represents social cognition and illustrates how much the particles trust the mean of the last distance traveled by the population. The reason why the formula (2) shows that the inertia weight is reduced along with the increase of the iteration times, and the formula (3) shows that the social cognition is increased along with the increase of the iteration times is that the sharing degree of the particle information in the particle swarm is gradually improved along with the increase of the iteration times, and the particles are gradually changed from the judgment of trusting themselves to the judgment of trusting groups, so that the generation of the test sample can be developed towards the direction of exposing the interface defects.
And 6, mutating the particles. The particles are moved to a new location according to the mutation strategy defined in step 1, and the particle travel direction and travel distance determined in steps 4 and 5, thereby generating a new test sample.
And 7, defining a fitness value calculation method. After the variation of the particle, the correctness of the particle advancing direction and the particle advancing distance needs to be judged by a fitness value. In the present disclosure, individuals with low fitness values are more favorable for finding potential defects of the interface. The running result of the test prediction problem solution defined in step 2 is used here to calculate the fitness value, as shown in equation (5).
Figure SMS_18
(5)
In the formula, the fitness value is denoted by fitness, the API denotes a deep learning library interface to be tested, and the particle denotes a particle. The OracleCuda function receives a deep learning library interface and particles to be tested, overtime defect judgment, error calculation defect judgment and type mismatching defect judgment are sequentially executed in the function, if the potential defect of the interface is detected in the running process, 1 is returned, and if the potential defect of the interface is not detected, 0 is returned. The OracleCrash function is the same, but overtime defect judgment, crash defect judgment and type mismatching defect judgment are sequentially executed in the function. The fitness value is determined by two functions of OracleCuda and OracleCrash, and the advancing direction and the advancing distance of the particles with low fitness value are more beneficial to the particle swarm to find potential defects of the interface.
And 8, updating the particle information. And updating the optimal positions of the particles, the optimal positions of the particle swarms, the particle adaptability values, the particle swarm adaptability values and the use times of the modification variation strategy according to the adaptability values calculated in the step 7. If the fitness value of the particle is smaller than 1 after mutation, the potential defect of the interface is found, and the selected mutation strategy is successful in mutation, so that the number of times of successful use of the mutation strategy needs to be modified.
For the whole particle swarm, the optimal fitness value which can be achieved by the particle swarm is 1/3 according to the calculation mode of the formula (5), namely, at least two running results which do not accord with the solution of the test prediction problem are found by the particles. Therefore, the stopping condition of the whole algorithm is that the fitness value of particles in the particle swarm is equal to 1/3, or the current iteration number exceeds the iteration number set in initialization. And when the algorithm is finished, returning the best fitness value and the optimal variation strategy of the particle swarm. If the current particle cannot meet the stop condition, the particle returns to step 4, the advancing direction and the advancing distance are reselected, and the subsequent steps are repeatedly executed to generate a new test sample.
The foregoing is illustrative of the present invention and various modifications and changes in form or detail will readily occur to those skilled in the art based upon the teachings herein and the application of the principles and principles disclosed herein, which are to be regarded as illustrative rather than restrictive on the broad principles of the present invention.

Claims (3)

1. A deep learning library interface testing method based on a particle swarm algorithm comprises the following steps:
step S1, defining a mutation strategy, and executing the mutation strategy by randomly selecting a specified number of parameters in a seed sample to generate a new test sample;
s2, defining a solution of a test prediction problem, and judging whether the execution result of the deep learning library interface to be tested in a given test sample meets the expected requirement or not;
s3, initializing a particle swarm, and taking a seed test sample as an initial position of a particle in the particle swarm;
s4, determining the advancing direction and the advancing distance of the particles;
in step S4, the method for determining the particle advancing direction includes:
s41, calculating the score of the mutation strategy according to the iteration stage of the particle swarm:
at the beginning of the iteration, for the specified mutation strategy, to
Figure QLYQS_1
To calculate its score;
middle iterative phase, using a given mutation strategy
Figure QLYQS_2
To calculate its score;
at the later stage of iteration, the specified mutation strategy is applied, so as to
Figure QLYQS_3
To calculate its score;
s42, selecting a variation strategy for the particles based on a Metropolis algorithm: setting the currently selected variation strategy of the particles as stra1, and randomly selecting one variation strategy from the four variation strategies as stra2; the probability of acceptance of a randomly selected mutation strategy is calculated according to equation (1):
Figure QLYQS_4
(1)
wherein, p represents the probability of selecting one of the four variation strategies, and rank (stra 1) and rank (stra 2) represent the scores of the variation strategies stra1 and stra2 calculated according to the procedure in S41;
s43 at [0,1 ]]Generates a random number alpha therebetween t
If α is t <If "= α", then it means randomThe mutation strategy stra2 chosen is acceptable, it will be the next direction of advancement of the particle;
if α is t >Alpha, randomly selecting a mutation strategy again, and evaluating according to the method until an acceptable mutation strategy is generated;
in step S4, the distance traveled by the particle per variation is determined using the following formula (4):
Figure QLYQS_5
(4)
wherein:
Figure QLYQS_6
(2)
Figure QLYQS_7
(3)
wherein, distance is the advancing distance in particle variation, w max Representing the upper bound, w, of the inertial weight min Represents the lower bound of the inertial weight, index represents the current iteration algebra, iter _ num represents the total number of iterations, c min Lower bound representing cognitive factor, c max The upper bound of the cognition factor is represented, particle represents particle, particle _ group represents particle group, distance refers to the distance of the last advancing of the particle, and particle _ group.avg _ distance refers to the average value of the last advancing distances of all the particles in the whole population;
s5, generating a new test sample by mutating particles according to the selected advancing direction and the selected advancing distance;
s6, defining a fitness value calculation method, and evaluating whether the advancing direction and the advancing distance of the particles are correct or not;
in step S6, the running result of the defined test prediction solution is used to calculate a fitness value, as shown in equation (5):
Figure QLYQS_8
(5)
in the formula, the fitness represents a fitness value, the API represents a deep learning library interface to be tested, and the particle represents a particle; the OracleCuda function receives a deep learning library interface and particles to be detected, overtime defect judgment, error calculation defect judgment and type mismatching defect judgment are sequentially executed in the function, if the potential defects of the interface are detected in the running process, 1 is returned, otherwise, 0 is returned;
the OracleCrash function receives a deep learning library interface and particles to be detected, overtime defect judgment, crash defect judgment and type mismatching defect judgment are sequentially executed in the function, if the potential defect of the interface is detected in the running process, 1 is returned, otherwise, 0 is returned;
step S7, updating particle information;
when the particles meet certain conditions, finishing the algorithm, and returning the best fitness value and the optimal variation strategy of the particle swarm; otherwise, the particles will return to step S4, reselect the advancing direction and the advancing distance, and repeat the subsequent steps to generate a new test sample;
wherein, when the particles satisfy the following conditions, the algorithm is ended: the fitness value of an individual in the population is equal to 1/3, or the current iteration number exceeds a specified iteration generation number.
2. The method of claim 1, wherein the mutation strategies comprise random value mutation, database value mutation, type mutation, and boundary value mutation, wherein the boundary value mutation is:
if the selected parameter is integer, floating point or character string, then randomly taking one of the boundary values of the parameter to assign, wherein:
for integer parameters, the range of values for the boundary values includes [ 2] n ,2 n -1,2 n +1,-(2 n ),-(2 n -1),-(2 n +1)],n∈[0, 64](ii) a For floating point type parameters, the boundary value range includes [2.0 ] n ,2.0 n -1,2.0 n +1,-(2.0 n ),-(2.0 n -1),-(2.0 n +1)],n∈[0, 64](ii) a For theThe value range of the boundary value comprises the values of other interfaces containing the character string type parameter except the interface to be detected in the interface document and a character string generated randomly;
if the selected parameter is a list or tuple type and the elements in the list or tuple are integer, floating point or character string, performing the boundary value mutation on the elements in the parameter;
no changes are made to other types of parameters.
3. The method of claim 1, wherein the testing predictive problem solutions comprises: judging error calculation defects, judging breakdown defects, judging overtime defects and judging type mismatching defects; wherein:
judging overtime defects, wherein the time for operating a single test sample by the interface exceeds a threshold value and no result is returned;
and judging the type mismatch defect, namely judging that a certain parameter type in the newly generated test sample is inconsistent with the parameter type of the seed test sample generating the test sample, but no error is reported in the test process.
CN202211462877.3A 2022-11-22 2022-11-22 Deep learning library interface test method based on particle swarm optimization Active CN115617693B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211462877.3A CN115617693B (en) 2022-11-22 2022-11-22 Deep learning library interface test method based on particle swarm optimization

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211462877.3A CN115617693B (en) 2022-11-22 2022-11-22 Deep learning library interface test method based on particle swarm optimization

Publications (2)

Publication Number Publication Date
CN115617693A CN115617693A (en) 2023-01-17
CN115617693B true CN115617693B (en) 2023-04-07

Family

ID=84878454

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211462877.3A Active CN115617693B (en) 2022-11-22 2022-11-22 Deep learning library interface test method based on particle swarm optimization

Country Status (1)

Country Link
CN (1) CN115617693B (en)

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103235743B (en) * 2013-04-07 2016-03-02 北京航空航天大学 A kind of based on decomposing and the multiple goal test assignment dispatching method of optimum solution follow-up strategy
CN113128781B (en) * 2021-04-30 2021-12-10 大连理工大学 Distributed industrial energy operation optimization platform for automatically constructing intelligent model and algorithm

Also Published As

Publication number Publication date
CN115617693A (en) 2023-01-17

Similar Documents

Publication Publication Date Title
Raghu et al. Evaluation of causal structure learning methods on mixed data types
CN110110858B (en) Automatic machine learning method based on reinforcement learning
CN109543740A (en) A kind of object detection method based on generation confrontation network
CN107103332A (en) A kind of Method Using Relevance Vector Machine sorting technique towards large-scale dataset
Nguyen et al. Particle swarm optimisation with genetic operators for feature selection
CN113076734B (en) Similarity detection method and device for project texts
CN113240113B (en) Method for enhancing network prediction robustness
CN113407185B (en) Compiler optimization option recommendation method based on Bayesian optimization
US20230281317A1 (en) False positive vulnerability detection using neural transformers
CN112164426A (en) Drug small molecule target activity prediction method and device based on TextCNN
CN113391894A (en) Optimization method of optimal hyper-task network based on RBP neural network
CN115617693B (en) Deep learning library interface test method based on particle swarm optimization
Doshi et al. Kepler: Robust learning for parametric query optimization
US11307867B2 (en) Optimizing the startup speed of a modular system using machine learning
CN117149615A (en) Method and corresponding device for generating test case execution path
KR102272921B1 (en) Hierarchical object detection method for extended categories
CN112488188A (en) Feature selection method based on deep reinforcement learning
CN111933215A (en) Transcription factor binding site searching method, system, storage medium and terminal
CN114356778A (en) Deep reinforcement learning software testing method based on coverage guide fuzzy test
Ernst et al. Time-staging enhancement of hybrid system falsification
Tamrakar et al. Lazy learning associative classification with WkNN and DWkNN algorithm
Aglin et al. Assessing optimal forests of decision trees
CN118312157B (en) Program development auxiliary method based on generation type AI
TWI819880B (en) Hardware-aware zero-cost neural network architecture search system and network potential evaluation method thereof
CN111274119A (en) Variation test data generation method based on multi-population coevolution

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant