Random testing method, device, equipment and storage medium for deep learning operators
By generating random sizes that meet the association relationship based on the tensor association relationship based on the deep learning operator, the problem of redundant illegal shapes and complex constraints in the prior art is solved, and the efficiency and accuracy of the random testing of deep learning operators are improved.
Patent Information
- Application Number
- CN202410475731.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-19
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2044-04-19
AI Technical Summary
In the random testing of deep learning operators, there are a large number of redundant illegal shapes when directly constructing the random shape of the input tensor, resulting in low testing efficiency and complex configuration of constraints, which increases the difficulty of testing.
By determining the expression containing the same random variables based on the correlation relationship between the first tensor and the second tensor of the deep learning operator, a random size that conforms to the correlation relationship is generated, reducing redundant illegal shapes and reducing testing difficulty.
It improves testing efficiency, reduces measurement workload, realizes automatic generation of expressions, and quickly recognizes that deep learning operators fail to pass the test, which improves the testing speed.
Smart Images

Figure CN118093436B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and more specifically, to a random testing method, device, equipment and storage medium for deep learning operators. Background Art
[0002] Deep learning operators are usually used to build various layers and components of neural networks to achieve data transmission, conversion and calculation. Deep learning operators are the basic building blocks of deep learning models. They define the structure and operation flow of the model, including input, output and intermediate calculations. In the development of deep learning software libraries, random testing of deep learning operators is an important part of supporting quality assurance of operator size and functional generalization.
[0003] How to effectively perform random testing of deep learning operators is a key challenge. In the prior art, the random shape of the operator's input tensor is directly constructed, and then illegal random shapes are eliminated through rule constraints, and the remaining legal random shapes are used to perform testing. However, there are usually a large number of redundant illegal shapes in the random shapes directly generated randomly, and filtering processing is required to remove illegal shapes, resulting in low efficiency of random testing. Summary of the invention
[0004] The present invention proposes a random testing method, device, equipment and storage medium for deep learning operators, which help to improve testing efficiency.
[0005] The technical solution of the embodiment of the present invention is as follows:
[0006] A random testing method for a deep learning operator, comprising:
[0007] Determine, based on an association relationship between a first size of a first tensor of a deep learning operator and a second size of a second tensor of the deep learning operator, a first expression representing the first size and a second expression representing the second size, wherein the first expression and the second expression contain the same random variable;
[0008] determining a random value of the random variable;
[0009] Based on the random value, determining the first size and the second size;
[0010] Based on the first size and the second size, the deep learning operator is tested.
[0011] In one embodiment, the first tensor is an input tensor or an output tensor of the deep learning operator, and the second tensor is an input tensor or an output tensor of the deep learning operator;
[0012] Determining the random value of the random variable includes:
[0013] Determining a value range of the random variable based on an attribute parameter of the deep learning operator or based on a value range setting instruction triggered by a user;
[0014] In the value range, a random value of the random variable is determined.
[0015] In one embodiment, the deep learning operator is a convolution operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following:
[0016] The input channel size of the convolution input tensor of the deep learning operator is the same as the input channel size of the convolution weight tensor of the deep learning operator;
[0017] The output channel size of the convolution output tensor of the deep learning operator is the same as the output channel size of the convolution weight tensor of the deep learning operator;
[0018] The height of the convolution output tensor of the deep learning operator is equal to (input_height+2×padding–dilation×(kernel_height_size-1)–1) / stride+1, where input_height is the height of the convolution input tensor of the deep learning operator; padding is the padding parameter of the deep learning operator; dilation is the expansion parameter of the deep learning operator; kernel_height_size is the height of the convolution kernel of the convolution weight tensor of the deep learning operator; stride is the step size of the deep learning operator;
[0019] The width of the convolution output tensor of the deep learning operator is equal to (input_width+2×padding–dilation×(kernel_width_size-1)–1) / stride+1, where input_width is the width of the convolution input tensor of the deep learning operator; padding is the padding parameter of the deep learning operator; dilation is the expansion parameter of the deep learning operator; kernel_width_size is the convolution kernel width of the convolution weight tensor of the deep learning operator; stride is the step size of the deep learning operator.
[0020] In one embodiment, the deep learning operator is a matrix multiplication operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following:
[0021] When the transpose of the first input tensor of the matrix multiplication operator is false and the transpose of the second input tensor of the matrix multiplication operator is false, the second dimension size of the first input tensor is the same as the first dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the second dimension size of the second input tensor;
[0022] When the transpose of the first input tensor of the matrix multiplication operator is true and the transpose of the second input tensor of the matrix multiplication operator is false, the size of the first dimension of the first input tensor is the same as the size of the first dimension of the second input tensor, the size of the first dimension of the output tensor of the matrix multiplication operator is the same as the size of the second dimension of the first input tensor, and the size of the second dimension of the output tensor of the matrix multiplication operator is the same as the size of the second dimension of the second input tensor;
[0023] When the transpose of the first input tensor of the matrix multiplication operator is false and the transpose of the second input tensor of the matrix multiplication operator is true, the second dimension size of the first input tensor is the same as the second dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the second input tensor;
[0024] When the transpose of the first input tensor of the matrix multiplication operator is true and the transpose of the second input tensor of the matrix multiplication operator is true, the first dimension size of the first input tensor is the same as the second dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the second dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the second input tensor.
[0025] In one embodiment, the deep learning operator is a bias vector addition operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following: the bias input size of the bias input tensor of the bias vector addition operator is the same as the channel size of the feature input tensor of the bias vector addition operator; the size of the output tensor of the bias vector addition operator is the same as the feature input size of the feature input tensor of the bias vector addition operator; or
[0026] The deep learning operator is a point-by-point operator, and the association relationship between a first size of a first tensor of the deep learning operator and a second size of a second tensor of the deep learning operator includes at least one of the following: the sizes of corresponding dimensions of two input tensors of the point-by-point operator are the same or 1, wherein a dimension of 1 indicates broadcasting in the dimension, and the point-by-point operator supports broadcasting; the sizes of each dimension of the output tensor of the point-by-point operator are the same as the maximum value of the sizes of the corresponding dimensions of the input tensors; or
[0027] The deep learning operator is a grouping operator, and the association relationship between a first size of a first tensor of the deep learning operator and a second size of a second tensor of the deep learning operator includes: a channel size of an input tensor in a group convolution operation and a group normalization operation of the grouping operator is an integer multiple of a group size of the grouping operator; or
[0028] The deep learning operator is an attention operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following: when the first dimension of the query input tensor, key input tensor and value input tensor of the attention operator is the product of the batch size and the number of heads, the sizes of the first dimensions of the query input tensor, key input tensor and value input tensor are the same; when the second dimension of the query input tensor, key input tensor and value input tensor of the attention operator is the sequence length, the sizes of the second dimensions of the key input tensor and the value input tensor are the same; when the third dimension of the query input tensor, key input tensor and value input tensor of the attention operator is the head size, the sizes of the third dimensions of the query input tensor, key input tensor and value input tensor are the same; the size of the output tensor of the attention operator is the same as the size of the query input tensor.
[0029] In one embodiment, the determining of a first expression representing the first size and a second expression representing the second size based on an association relationship between a first size of a first tensor of a deep learning operator and a second size of a second tensor of the deep learning operator includes:
[0030] Generate a script file containing rules, wherein in the rules: specify the association relationship between the first size of the first tensor and the second size of the second tensor based on the random variable;
[0031] The script file is called to generate the first expression and the second expression based on the rule.
[0032] In one embodiment, the testing the deep learning operator based on the first size and the second size includes at least one of the following:
[0033] When both the first tensor and the second tensor are input tensors, generate a first tensor use case that conforms to the first size and a second tensor use case that conforms to the second size; input the first tensor use case and the second tensor use case into a benchmark deep learning operator to obtain a benchmark output tensor use case; input the first tensor use case and the second tensor use case into the deep learning operator to obtain an output tensor use case; determine a test result of the deep learning operator based on a comparison result of the output tensor use case and the benchmark output tensor use case;
[0034] When the first tensor is an input tensor and the second tensor is an output tensor, generating a first tensor use case that meets the first size; inputting the first tensor use case into the deep learning operator to obtain an output tensor use case; when the size of the output tensor use case does not match the second size, determining that the deep learning operator fails the test;
[0035] When the first tensor is an input tensor and the second tensor is an output tensor, a first tensor use case that meets the first size is generated; the first tensor use case is input into the deep learning operator to obtain an output tensor use case; when the size of the output tensor use case matches the second size, the first tensor use case is input into a benchmark deep learning operator to obtain a benchmark output tensor use case; based on the comparison result of the output tensor use case and the benchmark output tensor use case, a test result of the deep learning operator is determined.
[0036] A random testing device for a deep learning operator, comprising:
[0037] A first determination module is configured to determine, based on an association relationship between a first size of a first tensor of a deep learning operator and a second size of a second tensor of the deep learning operator, a first expression representing the first size and a second expression representing the second size, wherein the first expression and the second expression contain the same random variable;
[0038] A second determination module, used to determine the random value of the random variable;
[0039] A third determining module, configured to determine the first size and the second size based on the random value;
[0040] A testing module is used to test the deep learning operator based on the first size and the second size.
[0041] An electronic device, comprising:
[0042] Memory;
[0043] processor;
[0044] The memory stores an application program executable by the processor, which is used to enable the processor to execute any of the random testing methods for deep learning operators described above.
[0045] A computer-readable storage medium having computer-readable instructions stored thereon, wherein when the computer-readable instructions are executed by a processor, the processor executes any of the random testing methods for deep learning operators described above.
[0046] It can be seen from the above technical solution that in an embodiment of the present invention, based on the association between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator, a first expression characterizing the first size and a second expression characterizing the second size are determined, wherein the first expression and the second expression contain the same random variable; a random value of the random variable is determined; based on the random value, the first size and the second size are determined; based on the first size and the second size, the deep learning operator is tested. Therefore, the embodiment of the present invention uses an expression containing the same random variable to constrain the association between the sizes, and can use expressions and random variables to quickly determine the random size of the tensor used to perform the test that meets the association, rather than blindly generating the size completely randomly, which not only reduces or overcomes redundant illegal shapes, but also does not require filtering processing, thereby reducing the measurement workload and improving the test efficiency.
[0047] Moreover, the use of scripts containing rules enables automatic expression generation, which reduces the difficulty of testing and improves testing efficiency. In addition, during the test process, when the size of the output tensor use case does not match the size of the output tensor, it can quickly determine that the deep learning operator fails the test, which improves the test speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 The present invention is a flowchart of a random testing method for deep learning operators in the related art.
[0049] Figure 2 4 is an exemplary flow chart of a random testing method for deep learning operators according to an embodiment of the present invention.
[0050] Figure 3 is an exemplary structural diagram of a random testing device for a deep learning operator according to an embodiment of the present invention.
[0051] Figure 4 is an exemplary structural diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0052] In order to make the objectives, technical solutions and advantages of the present invention more clear, the present invention is further described in detail below with reference to the accompanying drawings.
[0053] For the sake of brevity and intuitiveness in description, the scheme of the present invention is explained below by describing several representative implementations. A large number of details in the implementations are only used to help understand the scheme of the present invention. However, it is obvious that the technical scheme of the present invention may not be limited to these details when implemented. In order to avoid unnecessarily obscuring the scheme of the present invention, some implementations are not described in detail, but only a framework is given. Hereinafter, "including" means "including but not limited to", and "according to..." means "at least according to..., but not limited to only according to...". Due to the language habits of Chinese, when the number of a component is not specifically specified below, it means that the component can be one or more, or can be understood as at least one.
[0054] In the field of deep learning, tensors play an important role as a basic data structure. Tensors can be viewed as vectors, matrices, or arrays of any dimension. Similar to arrays and matrices, they can perform mathematical operations efficiently and process and analyze large data sets. Tensors are widely used to represent input data, model parameters, and output data. For example, for image data, it can be represented as a three-dimensional tensor, corresponding to width, height, and number of channels. Similarly, two-dimensional tensors can be used to represent text data. Model parameters can also be represented as tensors, and model training and optimization are achieved through tensor operations and transformations. Tensor shape refers to the dimensions of the tensor and the size of each dimension. For example, the shape of a tensor is represented by a tuple of integers, each integer representing the size of the corresponding dimension. For example, a tensor with a shape of (2, 3, 4) represents a three-dimensional array, where the first dimension size is 2, the second dimension size is 3, and the third dimension size is 4.
[0055] In the current random testing of deep learning operators, random shapes of tensors of deep learning operators are directly constructed, and then manually written rule constraints are used to perform legality checks to eliminate illegal random shapes. For example, for convolution operators, multiple groups of random shapes are first generated based on the constraint range specified by the alignment feature size and weight size, and then the constraint rules (such as requiring the number of input channels of the feature size to be equal to the number of input channels of the weight size, etc.) are used to eliminate illegal shapes from these multiple groups of random shapes, and the remaining legal shapes are used to perform tests on deep learning operators.
[0056] Figure 1 FIG. 1 is a flowchart of a random testing method for a deep learning operator in the related art. Figure 1 As shown, the random testing method in the related art includes:
[0057] Step 101: Configure a random range for the shape of the input tensor of the deep learning operator.
[0058] Step 102: Randomly generate a large number of shapes of the input tensor through independent random processes within a random range.
[0059] Step 103: Configure the constraints of the tensor.
[0060] Step 104: Based on the constraint conditions, filter the large number of shapes randomly generated in step 102, and determine whether there are any legal shapes left after filtering. If so, execute step 105; otherwise, return to execute step 102.
[0061] Step 105: Using tensors of legal shapes, perform tests on deep learning operators.
[0062] The inventor studied the above process and found that there are at least the following disadvantages:
[0063] (1) Due to the particularity of deep learning operator algorithms, there is a correlation between the sizes of many deep learning input tensors. However, this correlation is not taken into account in the above process. There are a large number of redundant illegal shapes in the independently randomly generated shapes, and an additional constraint check process is required to eliminate illegal shapes, resulting in low random test efficiency.
[0064] (2) If the correlation logic between the shapes of the operator's input tensors is complex, the constraint configuration process is complicated, which increases the difficulty of testing.
[0065] In the embodiments of the present invention, the objective law of correlation between the shapes of tensors (preferably, including input tensors and output tensors) of deep learning operators is fully considered, and random shapes that meet the correlation are generated based on random variables and tensor shape expressions. Compared with the existing processing mechanism of directly generating random shapes first and then filtering illegal shapes through legality checks, the embodiments of the present invention will not generate a large number of redundant illegal input combinations, and no additional filtering processing is required, thereby significantly improving the test efficiency.
[0066] The above disclosure details the technical defects existing in the related art, the causes of the technical defects, and the thinking and analysis process of overcoming the technical defects. In fact, the cognition of the above technical defects is not common knowledge in the field, but a novel discovery made by the inventor in his research. In addition, the cause tracing of the technical defects and the thinking and analysis process of overcoming the technical defects are also the gradual analysis results of the inventor in the actual research process, and are not common knowledge in the field.
[0067] Figure 2 4 is an exemplary flow chart of a random testing method for deep learning operators according to an embodiment of the present invention.
[0068] like Figure 2 As shown, the method includes:
[0069] Step 201: Based on the correlation between a first size of a first tensor of a deep learning operator and a second size of a second tensor of a deep learning operator, determine a first expression representing the first size and a second expression representing the second size, wherein the first expression and the second expression contain the same random variables.
[0070] Deep learning operators usually include: (1) Input: The input is the data source of the operator, which can be one or more tensors. These input tensors may contain information such as features, weights, biases, etc., which are used to perform the operator's calculations; (2) Compute logic: Compute logic is the core part of the operator, which defines the operator's mathematical operations, logical operations, and transformations. Compute logic determines how the operator converts input data into output data; (3) Parameters: Some operators have learnable parameters, such as the convolution kernel of the convolution operator and the weights of the fully connected layer. These parameters are learned through the training process, allowing the operator to adapt to the data; (4) Output: The output is the calculation result of the operator, which is also one or more tensors. The output tensor contains the data processed by the compute logic and can be used as the input of the next operator.
[0071] The tensor of an operator refers to a multidimensional array (or matrix) used to store and process data in a deep learning framework. In deep learning, input data, model parameters, intermediate features, etc. can all be represented as tensors, and operators are used to calculate and transform tensors. A tensor has multiple dimensions, and the number of dimensions is called the order of the tensor (also called axis or rank). For example: a 0-order tensor is a scalar, a 1-order tensor is a vector, a 2-order tensor is a matrix, a 3-order tensor is a cube, and so on. In practical applications, a 4-order tensor is common, which is used to represent image or video data. A tensor not only contains data, but also carries the shape, data type, and other attributes of the data. It can be seen that the tensor of an operator refers to a multidimensional array used to store and process data in a deep learning framework, which is used to represent input data, model parameters, and intermediate features, and is transferred and calculated between operators.
[0072] In one embodiment, the first tensor is an input tensor or an output tensor of a deep learning operator, and the second tensor is an input tensor or an output tensor of a deep learning operator. Moreover, there is an association relationship between the first size of the first tensor and the second size of the second tensor. The first expression is used to characterize the first size, and the second expression is used to characterize the second size, wherein the first expression and the second expression contain the same random variables. The specific meaning of containing the same random variables is that at least one of the same random variables is contained in the first expression and the second expression. Among them: the number of the first tensors can be one or more, and the number of the first expressions can be one or more accordingly; the number of the second tensors can be one or more, and the number of the second expressions can be one or more accordingly. The number of random variables contained in the first expression and the second expression can be one or more.
[0073] For example (1): The first tensor can be one (or more) input tensors of a deep learning operator, and the second tensor can be another (or more) input tensors of the deep learning operator. In this case, random testing is implemented based on the expression of the input tensors of the deep learning operator (without involving the output tensors).
[0074] Example (2): The first tensor can be one (or more) input tensors of a deep learning operator, and the second tensor can be one (or more) output tensors of the deep learning operator. In this case, random testing is implemented based on the expressions of the input tensors and output tensors of the deep learning operator.
[0075] Example (3): The first tensor can be one (or more) output tensors of a deep learning operator, and the second tensor can be one (or more) input tensors of the deep learning operator. In this case, random testing is implemented based on the expressions of the input tensors and output tensors of the deep learning operator.
[0076] Example (4): The first tensor can be one (or more) output tensors of a deep learning operator, and the second tensor can be another (or more) output tensors of the deep learning operator. In this case, random testing is implemented based on the expression of the output tensor of the deep learning operator (without involving the input tensor).
[0077] For example, the first tensor and the second tensor can be implemented as: (1) Convolution Operator: The convolution operator is a key operation for image processing and computer vision tasks. It extracts the features of the input data by sliding a convolution kernel on the input data and calculating the weighted sum at each position. (2) Pooling Operator: The pooling operator is used to reduce the size of the input data and retain important features. Max pooling and average pooling are common pooling operations. They reduce the dimension of the data by selecting the maximum value or average value in the local area of the input data, thereby improving computational efficiency and reducing overfitting. (3) Activation Function Operator: The activation function operator performs a nonlinear transformation on the output of the neuron and introduces the nonlinear ability of the network. Common activation functions include ReLU (rectified linear unit), Sigmoid and Tanh, etc.
[0078] The above exemplary descriptions are typical examples of deep learning operators. Those skilled in the art will appreciate that such descriptions are merely exemplary and are not intended to limit the scope of protection of the embodiments of the present invention.
[0079] In one embodiment, the deep learning operator is a convolution operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following:
[0080] (1) The input channel size of the convolution input tensor of the deep learning operator is the same as the input channel size of the convolution weight tensor of the deep learning operator.
[0081] (2) The output channel size of the convolution output tensor of the deep learning operator is the same as the output channel size of the convolution weight tensor of the deep learning operator.
[0082] (3) The height size of the convolution output tensor of the deep learning operator is equal to (input_height+2×padding–dilation×(kernel_height_size-1)–1) / stride+1, where input_height is the height size of the convolution input tensor of the deep learning operator; padding is the padding parameter of the deep learning operator; dilation is the expansion parameter of the deep learning operator; kernel_height_size is the height size of the convolution kernel of the convolution weight tensor of the deep learning operator; stride is the step size of the deep learning operator.
[0083] (4) The width size of the convolution output tensor of the deep learning operator is equal to (input_width+2×padding–dilation×(kernel_width_size-1)–1) / stride+1, where input_width is the height size of the convolution weight tensor of the deep learning operator; padding is the padding parameter of the deep learning operator; dilation is the expansion parameter of the deep learning operator; kernel_width_size is the width size of the convolution kernel of the convolution weight tensor of the deep learning operator; stride is the step size of the deep learning operator.
[0084] In one embodiment, the deep learning operator is a matrix multiplication operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following:
[0085] (1) When the transpose of the first input tensor of the matrix multiplication operator is False and the transpose of the second input tensor of the matrix multiplication operator is False, the size of the second dimension of the first input tensor is the same as the size of the first dimension of the second input tensor, the size of the first dimension of the output tensor of the matrix multiplication operator is the same as the size of the first dimension of the first input tensor, and the size of the second dimension of the output tensor of the matrix multiplication operator is the same as the size of the second dimension of the second input tensor.
[0086] (2) When the transpose of the first input tensor of the matrix multiplication operator is True and the transpose of the second input tensor of the matrix multiplication operator is False, the size of the first dimension of the first input tensor is the same as the size of the first dimension of the second input tensor, the size of the first dimension of the output tensor of the matrix multiplication operator is the same as the size of the second dimension of the first input tensor, and the size of the second dimension of the output tensor of the matrix multiplication operator is the same as the size of the second dimension of the second input tensor.
[0087] (3) When the transpose of the first input tensor of the matrix multiplication operator is false and the transpose of the second input tensor of the matrix multiplication operator is true, the size of the second dimension of the first input tensor is the same as the size of the second dimension of the second input tensor, the size of the first dimension of the output tensor of the matrix multiplication operator is the same as the size of the first dimension of the first input tensor, and the size of the second dimension of the output tensor of the matrix multiplication operator is the same as the size of the first dimension of the second input tensor.
[0088] (4) When the transpose of the first input tensor of the matrix multiplication operator is true and the transpose of the second input tensor of the matrix multiplication operator is true, the size of the first dimension of the first input tensor is the same as the size of the second dimension of the second input tensor, the size of the first dimension of the output tensor of the matrix multiplication operator is the same as the size of the second dimension of the first input tensor, and the size of the second dimension of the output tensor of the matrix multiplication operator is the same as the size of the first dimension of the second input tensor.
[0089] In one embodiment, the deep learning operator is a bias add operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following:
[0090] (1) The bias input tensor size of the bias vector addition operator is the same as the channel size of the feature input tensor of the bias vector addition operator.
[0091] (2) The size of the output tensor of the bias vector addition operator is the same as the feature input size of the feature input tensor of the bias vector addition operator.
[0092] In one embodiment, the deep learning operator is a pointwise operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following:
[0093] (1) The corresponding dimensions of the two input tensors of the point-by-point operator are the same size or 1, where a dimension of 1 indicates broadcasting in that dimension, and the point-by-point operator supports broadcasting;
[0094] (2) The size of each dimension of the output tensor of a point-by-point operator is the same as the maximum value of the size of the corresponding dimension of the input tensor.
[0095] In one embodiment, the deep learning operator is a group class operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes: the channel size of the input tensor in the group convolution (group conv) operation and the group normalization (group norm) operation of the group class operator is an integer multiple of the group size of the group class operator.
[0096] In one embodiment, the deep learning operator is an attention operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following:
[0097] (1) When the first dimension of the query input tensor, key input tensor, and value input tensor of the attention operator is the product of the batch size and the number of heads (batch_size×head_num), the first dimension of the query input tensor, key input tensor, and value input tensor has the same size.
[0098] (2) When the second dimension of the query input tensor, key input tensor, and value input tensor of the attention operator is the sequence length (seq_len), the second dimension of the key input tensor and the value input tensor have the same size.
[0099] (3) When the third dimension of the query input tensor, key input tensor, and value input tensor of the attention operator is the head size (head_size), the third dimension of the query input tensor, key input tensor, and value input tensor has the same size.
[0100] (4) The size of the output tensor of the attention operator is the same as the size of the query input tensor.
[0101] The above exemplarily describes the association relationship between the input tensors and between the output tensors of the deep learning operators. Those skilled in the art will appreciate that this description is merely exemplary and is not intended to limit the scope of protection of the embodiments of the present invention.
[0102] Step 202: Determine a random value of a random variable.
[0103] In one embodiment, step 202 includes:
[0104] (1) Based on the attribute parameters of the deep learning operator, determine the value range of the random variable; within the value range, determine the random value of the random variable.
[0105] For example, when the deep learning operator is a convolution operator, the value range of the common random variables in the shape expressions of the two input tensors and the output tensor of the convolution operator can be determined based on the attribute parameters of the convolution operator (for example, the batch support range, the support range of output channels and input channels, the support range of input height and weight, and the support range of convolution kernel height and weight).
[0106] (2) Based on a value range setting instruction triggered by a user, a value range of the random variable is determined; within the value range, a random value of the random variable is determined.
[0107] Here, the value range of the random variable is directly determined based on the value range setting instruction issued by the user.
[0108] Step 203: Determine the first size and the second size based on the random value.
[0109] Here, by inputting random values into the first expression and the second expression, specific values of the first size and the second size can be obtained.
[0110] Step 204: Test the deep learning operator based on the first size and the second size.
[0111] In one embodiment, step 204 specifically includes at least one of the following:
[0112] (1) When the first tensor and the second tensor are both input tensors, generate a first tensor use case that conforms to the first size and a second tensor use case that conforms to the second size; input the first tensor use case and the second tensor use case into a benchmark deep learning operator (which can be regarded as determining a deep learning operator that meets the test requirements) to obtain a benchmark output tensor use case; input the first tensor use case and the second tensor use case into the deep learning operator to obtain an output tensor use case; determine the test result of the deep learning operator based on the comparison result of the output tensor use case and the benchmark output tensor use case.
[0113] For example, when the difference between the output tensor use case and the benchmark output tensor use case is less than or equal to a predetermined threshold, the deep learning operator is deemed qualified, otherwise the deep learning operator is deemed unqualified.
[0114] (2) When the first tensor is an input tensor and the second tensor is an output tensor, a first tensor use case that meets the first size is generated; the first tensor use case is input into the deep learning operator to obtain an output tensor use case; when the size of the output tensor use case does not match the second size, it is determined that the deep learning operator fails the test.
[0115] Here, when the size of the output tensor case does not match the second size, it can be quickly determined that the deep learning operator fails the test.
[0116] (3) When the first tensor is an input tensor and the second tensor is an output tensor, generate a first tensor use case that meets the first size; input the first tensor use case into the deep learning operator to obtain an output tensor use case; when the size of the output tensor use case matches the second size, input the first tensor use case into the benchmark deep learning operator to obtain a benchmark output tensor use case; based on the comparison result of the output tensor use case and the benchmark output tensor use case, determine the test result of the deep learning operator.
[0117] Here, when the difference between the output tensor use case and the benchmark output tensor use case is less than or equal to a predetermined threshold, the deep learning operator is deemed qualified, otherwise the deep learning operator is deemed unqualified.
[0118] In one embodiment, in step 201, based on the association between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator, determining the first expression representing the first size and the second expression representing the second size includes:
[0119] A script file containing rules is generated, wherein in the rules: an association relationship between a first size of a first tensor and a second size of a second tensor is specified based on a random variable; and the script file is called to generate a first expression and a second expression based on the rules. Therefore, the script containing rules is used to realize automatic expression generation, reduce the difficulty of testing, and improve the efficiency of testing.
[0120] The following describes the implementation of the present invention in conjunction with specific examples.
[0121] Example 1: User-generated expressions
[0122] Step 1: Users configure the random variables required for the random test of deep learning operators through the configuration file, such as defining the name of the random variable and its random range. Each random variable can be understood as an independent random process, and there is no correlation between the random variables. For example, if the definition is: a=[100~200], b=[1~100], it means defining two random variables (a, b), where the value range of random variable a is 100 to 200, and the value range of random variable b is 1 to 100.
[0123] Step 2: Based on the defined random variables, the user uses the configuration file to describe the expressions of the shapes of the input and output tensors of the deep learning operators. The expressions characterize the relationship between the sizes of the input and output tensors (for example, the input channel size of the convolution input tensor size is the same as the input channel size of the convolution weight tensor size, the output channel size of the convolution output tensor size is the same as the output channel size of the convolution weight tensor size, etc.). Specifically, the expressions can contain random variables, constants, and basic operations.
[0124] For example, take the matrix multiplication operator as an example, which contains two input tensors (i.e., the convolution input tensor input1 and the convolution weight tensor input2) and one output tensor (i.e., the convolution output tensor output). Assume that the input tensor and output tensor of the matrix multiplication operator are both two-dimensional tensors. Based on the two random variables (a, b) defined above, the user gives the expressions of the convolution input tensor input1, the convolution weight tensor input2, and the convolution output tensor output respectively. Among them:
[0125] The expression of input1 is: input1 shape: [a, 2×b];
[0126] The expression of input2 is: shape: [2×b, a];
[0127] The expression of output is: shape: [a, a];
[0128] It can be seen that one input tensor (input1) of the matrix multiplication operator is a two-dimensional tensor, whose first and second dimensions are a and 2×b respectively. Another input tensor (input2) of the matrix multiplication operator is also a two-dimensional tensor, whose first and second dimensions are 2×b and a respectively. The output tensor (output) of the matrix multiplication operator is also a two-dimensional tensor, whose first and second dimensions are both a. The above three expressions based on random variables a and b can describe the relationship between the shapes of these three tensors. Through this richly correlated expression, legal test configurations can be effectively generated.
[0129] Step 3: Generate one or more random variable combinations based on the configuration of random variables. For example, assume that a=150, b=10 are obtained randomly. Substituting a=150 and b=10 into the above three expressions respectively, a set of shape combinations can be randomly generated. That is: input1 shape: [150, 20], input2 shape: [20, 150], output shape: [150, 150].
[0130] Step 4: Generate one or more sets of random test cases based on the generated random shape combinations (i.e., input1 shape: [150, 20], input2 shape: [20, 150], output shape: [150, 150]). Then, you can use this or more sets of random test cases to test the matrix multiplication operator.
[0131] It can be seen that an expression can be generated based on the user's prior knowledge to quickly determine the random size of the tensor that meets the association relationship and is used to perform the test, rather than blindly generating the size completely randomly. This not only reduces or overcomes redundant illegal shapes, but also eliminates the need to perform filtering processing, thereby reducing the measurement workload and improving test efficiency.
[0132] Example 2: Generate expressions in an automated way
[0133] Taking the matrix multiplication operator as an example, it contains two input tensors (i.e., the convolution input tensor input1 and the convolution weight tensor input2) and one output tensor (i.e., the convolution output tensor output).
[0134] Step 1: According to the relationship between input tensors and the relationship between input tensors and output tensors, set up a script file containing two rules.
[0135] Rule 1: The input channel size of the convolution input tensor input1 dimension is the same as the input channel size in the convolution weight tensor input2 dimension.
[0136] Rule 2: The output channel size in the convolution output tensor output dimension is the same as the output channel size in the convolution weight tensor input2 dimension.
[0137] Step 2: Based on the default input (for example, specifying the dimension of the matrix multiplication operator as 4; batch = 16; padding = 1; stride = 1; dilation = 1) and editable default rules (for example, width equals height), call the script file to execute rules 1 and 2, and automatically generate the following expression:
[0138] The expression of the convolution input tensor input1 is: [A, B, C, D];
[0139] The expression of the convolution weight tensor input2 is: [E, B, F, G];
[0140] The expression of the convolution output tensor output is: [A, E, (C + 2×padding–dilation×(F - 1)–1) / stride + 1, (D + 2×padding–dilation×(G - 1) – 1) / stride + 1];
[0141] Among them: A, B, C, D, E and F are all random variables.
[0142] Step 3: Using the attribute parameters of the convolution operator (for example, batch supports 1~1024, output channels and input channels support 1~8192, input height and weight support 1~8192, convolution kernel height and weight support 1~7), determine the random range of the random variable: A=1~1024, B=1~8192, C=1~8192, D=1~8192, E=1~8192, F=1~7, G=1~7.
[0143] Step 4: Randomly generate random values of the seven random variables within their respective random ranges. For example, A=10, B=31, C=52, D=63, E=24, F=3, G=1.
[0144] Step 5: Input these seven random values (i.e., A=10, B=31, C=52, D=63, E=24, F=3, G=1) into the above expression. The random shape combinations that can be obtained include: convolution input tensor input1: [10, 31, 52, 63]; convolution weight tensor input2: [24, 31, 3, 1]; convolution output tensor output: [10, 24, 18, 65].
[0145] Step 6: Generate one or more groups of random test cases based on the generated random shape combinations (i.e., convolution input tensor input1: [10, 31, 52, 63]; convolution weight tensor input2: [24, 31, 3, 1]; convolution output tensor output: [10, 24, 18, 65]), and then use this or more groups of random test cases to test the matrix multiplication operator.
[0146] It can be seen that the use of scripts containing rules can realize automatic expression generation, reduce the difficulty of testing, and improve testing efficiency. Moreover, the use of expressions to quickly determine the random size of the tensor used to perform the test that meets the association relationship, rather than blindly generating the size completely randomly, not only reduces or overcomes redundant illegal shapes, but also eliminates the need for filtering processing, thereby reducing the measurement workload and improving testing efficiency.
[0147] Therefore, in the embodiment of the present invention, independent random variables are first generated, and then the legal shape combination configuration can be directly generated through the shape expression, which improves the efficiency of generating the legal shape combination configuration of the operator, and no longer needs to generate a large number of shape combination configurations and then filter them. In addition, the expression of the embodiment of the present invention can include random variables, constants and basic operators, and can flexibly express the random range of shapes and the relationship between the shapes of input tensors and output tensors. It is no longer necessary to provide complex constraint descriptions, and the test efficiency is also improved.
[0148] Based on the above description, an embodiment of the present invention further proposes a random testing device for a deep learning operator.
[0149] Figure 3 FIG. 1 is an exemplary structural diagram of a random testing device for a deep learning operator according to an embodiment of the present invention. Figure 3As shown, the random testing device 300 for the deep learning operator includes: a first determination module 301, which is used to determine a first expression representing the first size and a second expression representing the second size based on the association between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator, wherein the first expression and the second expression contain the same random variable; a second determination module 302, which is used to determine the random value of the random variable; a third determination module 303, which is used to determine the first size and the second size based on the random value; a testing module 304, which is used to test the deep learning operator based on the first size and the second size.
[0150] In one embodiment, the first tensor is the input tensor or output tensor of the deep learning operator, and the second tensor is the input tensor or output tensor of the deep learning operator; the second determination module 302 determines the value range of the random variable based on the attribute parameters of the deep learning operator or based on the value range setting instruction triggered by the user; and determines the random value of the random variable within the value range.
[0151] In one embodiment, the deep learning operator is a convolution operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following: the input channel size of the convolution input tensor of the deep learning operator is the same as the input channel size of the convolution weight tensor of the deep learning operator; the output channel size of the convolution output tensor of the deep learning operator is the same as the output channel size of the convolution weight tensor of the deep learning operator; the height size of the convolution output tensor of the deep learning operator is equal to (input_height+2×padding–dilation×(kernel_height_size-1)–1) / stride+1, where input_height is the height size of the convolution input tensor of the deep learning operator; padding is the padding of the deep learning operator Parameters; dilation is the expansion parameter of the deep learning operator; kernel_height_size is the height of the convolution kernel of the convolution weight tensor of the deep learning operator; stride is the step size of the deep learning operator; the width of the convolution output tensor of the deep learning operator is equal to (input_width+2×padding–dilation×(kernel_width_size-1)–1) / stride+1, where input_width is the width of the convolution input tensor of the deep learning operator; padding is the padding parameter of the deep learning operator; dilation is the expansion parameter of the deep learning operator; kernel_width_size is the width of the convolution kernel of the convolution weight tensor of the deep learning operator; stride is the step size of the deep learning operator.
[0152] In one embodiment, the deep learning operator is a matrix multiplication operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following: when the transpose of the first input tensor of the matrix multiplication operator is false and the transpose of the second input tensor of the matrix multiplication operator is false, the second dimension size of the first input tensor is the same as the first dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the second dimension size of the second input tensor; when the transpose of the first input tensor of the matrix multiplication operator is true and the transpose of the second input tensor of the matrix multiplication operator is false, the first dimension size of the first input tensor is the same as the first dimension size of the second input tensor, and the first dimension size of the output tensor of the matrix multiplication operator is the same as the second dimension size of the first input tensor. The size is the same, the second dimension size of the output tensor of the matrix multiplication operator is the same as the second dimension size of the second input tensor; when the transpose of the first input tensor of the matrix multiplication operator is false and the transpose of the second input tensor of the matrix multiplication operator is true, the second dimension size of the first input tensor is the same as the second dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the second input tensor; when the transpose of the first input tensor of the matrix multiplication operator is true and the transpose of the second input tensor of the matrix multiplication operator is true, the first dimension size of the first input tensor is the same as the second dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the second dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the second input tensor.
[0153] In one embodiment, the deep learning operator is a bias vector addition operator, and the association relationship between a first size of a first tensor of the deep learning operator and a second size of a second tensor of the deep learning operator includes at least one of the following: a bias input size of a bias input tensor of the bias vector addition operator is the same as a channel size of a feature input tensor of the bias vector addition operator; a size of an output tensor of the bias vector addition operator is the same as a feature input size of a feature input tensor of the bias vector addition operator.
[0154] In one embodiment, the deep learning operator is a point-by-point operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following: the sizes of corresponding dimensions of the two input tensors of the point-by-point operator are the same or 1, wherein a dimension of 1 indicates broadcasting in the dimension, and the point-by-point operator supports broadcasting; the sizes of each dimension of the output tensor of the point-by-point operator are the same as the maximum value of the sizes of the corresponding dimensions of the input tensors.
[0155] In one embodiment, the deep learning operator is a grouping operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes: the channel size of the input tensor in the group convolution operation and the group normalization operation of the grouping operator is an integer multiple of the group size of the grouping operator.
[0156] In one embodiment, the deep learning operator is an attention operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following: when the first dimension of the query input tensor, key input tensor, and value input tensor of the attention operator is the product of the batch size and the number of heads, the sizes of the first dimensions of the query input tensor, key input tensor, and value input tensor are the same; when the second dimension of the query input tensor, key input tensor, and value input tensor of the attention operator is the sequence length, the sizes of the second dimensions of the key input tensor and the value input tensor are the same; when the third dimension of the query input tensor, key input tensor, and value input tensor of the attention operator is the head size, the sizes of the third dimensions of the query input tensor, key input tensor, and value input tensor are the same; the size of the output tensor of the attention operator is the same as the size of the query input tensor.
[0157] In one embodiment, the first determination module 301 is used to generate a script file containing rules, wherein in the rules: an association relationship between a first size of a first tensor and a second size of a second tensor is specified based on a random variable; and the script file is called to generate a first expression and a second expression based on the rules.
[0158] In one embodiment, the test module 304 is used to perform at least one of the following: when the first tensor and the second tensor are both input tensors, generate a first tensor use case that conforms to the first size and a second tensor use case that conforms to the second size; input the first tensor use case and the second tensor use case into a benchmark deep learning operator to obtain a benchmark output tensor use case; input the first tensor use case and the second tensor use case into the deep learning operator to obtain an output tensor use case; based on the comparison result of the output tensor use case and the benchmark output tensor use case, determine the test result of the deep learning operator; when the first tensor is the input tensor and the second tensor is the output tensor, generate a first tensor use case that conforms to the first size. A tensor use case; inputting the first tensor use case into a deep learning operator to obtain an output tensor use case; when the size of the output tensor use case does not match the second size, determining that the deep learning operator fails the test; when the first tensor is an input tensor and the second tensor is an output tensor, generating a first tensor use case that meets the first size; inputting the first tensor use case into the deep learning operator to obtain an output tensor use case; when the size of the output tensor use case matches the second size, inputting the first tensor use case into a benchmark deep learning operator to obtain a benchmark output tensor use case; based on the comparison result of the output tensor use case and the benchmark output tensor use case, determining the test result of the deep learning operator.
[0159] In summary, in an embodiment of the present invention, based on the association between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator, a first expression characterizing the first size and a second expression characterizing the second size are determined, wherein the first expression and the second expression contain the same random variable; a random value of the random variable is determined; based on the random value, the first size and the second size are determined; based on the first size and the second size, the deep learning operator is tested. Therefore, the embodiment of the present invention uses an expression containing the same random variable to constrain the association between the sizes, and can use expressions and random variables to quickly determine the random size of the tensor that meets the association and is used to perform the test, rather than blindly generating the size completely randomly, which not only reduces or overcomes redundant illegal shapes, but also eliminates the need to perform filtering processing, thereby reducing the measurement workload and improving the test efficiency.
[0160] Moreover, the use of scripts containing rules enables automatic expression generation, which reduces the difficulty of testing and improves testing efficiency. In addition, during the test process, when the size of the output tensor use case does not match the size of the output tensor, it can be quickly determined that the deep learning operator has failed the test, which improves the test speed.
[0161] The embodiment of the present invention further provides an electronic device having a processor-memory architecture. Figure 4 is a structural diagram of an electronic device according to an embodiment of the present invention. Figure 4As shown, the electronic device 400 includes a processor 401, a memory 402, and a computer program stored in the memory 402 and executable on the processor 401. When the computer program is executed by the processor 401, any of the above-mentioned random testing methods for deep learning operators is implemented. Among them, the memory 402 can be specifically implemented as a variety of storage media such as an electrically erasable programmable read-only memory (EEPROM), a flash memory (Flash memory), and a programmable program read-only memory (PROM). The processor 401 can be implemented as including one or more central processing units or one or more field programmable gate arrays, wherein the field programmable gate array integrates one or more central processing unit cores. Specifically, the central processing unit or the central processing unit core can be implemented as a CPU, a GPU, a GPGPU, an MCU or a DSP, and the like.
[0162] It should be noted that not all steps and modules in the above processes and structure diagrams are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The division of each module is only for the convenience of describing the functional division adopted. In actual implementation, a module can be implemented by multiple modules, and the functions of multiple modules can also be implemented by the same module. These modules can be located in the same device or in different devices.
[0163] The hardware modules in each embodiment may be implemented mechanically or electronically. For example, a hardware module may include a specially designed permanent circuit or logic device (such as a dedicated processor, such as an FPGA or ASIC) to perform a specific operation. For example, specific operations can be performed in various types of chips (for example, artificial intelligence chips). The hardware module may also include a programmable logic device or circuit (such as a general-purpose processor or other programmable processor) temporarily configured by software to perform specific operations. As for whether to implement the hardware module mechanically, or using a dedicated permanent circuit, or a temporarily configured circuit (such as configured by software), it can be decided based on cost and time considerations.
[0164] The present invention also provides a machine-readable storage medium, storing instructions for a machine to perform a method as described in the present application. Specifically, a system or device equipped with a storage medium can be provided, on which a software program code for implementing the functions of any of the embodiments described in the above embodiments is stored, and the computer (or CPU or MPU) of the system or device reads out and executes the program code stored in the storage medium. In addition, the operating system operated on the computer can also be made to complete part or all of the actual operations by instructions based on the program code. The program code read out from the storage medium can also be written to a memory provided in an expansion board inserted into the computer or to a memory provided in an expansion unit connected to the computer, and then the CPU installed on the expansion board or the expansion unit is made to perform part and all of the actual operations based on the instructions of the program code, thereby realizing the functions of any of the embodiments described in the above embodiments. The storage medium implementation for providing the program code includes a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card and a ROM. Alternatively, the program code can be downloaded from a server computer or a cloud by a communication network.
[0165] In this article, "schematic" means "serving as an example, instance or explanation", and any diagram or implementation method described as "schematic" in this article should not be interpreted as a more preferred or more advantageous technical solution. In order to make the drawings concise, only the parts related to the present invention are schematically shown in each figure, and do not represent the actual structure of the product. In addition, in order to make the drawings concise and easy to understand, in some figures, only one of the parts with the same structure or function is schematically drawn, or only one of them is marked. In this article, "one" does not mean that the number of the relevant parts of the present invention is limited to "only one", and "one" does not mean that the number of the relevant parts of the present invention is "more than one". In this article, "upper", "lower", "front", "back", "left", "right", "inside", "outside", etc. are only used to indicate the relative position relationship between the relevant parts, rather than to limit the absolute position of these relevant parts.
[0166] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A random testing method for deep learning operators, characterized in that: The method is executed by a processor, and the method includes: Determine, based on an association relationship between a first size of a first tensor of a deep learning operator and a second size of a second tensor of the deep learning operator, a first expression representing the first size and a second expression representing the second size, wherein the first expression and the second expression contain the same random variable; determining a random value of the random variable; Based on the random value, determining the first size and the second size; Based on the first size and the second size, testing the deep learning operator, the deep learning operator comprising: a convolution operator in image processing and computer vision tasks; A neural network for image processing and computer vision tasks is constructed based on the convolution operator to extract features of input image data represented as a three-dimensional tensor; wherein the convolution operator slides a convolution kernel on the input image data and calculates a weighted sum at each position to extract features of the input image data, wherein the three-dimensional tensor corresponds to width, height, and number of channels respectively; The association relationship between the first size of the first tensor of the convolution operator and the second size of the second tensor of the convolution operator includes at least one of the following: The input channel size of the convolution input tensor of the convolution operator is the same as the input channel size of the convolution weight tensor of the convolution operator; The output channel size of the convolution output tensor of the convolution operator is the same as the output channel size of the convolution weight tensor of the convolution operator; The height of the convolution output tensor of the convolution operator is equal to (input_height+2×padding–dilation×(kernel_height_size-1)–1) / stride+1, where input_height is the height of the convolution input tensor of the convolution operator; padding is the padding parameter of the convolution operator; dilation is the expansion parameter of the convolution operator; kernel_height_size is the height of the convolution kernel of the convolution weight tensor of the convolution operator; stride is the step size of the convolution operator; The width of the convolution output tensor of the convolution operator is equal to (input_width+2×padding–dilation×(kernel_width_size-1)–1) / stride+1, where input_width is the width of the convolution input tensor of the convolution operator; padding is the padding parameter of the convolution operator; dilation is the expansion parameter of the convolution operator; kernel_width_size is the convolution kernel width of the convolution weight tensor of the convolution operator; stride is the step size of the convolution operator.
2. The method according to claim 1, characterized in that The first tensor is an input tensor or an output tensor of the deep learning operator, and the second tensor is an input tensor or an output tensor of the deep learning operator; Determining the random value of the random variable includes: Determining a value range of the random variable based on an attribute parameter of the deep learning operator or based on a value range setting instruction triggered by a user; In the value range, a random value of the random variable is determined.
3. The method according to claim 1, characterized in that The deep learning operator is a matrix multiplication operator, and the association relationship between a first size of a first tensor of the deep learning operator and a second size of a second tensor of the deep learning operator includes at least one of the following: When the transpose of the first input tensor of the matrix multiplication operator is false and the transpose of the second input tensor of the matrix multiplication operator is false, the second dimension size of the first input tensor is the same as the first dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the second dimension size of the second input tensor; When the transpose of the first input tensor of the matrix multiplication operator is true and the transpose of the second input tensor of the matrix multiplication operator is false, the size of the first dimension of the first input tensor is the same as the size of the first dimension of the second input tensor, the size of the first dimension of the output tensor of the matrix multiplication operator is the same as the size of the second dimension of the first input tensor, and the size of the second dimension of the output tensor of the matrix multiplication operator is the same as the size of the second dimension of the second input tensor; When the transpose of the first input tensor of the matrix multiplication operator is false and the transpose of the second input tensor of the matrix multiplication operator is true, the second dimension size of the first input tensor is the same as the second dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the second input tensor; When the transpose of the first input tensor of the matrix multiplication operator is true and the transpose of the second input tensor of the matrix multiplication operator is true, the first dimension size of the first input tensor is the same as the second dimension size of the second input tensor, the first dimension size of the output tensor of the matrix multiplication operator is the same as the second dimension size of the first input tensor, and the second dimension size of the output tensor of the matrix multiplication operator is the same as the first dimension size of the second input tensor.
4. The method according to claim 1, characterized in that: The deep learning operator is a bias vector addition operator, and the association relationship between a first size of a first tensor of the deep learning operator and a second size of a second tensor of the deep learning operator includes at least one of the following: a bias input size of a bias input tensor of the bias vector addition operator is the same as a channel size of a feature input tensor of the bias vector addition operator; a size of an output tensor of the bias vector addition operator is the same as a feature input size of a feature input tensor of the bias vector addition operator; or The deep learning operator is a point-by-point operator, and the association relationship between a first size of a first tensor of the deep learning operator and a second size of a second tensor of the deep learning operator includes at least one of the following: the sizes of corresponding dimensions of two input tensors of the point-by-point operator are the same or 1, wherein a dimension of 1 indicates broadcasting in the dimension, and the point-by-point operator supports broadcasting; the sizes of each dimension of the output tensor of the point-by-point operator are the same as the maximum value of the sizes of the corresponding dimensions of the input tensors; or The deep learning operator is a grouping operator, and the association relationship between a first size of a first tensor of the deep learning operator and a second size of a second tensor of the deep learning operator includes: a channel size of an input tensor in a group convolution operation and a group normalization operation of the grouping operator is an integer multiple of a group size of the grouping operator; or The deep learning operator is an attention operator, and the association relationship between the first size of the first tensor of the deep learning operator and the second size of the second tensor of the deep learning operator includes at least one of the following: when the first dimension of the query input tensor, key input tensor and value input tensor of the attention operator is the product of the batch size and the number of heads, the sizes of the first dimensions of the query input tensor, key input tensor and value input tensor are the same; when the second dimension of the query input tensor, key input tensor and value input tensor of the attention operator is the sequence length, the sizes of the second dimensions of the key input tensor and the value input tensor are the same; when the third dimension of the query input tensor, key input tensor and value input tensor of the attention operator is the head size, the sizes of the third dimensions of the query input tensor, key input tensor and value input tensor are the same; the size of the output tensor of the attention operator is the same as the size of the query input tensor.
5. The method according to any one of claims 1 to 4, characterized in that The determining of a first expression representing the first size and a second expression representing the second size based on an association relationship between a first size of a first tensor of a deep learning operator and a second size of a second tensor of the deep learning operator comprises: Generate a script file containing rules, wherein in the rules: specify the association relationship between the first size of the first tensor and the second size of the second tensor based on the random variable; The script file is called to generate the first expression and the second expression based on the rule.
6. The method according to any one of claims 1 to 4, characterized in that The testing the deep learning operator based on the first size and the second size includes at least one of the following: When both the first tensor and the second tensor are input tensors, generating a first tensor use case conforming to the first size and a second tensor use case conforming to the second size; inputting the first tensor use case and the second tensor use case into a benchmark deep learning operator to obtain a benchmark output tensor use case; Input the first tensor use case and the second tensor use case into the deep learning operator to obtain an output tensor use case; Determining a test result of the deep learning operator based on a comparison result of the output tensor use case with a benchmark output tensor use case; When the first tensor is an input tensor and the second tensor is an output tensor, generating a first tensor use case that meets the first size; inputting the first tensor use case into the deep learning operator to obtain an output tensor use case; When the size of the output tensor use case does not match the second size, determining that the deep learning operator fails the test; When the first tensor is an input tensor and the second tensor is an output tensor, generating a first tensor use case that meets the first size; inputting the first tensor use case into the deep learning operator to obtain an output tensor use case; When the size of the output tensor use case matches the second size, inputting the first tensor use case into a benchmark deep learning operator to obtain a benchmark output tensor use case; Based on the comparison result of the output tensor use case and the benchmark output tensor use case, a test result of the deep learning operator is determined.
7. An execution device of a random testing method for a deep learning operator, characterized in that: The execution device includes a processor, and the execution device includes: A first determination module is configured to determine, based on an association relationship between a first size of a first tensor of a deep learning operator and a second size of a second tensor of the deep learning operator, a first expression representing the first size and a second expression representing the second size, wherein the first expression and the second expression contain the same random variable; A second determination module, used to determine the random value of the random variable; A third determining module, configured to determine the first size and the second size based on the random value; A testing module, configured to test the deep learning operator based on the first size and the second size, wherein the deep learning operator includes: a convolution operator in image processing and computer vision tasks; constructing a neural network for image processing and computer vision tasks based on the convolution operator to extract features of input image data represented as a three-dimensional tensor; wherein the convolution operator slides a convolution kernel on the input image data and calculates a weighted sum at each position to extract features of the input image data, wherein the three-dimensional tensor corresponds to width, height, and number of channels, respectively; The association relationship between the first size of the first tensor of the convolution operator and the second size of the second tensor of the convolution operator includes at least one of the following: The input channel size of the convolution input tensor of the convolution operator is the same as the input channel size of the convolution weight tensor of the convolution operator; The output channel size of the convolution output tensor of the convolution operator is the same as the output channel size of the convolution weight tensor of the convolution operator; The height of the convolution output tensor of the convolution operator is equal to (input_height+2×padding–dilation×(kernel_height_size-1)–1) / stride+1, where input_height is the height of the convolution input tensor of the convolution operator; padding is the padding parameter of the convolution operator; dilation is the expansion parameter of the convolution operator; kernel_height_size is the height of the convolution kernel of the convolution weight tensor of the convolution operator; stride is the step size of the convolution operator; The width of the convolution output tensor of the convolution operator is equal to (input_width+2×padding–dilation×(kernel_width_size-1)–1) / stride+1, where input_width is the width of the convolution input tensor of the convolution operator; padding is the padding parameter of the convolution operator; dilation is the expansion parameter of the convolution operator; kernel_width_size is the convolution kernel width of the convolution weight tensor of the convolution operator; stride is the step size of the convolution operator.
8. An electronic device, characterized in that: include: Memory; processor; The memory stores an application program executable by the processor, which is used to enable the processor to execute the random testing method for the deep learning operator as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, cause the processor to execute the random testing method for a deep learning operator according to any one of claims 1 to 6.
