Pruning method of neural network and data processing method and device
By using a smaller-granularity semi-structured sparse method for progressive pruning in the neural network, the problem of insufficient accuracy and inference performance caused by the lack of regularity of the sparse method in the existing technology is solved, and the accuracy and acceleration are achieved. to achieve a balancing effect.
Patent Information
- Application Number
- CN202310470198.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-25
- Publication Date
- 2024-10-25
AI Technical Summary
In existing neural network pruning methods, the selection of non-critical weights in a sparse manner lacks regularity, resulting in insufficient inference performance and accuracy, and it is difficult to optimize the calculation amount and power consumption.
Using a smaller-granularity semi-structured sparse method, by obtaining the weight tensor of the neural network to be pruned, progressive pruning is performed in an increasing sparsity manner, and only one non-zero element in every K pruning vectors is selected to participate. Compute, reduce the amount of calculation and reduce power consumption.
It achieves a balance between accuracy and acceleration, improves the application accuracy and computing speed of neural networks, is suitable for acceleration hardware, and reduces the calculation amount and power consumption of the model.
Smart Images

Figure CN118839740A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of deep learning technology, and in particular to a neural network pruning method, a data processing method and a device. Background Art
[0002] At present, the scale of neural networks is constantly increasing, and the number of parameters and the amount of calculation are also increasing. In order to reduce the number of parameters and the amount of calculation, pruning, quantization, distillation or lightweight model design can be used. Pruning is widely used. Pruning refers to resetting some non-critical weights to 0 in redundant large models to achieve a sparse model. The selection method of the part that needs to be pruned can adopt any sparse method, but the distribution position of the 0 element in any pruning method is relatively random. Since there is no rule to follow, it does not bring about the optimization of reasoning performance. The selection method of the part that needs to be pruned can also adopt a structured sparse method, but in the structured sparse method, the weights of the convolution are pruned according to the channel, the sparse granularity is coarse, and the accuracy is low. Summary of the invention
[0003] The embodiments of the present application provide a neural network pruning method, a data processing method and a device, so as to provide a pruning method that balances reasoning performance and accuracy.
[0004] In a first aspect, an embodiment of the present application provides a pruning method for a neural network, which can be performed by a pruning device, such as a processor in the pruning device. The method includes: obtaining a first weight tensor of the neural network to be pruned; performing at least one pruning process on the first weight tensor to obtain a second weight tensor; wherein the second weight tensor includes multiple data blocks, each of which is composed of K pruning vectors, and each pruning vector is composed of M weights; K and M are both positive integers; the weight corresponding to the first position in the first pruning vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the other pruning vectors in the first data block except the first pruning vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruning vector is any pruning vector in the first data block.
[0005] Compared with the single-channel or block-based sparse method, the embodiment of the present application uses a smaller granularity for sparseness, which can improve the accuracy of the application of the network model. Compared with the use of any sparse method, sparseness is performed in a complementary manner, with certain rules, which is understood as a kind of semi-structured sparseness. Therefore, there is no need to use dense calculations in the reasoning stage, which reduces the amount of calculation of the model. In the pruning method provided in the embodiment of the present application, only one non-zero element is selected for the same position of each K pruning vector to participate in the calculation. Since the other weights at the same position are all zero elements, the operation speed can be improved and the power consumption can be reduced when applied to acceleration hardware. The solution provided in the embodiment of the present application can balance accuracy and acceleration.
[0006] In one possible design, the sparsity S of the second weight tensor satisfies: S = 1-1 / K. In the above scheme, the number of pruned vectors can be determined based on the sparsity, providing a feasible way to make the position where the non-zero element in a pruned vector is located, and other pruned vectors in the data block to which the pruned vector belongs have zero elements at that position.
[0007] In a possible design, the pruning process is performed N times in a manner of increasing sparsity. The accuracy of the network can be improved by using a progressive sparsification method.
[0008] In one possible design, the number of times N that the pruning process is performed is related to the number K of pruning vectors included in the data block and / or the sparsity of the second weight tensor.
[0009] In one possible design, the pruning process is performed a number of times that satisfies: N=S / (1-S), or N=K-1.
[0010] It can be understood that the weight tensor is pruned along each M*K. Each pruning can be understood as pruning the number of weights included in one pruning vector. Compared with pruning a considerable number of weights at a time, the accuracy of the network can be improved.
[0011] In one possible design, N = K-1, and the sparsity of the i-th pruning process satisfies:
[0012] Among them, S i Indicates the sparsity of the i-th pruning process, i is a positive integer, 1≤i <K。
[0013] In one possible design, the i-th pruning process is performed, where i is less than or equal to N, including:
[0014] A deformed three-dimensional weight tensor obtained by deforming an input four-dimensional weight tensor, wherein the three-dimensional weight tensor includes G data blocks, each data block is composed of K pruning vectors, and each pruning vector is composed of M weights;
[0015] The three-dimensional weight tensor is pruned along the K dimension, and the least important q i The weights are reset to zero to obtain the three-dimensional weight vector after the i-th pruning;
[0016] Then the three-dimensional weight tensor after the i-th pruning is deformed to obtain a deformed four-dimensional weight tensor;
[0017] Training the deformed four-dimensional weight tensor to obtain a four-dimensional weight tensor that has undergone the i-th pruning process;
[0018] Among them, the input four-dimensional weight tensor is the first weight tensor or the four-dimensional weight tensor that has undergone the i-1th pruning process.
[0019] In the above design, a progressive pruning method is adopted, and a part of the weights are reduced in each generation of training. Compared with pruning a considerable number of weights at one time, the accuracy of the network can be improved.
[0020] In one possible design, the shape of the input 4D weight tensor is (C out ,C in , FH, FW), the shape of the deformed three-dimensional weight tensor is (G, K, M); where G satisfies:
[0021]
[0022] Among them, C out represents the number of activations of the neural network output, C in represents the number of activations of the neural network input, the FH represents the kernel height of the neural network, and the FW represents the kernel width of the neural network; C i n *FH*FW=K*M, or, the C i n =K*M.
[0023] In the above design, the embodiment of the present application is in C i n or C i n *FH*FW sparse processing on the dimension can improve the accuracy compared with the outer vector wise (OVW) sparse method. The OVW sparse method is based on the C outThe sparse processing is performed on the dimension. Compared with this method, the embodiment of the present application can improve the acceleration efficiency.
[0024] In one possible design, the least important q in K dimensions is i The weights are reset to zero, including:
[0025] The q with the smallest L1 norm in K dimensions i The weights are reset to zero; or
[0026] The q with the smallest L2 norm in K dimensions i The weights are reset to zero.
[0027] In one possible design, when the training process adjusts all weights, the q i =i; or,
[0028] When the training process adjusts only the unpruned weights, the q i =1.
[0029] In a second aspect, an embodiment of the present application provides a data processing method, including:
[0030] Acquire data to be processed, and generate a vector representation of the data to be processed;
[0031] Performing calculations on the vector representation of the data to be processed and the weight tensor included in the neural network to obtain a processing result of the data to be processed;
[0032] Among them, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each of which is composed of K pruned vectors, and each pruned vector is composed of M weights; K and M are both positive integers; the weight corresponding to the first position in the first pruned vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the other pruned vectors in the first data block except the first pruned vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruned vector is any pruned vector in the first data block.
[0033] In the solution provided by the embodiment of the present application, only one non-zero element is selected at the same position of each K pruning vectors to participate in the calculation. Since the other weights at the same position are all zero elements, the calculation speed can be increased and the power consumption can be reduced when applied to acceleration hardware. The solution provided by the embodiment of the present application can balance accuracy and acceleration.
[0034] In one possible design, performing calculations on the vector representation of the data to be processed and the weight tensor included in the neural network includes:
[0035] The vector representation of the data to be processed is a first matrix, and the weight tensor is processed to obtain a second matrix and the index of the non-zero elements in the second matrix;
[0036] A multiplication operation is performed on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result.
[0037] In a possible design, each row element in the second matrix corresponds to the weight of a data block, and the number of column elements in the first matrix is K*M.
[0038] In a possible design, performing a multiplication operation on the second matrix and the first matrix to obtain a calculation result according to an index of each non-zero element in the second matrix includes:
[0039] The elements in the first matrix to be operated on with the non-zero elements in the i-th row in the second matrix are determined according to the indices of the non-zero elements in the second matrix, so as to perform a multiplication operation on the second matrix and the first matrix to obtain a calculation result.
[0040] In a possible design, the number of non-zero elements in each data block is M; the index value of the k-th non-zero element in each data block is k-1, which is used to indicate the index of the pruning vector to which the k-th non-zero element belongs;
[0041] When the index value of the first non-zero element in the second matrix is g, the row r of the element in the first matrix that is multiplied with the first non-zero element satisfies: r=g*M.
[0042] In one possible design, the shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel height of the neural network; the number of column elements of the second matrix is C out *FH*FW, the number of row elements of the second matrix is C in ; C in =K*M, the number of data blocks included in the weight tensor
[0043] In one possible design, the shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C inrepresents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel width of the neural network; the number of column elements of the second matrix is C out , the number of row elements of the second matrix is C in *FH*FW;C in *FH*FW=K*M, the number of data blocks included in the weight tensor
[0044] In a third aspect, an embodiment of the present application provides an accelerator, including:
[0045] A storage circuit, used to store a first matrix corresponding to the data to be processed, a second matrix corresponding to the weight tensor of the neural network, and the index of the non-zero elements in the second matrix;
[0046] Wherein, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each of which is composed of K pruned vectors, and each pruned vector is composed of M weights; K and M are both positive integers; the weight corresponding to the first position in the first pruned vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the other pruned vectors in the first data block except the first pruned vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruned vector is any pruned vector in the first data block;
[0047] An operation circuit is used to perform a multiplication operation on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result.
[0048] In a possible design, each row element in the second matrix corresponds to the weight of a data block, and the number of column elements in the first matrix is K*M.
[0049] In one possible design, the operation circuit includes a selection unit and a calculation unit;
[0050] The selection unit is used to read the non-zero elements of the i-th row in the second matrix from the storage circuit according to the index of the non-zero elements in the second matrix, and read the elements in the i-th column of the first matrix that are operated on the non-zero elements of the second matrix from the storage circuit according to the index of the non-zero elements of the second matrix;
[0051] The calculation unit is used to perform multiplication and addition operations on the non-zero elements in the i-th row of the second matrix and the elements in the i-th column of the read first matrix.
[0052] In a possible design, the storage circuit includes a storage unit and a selection unit, the storage unit is used to store a first matrix corresponding to the data to be processed, a second matrix corresponding to the weight tensor included in the neural network, and the index of non-zero elements in the second matrix;
[0053] The selection unit is used to read the non-zero elements of the i-th row in the second matrix from the storage circuit according to the index of the non-zero elements in the second matrix, and send the non-zero elements of the i-th row in the second matrix to the operation circuit; and read the elements of the i-th column elements of the first matrix that are operated with the non-zero elements of the i-th row in the second matrix from the storage circuit according to the index of the non-zero elements of the second matrix, and send the elements of the i-th column elements of the first matrix that are operated with the non-zero elements of the i-th row in the second matrix to the operation circuit;
[0054] The operation circuit is specifically used to perform multiplication and addition operations on the non-zero elements in the i-th row of the second matrix and the elements in the i-th column of the first matrix and the non-zero elements in the i-th row of the second matrix.
[0055] In a possible design, the number of non-zero elements in each data block is M; the index value of the k-th non-zero element in each data block is k-1, which is used to indicate the index of the pruning vector to which the k-th non-zero element belongs;
[0056] When the index value of the first non-zero element in the second matrix is g, the row r of the element in the first matrix that is multiplied with the first non-zero element satisfies: r=g*M.
[0057] In one possible design, the shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of input activations of the neural network, FH represents the kernel height of the neural network, and FW represents the kernel width of the neural network; the number of column elements of the second matrix is C out *FH*FW, the number of row elements of the second matrix is C in ; C in =K*M, the number of data blocks included in the weight tensor
[0058] In one possible design, the shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C inrepresents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel height of the neural network; the number of column elements of the second matrix is C out , the number of row elements of the second matrix is C in *FH*FW;C in *FH*FW=K*M, the number of data blocks included in the weight tensor
[0059] In a fourth aspect, an embodiment of the present application provides a processing system, including:
[0060] A processor, configured to obtain data to be processed and generate a vector representation of the data to be processed;
[0061] An accelerator, configured to perform calculations on the vector representation of the data to be processed and the weight tensor included in the neural network to obtain a processing result of the data to be processed;
[0062] Among them, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each of which is composed of K pruned vectors, and each pruned vector is composed of M weights; K and M are both positive integers; the weight corresponding to the first position in the first pruned vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the other pruned vectors in the first data block except the first pruned vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruned vector is any pruned vector in the first data block.
[0063] In one possible design, the processor is further used to process the vector representation of the data to be processed into a first matrix, and process the weight tensor to obtain a second matrix and the index of the non-zero elements in the second matrix, and send the first matrix, the second matrix and the index of the non-zero elements in the second matrix to the accelerator;
[0064] The accelerator is specifically used to perform a multiplication operation on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result.
[0065] In a possible design, each row element in the second matrix corresponds to the weight of a data block, and the number of column elements in the first matrix is K*M.
[0066] In one possible design, the accelerator is specifically used to determine the elements in the first matrix to be operated on the non-zero elements in the i-th row of the second matrix according to the indices of the non-zero elements in the second matrix, so as to perform multiplication operations on the second matrix and the first matrix to obtain a calculation result.
[0067] In a possible design, the number of non-zero elements in each data block is M; the index value of the k-th non-zero element in each data block is k-1, which is used to indicate the index of the pruning vector to which the k-th non-zero element belongs;
[0068] When the index value of the first non-zero element in the second matrix is g, the row r of the element in the first matrix that is multiplied with the first non-zero element satisfies: r=g*M.
[0069] In one possible design, the shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of input activations of the neural network, FH represents the kernel height of the neural network, and FW represents the kernel width of the neural network; the number of column elements of the second matrix is C out *FH*FW, the number of row elements of the second matrix is C in ; C in =K*M, the number of data blocks included in the weight tensor
[0070]
[0071] In one possible design, the shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel height of the neural network; the number of column elements of the second matrix is C out , the number of row elements of the second matrix is C in *FH*FW;C in *FH*FW=K*M, the number of data blocks included in the weight tensor
[0072] In a fifth aspect, the present application further provides a pruning device, which has the function of implementing the method of the first aspect. The function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions.
[0073] In one possible design, the structure of the pruning device may include an acquisition unit and a pruning unit, which can perform the corresponding functions in the above method example. For details, please refer to the detailed description in the method example, which will not be repeated here. The pruning device may also include a training unit for performing training operations.
[0074] In a possible design, the structure of the pruning device may include a processor and a memory, wherein the processor is configured to execute the above-mentioned method. The memory is coupled to the processor and stores necessary program instructions and data for the pruning device.
[0075] In a sixth aspect, the present application further provides a computer storage medium, in which computer executable instructions are stored. When the computer executable instructions are called by the computer, the computer is used to enable the computer to execute any one of the methods mentioned in the first aspect above, or to execute any one of the methods mentioned in the second aspect above.
[0076] In a seventh aspect, the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the methods mentioned in the first aspect above, or execute any of the methods mentioned in the second aspect above.
[0077] In an eighth aspect, the present application also provides a chip, which is coupled to a memory and is used to read and execute program instructions stored in the memory to implement any of the methods mentioned in the first aspect above, or to execute any of the methods mentioned in the second aspect above.
[0078] Based on the implementations provided in the above aspects, the present application can also be further combined to provide more implementations. BRIEF DESCRIPTION OF THE DRAWINGS
[0079] Figure 1 Schematic diagram of the convolutional neural network structure;
[0080] Figure 2 A schematic diagram of a system architecture 10 provided in an embodiment of the present application;
[0081] Figure 3 A schematic diagram of the structure of a data processing device 200 provided in an embodiment of the present application.
[0082] Figure 4 A schematic diagram of a pruning method flow chart provided in an embodiment of the present application;
[0083] Figure 5 A schematic diagram of a pruned data block provided in an embodiment of the present application;
[0084] Figure 6 A schematic diagram showing the correspondence between sparsity and the number of pruning times provided in an embodiment of the present application;
[0085] Figure 7 A schematic diagram of a progressive pruning process provided in an embodiment of the present application;
[0086] Fig. 8A A schematic diagram of a data processing method flow provided in an embodiment of the present application;
[0087] Figure 8B A schematic diagram of a method for encoding a non-zero index of a data block provided in an embodiment of the present application;
[0088] Fig.9A A schematic diagram of an accelerator structure provided in an embodiment of the present application;
[0089] Fig. 9B A schematic diagram of another accelerator structure provided in an embodiment of the present application;
[0090] Fig. 10A A schematic diagram of a processing system structure provided in an embodiment of the present application;
[0091] Fig. 10B A schematic diagram of another processing system structure provided in an embodiment of the present application;
[0092] Fig.11A A schematic diagram of a data processing flow provided in an embodiment of the present application;
[0093] Fig. 11B Another data processing flow diagram provided in the embodiment of the present application;
[0094] Fig.12 A schematic diagram of the structure of a pruning device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0095] Before describing a neural network pruning method, a data processing method, and a device provided in the embodiments of the present application, the related concepts involved in the embodiments of the present application are first described.
[0096] (1) Neural Network:
[0097] Neural networks are used to implement machine learning, deep learning, search, reasoning, decision making, etc. The neural networks mentioned in this application may include various types, such as deep neural networks (DNN), convolutional neural networks (CNN), recurrent neural networks (RNN), residual networks, neural networks using transformer models or other neural networks, etc. Some neural networks are introduced as examples below.
[0098] (2) Convolutional Neural Networks:
[0099] Convolutional neural networks (CNN) are deep neural networks with convolutional structures. They are deep learning architectures, which refer to multiple levels of learning at different levels of abstraction through machine learning algorithms. As a deep learning architecture, CNN is a feed-forward artificial neural network, in which each neuron processes the data input into it.
[0100] like Figure 1 As shown, the convolutional neural network (CNN) 100 may include an input layer 110, a convolutional layer / pooling layer 120, wherein the pooling layer is optional, and a neural network layer 130. Figure 1 The convolution layer / pooling layer 120 shown may include layers 121-126 as shown in the examples. In one implementation, layer 121 is a convolution layer, layer 122 is a pooling layer, layer 123 is a convolution layer, layer 124 is a pooling layer, layer 125 is a convolution layer, and layer 126 is a pooling layer; in another implementation, layers 121 and 122 are convolution layers, layer 123 is a pooling layer, layers 124 and 125 are convolution layers, and layer 126 is a pooling layer. That is, the output of the convolution layer can be used as the input of the subsequent pooling layer, or as the input of another convolution layer to continue the convolution operation. Taking the convolution layer 121 as an example, the convolution layer 121 may include many convolution operators, which are also called convolution kernels. The convolution operator can essentially be a weight matrix, which is usually predefined. Taking image processing as an example, different weight matrices extract different features in the image. For example, one weight matrix is used to extract image edge information, another weight matrix is used to extract specific colors of the image, and another weight matrix is used to blur unnecessary noise in the image.
[0101] The weight values in these weight matrices need to be obtained through a lot of training in practical applications. The weight matrices formed by the weight values obtained through training can extract information from the input data, thereby helping the convolutional neural network 100 to make correct predictions.
[0102] When the convolutional neural network 100 has multiple convolutional layers, the initial convolutional layer (for example, 121) often extracts more general features, which can also be called low-level features. As the depth of the convolutional neural network 100 increases, the features extracted by the later convolutional layers (for example, 126) become more and more complex, such as high-level semantic features. Features with higher semantics are more suitable for the problem to be solved.
[0103] Pooling layer:
[0104] Since it is often necessary to reduce the number of training parameters, it is often necessary to periodically introduce a pooling layer after the convolution layer, such as Figure 1 The layers 121-126 illustrated in 120 may be a convolution layer followed by a pooling layer, or may be multiple convolution layers followed by one or more pooling layers. In the image processing process, the only purpose of the pooling layer is to reduce the spatial size of the image. The pooling layer may include an average pooling operator and / or a maximum pooling operator for sampling the input image to obtain an image of smaller size. The average pooling operator may calculate the pixel values in the image within a specific range to generate an average value. The maximum pooling operator may take the pixel with the largest value within a specific range as the result of the maximum pooling. In addition, just as the size of the weight matrix used in the convolution layer should be related to the image size, the operator in the pooling layer should also be related to the image size. The size of the image output after processing by the pooling layer may be smaller than the size of the image input to the pooling layer, and each pixel in the image output by the pooling layer represents the average value or maximum value of the corresponding sub-region of the image input to the pooling layer.
[0105] After being processed by the convolution layer / pooling layer 120, the convolution neural network 100 is not sufficient to output the required output information. As mentioned above, the convolution layer / pooling layer 120 only extracts features and reduces the parameters brought by the input image. However, in order to generate the final output information (the required class information or other related information), the convolution neural network 100 needs to use the neural network layer 130 to generate one or a group of outputs of the required number of classes. Therefore, the neural network layer 130 may include multiple hidden layers (such as Figure 1 131, 132 to 13n) and the output layer 140 shown, the parameters contained in the multi-layer hidden layers can be pre-trained according to relevant training data of a specific task type. For example, the task type may include image recognition, image classification, image super-resolution reconstruction, etc.
[0106] After the multiple hidden layers in the neural network layer 130, that is, the last layer of the entire convolutional neural network 100 is the output layer 140, which has a loss function similar to the classification cross entropy, specifically used to calculate the prediction error. Once the forward propagation of the entire convolutional neural network 100 (such as Figure 1 The propagation from 110 to 140 is forward propagation), and the reverse propagation (such as Figure 1 The propagation from 140 to 110 is called back propagation) and then the weight values and biases of the aforementioned layers will begin to be updated to reduce the loss of the convolutional neural network 100 and the error between the result output by the convolutional neural network 100 through the output layer and the ideal result.
[0107] It should be noted that if Figure 1 The convolutional neural network 100 shown is only an example of a convolutional neural network. In specific applications, the convolutional neural network can also exist in the form of other network models. For example, multiple convolutional layers / pooling layers are in parallel, and the extracted features are input into the neural network layer 130 for processing.
[0108] (3) Pruning / thinning:
[0109] Sparsification / pruning is to set the weight values of non-critical parts of a neural network (or neural network) to zero (0). Sparse methods can include arbitrary sparsity, structured sparsity, and unstructured sparsity. Arbitrary sparsity means that the weights chosen to be set to 0 can be at any position, and the inference calculation uses the sparse weight calculation. Structured sparsity is to prune according to certain rules, such as whole channel pruning in convolution, whole column pruning in full connection, and after pruning, the inference calculation still uses dense calculation through rearrangement. Unstructured sparsity (also called semi-structured sparsity) can be understood as between structured sparsity and arbitrary sparsity. Compared with structured sparsity, it has a lower granularity and needs to be pruned according to certain rules, but the rules are relatively weak, and customized code implementation is required to achieve good inference performance. For example The proposed 2:4 sparseness has two positions with zero weights in the vector of length 4.
[0110] (4) Sparsity: the ratio of the number of 0 elements to the total number of elements.
[0111] In the description of this application, unless otherwise specified, "multiple" means two or more than two. In addition, " / " indicates that the objects associated before and after are in an "or" relationship, for example, A / B can represent A or B; "and / or" in this application is only a description of the association relationship of the associated objects, indicating that there can be three relationships, for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In addition, in order to facilitate the clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "first" and "second" are used to distinguish the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different. It should also be noted that, unless otherwise specified, the specific description of some technical features in one embodiment can also be used to explain the corresponding technical features mentioned in other embodiments.
[0112] See also Figure 2 , which is a schematic diagram of a system architecture 10 provided in an embodiment of the present application. The system architecture 10 includes a pruning device 100 and a data processing device 200 .
[0113] The pruning device 100 is used to execute the pruning method of the neural network provided in the embodiment of the present application, and the data processing device 200 is used to implement the data processing method provided in the embodiment of the present application. After the pruning device 100 completes pruning of the neural network, the pruned neural network can be sent to the data processing device 200.
[0114] The pruning device 100 may be implemented by software or hardware.
[0115] The pruning device 100 is taken as an example of a software functional unit, and the pruning device 100 may include code running on a computing instance. Among them, the computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Further, the above-mentioned computing instance may be one or more. For example, the pruning device 100 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region (region) or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, and each AZ includes a data center or multiple data centers with close geographical locations. Among them, usually a region can include multiple AZs.
[0116] Similarly, multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, a VPC is set up in a region. For cross-region communication between two VPCs in the same region and between VPCs in different regions, a communication gateway needs to be set up in each VPC to achieve interconnection between VPCs through the communication gateway.
[0117] The pruning device 100 is taken as an example of a hardware functional unit, and the pruning device 100 may include at least one computing device, such as a server, etc. The at least one computing device may be deployed in a cloud network or locally. Alternatively, the pruning device 100 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The above-mentioned PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
[0118] In some scenarios, the multiple computing devices included in the pruning apparatus 100 may be distributed in the same region or in different regions.
[0119] The system architecture 10 also includes a data storage system 300. Optionally, the pruning device 100 cooperates with other computing devices, such as data storage, routers, load balancers, etc. The pruning device 100 can use the data in the data storage system 300, or call the program code in the data storage system 300 to implement the neural network pruning method provided in the present application.
[0120] Figure 3 The structural diagram of a data processing device 200 provided by the present application is exemplarily shown. Figure 3As shown, the data processing device 200 includes a processing system 210, a hardware accelerator 220, a data bus 230 and a control bus 240. The processing system 210 and the hardware accelerator 220 can transmit data through the data bus 230 and can transmit control information through the control bus 240. The processing system 210 is the control component of the entire system, including a processor 211, and optionally, the processing system 210 also includes a memory 212. The processor 211 is used to run the code of the software end and load the acceleration task (such as a matrix or vector) to the hardware accelerator 220. Optionally, the hardware accelerator 220 may include one or more intellectual property (IP) cores, and the hardware accelerator 220 may control the working state and data reading of the one or more IP cores. The functions of the IP core include, for example: designing some commonly used but relatively complex functional blocks in digital circuits, such as synchronous dynamic random access memory (SDRAM) controllers, peripheral component interconnect (PCI) interfaces, etc., into circuits with modifiable parameters. The processor 211 may be a central processing unit (CPU), a network processor (NP) or a combination of a CPU and a NP. The processor 211 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.The memory 212 is used to store data. The processor 211 can control the reading or writing of data to the memory 212. The memory 212 can be a double data rate synchronous dynamic random access memory (DDR SDRAM), a random-access memory (RAM) or a non-volatile memory, such as a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD). The memory 112 can also include a combination of the above types of memories.
[0121] The hardware accelerator 220, which can also be referred to as an accelerator, is a hardware acceleration component of the entire system. It can design and implement a dedicated acceleration IP core according to a specific computing task. The IP core on the hardware accelerator can accelerate the algorithm. In the embodiment of the present application, the hardware accelerator 200 can be applied in a neural network to accelerate the neural network algorithm. After the data interaction is completed, the hardware accelerator 220 and the processing system 10 can independently execute tasks in parallel. The hardware accelerator 220 can be a graphics processing unit (GPU), or an FPGA, or an application specific integrated circuit (ASIC) for special applications, or a microcontroller (MCU), etc.
[0122] The data bus 230 is used for data transmission between the entire processing system 210 and the hardware accelerator 220. The data bus 230 may adopt the advanced extensible interface-Stream (AXI-Stream) protocol or the PCI Express (PCI-E) bus protocol. AXI is a bus protocol, and the AXI-Stream protocol is a high-performance transmission protocol that allows unlimited data burst transmission.
[0123] The control bus 240 is used for transmission of control signals between the entire processing system 210 and the hardware accelerator 220. The control bus 40 may adopt the AXI-Lite protocol, which is a lightweight address-mapped single-transmission protocol suitable for transmission of control signals of hardware computing circuits.
[0124] In some possible implementations, the processing system 210 may have a hardware acceleration function, that is, the functions of the processing system 210 and the hardware accelerator 220 are implemented by one device, such as a CPU.
[0125] The data processing device 200 interacts with the pruning device 100 via a communication network of any communication mechanism / communication standard. The communication network may be a wide area network, a local area network, a point-to-point connection, or any combination thereof.
[0126] The solution provided by the embodiment of the present application can be applied to deep learning scenarios, such as scenarios using convolutional neural networks and scenarios using deep neural networks. In addition, the embodiment of the present application is applicable to scenarios of Transformer networks or fusion networks of transformers + CNN.
[0127] The following is a description of the neural network pruning method provided in the embodiment of the present application. Figure 4 A schematic diagram of a neural network pruning method provided in an embodiment of the present application. The neural network pruning method can be executed by the pruning device 100 or by a module in the pruning device 100.
[0128] S401, obtaining a first weight tensor of the neural network to be pruned.
[0129] The neural network to be pruned can be a pre-trained neural network or an untrained neural network.
[0130] The neural network to be pruned may be a convolutional neural network, such as a neural network used for image classification, target recognition, image processing, image denoising, and the like.
[0131] The first weight tensor can be understood as a vector representation of the weight of the convolution kernel. The convolution kernel can be single-channel or multi-channel. For example, the shape of the convolution kernel is (C out ,C in ,FH,FW). C out represents the number of output activations of the convolution kernel (or the number of output channels of the convolution kernel), C in It represents the number of convolution kernel input activations (or the number of convolution kernel input channels), FH represents the kernel height of the convolution kernel, and FW represents the kernel height of the convolution kernel.
[0132] S402, perform at least one pruning process on the first weight tensor to obtain a second weight tensor.
[0133] The second weight tensor includes multiple data blocks, each data block consists of K pruned vectors, and each pruned vector consists of M weights. K and M are both positive integers. The weight corresponding to the first position in the first pruned vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the pruned vectors other than the first pruned vector in the first data block is a zero element. The first data block is any data block among the multiple data blocks. The first pruned vector is any pruned vector in the first data block. A data block can also be understood as being composed of multiple pruned vectors. The size of the data block is related to the specifications of the hardware that performs neural network operation acceleration, such as the specifications of the hardware that performs neural network operation acceleration is the length of the vector included in the data block.
[0134] The pruning vector may also be referred to as a vector, or as a shortest vector, or may be named by other names. The embodiment of the present application does not specifically limit the name of the pruning vector.
[0135] It should be understood that each data block satisfies the condition satisfied by the first data block, that is, at the position where a non-zero element in a pruned vector is located, other pruned vectors in the data block to which the pruned vector belongs have zero elements at that position. Figure 5 As shown, in the pruning vector of M=4, the data block includes two pruning vectors, the weights of the 0th position and the 3rd position of the first pruning vector are non-zero elements, and the weights of the 1st position and the 2nd position of the first pruning vector are zero elements, so that the weights of the 0th position and the 3rd position of the second pruning vector are both zero elements, and the weights of the 1st position and the 2nd position of the second pruning vector are non-zero elements. That is, the positions of the zero elements of the first pruning vector and the second pruning vector are complementary. Based on this, the pruning method provided in the embodiment of the present application can be called complementary sparse or complementary pruning. Of course, other names can also be used for naming, and the embodiment of the present application does not specifically limit this. For the convenience of description, the pruning method provided in the embodiment of the present application will be referred to as complementary sparse in the following.
[0136] Compared with the single-channel or block-based sparse method, the embodiment of the present application uses a smaller granularity for sparseness, which can improve the accuracy of the application of the network model. Compared with the use of any sparse method, the sparse method is complementary, and there is no need to use dense calculations in the reasoning stage, which reduces the amount of calculation of the model. The solution provided by the embodiment of the present application can balance accuracy and acceleration.
[0137] In complementary sparsity, K pruned vectors can be combined into a vector (i.e., data block) for operation, so that the relationship between the sparsity after pruning and K satisfies formula (1):
[0138]
[0139] For example, when K=2, the sparsity S=50%. For another example, when K=4, the sparsity S=75%, and so on.
[0140] The embodiment of the present application may adopt a one-step approach when performing pruning, that is, perform pruning once, or may adopt a progressive pruning approach (or progressive thinning approach).
[0141] If the progressive pruning method is described, the progressive pruning method is performed N times in a manner of increasing sparsity. In some embodiments, the number K of pruning vectors included in each data block and / or the sparsity of the second weight tensor (i.e., the sparsity required for pruning) can be determined.
[0142] For example, the relationship between N and K satisfies the following formula (2):
[0143] N=K-1 formula (2).
[0144] For another example, the relationship between N and S satisfies the following formula (3):
[0145]
[0146] Taking N=K-1 as an example, the sparsity of each pruning process can satisfy the following formula (4):
[0147]
[0148] Among them, S i Indicates the sparsity of the i-th pruning process, i is a positive integer, 1≤i <K。
[0149] For example, to train a neural network with a sparsity of 75%, after 3 prunings, the sparsity changes as follows: 0->25%->50%->75%. For another example, to train a neural network with a sparsity of 87.5%, after 7 prunings, the sparsity changes as follows: 0->12.5%->25%->37.5%->50%->62.5%->75%->87.5.
[0150] It can be understood that for an M*K data block (or matrix), when the progressive sparsity is performed, the increased sparsity is equivalent to subtracting the number of weights included in the shortest vector for each increase in the number of executions by 1. Based on this, the embodiment of the present application can also refer to the progressive sparsity method as vector-by-vector progressive sparsity. Of course, other names can also be used, and the embodiment of the present application is not limited to this.
[0151] In the embodiment of the present application, each time pruning is performed, one generation of training (also referred to as epoch) is performed. Based on this, the pruning process mentioned above may include a pruning operation and a training operation. In some embodiments, when a vector-by-vector progressive sparsification method is adopted, the number of trainings at each sparsity value may be the same. See Figure 6 As shown, the different steps corresponding to different sparsities are of equal width, that is, the number of training times at each sparsity value is the same. The training corresponding to different sparsity values can use the same training sample set or different training sample sets. For example, the sample set can be split into multiple training sample subsets, and each time the pruning process is performed, a training sample subset is used to perform a generation of training. For example, different training sample subsets include the same number of batches (indicating a batch of data), so the number of training times at each sparsity value is the same. Use a small portion of samples in the training set to perform a back-propagation parameter update on the weights retained by the neural network. This small portion of samples is called a "batch of data."
[0152] The pruning process is described below. Taking the i-th pruning as an example, i is less than or equal to N. For example, each pruning operation can be divided into three steps, namely (1) deformation, (2) pruning and (3) restoration (also called inverse deformation or anti-deformation).
[0153] (1) Deformation: The input four-dimensional weight tensor is deformed to obtain a deformed three-dimensional weight tensor. The three-dimensional weight tensor includes G data blocks, each of which is composed of K pruned vectors, and each pruned vector is composed of M weights.
[0154] It can be understood that when pruning is performed for the first time, the input four-dimensional weight tensor can be understood as the first weight tensor. When pruning is performed for the second to Nth times, the input four-dimensional weight tensor can be understood as the four-dimensional weight tensor that has undergone the i-th pruning process.
[0155] The shape of the input four-dimensional weight tensor can be described as (C out , C in , FH, FW). out represents the number of output activations of the convolution kernel (or the number of output channels of the convolution kernel), C in represents the number of convolution kernel input activations (or the number of convolution kernel input channels), FH represents the kernel height of the convolution kernel, and FW represents the kernel height of the convolution kernel). Four sets of parameters are used to describe the weight tensor. Of course, in some scenarios, in the case of a single output channel, C in the weight tensor out = 1, in this case, the shape of the input weight tensor can be understood as three-dimensional, that is, (C in , FH, FW). In the case of a single input channel, C in the weight tensor in= 1, the shape of the input weight tensor can be understood as three-dimensional, that is, (C out , FH, FW).
[0156] The shape of the input weight tensor is (C out , C in , FH, FW) as an example, the shape of the deformed three-dimensional weight tensor is G, K, M); where G satisfies the following formula (5):
[0157]
[0158] In some scenarios, in order to achieve acceleration on general parallel computing hardware or dedicated acceleration hardware, K*M satisfies the following formula (6):
[0159] K*M=L,L∈{C in , C in *FH*FW} Formula (6).
[0160] For example, dedicated acceleration hardware can be a circuit or hardware with independent functions that can accelerate the complementary sparseness provided in the embodiments of the present application, such as a dedicated MCU, a dedicated GPU, or a dedicated CPU, etc. The value of L is related to the specifications of the acceleration hardware (dedicated acceleration hardware or general parallel computing hardware). For example, the specifications of the acceleration hardware can be the size of the matrix of the matrix product supported by the acceleration hardware. For example, the acceleration hardware supports the product operation of the matrix A*L and the matrix L*B. For example, in the specifications of the acceleration hardware, L=C in For example, in the acceleration hardware specification, L = C in *FH*FW. In some embodiments, L can also be C in *FH or, C in *FW.
[0161] In some embodiments, L = C in For example, when performing deformation, the input four-dimensional weight tensor can be rearranged into (FH, FW, C out , C in ). The purpose of deformation is to facilitate the in The rearranged weight tensor is further transformed into a three-dimensional weight tensor of (G, K, M). At this time, G = C out *FH*FW.
[0162] In some other embodiments, L=C in *FH*FW as an example, when performing deformation, the input four-dimensional weight tensor can be rearranged as (C out ,FH,FW,C in), further, the rearranged weight tensor is transformed into a three-dimensional weight tensor of (G, K, M). At this time, G = C out .
[0163] (2) Pruning: Prune the three-dimensional weight tensor along the K dimension, and remove the least important q i The weights are reset to zero to obtain the three-dimensional weight vector after the i-th pruning.
[0164] The three-dimensional weight tensor of (G, K, M) can be understood as G K*M data blocks. Each K*M data block is pruned in the K dimension. It can be understood that the K weights in each column have the smallest importance q i The weights are reset to zero.
[0165] For example, the q with the smallest importance in the K dimension i The weights are reset to zero and can be:
[0166] The q with the smallest L1 norm in K dimensions i The weights are reset to zero; or
[0167] The q with the smallest L2 norm in K dimensions i The weights are reset to zero.
[0168] For example, the q i =i, or q i =1.
[0169] (3) Restoration: deforming the three-dimensional weight tensor after the i-th pruning to obtain a deformed four-dimensional weight tensor, wherein the input four-dimensional weight tensor is the first weight tensor or the four-dimensional weight tensor after the i-1-th pruning.
[0170] In a possible implementation, in each pruning process in the embodiment of the present application, the pruning operation may be performed first and then the training operation, or the training operation may be performed first and then the pruning operation. During the training process, the pruned weights may or may not be updated.
[0171] In one example, the pruning operation is performed first and then the training operation is performed, and the subtracted weight is updated as an example. i =i.
[0172] Before training, the first pruning is performed, i=1, and the sparsity after the first pruning is S1=1 / K. It can be understood that when the first pruning is performed, M weights are subtracted from the data block composed of each K pruned vector. For each K*M data block, the least important weight among the K weights in each column is reset to zero, that is, M weights are subtracted from each data block. Then the first generation of training is performed for the pruned weight vector, and each weight is adjusted during the training process. Then continue to perform the second pruning, i=2, and the sparsity after the second pruning is S2=2 / K. It can be understood that when the second pruning is performed, 2*M weights are subtracted from the data block composed of each K pruned vector. For each K*M data block, the two least important weights among the K weights in each column are reset to zero, that is, 2*M weights are subtracted from each data block. Then the second generation of training is performed for the pruned weight vector, and each weight is adjusted during the training process. And so on.
[0173] It should be noted that after the last pruning, only the weights that have not been pruned can be adjusted during the last generation of training.
[0174] In another example, the pruning operation can be performed first and then the training operation, and the subtracted weights are not updated. i =1.
[0175] Before training, the first pruning is performed, i=1, and the sparsity after the first pruning is S1=1 / K. It can be understood that when the first pruning is performed, M weights are subtracted from the data block composed of each K pruned vector. For each K*M data block, the least important weight among the K weights in each column is reset to zero, that is, M weights are subtracted from each data block. Then the first generation of training is performed for the pruned weight vectors, and the weights that have not been subtracted are adjusted during the training process. Then continue to perform the second pruning, i=2, and the sparsity after the second pruning is S2=2 / K. It can be understood that when the second pruning is performed, M weights continue to be subtracted from the data block composed of each K pruned vector. For each K*M data block, the least important weight among the K weights in each column except the subtracted weights is reset to zero, and at this time 2*M weights have been subtracted from each data block. Then the second generation of training is performed on the pruned weight vector, and the weights that have not been pruned are adjusted during the training process. And so on.
[0176] In another example, the training operation can be performed first and then the pruning operation can be performed, and the subtracted weights can be updated. i =i.
[0177] Before performing the first pruning, the first generation of training is performed, i=1, and each weight is adjusted during the training process. Then the first pruning operation is performed, and the sparsity after the first pruning is S1=1 / K. It can be understood that when performing the first pruning, M weights are subtracted from each data block consisting of K pruned vectors. For each K*M data block, the least important weight among the K weights in each column is reset to zero, that is, M weights are subtracted from each data block. Then the second generation of training is performed for the pruned weight vectors, and all weights are adjusted during the training process. Then continue to perform the second pruning, i=2, and the sparsity after the second pruning is S2=2 / K. It can be understood that when performing the second pruning, 2*M weights are subtracted from each data block consisting of K pruned vectors. For each K*M data block, the two least important weights among the K weights in each column are reset to zero, and at this time, 2*M weights have been subtracted in each data block. And so on.
[0178] In another example, the training operation can be performed first and then the pruning operation can be performed, and the subtracted weights are not updated. i =i.
[0179] Before performing the first pruning, the first generation of training is performed, i=1, and each weight is adjusted during the training process. Then the first pruning operation is performed, and the sparsity after the first pruning is S1=1 / K. It can be understood that when the first pruning is performed, M weights are subtracted from the data block composed of each K pruned vectors. For each K*M data block, the least important weight among the K weights in each column is reset to zero, that is, M weights are subtracted from each data block. Then the second generation of training is performed for the pruned weight vectors, and the weights that have not been subtracted are adjusted during the training process. Then continue to perform the second pruning, i=2, and the sparsity after the second pruning is S2=2 / K. It can be understood that when the second pruning is performed, M weights are subtracted from the data block composed of each K pruned vectors. For each K*M data block, the K weights in each column are reset to zero after the weight with the least importance is subtracted. At this time, 2*M weights have been subtracted in each data block. And so on.
[0180] For example, see Figure 7 As shown in the figure, the progressive pruning process of a tensor with a deformed shape of (1,4,4), we can see that as the sparsity increases, the number of retained elements in the K dimension decreases. It should be noted that Figure 7 This is just an example. In the actual pruning process, the weight value will change after training. Figure 7 Only the change in the number of pruning branches and the change in sparsity are shown.
[0181] The following is a description of the data processing method provided in the embodiment of the present application. Fig. 8A Schematic diagram of data processing flow provided in the embodiment of the present application. The data processing method can be executed by the data processing device 200, or by a module in the data processing device 200. The processor in this embodiment can be Figure 3 The processor 211 in the embodiment of the present invention may be a processor 211 in the embodiment of the present invention. Figure 3 The hardware accelerator 220 in FIG.
[0182] S801: The processor 211 obtains data to be processed and generates a vector representation of the data to be processed.
[0183] The vector representation of the data to be processed may be a representation in matrix form, for example, the vector representation of the data to be processed is a first matrix.
[0184] S802, the hardware accelerator 220 performs calculations on the vector representation of the data to be processed and the weight tensor included in the neural network to obtain a processing result of the data to be processed. The weight tensor included in the neural network can be a matrix representation, such as a second matrix.
[0185] In some embodiments, the processor 211 may process the vector representation of the data to be processed into a first matrix, process the weight tensor to obtain a second matrix and the index of the non-zero elements in the second matrix, and send the first matrix, the second matrix, and the index of the non-zero elements in the second matrix to the accelerator. Then, the accelerator performs a multiplication operation (also described as a multiplication operation) on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result.
[0186] In some embodiments, the hardware accelerator 220 (referred to as accelerator 220) performs calculations on the vector representation of the data to be processed and the weight tensor included in the neural network, which can be understood as multiplying the first matrix of the data to be processed and the second matrix of the neural network.
[0187] Among them, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each of which is composed of K pruned vectors, and each pruned vector is composed of M weights; K and M are both positive integers; the weight corresponding to the first position in the first pruned vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the other pruned vectors in the first data block except the first pruned vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruned vector is any pruned vector in the first data block.
[0188] In one possible implementation, the weight tensor may be encoded. A pruned weight tensor may be encoded as non-zero weights + indices. When storing non-zero weights, they may be compactly stored in the order of the concatenated vectors. Each non-zero weight corresponds to an index. When the accelerator performs calculations on the vector representation of the data to be processed and the weight tensor included in the neural network, the second matrix and the first matrix may be multiplied according to the index of each non-zero weight in the second matrix to obtain a calculation result. In some embodiments, each row element in the second matrix corresponds to the weight of a data block, that is, the number of row elements of the second matrix is K*M. The number of column elements of the first matrix is K*M. When performing matrix multiplication, the second matrix × first matrix method is adopted. In other implementations, each column element in the second matrix may correspond to the weight of a data block, that is, the number of column elements of the second matrix is K*M. The number of row elements of the first matrix is K*M. When performing matrix multiplication, the first matrix × second matrix method is adopted.
[0189] In one possible implementation, when the accelerator performs a multiplication operation on the second matrix and the first matrix to obtain a calculation result according to the index of each non-zero element in the second matrix, it can determine the elements in the first matrix that are operated on the non-zero elements in the i-th row of the second matrix according to the index of the non-zero elements in the second matrix, so as to perform a multiplication operation on the second matrix and the first matrix to obtain a calculation result.
[0190] As an example, the index of the non-zero elements in the second matrix can be encoded as follows: the number of non-zero elements in each data block is M; the index value of the kth non-zero element in each data block is k-1, which is used to indicate the index of the pruning vector to which the kth non-zero element belongs.
[0191] For example, see Figure 8B As shown, it is a schematic diagram of the encoding method of the non-zero index of the data block provided in an embodiment of the present application. Figure 8B In the example, taking the sparsity of 50%, K = 2, and M = 8. When binary encoding is performed on the non-zero elements of pruning vector 1 and pruning vector 2, the weight of the first non-zero element in the M dimension belongs to pruning vector 1, and the index is 0; the weight of the second non-zero element in the M dimension belongs to pruning vector 2, and the index is 1; the weight of the third non-zero element in the M dimension belongs to pruning vector 3, and the index is 1; the weight of the fourth non-zero element in the M dimension belongs to pruning vector 1, and the index is 0, and so on. Figure 8BIn the example, taking the sparsity of 75%, K=4, and M=4. When binary encoding is performed on the non-zero elements of pruning vector 1-pruning vector 4, the weight of the first non-zero element on the M dimension belongs to pruning vector 1, the index is 0, and the binary encoding is 0. The weight of the second non-zero element on the M dimension belongs to pruning vector 3, the index is 2, and the binary encoding is 10. The weight of the third non-zero element on the M dimension belongs to pruning vector 2, the index is 1, and the binary encoding is 01. The weight of the fourth non-zero element on the M dimension belongs to pruning vector 4, the index is 3, and the binary encoding is 11.
[0192] Exemplarily, in combination with the above-mentioned encoding method, when determining the elements in the first matrix that are operated on with the non-zero elements in the i-th row of the second matrix according to the indices of the non-zero elements in the second matrix, for example, when the index value of the first non-zero element in the second matrix is g, the row r of the element in the first matrix that is multiplied with the first non-zero element satisfies: r=g*M.
[0193] The shape of the weight tensor is (C out , C in , FH, FW) for illustration. For example, the weight tensor is described as a convolution kernel. In one example, L = K * M = C in For example, the processor can make a pruned shape (C out , C in , FH, FW) is deformed into (C out *FH*FW,C in ). The shape of the data to be processed is (C in , IW, IH), the processor transforms the data to be processed into (C in , OH*OW) matrix. Padding indicates the padding of zero elements. Stride indicates the stride, which is used to reduce the number of input parameters and the amount of calculation. The purpose of padding zero elements is to make the input squares serve as the center of the convolution kernel window. The accelerator then performs the operation of the first matrix × the second matrix. The subsequent description takes the operation of the first matrix × the second matrix as an example. For the (i, j)th element w of the convolution kernel matrix (i.e., the second matrix) ij , such as the w ij is a non-zero element. ij Need to correspond to the element x in column j of the first matrix rj When multiplied, the second matrix w ij When the index value of is g, r = g*M. Then, after completing the matrix multiplication, the shape of the resulting matrix is (C out*FH*FW, OH*OW). Further parallel matrix row reduction operation is performed, that is, each FH*FW number in the result matrix can be summed to obtain a number. After the parallel matrix row reduction operation, the shape of the matrix is (C out , OW×OH). Then the shape is (C out , OW×OH) is converted to (C out , OW, OH), which is the calculation result.
[0194] In another example, L=K*M=C in *FW*FH as an example, the processor can make a pruned shape (C out , C in , FH, FW) is deformed into (C out , C in *FH*FW). The shape of the data to be processed is (C in , IW, IH), the processor transforms the data to be processed into (C in *FH*FW, OH*OW). Padding indicates the padding of zero elements. Stride indicates the stride, which is used to reduce the number of input parameters and the amount of calculation. The purpose of padding zero elements is to make the input squares serve as the center of the convolution kernel window. Then the accelerator performs the operation of the first matrix × the second matrix. For the (i, j)th element w of the convolution kernel matrix (i.e., the second matrix) ij , such as the wi j is a non-zero element. ij Need to correspond to the element x in column j of the first matrix rj When multiplied, the second matrix w ij When the index value of is g, r = g*M. Then, after completing the matrix multiplication, the result matrix is in the shape of (OC, OW×OH), which is converted into (OC, OW, OH), which is the calculation result.
[0195] The following is an example of the structure of the accelerator. Fig.9A and Fig. 9B As shown, the accelerator may include a storage circuit 910 and an operation circuit 920. The accelerator may be Figure 3 The hardware accelerator 220 in the embodiment of the present invention. The storage circuit 910 can be used for a first matrix corresponding to the data to be processed, a second matrix corresponding to the weight tensor of the neural network, and the index of the non-zero elements in the second matrix. The operation circuit 920 is used to perform a multiplication operation on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result.
[0196] In some scenarios, not all elements in the input first matrix participate in the operation, but only elements that need to be multiplied with non-zero elements in the second matrix participate in the operation. Therefore, the elements of the first matrix that need to be operated can be selected through a selection circuit (it can also be understood that the first matrix is sparse). The selection circuit can also be called a selection unit. In the subsequent description, the selection circuit is called a selection unit for example.
[0197] In a possible implementation, the selection unit is disposed in the operation circuit. Fig.9A As shown, exemplarily, the operation circuit 920 may include a selection unit 921 and a calculation unit 922. The selection unit 921 reads the non-zero elements of the i-th row in the second matrix from the storage circuit according to the index of the non-zero elements in the second matrix, and reads the elements of the i-th column of the first matrix from the storage circuit according to the index of the non-zero elements of the second matrix to be operated with the non-zero elements of the second matrix. The calculation unit 922 is used to perform multiplication and addition operations on the non-zero elements of the i-th row of the second matrix and the elements of the i-th column in the read first matrix. It can be understood that the selection unit 921 selects only one non-zero element at the same position of the K pruning vectors for calculation, and the other elements are all zero elements. The acceleration ratio on the hardware thus achieved is strictly related to the sparsity, for example, the convolution acceleration ratio of 50% sparsity is 2. The convolution acceleration ratio of 75% sparsity is 4, and so on.
[0198] In some possible application scenarios, the operation circuit 920 may use one or more arithmetic and logic units (ALUs). For example, the accelerator may be an MCU, a CPU, or a GPU, etc. The ALU is the operation unit of the IP core of the accelerator, a data processing component, and the most special data channel unit in the data channel. It implements multiple operations such as addition, subtraction, and, or, XOR, not, left shift, right shift, and half-byte exchange. The selection unit 921 may be executed by a single ALU or embedded in other ALUs that perform operations.
[0199] In another possible implementation, the selection unit is disposed in a storage circuit. Fig. 9B As shown, the storage circuit 910 includes a storage unit 911 and a selection unit 912. The storage unit 911 stores a first matrix corresponding to the data to be processed, a second matrix corresponding to the weight tensor included in the neural network, and the index of the non-zero elements in the second matrix. In some scenarios, the storage circuit 910 is also responsible for data reading, and the first matrix can be sparse during the data reading process of the storage circuit.
[0200] The selection unit 912 reads the non-zero elements of the i-th row in the second matrix from the storage unit 911 according to the index of the non-zero elements in the second matrix, and sends the non-zero elements of the i-th row in the second matrix to the operation circuit; and reads the elements in the i-th column of the first matrix that are operated with the non-zero elements of the i-th row in the second matrix from the storage unit 911 according to the index of the non-zero elements in the second matrix, and sends the elements in the i-th column of the first matrix that are operated with the non-zero elements of the i-th row in the second matrix to the operation circuit 920. Further, the operation circuit 912 performs multiplication and addition operations on the non-zero elements of the i-th row in the second matrix and the elements in the i-th column of the first matrix that are operated with the non-zero elements of the i-th row in the second matrix.
[0201] In some embodiments, the selection unit is deployed in the storage circuit 910 as an example, that is, the storage circuit 910 includes a selection unit 912, see Fig.9A As shown, the storage unit 911 in the storage circuit 910 may further include a first data buffer area 9111 , a second data buffer area 9112 , and an index information buffer area 9113 .
[0202] The first data cache area 9111 is used to cache data loaded from the processor's memory 212 into the hardware accelerator. For example, the first data cache area 9111 can cache the convolution kernel parameter matrix (including the second matrix) of each layer of the neural network. The second matrix can be compactly stored. The K*M non-zero elements that need to be multiplied with the first matrix are compactly stored, such as row storage, and the non-zero elements of the row are read each time.
[0203] The second data buffer area 9112 is used to cache data loaded from the memory 212 into the hardware accelerator. For example, when the hardware accelerator is applied to a neural network, the second data buffer area 9112 can cache the input matrix (including the first matrix). The index information buffer area 9113 can be used to cache the index of the non-zero elements of the second matrix and the index of the elements in the first matrix. The index of the non-zero elements in the second matrix can be used in the manner described above. The elements of the first matrix may include a row index (which can also be understood as a row address) and a column index (which can be understood as a column address).
[0204] The selection unit 912 is used to select data at a corresponding position according to the index cached in the index information cache area 9113, for example, to determine the elements of the first matrix that need to be multiplied with the non-zero elements in the first matrix according to the index of the second matrix cached in the index information cache area 9113.
[0205] The operation circuit 920 is the core component of the hardware accelerator, and various functional units of the operation circuit are solidified inside. Exemplarily, the operation circuit 920 may include a multiplication unit 9201, an accumulation unit 9202, an excitation function unit 9203 and a vector calculation unit 9204. The multiplication unit is used to multiply the elements of the corresponding positions of the input vector and the matrix to obtain an intermediate value, or to multiply the input matrix and the matrix to obtain an intermediate value. The multiplication unit 9201 can be a matrix and vector multiplication unit or a matrix and matrix multiplication unit. The accumulation unit 9202 is used to accumulate the intermediate values calculated by the multiplication unit 9201 to obtain each gate vector value. The excitation function unit 9203 is used to perform excitation function processing on the gate vector value obtained by the accumulation unit, and the vector calculation unit 9204 is used to calculate each gate vector to obtain the final result.
[0206] In some possible implementations, the hardware accelerator may further include an input buffer 923 and an output buffer 924 for temporarily storing input and output data in the hardware accelerator. After the operation circuit 920 completes the calculation, the result may be placed in the output buffer 924 and output, wherein the output buffer 924 may be written back to the processor at one time after the cache is full. The input buffer 923 and the output buffer 924 may be deployed inside the operation circuit 920 or outside the operation circuit 920.
[0207] In some embodiments, the hardware accelerator may include a memory access unit 913. The memory access unit 913 may use direct memory access (DMA). The memory access unit 913 may be used for data transmission between the hardware accelerator and other devices. Figure 3 The hardware accelerator in Fig.9A Taking the structure shown in FIG. 1 as an example, the hardware and software collaborative framework of the data processing device 200 is shown in FIG. Fig. 10A The memory access unit 913 can be used for data transmission between the hardware accelerator 200 and the memory 212. The memory access unit 913 can be deployed inside the storage circuit 910 or outside the storage circuit 910. Fig. 10A In the figure, deployment outside the storage circuit 910 is taken as an example.
[0208] In some embodiments, the memory access unit 913 uses DMA as an example. Each circuit of the hardware accelerator can be equipped with a DMA to implement parallel data reading. In some embodiments, the hardware accelerator can also include a control interconnection circuit for interconnecting the control signal line between the processing system 210. Fig. 10A, under the control of the processor 211 in the processing system 210, the DMA is controlled to be turned on through the control bus and the data bus respectively, and the DMA transfers the first matrix of the data to be processed in the memory 211 and the second matrix corresponding to the weight tensor and the index of the non-zero elements in the second matrix to the storage circuit 910 in the hardware accelerator 220, such as transferring the second matrix to the first data buffer area 9111, transferring the first matrix to the second data buffer area 9112, and transferring the index of the non-zero elements of the second matrix to the index information buffer unit 9113. Then, the target result is obtained through the processing of the operation circuit 920. See Fig.11A As shown, the selection unit 912 reads the j-th row non-zero elements in the second matrix from the first data buffer area 9111. It can be understood that each column of non-zero elements is compactly stored in rows in the first data buffer area 9111. The selection unit 912 can read the storage row where the j-th row is located from the first data buffer area 9111. The selection unit 912 reads the index of the j-th row non-zero element in the second matrix from the index information buffer area 9113, and then reads the element in the j-th column of the first matrix multiplied with the j-th row non-zero element in the second matrix from the second data buffer area 9112 according to the index of the j-th row non-zero element. The selection unit 912 can send the read data (including the j-th row non-zero element in the second matrix, and the element in the j-th column of the first matrix that needs to be multiplied with the j-th row non-zero element) to the operation circuit 920. For example, the selection unit 912 can output the read data to the input buffer area 923 (which can be inside the operation circuit 920 or inside the operation circuit 920). If outside the operation circuit 920, the operation circuit 920 can obtain read data from the input buffer area 923 for operation. For example, the multiplication unit performs multiplication operations on the non-zero elements in the j-th row of the second matrix and the elements in the j-th column of the first matrix that need to be multiplied with the non-zero elements in the j-th row to obtain multiple values, and then the accumulation unit 9202 performs addition operations on the multiple values.
[0209] In some other embodiments, the selection unit is deployed in the operation circuit as an example, that is, the operation circuit 920 includes the selection unit 921, see Fig. 9B As shown, the storage unit 911 in the storage circuit 910 may also include a first data buffer 9111, a second data buffer 9112, and an index information buffer 9113. The functions of the first data buffer 9111, the second data buffer 9112, and the index information buffer 9113 are as described above and will not be repeated here. Exemplarily, the calculation unit 922 in the operation circuit 920 may include a multiplication unit 9201, an accumulation unit 9202, an excitation function unit 9203, and a vector calculation unit 9204. The functions of the multiplication unit 9201, the accumulation unit 9202, the excitation function unit 9203, and the vector calculation unit 9204 are as described above and will not be repeated here.
[0210] In some possible implementations, the hardware accelerator may further include an input buffer 923 and an output buffer 924 for temporarily storing input and output data in the hardware accelerator. After the operation circuit 920 completes the calculation, the result may be placed in the output buffer 924 and output, wherein the output buffer 924 may be written back to the processor at one time after the cache is full. The input buffer 923 and the output buffer 924 may be deployed inside the operation circuit 920 or outside the operation circuit 920. Fig. 9B Take the case where the input buffer area 923 and the output buffer area 924 are disposed outside the computing circuit 920 as an example.
[0211] In some embodiments, the hardware accelerator may include a memory access unit 913. The memory access unit 913 may use direct memory access (DMA). The memory access unit 913 may be used for data transmission between the hardware accelerator and other devices. Figure 3 The hardware accelerator in Fig. 9B Taking the structure shown in FIG. 1 as an example, the hardware and software collaborative framework of the data processing device 200 is shown in FIG. Fig. 10B The memory access unit 913 can be used for data transmission between the hardware accelerator 200 and the memory 212. The memory access unit 913 can be deployed inside the storage circuit 910 or outside the storage circuit 910. Fig. 10B In the figure, deployment outside the storage circuit 910 is taken as an example.
[0212] In some embodiments, the memory access unit 913 adopts DMA as an example. Each circuit of the hardware accelerator can be equipped with a DMA to implement parallel data reading. In some embodiments, the hardware accelerator can also include a control interconnection circuit ( Fig. 10B (not shown) for interconnecting the control signal lines between the processing system 210. Fig. 10B , under the control of the processor 211 in the processor 210, the DMA is respectively controlled to be turned on through the control bus and the data bus, and the DMA transfers the first matrix of the data to be processed in the memory 211 and the second matrix corresponding to the weight tensor and the index of the non-zero elements in the second matrix to the storage circuit 910 in the hardware accelerator 220, such as transferring the second matrix to the first data buffer area 9111, transferring the first matrix to the second data buffer area 9112, and transferring the index of the non-zero elements of the second matrix to the index information buffer unit 9113. Then, the target result is obtained through the processing of the operation circuit 920. See Fig. 11BAs shown, the selection unit 921 reads the j-th row non-zero elements in the second matrix from the first data buffer area 9111. It can be understood that each column of non-zero elements is compactly stored in the first data buffer area 9111 by row. The selection unit 921 can read the storage row where the j-th row is located from the first data buffer area 9111. The selection unit 921 obtains the index of the j-th row non-zero element in the second matrix from the index information buffer area 9113, and then reads the element in the j-th column of the first matrix multiplied with the j-th row non-zero element in the second matrix from the second data buffer area 9112 according to the index of the j-th row non-zero element. For example, the selection unit 921 can read the elements in the j-th column of the first matrix from the second data buffer area 9112, and each column of elements in the first matrix is stored in the second data buffer area 9112 by row. The storage circuit 910 can output the storage row where the j-th column in the first matrix is located, the j-th row non-zero element in the second matrix, and the index of the j-th row non-zero element to the input buffer area 923. Then the selection unit 921 obtains the elements that need to be multiplied with the non-zero elements in the j-th row from the elements in the j-th column of the first matrix according to the index of the non-zero elements in the j-th row. The calculation unit 922 can calculate the elements that need to be multiplied with the non-zero elements in the j-th row and the non-zero elements in the j-th row in the elements in the j-th column of the first matrix according to the selection result of the selection unit 921. For example, the multiplication unit 9201 performs multiplication operations on the non-zero elements in the j-th row of the second matrix and the elements in the j-th column of the first matrix that need to be multiplied with the non-zero elements in the j-th row to obtain multiple values, and then the accumulation unit 9202 performs addition operations on the multiple values.
[0213] Based on the above embodiments, see Fig.12 The structure diagram of the pruning device provided in the embodiment of the present application is shown. The pruning device is used to implement Figure 4 The pruning method shown. The pruning device may include an acquisition unit 1201 and a pruning unit 1202. The acquisition unit can be used to obtain a first weight tensor of the neural network to be pruned. The pruning unit 1202 performs at least one pruning process on the first weight tensor to obtain a second weight tensor. In some embodiments, the pruning device may also include a training unit 1203. The pruning unit 1201 is specifically used to deform the input four-dimensional weight tensor to obtain a deformed three-dimensional weight tensor, wherein the three-dimensional weight tensor includes G data blocks, each of which is composed of K pruning vectors, and each pruning vector is composed of M weights; the three-dimensional weight tensor is pruned along the K dimension, and the q with the least importance in the K dimension is pruned. i The weights are reset to zero to obtain a three-dimensional weight vector after the i-th pruning; then the three-dimensional weight tensor after the i-th pruning is deformed to obtain a deformed four-dimensional weight tensor. The training unit 1203 is used to train the deformed four-dimensional weight tensor to obtain a four-dimensional weight tensor that has undergone the i-th pruning process.
[0214] The technical effects achieved by the solutions provided in the embodiments of the present application are described below.
[0215] at present In the hardware 2:4 sparse method, there are two positions in the vector of length 4 that are 0. There is no rule between the two positions. Architecture and The method designed for GPUs with architectures is therefore not applicable to general acceleration hardware structures, such as general GPUs or CPUs. The solution provided in the embodiments of the present application can be applied to general parallel computing hardware. It can also be accelerated on dedicated hardware structures. The embodiments of the present application adopt a complementary sparse progressive pruning method, which can improve the accuracy of the trained network compared to a single pruning. In addition, the solution provided in the embodiments of the present application is in C i n or C i n *FH*FW sparse processing on the dimension can improve the accuracy compared with the outer vector wise (OVW) sparse method. The OVW sparse method is based on the C out The sparse processing is performed on the dimension. Compared with this method, the embodiment of the present application can improve the acceleration efficiency.
[0216] In addition, it should be noted that the embodiments of the present application can also be applied to optimization scenarios using semi-structured sparse matrix multiplication. 1×1 convolution can also be understood as matrix multiplication, so any scenario where matrix multiplication is sparse can also use the solution provided by the embodiments of the present application.
[0217] It should be understood that the division of the various units of the above device is only a division of logical functions, and in actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated.
[0218] In the above embodiments, it can be implemented in whole or in part by software, hardware or a combination thereof. When implemented using a software program, it can be implemented in whole or in part in the form of a computer program product. A computer program product includes one or more instructions. When a computer program instruction is loaded and executed on a computer, a process or function according to the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Instructions may be stored in a computer storage medium or transmitted from one computer storage medium to another computer storage medium. For example, instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired (e.g., coaxial cable, optical fiber, twisted pair) or wireless (e.g., infrared, wireless, microwave, etc.) means. Computer storage media may be any medium that a computer can access or a data storage device such as a server or data center that includes one or more media integrations. The medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape, a magneto-optical disk (MO), etc.), an optical medium (e.g., an optical disk), or a semiconductor medium (e.g., a ROM, EPROM, EEPROM, a solid state disk (SSD)), etc.
[0219] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by instructions. These instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0220] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0221] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0222] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A neural network pruning method, characterized in that: include: Obtain the first weight tensor of the neural network to be pruned; Perform at least one pruning process on the first weight tensor to obtain a second weight tensor; The second weight tensor includes a plurality of data blocks, each of which is composed of K pruning vectors, each of which is composed of M weights; K and M are both positive integers; The weight corresponding to the first position in the first pruning vector included in the first data block is a non-zero element, the weight corresponding to the first position in other pruning vectors in the first data block except the first pruning vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruning vector is any pruning vector in the first data block.
2. The method according to claim 1, characterized in that The sparsity S of the second weight tensor satisfies: S=1-1 / K.
3. The method according to claim 1 or 2, characterized in that The pruning process is performed N times in a manner of increasing sparsity.
4. The method according to claim 3, characterized in that The number of times N that the pruning process is performed is related to the number K of pruning vectors included in the data block and / or the sparsity of the second weight tensor.
5. The method according to claim 4, characterized in that The number of times the pruning process is performed satisfies: N=S / (1-S), or, N=K-1.
6. The method according to any one of claims 3 to 5, characterized in that: N = K-1, the sparsity of the i-th pruning process satisfies: Among them, S i Indicates the sparsity of the i-th pruning process, i is a positive integer, 1≤i <K。 7. The method according to any one of claims 3 to 6, characterized in that: Perform the i-th pruning process, where i is less than or equal to N, including: A deformed three-dimensional weight tensor obtained by deforming an input four-dimensional weight tensor, wherein the three-dimensional weight tensor includes G data blocks, each data block is composed of K pruning vectors, and each pruning vector is composed of M weights; The three-dimensional weight tensor is pruned along the K dimension, and the least important q i The weights are reset to zero to obtain the three-dimensional weight vector after the i-th pruning; Then the three-dimensional weight tensor after the i-th pruning is deformed to obtain a deformed four-dimensional weight tensor; Training the deformed four-dimensional weight tensor to obtain a four-dimensional weight tensor that has undergone the i-th pruning process; Among them, the input four-dimensional weight tensor is the first weight tensor or the four-dimensional weight tensor that has undergone the i-1th pruning process.
8. The method according to claim 7, characterized in that The shape of the input four-dimensional weight tensor is (C out ,C in , FH, FW), the shape of the deformed three-dimensional weight tensor is (G, K, M); where G satisfies: Among them, C out represents the number of activations of the neural network output, C in represents the number of activations of the neural network input, the FH represents the kernel height of the neural network, and the FW represents the kernel width of the neural network; C in *FH*FW=K*M, or, the C in =K*M.
9. The method according to claim 7 or 8, characterized in that The q with the smallest importance in the K dimension i The weights are reset to zero, including: The q with the smallest L1 norm in K dimensions i The weights are reset to zero; or The q with the smallest L2 norm in K dimensions i The weights are reset to zero.
10. The method according to any one of claims 7 to 9, characterized in that: When the training process adjusts all weights, the q i =i; or, When the training process adjusts only the unpruned weights, the q i =1.
11. A data processing method, characterized in that: include: Acquire data to be processed, and generate a vector representation of the data to be processed; Performing calculations on the vector representation of the data to be processed and the weight tensor included in the neural network to obtain a processing result of the data to be processed; Among them, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each of which is composed of K pruned vectors, and each pruned vector is composed of M weights; K and M are both positive integers; the weight corresponding to the first position in the first pruned vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the other pruned vectors in the first data block except the first pruned vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruned vector is any pruned vector in the first data block.
12. The method according to claim 11, characterized in that Performing calculations on the vector representation of the data to be processed and the weight tensor included in the neural network, including: The vector representation of the data to be processed is a first matrix, and the weight tensor is processed to obtain a second matrix and the index of the non-zero elements in the second matrix; A multiplication operation is performed on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result.
13. The method according to claim 12, characterized in that Each row element in the second matrix corresponds to the weight of a data block, and the number of column elements in the first matrix is K*M.
14. The method according to claim 13, characterized in that Performing a multiplication operation on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result includes: The elements in the first matrix to be operated on with the non-zero elements in the i-th row in the second matrix are determined according to the indices of the non-zero elements in the second matrix, so as to perform a multiplication operation on the second matrix and the first matrix to obtain a calculation result.
15. The method according to claim 14, characterized in that The number of non-zero elements in each data block is M; the index value of the k-th non-zero element in each data block is k-1, which is used to indicate the index of the pruning vector to which the k-th non-zero element belongs; When the index value of the first non-zero element in the second matrix is g, the row r of the element in the first matrix that is multiplied with the first non-zero element satisfies: r=g*M.
16. The method according to any one of claims 12 to 15, characterized in that: The shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel height of the neural network; the number of column elements of the second matrix is C out *FH*FW, the number of row elements of the second matrix is C in ; C in =K*M, the number of data blocks included in the weight tensor 17. The method according to any one of claims 12 to 15, characterized in that: The shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel width of the neural network; the number of column elements of the second matrix is C out , the number of row elements of the second matrix is C in *FH*FW;C in *FH*FW=K*M, the number of data blocks included in the weight tensor 18. An accelerator, characterized in that: include: A storage circuit, used to store a first matrix corresponding to the data to be processed, a second matrix corresponding to the weight tensor of the neural network, and the index of the non-zero elements in the second matrix; Wherein, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each of which is composed of K pruned vectors, and each pruned vector is composed of M weights; K and M are both positive integers; the weight corresponding to the first position in the first pruned vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the other pruned vectors in the first data block except the first pruned vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruned vector is any pruned vector in the first data block; An operation circuit is used to perform a multiplication operation on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result.
19. The accelerator according to claim 18, characterized in that Each row element in the second matrix corresponds to the weight of a data block, and the number of column elements in the first matrix is K*M.
20. The accelerator according to claim 19, characterized in that The operation circuit includes a selection unit and a calculation unit; The selection unit is used to read the non-zero elements of the i-th row in the second matrix from the storage circuit according to the index of the non-zero elements in the second matrix, and read the elements in the i-th column of the first matrix that are operated on the non-zero elements of the second matrix from the storage circuit according to the index of the non-zero elements of the second matrix; The calculation unit is used to perform multiplication and addition operations on the non-zero elements in the i-th row of the second matrix and the elements in the i-th column of the read first matrix.
21. The accelerator according to claim 19, characterized in that The storage circuit includes a storage unit and a selection unit, wherein the storage unit is used to store a first matrix corresponding to the data to be processed, a second matrix corresponding to the weight tensor included in the neural network, and an index of a non-zero element in the second matrix; The selection unit is used to read the non-zero elements of the i-th row in the second matrix from the storage circuit according to the index of the non-zero elements in the second matrix, and send the non-zero elements of the i-th row in the second matrix to the operation circuit; and reading, from the storage circuit according to the index of the non-zero element of the second matrix, the element in the i-th column of the first matrix to be operated with the non-zero element in the i-th row of the second matrix, and sending the element in the i-th column of the first matrix to be operated with the non-zero element in the i-th row of the second matrix to the operation circuit; The operation circuit is specifically used to perform multiplication and addition operations on the non-zero elements in the i-th row of the second matrix and the elements in the i-th column of the first matrix and the non-zero elements in the i-th row of the second matrix.
22. The accelerator according to claim 20 or 21, characterized in that The number of non-zero elements in each data block is M; the index value of the k-th non-zero element in each data block is k-1, which is used to indicate the index of the pruning vector to which the k-th non-zero element belongs; When the index value of the first non-zero element in the second matrix is g, the row r of the element in the first matrix that is multiplied with the first non-zero element satisfies: r=g*M.
23. The accelerator according to any one of claims 18 to 22, characterized in that: The shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel width of the neural network; the number of column elements of the second matrix is C out *FH*FW, the number of row elements of the second matrix is C in ; C in =K*M, the number of data blocks included in the weight tensor 24. The accelerator according to any one of claims 18 to 22, characterized in that:The shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel height of the neural network; the number of column elements of the second matrix is C out , the number of row elements of the second matrix is C in *FH*FW;C in *FH*FW=K*M, the number of data blocks included in the weight tensor 25. A processing system, characterized in that include: A processor, configured to obtain data to be processed and generate a vector representation of the data to be processed; An accelerator, configured to perform calculations on the vector representation of the data to be processed and the weight tensor included in the neural network to obtain a processing result of the data to be processed; Among them, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each of which is composed of K pruned vectors, and each pruned vector is composed of M weights; K and M are both positive integers; the weight corresponding to the first position in the first pruned vector included in the first data block is a non-zero element, and the weight corresponding to the first position in the other pruned vectors in the first data block except the first pruned vector is a zero element, the first data block is any data block among the multiple data blocks, and the first pruned vector is any pruned vector in the first data block.
26. The system of claim 25, wherein: The processor is further configured to process the vector representation of the data to be processed into a first matrix, process the weight tensor to obtain a second matrix and the index of non-zero elements in the second matrix, and send the first matrix, the second matrix and the index of non-zero elements in the second matrix to the accelerator; The accelerator is specifically used to perform a multiplication operation on the second matrix and the first matrix according to the index of each non-zero element in the second matrix to obtain a calculation result.
27. The system of claim 26, wherein: Each row element in the second matrix corresponds to the weight of a data block, and the number of column elements in the first matrix is K*M.
28. The system of claim 27, wherein: The accelerator is specifically used to determine the elements in the first matrix that are operated on the non-zero elements in the i-th row in the second matrix according to the indexes of the non-zero elements in the second matrix, so as to perform multiplication operations on the second matrix and the first matrix to obtain a calculation result.
29. The system of claim 28, wherein: The number of non-zero elements in each data block is M; the index value of the k-th non-zero element in each data block is k-1, which is used to indicate the index of the pruning vector to which the k-th non-zero element belongs; When the index value of the first non-zero element in the second matrix is g, the row r of the element in the first matrix that is multiplied with the first non-zero element satisfies: r=g*M.
30. The system according to any one of claims 26 to 29, characterized in that: The shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel width of the neural network; the number of column elements of the second matrix is C out *FH*FW, the number of row elements of the second matrix is C in ; C in =K*M, the number of data blocks included in the weight tensor 31. The system according to any one of claims 26 to 29, characterized in that: The shape of the weight tensor is (C out ,C in ,FH,FW),C out represents the number of output activations of the neural network, C in represents the number of activations of the neural network input, FH represents the kernel height of the neural network, and FW represents the kernel height of the neural network; the number of column elements of the second matrix is C out , the number of row elements of the second matrix is C in *FH*FW;C in *FH*FW=K*M, the number of data blocks included in the weight tensor 32. A pruning device, characterized in that: include: A memory for storing program instructions; A processor is used to be coupled with the memory, call program instructions in the memory, and execute the method according to any one of claims 1 to 10, or execute the method according to any one of claims 11 to 17.
33. A computer storage medium, characterized in that The computer storage medium stores a computer program, and when the computer program is executed by a computer, the computer executes the method according to any one of claims 1 to 10, or the computer executes the method according to any one of claims 11 to 17.
