Neural network pruning method and apparatus, and data processing method and apparatus

By adopting a smaller-granularity semi-structured sparse method and a progressive pruning method in the neural network, the problem of lack of regularity and coarse granularity in the sparse method in the existing technology is solved, and the accuracy and acceleration efficiency of the neural network are improved.

WO2024222115A1PCT designated stage expired Publication Date: 2024-10-31HUAWEI TECH CO LTD

Patent Information

Application Number
PCT/CN2024/074982
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-25
Filing Date
2024-01-31
Publication Date
2024-10-31

AI Technical Summary

Technical Problem

In the existing neural network pruning method, the 0 elements in the sparse method are randomly distributed and lack regularity, resulting in insufficient optimization of inference performance. In addition, the structured sparse method prunes the convolution weights at a coarse granularity and low accuracy.

Method used

Using a smaller-granularity semi-structured sparse method, by obtaining the weight tensor of the neural network to be pruned, sparse processing is performed in a complementary manner. Only one non-zero element is selected for each K pruning vectors to participate in the calculation, reducing the amount of calculation and Reduce power consumption and combine with progressive pruning to gradually improve the accuracy of the network.

Benefits of technology

It achieves a balance between accuracy and acceleration, improves the application accuracy and computing speed of neural networks, is suitable for accelerating hardware, and reduces power consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024074982_31102024_PF_FP_ABST
    Figure CN2024074982_31102024_PF_FP_ABST
Patent Text Reader

Abstract

A neural network pruning method and apparatus, and a data processing method and apparatus. A complementary sparse mode is provided. Therefore, every K pruning vectors with a length of M in weight tensors are spliced into one data block (or vector), and after sparsity, at the position of a non-zero element in one pruning vector, the other pruning vectors in a data block to which the pruning vector belongs are zero elements. The method improves the accuracy of application of a network model, reduces the calculation amount of the model, and can balance the accuracy and acceleration.
Need to check novelty before this filing date? Find Prior Art

Description

Neural network pruning method, data processing method and device

[0001] CROSS-REFERENCE TO RELATED APPLICATIONS

[0002] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of the People's Republic of China on April 25, 2023, with application number 202310470198.9 and invention name “Pruning method, data processing method and device for neural network”, the entire contents of which are incorporated by reference into this application. Technical Field

[0003] 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

[0004] The scale of neural networks continues to grow, and the number of parameters and computational complexity is also increasing. To reduce these requirements, pruning, quantization, distillation, or lightweight model design can be used. Pruning is widely used. Pruning involves resetting some non-critical weights to 0 in redundant, larger models to achieve a sparse model. While arbitrary sparsity methods can be used to select parts to prune, the distribution of zero elements in arbitrary pruning methods is relatively random, and since there's no pattern to follow, this doesn't optimize inference performance. Structured sparsity can also be used to select parts to prune, but this method prunes convolutional weights on a channel-by-channel basis, resulting in a coarser granularity and lower accuracy.

[0005] Summary of the Invention

[0006] The embodiments of the present application provide a neural network pruning method, a data processing method, and an apparatus, for providing a pruning method that balances reasoning performance and accuracy.

[0007] 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 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 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, and the first pruned vector is any pruned vector in the first data block.

[0008] Compared with the single-channel or block-based sparse approach, the embodiment of the present application adopts a smaller granularity for sparseness, which can improve the accuracy of the application of the network model. Compared with the use of any sparse approach, sparseness is performed in a complementary manner with certain rules, which is understood as a type 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. The pruning method provided by the embodiment of the present application selects only one non-zero element to participate in the calculation at the same position of each K pruning vectors. 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 by the embodiment of the present application can balance accuracy and acceleration.

[0009] 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 method to ensure that the position where a non-zero element in a pruned vector is located has a zero element in other pruned vectors in the data block to which the pruned vector belongs.

[0010] In one possible design, the pruning process is performed N times in a manner of increasing sparsity. According to the progressive sparsification method, the accuracy of the network can be improved.

[0011] In one possible design, the number of times N that the pruning process is performed is related to the number K of pruned vectors included in the data block and / or the sparsity of the second weight tensor.

[0012] In one possible design, the pruning process is performed a number of times that: N = S / (1-S), or N = K-1.

[0013] 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.

[0014] In one possible design, N = K-1, and the sparsity of the i-th pruning process satisfies:

[0015] Among them, S i Indicates the sparsity of the i-th pruning process, i is a positive integer, 1≤i<K.

[0016] In one possible design, performing the i-th pruning process, where i is less than or equal to N, includes:

[0017] 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 consists of K pruned vectors, and each pruned vector consists of M weights;

[0018] 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;

[0019] Then the three-dimensional weight tensor after the i-th pruning is deformed to obtain the deformed four-dimensional weight tensor;

[0020] Training the deformed four-dimensional weight tensor to obtain a four-dimensional weight tensor that has undergone the i-th pruning process;

[0021] 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.

[0022] 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.

[0023] In one possible design, 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:

[0024] 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, FH represents the kernel height of the neural network, and FW represents the kernel width of the neural network; C in *FH*FW=K*M, or, the C in =K*M.

[0025] In the above design, the embodiment of the present application is in C in or C in *FH*FW is sparsely processed on the dimension, which can improve the accuracy compared with the outer vector wise (OVW) sparse method. out The embodiment of the present application can improve the acceleration efficiency compared with this method.

[0026] In one possible design, the least important q in K dimensions isi The weights are reset to zero, including:

[0027] The q with the smallest L1 norm in K dimensions i The weights are reset to zero; or

[0028] The q with the smallest L2 norm in K dimensions i The weights are reset to zero.

[0029] In one possible design, when the training process adjusts all weights, the q i =i; or,

[0030] When the training process adjusts only the weights that are not pruned, the q i =1.

[0031] In a second aspect, an embodiment of the present application provides a data processing method, including:

[0032] Acquire data to be processed and generate a vector representation of the data to be processed;

[0033] 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;

[0034] In which, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each data block 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 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.

[0035] The solution provided by the embodiment of the present application selects only one non-zero element at the same position in each of the K pruned vectors for calculation. Since all other weights at the same position are zero, this can improve computational speed and reduce power consumption when applied to acceleration hardware. The solution provided by the embodiment of the present application achieves a balance between accuracy and acceleration.

[0036] 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:

[0037] 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 indices of non-zero elements in the second matrix;

[0038] 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.

[0039] 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.

[0040] In one possible design, 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:

[0041] An element in the first matrix to be operated on with the non-zero element in the i-th row of the second matrix is ​​determined according to the index of the non-zero element in the second matrix, so as to perform a multiplication operation on the second matrix and the first matrix to obtain a calculation result.

[0042] In one 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;

[0043] 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 by the first non-zero element satisfies: r=g*M.

[0044] 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

[0045] 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 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 ​​Cin *FH*FW;C in *FH*FW=K*M, the number of data blocks included in the weight tensor

[0046] In a third aspect, an embodiment of the present application provides an accelerator, comprising:

[0047] A storage circuit, configured 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 indices of non-zero elements in the second matrix;

[0048] The weight tensor of the neural network is obtained through pruning, 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 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, and the first pruned vector is any pruned vector in the first data block;

[0049] 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.

[0050] 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.

[0051] In one possible design, the operation circuit includes a selection unit and a calculation unit;

[0052] The selection unit is configured to read the non-zero elements in the i-th row of 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 to be operated on the non-zero elements of the second matrix from the storage circuit according to the index of the non-zero elements in the second matrix;

[0053] The calculation unit is configured to perform a multiplication and addition operation 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 read.

[0054] In one possible design, 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 the index of non-zero elements in the second matrix;

[0055] The selection unit is configured to read the non-zero elements in the i-th row of 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 in the i-th row of the second matrix to the operation circuit; and read the elements in the i-th column of the first matrix to be operated on with the non-zero elements in the i-th row of the second matrix from the storage circuit according to the index of the non-zero elements in the second matrix, and send the elements in the i-th column of the first matrix to be operated on with the non-zero elements in the i-th row of the second matrix to the operation circuit;

[0056] 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.

[0057] In one 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;

[0058] 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 by the first non-zero element satisfies: r=g*M.

[0059] 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 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

[0060] 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;Cin *FH*FW=K*M, the number of data blocks included in the weight tensor

[0061] In a fourth aspect, an embodiment of the present application provides a processing system, including:

[0062] A processor, configured to obtain data to be processed and generate a vector representation of the data to be processed;

[0063] 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;

[0064] In which, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each data block 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 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.

[0065] In one possible design, 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 indices of non-zero elements in the second matrix, and send the first matrix, the second matrix, and the indices of non-zero elements in the second matrix to the accelerator;

[0066] The accelerator is specifically configured 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.

[0067] 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.

[0068] In one possible design, the accelerator is specifically used to determine the elements in the first matrix to be operated on with the non-zero elements in the i-th row of the second matrix based on 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.

[0069] In one 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;

[0070] 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 by the first non-zero element satisfies: r=g*M.

[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 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

[0072] 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

[0073] In a fifth aspect, the present application further provides a pruning device that implements the method of the first aspect. The functionality can be implemented via hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the functionality.

[0074] In one possible design, the pruning device may include an acquisition unit and a pruning unit. These units may perform the corresponding functions described in the above method examples. For details, please refer to the detailed description of the method examples and are not repeated here. The pruning device may also include a training unit for performing training operations.

[0075] In one 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 program instructions and data necessary for the pruning device.

[0076] In a sixth aspect, the present application also 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.

[0077] 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.

[0078] 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.

[0079] Based on the implementations provided in the above aspects, this application can also be further combined to provide more implementations. BRIEF DESCRIPTION OF THE DRAWINGS

[0080] Figure 1 is a schematic diagram of the convolutional neural network structure;

[0081] FIG2 is a schematic diagram of a system architecture 10 provided in an embodiment of the present application;

[0082] FIG3 is a schematic structural diagram of a data processing device 200 provided in an embodiment of the present application;

[0083] FIG4 is a schematic diagram of a pruning method according to an embodiment of the present application;

[0084] FIG5 is a schematic diagram of a pruned data block provided in an embodiment of the present application;

[0085] FIG6 is a schematic diagram showing the correspondence between sparsity and the number of pruning times provided in an embodiment of the present application;

[0086] FIG7 is a schematic diagram of a progressive pruning process according to an embodiment of the present application;

[0087] FIG8A is a flow chart of a data processing method according to an embodiment of the present application;

[0088] FIG8B is a schematic diagram of a coding method for non-zero indexes of data blocks provided in an embodiment of the present application;

[0089] FIG9A is a schematic diagram of an accelerator structure provided in an embodiment of the present application;

[0090] FIG9B is a schematic diagram of another accelerator structure provided in an embodiment of the present application;

[0091] FIG10A is a schematic diagram of a processing system structure provided in an embodiment of the present application;

[0092] FIG10B is a schematic diagram of another processing system structure provided in an embodiment of the present application;

[0093] FIG11A is a schematic diagram of a data processing flow provided in an embodiment of the present application;

[0094] FIG11B is a schematic diagram of another data processing flow provided in an embodiment of the present application;

[0095] FIG12 is a schematic diagram of the structure of the pruning device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0096] Before describing a neural network pruning method, a data processing method, and an apparatus provided in the embodiments of the present application, the relevant concepts involved in the embodiments of the present application are first described.

[0097] (1) Neural Network:

[0098] Neural networks are used to implement machine learning, deep learning, search, reasoning, decision-making, etc. The neural networks mentioned in this application can include various types, such as deep neural networks (DNNs), convolutional neural networks (CNNs), recurrent neural networks (RNNs), residual networks, neural networks using transformer models, or other neural networks. The following is an illustrative introduction to some neural networks.

[0099] (2) Convolutional Neural Networks:

[0100] Convolutional neural networks (CNNs) are deep neural networks with a convolutional structure and a deep learning architecture. Deep learning architectures use machine learning algorithms to perform multiple levels of learning at different levels of abstraction. As a deep learning architecture, CNNs are feed-forward artificial neural networks, in which individual neurons process input data.

[0101] As shown in Figure 1, a 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. As shown in Figure 1, the convolutional layer / pooling layer 120 may include layers 121-126, for example. In one implementation, layer 121 is a convolutional layer, layer 122 is a pooling layer, layer 123 is a convolutional layer, layer 124 is a pooling layer, layer 125 is a convolutional layer, and layer 126 is a pooling layer; in another implementation, layers 121 and 122 are convolutional layers, layer 123 is a pooling layer, layer 124 and 125 are convolutional layers, and layer 126 is a pooling layer. That is, the output of a convolutional layer can serve as the input of a subsequent pooling layer, or as the input of another convolutional layer to continue the convolution operation. Taking convolutional layer 121 as an example, convolutional layer 121 may include many convolution operators, which are also called convolution kernels. The convolution operator is essentially a weight matrix, which is usually predefined. For example, in image processing, different weight matrices extract different features from the image. For example, one weight matrix is ​​used to extract image edge information, another weight matrix is ​​used to extract specific colors, and yet another weight matrix is ​​used to blur unwanted noise in the image.

[0102] 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.

[0103] 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.

[0104] Pooling layer:

[0105] Because it's often desirable to reduce the number of training parameters, pooling layers are often periodically introduced after convolutional layers. For example, as shown in the example of 120 in Figure 1, layers 121-126 can be composed of one convolutional layer followed by one pooling layer, or multiple convolutional layers followed by one or more pooling layers. In image processing, the sole purpose of a pooling layer is to reduce the spatial size of an image. Pooling layers can include average pooling and / or max pooling operators, which are used to downsample the input image to produce a smaller image. The average pooling operator calculates the average value of pixel values ​​within a specific range. The max pooling operator takes the pixel with the largest value within a specific range as the result of max pooling. Furthermore, just as the size of the weight matrix used in the convolutional layer should be related to the image size, the operators in the pooling layer should also be related to the image size. The output image size after processing by the pooling layer can be smaller than the size of the image input to the pooling layer. Each pixel in the output image of the pooling layer represents the average or maximum value of the corresponding subregion of the image input to the pooling layer.

[0106] After being processed by the convolution layer / pooling layer 120, the convolution neural network 100 is still insufficient to output the required output information. Because 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 relevant 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 (131, 132 to 13n as shown in Figure 1) and an output layer 140. The parameters contained in the multiple hidden layers can be pre-trained based on relevant training data of a specific task type. For example, the task type may include image recognition, image classification, image super-resolution reconstruction, etc.

[0107] 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. The output layer 140 has a loss function similar to the classification cross entropy, which is specifically used to calculate the prediction error. Once the forward propagation of the entire convolutional neural network 100 (such as the propagation from 110 to 140 in Figure 1 is forward propagation) is completed, the back propagation (such as the propagation from 140 to 110 in Figure 1 is back propagation) will begin to update the weight values ​​and biases of the aforementioned layers 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.

[0108] It should be noted that the convolutional neural network 100 shown in Figure 1 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 run in parallel, and the extracted features are input into the neural network layer 130 for processing.

[0109] (3) Pruning / thinning:

[0110] Sparse / pruning is to set the weight values ​​of non-critical parts in 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 sparsified weights. 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, the granularity is lower and needs to be pruned according to certain rules, but the rules are relatively weak and require customized code implementation to achieve good inference performance. For example, NVIDIA The proposed 2:4 sparse model has two positions with zero weights in the length 4 vector.

[0111] (4) Sparsity: the ratio of the number of 0 elements to the total number of elements.

[0112] In the description of this application, unless otherwise specified, "plurality" means two or more than two. Furthermore, " / " indicates that the objects associated with each other are in an "or" relationship. For example, A / B can mean A or B. "And / or" in this application is merely a description of the association relationship between associated objects, indicating that three relationships can exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, or B exists alone. A and B can be singular or plural. Furthermore, to facilitate the clear description of the technical solutions of the embodiments of this application, the embodiments of this application use terms such as "first" and "second" to distinguish between identical or similar items with substantially the same functions and effects. Those skilled in the art will understand that terms such as "first" and "second" do not limit the quantity or order of execution, and that terms such as "first" and "second" do not necessarily define differences. It should also be noted that, unless otherwise specified, the specific description of certain technical features in one embodiment can also be used to explain the corresponding technical features mentioned in other embodiments.

[0113] 2 , which is a schematic diagram of a system architecture 10 provided in an embodiment of the present application, includes a pruning device 100 and a data processing device 200 .

[0114] The pruning device 100 is used to execute the neural network pruning method 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, it can send the pruned neural network to the data processing device 200.

[0115] The pruning device 100 can be implemented by software or hardware.

[0116] The pruning device 100 is an example of a software functional unit. The pruning device 100 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Furthermore, the 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 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, each AZ including one data center or multiple geographically close data centers. Typically, a region may include multiple AZs.

[0117] Similarly, multiple hosts / virtual machines / containers running the code can be distributed within the same virtual private cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Cross-region communication between two VPCs within the same region, or between VPCs in different regions, requires a communication gateway within each VPC to interconnect the VPCs.

[0118] As an example of a hardware functional unit, the pruning device 100 may include at least one computing device, such as a server. The at least one computing device may be deployed in a cloud network or locally. Alternatively, the pruning device 100 may be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0119] In some scenarios, the multiple computing devices included in the pruning apparatus 100 may be distributed in the same region or in different regions.

[0120] System architecture 10 also includes a data storage system 300. Optionally, pruning device 100 cooperates with other computing devices, such as data storage, routers, and load balancers. Pruning device 100 can use data in data storage system 300 or call program code in data storage system 300 to implement the neural network pruning method provided in this application.

[0121] FIG3 exemplarily shows a structural diagram of a data processing device 200 provided in the present application. As shown in FIG3 , 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 transmit control information through the control bus 240. The processing system 210 is the control component of the entire system, and includes a processor 211. Optionally, the processing system 210 also includes a memory 212. The processor 211 is used to run the code on the software side and load the acceleration task (such as a matrix or vector) onto 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 status 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 and peripheral component interconnect (PCI) interfaces, into circuits with modifiable parameters. The processor 211 can be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and an NP. The processor 211 can further include a hardware chip. The above-mentioned hardware chip can be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above-mentioned PLD can 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 (non-volatile memory), such as a flash memory, a hard disk drive (HDD), or a solid-state drive (SSD). The memory 212 can also include a combination of the above types of memory.

[0122] The hardware accelerator 220, which can also be referred to as the accelerator, is the 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 220 can be used in a neural network to accelerate the neural network algorithm. After the data exchange is completed, the hardware accelerator 220 and the processing system 210 can independently execute tasks in parallel. The hardware accelerator 220 can be a graphics processing unit (GPU), or an FPGA, or an integrated circuit (application specific integrated circuit, ASIC) for special applications, or a microcontroller (micro control unit, MCU), etc.

[0123] Data bus 230 is used for data transmission between the entire processing system 210 and the hardware accelerator 220. Data bus 230 can use the Advanced Extensible Interface-Stream (AXI-Stream) protocol or the PCI Express (PCI-E) bus protocol. AXI is a bus protocol, and AXI-Stream is a high-performance transmission protocol that allows unlimited data burst transmission.

[0124] The control bus 240 is used to transmit control signals between the entire processing system 210 and the hardware accelerator 220. The control bus 40 may use the AXI-Lite protocol, which is a lightweight, address-mapped, single-transfer protocol suitable for transmitting control signals in hardware computing circuits.

[0125] 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.

[0126] The data processing device 200 interacts with the pruning device 100 via a communication network using 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.

[0127] The solution provided by the embodiments 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 embodiments of the present application are applicable to scenarios using Transformer networks or Transformer+CNN fusion networks.

[0128] The following describes the process flow of the neural network pruning method provided in an embodiment of the present application. FIG4 is a schematic diagram of the process flow of the 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 within the pruning device 100.

[0129] S401, obtaining a first weight tensor of the neural network to be pruned.

[0130] The neural network to be pruned can be a pre-trained neural network or an untrained neural network.

[0131] 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.

[0132] The first weight tensor can be understood as the 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.

[0133] S402: Perform at least one pruning process on the first weight tensor to obtain a second weight tensor.

[0134] 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. For example, the specifications of the hardware that performs neural network operation acceleration are the length of the vector included in the data block.

[0135] 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.

[0136] It should be understood that each data block satisfies the conditions satisfied by the first data block, and the position of the non-zero element in a pruned vector is a zero element in the other pruned vectors in the data block to which the pruned vector belongs. For example, referring to FIG5 , in the pruned vector of M=4, the data block includes two pruned vectors, the weights of the 0th position and the 3rd position of the first pruned vector are non-zero elements, and the weights of the 1st position and the 2nd position of the first pruned vector are zero elements, so that the weights of the 0th position and the 3rd position of the second pruned vector are both zero elements, and the weights of the 1st position and the 2nd position of the second pruned vector are non-zero elements. That is, the positions of the zero elements of the first pruned vector and the second pruned 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 ease of description, the pruning method provided in the embodiment of the present application will be referred to as complementary sparse in the following.

[0137] Compared to using a single-channel or block-based sparsification approach, the embodiments of the present application use a smaller granularity for sparsification, which can improve the accuracy of network model applications. Compared to using arbitrary sparsification methods, sparsification in a complementary manner eliminates the need for dense computing during the inference phase, reducing the computational complexity of the model. The solutions provided by the embodiments of the present application can strike a balance between accuracy and acceleration.

[0138] 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):

[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 can adopt a one-step approach when performing pruning, that is, performing pruning once, or 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 an increasing sparsity manner. In some embodiments, the number K of pruned 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): N=K-1 formula (2).

[0143] For another example, the relationship between N and S satisfies the following formula (3):

[0144] Taking N=K-1 as an example, the sparsity of each pruning process can satisfy the following formula (4):

[0145] Among them, S i Indicates the sparsity of the i-th pruning process, i is a positive integer, 1≤i<K.

[0146] For example, to train a neural network with a sparsity of 75%, after 3 pruning cycles, 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 pruning cycles, the sparsity changes as follows: 0 -> 12.5% ​​-> 25% -> 37.5% -> 50% -> 62.5% -> 75% -> 87.5%.

[0147] It can be understood that for an M*K data block (or matrix) when progressive sparsification 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 sparsification method as vector-by-vector progressive sparsification. Of course, other names can also be used, and the embodiment of the present application does not limit this.

[0148] 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 pruning operations and training operations. In some embodiments, when a vector-by-vector progressive sparsification method is adopted, the number of training times at each sparsity value may be the same. As shown in FIG6 , different steps (stages) 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 ​​may use the same training sample set or different training sample sets. For example, the sample set may be split into multiple training sample subsets, and each time a pruning process is performed, one generation of training is performed using a training sample subset. For example, different training sample subsets include the same number of batches (representing a batch of data), and the number of training times at each sparsity value is the same. A small portion of samples in the training set is used to perform a backpropagation parameter update on the weights retained by the neural network. This small portion of samples is called a "batch of data."

[0149] The following describes the pruning process. Take the i-th pruning as an example, where i is less than or equal to N. For example, each pruning operation can be divided into three steps: (1) deformation, (2) pruning, and (3) restoration (also known as inverse deformation or reverse deformation).

[0150] (1) Deformation: Deform the input four-dimensional weight tensor 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.

[0151] It is understandable 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.

[0152] The shape of the input four-dimensional weight tensor can be described as (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 Indicates the number of convolution kernel input activations (or the number of convolution kernel input channels), FH indicates the kernel height of the convolution kernel, and FW indicates 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 is 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, the weight tensor C in=1, the shape of the input weight tensor can be understood as three-dimensional, that is, (C out ,FH,FW).

[0153] 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):

[0154] In some scenarios, in order to achieve acceleration on general parallel computing hardware or dedicated acceleration hardware, K*M satisfies the following formula (6): K*M=L, L∈{C in ,C in *FH*FW} formula (6).

[0155] For example, dedicated acceleration hardware can be a circuit or hardware with independent functions that can accelerate the complementary sparseness provided by 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 set to C in *FH or C in *FW.

[0156] 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 Dimensions are pruned. Further, the rearranged weight tensor is transformed into a three-dimensional weight tensor of (G, K, M). At this time, G = C out *FH*FW.

[0157] In some other embodiments, L=C in *FH*FW as an example, when performing deformation, the input four-dimensional weight tensor can be rearranged into (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 .

[0158] (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.

[0159] The three-dimensional weight tensor (G, K, M) can be understood as G K*M data blocks. Each K*M data block is pruned in the K dimension, and the K weights in each column have the smallest importance q. i The weights are reset to zero.

[0160] For example, the q with the smallest importance in the K dimension i The weights are reset to zero and can be:

[0161] The q with the smallest L1 norm in K dimensions i The weights are reset to zero; or

[0162] The q with the smallest L2 norm in K dimensions i The weights are reset to zero.

[0163] For example, the q i =i, or q i =1.

[0164] (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.

[0165] In one 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.

[0166] 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.

[0167] Before training, the first pruning is performed, with i = 1. The sparsity after the first pruning is S1 = 1 / K. It can be understood that during 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, meaning that M weights are subtracted from each data block. The first generation of training is then performed on the pruned weight vectors, with individual weights adjusted during training. The second pruning is then performed, with i = 2. The sparsity after the second pruning is S2 = 2 / K. It can be understood that during 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, meaning that 2*M weights are subtracted from each data block. The second generation of training is then performed on the pruned weight vectors, with individual weights adjusted during training. And so on.

[0168] 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.

[0169] In another example, the pruning operation can be performed first and then the training operation, and the subtracted weights are not updated. i =1.

[0170] Before training, the first pruning is performed, with i = 1. The sparsity after the first pruning is S1 = 1 / K. It can be understood that during 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, meaning that M weights are subtracted from each data block. The first generation of training is then performed on the pruned weight vectors, and the weights that were not subtracted are adjusted during training. The second pruning is then performed, with i = 2. The sparsity after the second pruning is S2 = 2 / K. It can be understood that during the second pruning, M weights are further 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, meaning that 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 were not pruned are adjusted during the training process. And so on.

[0171] 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.

[0172] Before executing 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 executing 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 on the pruned weight vectors, and all weights are adjusted during the training process. Then continue to execute the second pruning, i=2, and the sparsity after the second pruning is S2=2 / K. It can be understood that when executing 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. At this point, 2*M weights have been subtracted from each data block. And so on.

[0173] 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.

[0174] Before executing 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 executing 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 on the pruned weight vectors, and the weights that have not been subtracted are adjusted during the training process. Then continue to execute the second pruning, i=2, and the sparsity after the second pruning is S2=2 / K. It can be understood that when executing the second pruning, M weights are subtracted from each data block consisting of K pruned vectors. For each K*M data block, the K weights in each column are reset to zero after the least important weight is subtracted. At this point, 2*M weights have been subtracted from each data block. And so on.

[0175] For example, Figure 7 shows the progressive pruning process for a tensor with a deformed shape of (1, 4, 4). As the sparsity increases, the number of retained K dimensions decreases. It should be noted that Figure 7 is only an example. In actual pruning, the values ​​of weights will change after training. Figure 7 only illustrates the changes in the number of pruned weights and the sparsity.

[0176] The following describes the data processing method provided in an embodiment of the present application. See FIG8A for a schematic diagram of the data processing flow provided in an embodiment of the present application. The data processing method can be executed by the data processing device 200 or by a module within the data processing device 200. The processor in this embodiment can be the processor 211 in FIG3 , and the accelerator can be the hardware accelerator 220 in FIG3 .

[0177] S801: The processor 211 obtains data to be processed and generates a vector representation of the data to be processed.

[0178] 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.

[0179] S802: The hardware accelerator 220 performs a calculation 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.

[0180] 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 indices of the non-zero elements in the second matrix, and send the first matrix, the second matrix, and the indices of the non-zero elements in the second matrix to the accelerator. The accelerator then performs a multiplication operation (also described as a multiplication operation) on the second matrix and the first matrix based on the index of each non-zero element in the second matrix to obtain a calculation result.

[0181] 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.

[0182] In which, the weight tensor of the neural network is obtained through pruning processing, and the weight tensor includes multiple data blocks, each data block 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 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.

[0183] In one possible implementation, the weight tensor can be encoded. A pruned weight tensor can be encoded as non-zero weight + index. When storing, the non-zero weight can be compactly stored in the order of the spliced ​​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 can 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.

[0184] In one possible embodiment, when the accelerator performs 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, 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.

[0185] 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 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.

[0186] For example, see FIG8B , which 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. In FIG8B , taking the sparsity of 50% as an example, K=2, and M=8 as an example. 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 on the M dimension belongs to pruning vector 1, and the index is 0; the weight of the second non-zero element on the M dimension belongs to pruning vector 2, and the index is 1; the weight of the third non-zero element on the M dimension belongs to pruning vector 3, and the index is 1; the weight of the fourth non-zero element on the M dimension belongs to pruning vector 1, and the index is 0, and so on. In FIG8B , taking the sparsity of 75% as an example, K=4, and M=4 as an example. 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 in the M dimension belongs to pruning vector 1, the index is 0, the binary encoding is 0, the weight of the second non-zero element in 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 in the M dimension belongs to pruning vector 2, the index is 1, the binary encoding is 01, and the weight of the fourth non-zero element in the M dimension belongs to pruning vector 4, the index is 3, and the binary encoding is 11.

[0187] Exemplarily, in combination with the above-mentioned encoding method, when determining the element in the first matrix to be operated on with the non-zero element in the i-th row of the second matrix according to the index of the non-zero element in the second matrix, for example, when the index value of the first non-zero element in the second matrix is ​​g, then the row r of the element in the first matrix that is multiplied with the first non-zero element satisfies: r = g*M.

[0188] The shape of the weight tensor is (C out ,C in , FH, FW) is used 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 represents the zero elements filled. Stride represents the stride, which is used to reduce the number of input parameters and the amount of calculation. The purpose of padding with 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 result matrix is ​​(C out *FH*FW,OH*OW). Further parallel matrix row reduction operation is performed, that is, the sum of each FH*FW number in the result matrix can be obtained. 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.

[0189] 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 represents the padding of zero elements. Stride represents 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. 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 ijWhen the index value 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 to (OC, OW, OH), which is the calculation result.

[0190] As an example, the structure of the accelerator is described below. As shown in Figures 9A and 9B, the accelerator may include a storage circuit 910 and an operation circuit 920. The accelerator may be the hardware accelerator 220 in Figure 3. 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.

[0191] In some scenarios, not all elements in the input first matrix participate in the operation. Instead, only elements that need to be multiplied by non-zero elements in the second matrix participate in the operation. Therefore, a selection circuit can be used to select the elements of the first matrix that need to be operated on (which can also be understood as sparsely performing the operation on the first matrix). The selection circuit can also be called a selection unit. In the following description, the selection circuit will be referred to as the selection unit as an example.

[0192] In one possible implementation, the selection unit is deployed in the arithmetic circuit. As shown in FIG9A , the arithmetic circuit 920 may illustratively include a selection unit 921 and a computation unit 922. The selection unit 921 reads the nonzero elements in the i-th row of the second matrix from the storage circuit based on the indices of the nonzero elements in the second matrix, and reads the elements in the i-th column of the first matrix from the storage circuit based on the indices of the nonzero elements in the second matrix to be operated on with the nonzero elements in the second matrix. The computation unit 922 is configured to perform a multiplication-addition operation on the nonzero elements in the i-th row of the second matrix and the elements in the i-th column of the first matrix read from the storage circuit. It is understood that the selection unit 921 selects only one nonzero element from the same position of the K pruned vectors for computation, while all other elements are zero. The resulting hardware speedup is strictly related to sparsity. For example, the convolution speedup for 50% sparsity is 2, the convolution speedup for 75% sparsity is 4, and so on.

[0193] In some possible application scenarios, the arithmetic circuit 920 may employ one or more arithmetic and logic units (ALUs). For example, the accelerator may be an MCU, a CPU, or a GPU. The ALU is the arithmetic unit of the accelerator's IP core, the data processing component, and the most specialized data path unit in the data path. It implements various operations, including addition, subtraction, AND, OR, XOR, NOT, left shift, right shift, and nibble swap. The selection unit 921 may be implemented by a separate ALU or embedded within another ALU performing operations.

[0194] In another possible embodiment, the selection unit is deployed in the storage circuit. For example, as shown in Figure 9B, 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.

[0195] The selection unit 912 reads the non-zero elements in the i-th row of 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 in the i-th row of the second matrix to the operation circuit; and reads the elements in the i-th column of the first matrix that are operated on with the non-zero elements in the i-th row of 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 on with the non-zero elements in the i-th row of the second matrix to the operation circuit 920. Furthermore, the operation circuit 920 performs a multiplication and addition operation 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 that are operated on with the non-zero elements in the i-th row of the second matrix.

[0196] In some embodiments, taking the example of a selection unit deployed in the storage circuit 910, that is, the storage circuit 910 includes a selection unit 912, as shown in Figure 9A, the storage unit 911 in the storage circuit 910 can also include a first data cache area 9111, a second data cache area 9112, and an index information cache area 9113.

[0197] The first data cache 9111 is used to cache data loaded from the processor's memory 212 into the hardware accelerator. For example, the first data cache 9111 can cache the convolution kernel parameter matrix (including the second matrix) of each layer of the neural network. The second matrix can be stored in a compact manner. The K*M non-zero elements that need to be multiplied with the first matrix are compactly stored, for example, by row, and the non-zero elements of the row are read each time.

[0198] The second data buffer 9112 is used to cache data loaded from the memory 212 into the hardware accelerator. For example, when the hardware accelerator is used in a neural network, the second data buffer 9112 can cache input matrices (including the first matrix). The index information buffer 9113 can be used to cache the indices of the non-zero elements of the second matrix and the indices of the elements in the first matrix. The indices of the non-zero elements in the second matrix can be used in the manner described above. The elements of the first matrix can include row indices (which can also be understood as row addresses) and column indices (which can be understood as column addresses).

[0199] 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.

[0200] The arithmetic circuit 920 is the core component of the hardware accelerator, and various functional units of the arithmetic circuit are solidified inside. For example, the arithmetic 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. The vector calculation unit 9204 is used to calculate each gate vector to obtain the final result.

[0201] 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 computation circuit 920 completes the computation, the result may be stored in the output buffer 924 and output. The output buffer 924 may be written back to the processor all at once after the buffer is full. The input buffer 923 and the output buffer 924 may be deployed within or outside the computation circuit 920.

[0202] 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. Taking the hardware accelerator in Figure 3 using the structure shown in Figure 9A as an example, the software and hardware collaborative framework of the data processing device 200 is shown in Figure 10A. The memory access unit 913 may be used for data transmission between the hardware accelerator 220 and the memory 212. The memory access unit 913 may be deployed inside the storage circuit 910 or outside the storage circuit 910. Figure 10A takes deployment outside the storage circuit 910 as an example.

[0203] 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 achieve parallel data reading. In some embodiments, the hardware accelerator may also include a control interconnect circuit for interconnecting the control signal lines between the processing system 210. With reference to Figure 10A, under the control of the processor 211 in the processing system 210, the DMA is activated via the control bus and the data bus respectively. The DMA transfers the first matrix of the data to be processed and the second matrix corresponding to the weight tensor in the memory 212, as well as the indices of the non-zero elements in the second matrix, to the storage circuit 910 in the hardware accelerator 220. For example, the second matrix is ​​transferred to the first data buffer 9111, the first matrix is ​​transferred to the second data buffer 9112, and the indices of the non-zero elements of the second matrix are transferred to the index information cache unit 9113. The target result is then obtained through processing by the operation circuit 920. As shown in Figure 11A, the selection unit 912 reads the non-zero elements in the jth row of the second matrix from the first data buffer 9111. It can be understood that the non-zero elements in each column are compactly stored row-by-row in the first data buffer 9111. The selection unit 912 can read the storage row where the j-th row is located from the first data buffer 9111. The selection unit 912 reads the index of the non-zero element in the j-th row of the second matrix from the index information buffer 9113, and then reads the element in the j-th column of the first matrix to be multiplied with the non-zero element in the j-th row of the second matrix from the second data buffer 9112 based on the index of the non-zero element in the j-th row. The selection unit 912 can send the read data (including the non-zero element in the j-th row of the second matrix and the element in the j-th column of the first matrix to be multiplied with the non-zero element in the j-th row) to the operation circuit 920. For example, the selection unit 912 can output the read data to the input buffer 923 (which can be within the operation circuit 920 or outside 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.

[0204] In other embodiments, taking the example of a selection unit being deployed in an arithmetic circuit, that is, the arithmetic circuit 920 includes a selection unit 921, as shown in FIG9B , the storage unit 911 in the storage circuit 910 may further 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 are not further described here. For example, the arithmetic unit 922 in the arithmetic 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 are not further described here.

[0205] 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 within the hardware accelerator. After the computation circuit 920 completes the calculation, the result may be placed in the output buffer 924 and output. The output buffer 924 may be written back to the processor once the buffer is full. The input buffer 923 and the output buffer 924 may be deployed inside or outside the computation circuit 920. Figure 9B illustrates an example where the input buffer 923 and the output buffer 924 are deployed outside the computation circuit 920.

[0206] 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. Taking the hardware accelerator in Figure 3 using the structure shown in Figure 9B as an example, the software and hardware collaborative framework of the data processing device 200 is shown in Figure 10B. The memory access unit 913 may be used for data transmission between the hardware accelerator 220 and the memory 212. The memory access unit 913 may be deployed inside the storage circuit 910 or outside the storage circuit 910. Figure 10B takes deployment outside the storage circuit 910 as an example.

[0207] 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 realize parallel data reading. In some embodiments, the hardware accelerator may also include a control interconnection circuit (not shown in Figure 10B) for interconnecting the control signal lines between the processing system 210. In conjunction with Figure 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. The DMA transfers the first matrix of the data to be processed in the memory 212 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 cache unit 9113. The target result is then obtained after processing by the operation circuit 920. Referring to Figure 11B, the selection unit 921 reads the j-th non-zero element in the second matrix from the first data buffer area 9111. It can be understood that the non-zero elements in each column are compactly stored row-by-row in the first data buffer 9111. The selection unit 921 can read the storage row where the j-th row is located from the first data buffer 9111. The selection unit 921 obtains the index of the non-zero element in the j-th row of the second matrix from the index information buffer 9113, and then reads the element in the j-th column of the first matrix multiplied by the non-zero element in the j-th row of the second matrix from the second data buffer 9112 based on the index of the non-zero element in the j-th row. For example, the selection unit 921 can read the element in the j-th column of the first matrix from the second data buffer 9112, and the elements of each column in the first matrix are stored row-by-row in the second data buffer 9112. The storage circuit 910 can output the storage row where the j-th column of the first matrix is ​​located, the non-zero element in the j-th row of the second matrix, and the index of the non-zero element in the j-th row to the input buffer 923. Then, the selection unit 921 obtains the element in the jth column of the first matrix that needs to be multiplied with the non-zero element in the jth row of the second matrix based on the index of the non-zero element in the jth row. The calculation unit 922 can calculate the element in the jth column of the first matrix that needs to be multiplied with the non-zero element in the jth row, as well as the non-zero element in the jth row, based on the selection result of the selection unit 921. For example, the multiplication unit 9201 performs multiplication operations on the non-zero element in the jth row of the second matrix and the element in the jth column of the first matrix that needs to be multiplied with the non-zero element in the jth row to obtain multiple values, and then the accumulation unit 9202 performs an addition operation on the multiple values.

[0208] Based on the above embodiments, refer to FIG12 , which is a structural diagram of a pruning device provided in an embodiment of the present application. The pruning device is used to implement the pruning method shown in FIG4 . The pruning device may include an acquisition unit 1201 and a pruning unit 1202. The acquisition unit may be used to acquire 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 further include a training unit 1203. The pruning unit 1202 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; the three-dimensional weight tensor after the i-th pruning is then 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.

[0209] The following describes the technical effects achieved by the solutions provided in the embodiments of the present application.

[0210] 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 these two positions, which is for Architecture and The method designed for GPUs with a specific architecture is not suitable for general-purpose acceleration hardware structures, such as general-purpose GPUs or CPUs. The solution provided in the embodiment of the present application can be applied to general-purpose parallel computing hardware. It can also be accelerated on dedicated hardware structures. The embodiment of the present application adopts 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 embodiment of the present application is in C in or C in *FH*FW is sparsely processed on the dimension, which can improve the accuracy compared with the outer vector wise (OVW) sparse method. out The embodiment of the present application can improve the acceleration efficiency compared with this method.

[0211] Furthermore, it should be noted that the embodiments of this 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 solutions provided by the embodiments of this application.

[0212] It should be understood that the division of the various units of the above device is merely 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.

[0213] In the above embodiments, all or part of the embodiments can be implemented through software, hardware, or a combination thereof. When implemented using a software program, all or part of the embodiments can be implemented in the form of a computer program product. A computer program product includes one or more instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions according to the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The instructions can be stored in a computer storage medium or transmitted from one computer storage medium to another. For example, the instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, twisted pair) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer storage medium can be any medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more integrated media. The medium can be a magnetic medium (e.g., a floppy disk, hard disk, magnetic tape, magneto-optical disk (MO), etc.), an optical medium (e.g., an optical disk), or a semiconductor medium (e.g., a ROM, EPROM, EEPROM, or a solid-state drive (SSD)).

[0214] 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 box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0215] These computer program instructions may also be stored in a computer-readable memory that can direct 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 a product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0216] 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, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0217] Obviously, those skilled in the art may 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 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; The weight tensor of the neural network is obtained through pruning, and the 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 weights of other pruning vectors in the first data block except the first pruning vector are non-zero elements. The weight corresponding to the first position in the 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.

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 a calculation on the non-zero elements of the i-th row of the second matrix and the elements of the i-th column of the first matrix read. Row multiplication and addition operation.

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.

Citation Information

Patent Citations

  • Convolutional neural network compression and transplantation method and device, equipment and storage medium

    CN113850365A

  • Method and system for balanced-weight sparse convolution processing

    US11113601B1

  • Mixed-granularity-based joint sparse method for neural network

    US20220207374A1

Cited By

  • Self-adaptive dw type operator data distribution method and device in many-core environment

    CN119166948A