Model reasoning acceleration method, device, equipment, medium and program product

By focusing on the sparse nature of the target layer parameter matrix of the neural network model and multiplying SIMD instructions, combined with fine-grained pruning, the problem of slow matrix multiplication is solved, efficient model inference acceleration is achieved, and the pruning ratio and efficiency are significantly improved.

CN118780339AInactive Publication Date: 2024-10-15ANT GROUP CO LTD

Patent Information

Application Number
CN202411273650.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2024-10-15
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Matrix multiplication in neural network models is slow, resulting in low model inference efficiency. Especially in scenarios that require privacy protection, the multiplication calculation of the ciphertext activation value matrix and the plaintext parameter matrix takes a lot of time, and the existing pruning method is not effective. accelerate.

Method used

Through the sparse nature of each column of the target layer parameter matrix of the neural network model, if the element in the jth row is zero, it is set to all 0. If it is not zero, P copies are copied and the SIMD instruction is used to multiply the activation value matrix to reduce the same The number of state multiplication operations is reduced, and fine-grained pruning methods are combined to improve reasoning efficiency.

Benefits of technology

It significantly reduces the number of matrix multiplication operations, improves the acceleration effect of model inference, and the pruning ratio can reach close to 90%. It also reduces the time consumption of rotation operations and improves inference efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118780339A_ABST
    Figure CN118780339A_ABST
Patent Text Reader

Abstract

The invention provides a model reasoning acceleration method. The method is applied to first equipment and is used for executing inference operation of any target layer of a neural network model. During reasoning, for each column of the Q * N-dimensional parameter matrix of the target layer, when the element of the jth row in the ith column is 0, the jth row of the intermediate matrix is set to be 0. When the jth row element in the column is not 0, copying P copies of the jth row element, and loading the copies to the first vector register. Elements in the ith row in the N * P-dimensional activation value matrix are stored in the second vector register. And performing para-position multiplication operation on the first vector register and the second vector register through an SIMD instruction to obtain a result which is the jth row of the intermediate matrix. And summing the obtained N intermediate matrixes to obtain an operation result of the layer. According to the method, as long as one element in the parameter matrix is 0, one time of homomorphic multiplication can be reduced, and the pruning proportion can be converted into acceleration of the model to a large extent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of computer application technology, and in particular, to a model reasoning acceleration method, apparatus, device, medium and program product. Background Art

[0002] Neural network models are widely used in many practical application scenarios. For example, Transformer neural network models are widely used in personal assistants, chatbots and other fields.

[0003] ‌‌There are a large number of linear operations in the linear layer of the neural network model, and the linear operations are mainly reflected in matrix multiplication. Specifically, the linear layer of the neural network model has a parameter matrix, and the elements in the parameter matrix are also called weights. The input of the linear layer of the neural network model is in the form of a vector or matrix, which is referred to as the activation value matrix below. In the linear layer of the neural network model, it is necessary to calculate the product of the parameter matrix and the activation value matrix. In scenarios where privacy protection is required, the activation value matrix may be in ciphertext form. This brings greater computational complexity and hardware requirements for model reasoning.

[0004] However, in the prior art, the matrix multiplication speed of the neural network model is slow and the model reasoning efficiency is low. Summary of the invention

[0005] In view of this, one or more embodiments of the present specification provide a model reasoning acceleration method, apparatus, device, medium and program product.

[0006] According to a first aspect of one or more embodiments of this specification, a model reasoning acceleration method is proposed, which is applied to a first device and is used to perform reasoning operations on any target layer in a neural network model. The method includes:

[0007] For each column of the Q×N dimensional parameter matrix corresponding to the target layer, the first operation is performed in sequence to obtain N intermediate matrices; wherein the first operation for the i-th column includes:

[0008] If the j-th row element in the column is zero, set the j-th row of the intermediate matrix to all 0s;

[0009] If the j-th row element is not zero, copy it P times to form a vector and load it into the first vector register; use the single instruction multiple data SIMD instruction to perform bitwise multiplication on the data in the first vector register and the second vector register, and use the result vector as the vector of the j-th row of the intermediate matrix; wherein the second vector register stores the i-th row element in the N×P-dimensional activation value matrix corresponding to the target layer;

[0010] The N intermediate matrices are summed to obtain the operation result of this layer.

[0011] According to a second aspect of one or more embodiments of this specification, a model reasoning acceleration device is provided, which is applied to a first device and is used to perform reasoning operations on any target layer in a neural network model. The device includes:

[0012] The matrix multiplication module is used to perform the first operation on each column of the Q×N dimensional parameter matrix corresponding to the target layer in sequence to obtain N intermediate matrices; wherein the first operation on the i-th column includes:

[0013] If the j-th row element in the column is zero, set the j-th row of the intermediate matrix to all 0s;

[0014] If the j-th row element is not zero, copy it P times to form a vector and load it into the first vector register; use the single instruction multiple data SIMD instruction to perform bitwise multiplication on the data in the first vector register and the second vector register, and use the result vector as the vector of the j-th row of the intermediate matrix; wherein the second vector register stores the i-th row element in the N×P-dimensional activation value matrix corresponding to the target layer;

[0015] The matrix addition module sums the N intermediate matrices to obtain the operation result of this layer.

[0016] According to a third aspect of an embodiment of this specification, a computer-readable storage medium is provided, on which computer instructions are stored. When the instructions are executed by a processor, the model reasoning acceleration method described in the first aspect of the embodiment of this specification is implemented.

[0017] According to the fourth aspect of the embodiments of this specification, a computer device is provided, comprising: a processor; a memory for storing processor executable instructions; the processor executes the executable instructions to implement the model reasoning acceleration method as described in the first aspect of the embodiments of this specification.

[0018] According to the fifth aspect of the embodiments of this specification, a computer program product is provided, which, when executed by a processor, implements the model reasoning acceleration method as described in the first aspect of the embodiments of this specification.

[0019] This specification provides a model reasoning acceleration method. The method is applied to a first device and is used to perform reasoning operations on any target layer of a neural network model. When performing reasoning, for each column of the Q×N dimensional parameter matrix of the target layer: when the j-th row element in the i-th column is 0, set the j-th row of the intermediate matrix to 0. When the j-th row element in the column is not 0, copy it P times and load it into the first vector register. The second vector register stores the i-th row elements in the N×P dimensional activation value matrix. Through the SIMD instruction, the first vector register and the second vector register are bitwise multiplied, and the result obtained is the j-th row of the intermediate matrix. Through the above operation, N intermediate matrices can be obtained, and the N intermediate matrices are summed to obtain the operation result of this layer.

[0020] In the above method, during the multiplication process, each operation is to copy each element in the parameter matrix into P copies and multiply it with a row in the activation value matrix. Therefore, as long as one element in the parameter matrix is ​​0, one homomorphic multiplication operation can be reduced. On this basis, the pruning ratio can be converted into model acceleration to a large extent.

[0021] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present specification. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the specification and, together with the description, serve to explain the principles of the specification.

[0023] Figure 1 is a schematic diagram of a pruning method in a related technology; Figure 2 is a schematic diagram of a diagonal encoding method in the related art; Figure 3 is a flow chart of a model reasoning acceleration method shown in this specification according to an exemplary embodiment; Figure 4 is a schematic diagram of a model reasoning acceleration method shown in this specification according to a specific embodiment; Figure 5 is a schematic diagram of another model reasoning acceleration method shown in this specification according to a specific embodiment; Figure 6 is a schematic diagram of another model reasoning acceleration method shown in this specification according to a specific embodiment; Figure 7 is a block diagram of a model reasoning acceleration device according to an exemplary embodiment of the present specification; Figure 8 It is a hardware structure diagram of a computer device shown in this specification according to an exemplary embodiment. DETAILED DESCRIPTION

[0024] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0025] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0026] First, the sparse nature of the neural network is explained. The parameter matrix in the neural network model is large and has a high complexity when calculated. In the related art, the neural network model is generally pruned to accelerate the calculation of the neural network by utilizing the sparse nature of the neural network model.

[0027] Specifically, the natural sparse nature of the neural network model allows some parameters in the linear layer to be set to 0 and no longer participate in the calculation. During inference, the multiplication operation corresponding to the parameter being 0 can be skipped. Moreover, the neural network model can achieve a high sparsity without affecting the inference accuracy.

[0028] Neural network models can achieve sparse properties through pruning, which is the process of setting some parameters of the neural network model to 0. There are many ways to prune, such as Figure 1 As shown, Figure 1 The fine-grained pruning on the left is also called element-by-element pruning, which determines whether to set each parameter element to 0 based on its importance. Fine-grained pruning can achieve a pruning rate of almost 90%.

[0029] Figure 1 The figure also shows vector pruning (vector-level), kernel pruning (kernel-level) and filter pruning (filter-level). Vector pruning is pruning according to vectors. Kernel pruning is to remove a convolution kernel. Filter pruning is to prune the entire convolution kernel group. Figure 1Among the four pruning methods shown, the pruning granularity increases gradually from left to right.

[0030] When the parameter matrix and activation value matrix are plain text, kernel-wise or vector-wise pruning is generally used to facilitate the calculation of the graphics processing unit (GPU). When the GPU calculates the plain text, it generally splits the matrix into multiple small blocks and uses the multiplication between the multiple small blocks to calculate the result of the matrix multiplication. Therefore, when performing plain text operations, pruning can be converted into a speedup ratio through kernel-wise or vector-wise pruning.

[0031] As the application scenarios of neural network models gradually increase, the data processed by neural network models are becoming more and more sensitive. Privacy protection is an issue that needs to be considered when deploying neural network models. Secure Multi-Party Computation (MPC) is a privacy protection technology. MPC technology is combined with neural network models to protect the privacy data of multiple participants.

[0032] For example, in the scenario where MPC technology is combined with a neural network model, privacy protection can be provided for the interaction between the client and the server. Specifically, the client has private data and the server has a neural network model. The client needs to obtain the output from the neural network model provided by the server. Through MPC technology, the server cannot know the private data input by the client, and the client cannot obtain other information about the neural network model except the output of the neural network model.

[0033] In the above scenario, when performing matrix multiplication calculations on the linear layer of the neural network model, it is necessary to calculate the product between the plaintext parameter matrix and the ciphertext activation matrix. The ciphertext activation matrix is ​​implemented by performing homomorphic encryption (HE) on each element in the activation matrix. Homomorphic encryption is an encryption method that can make the result of multiplying the ciphertext activation matrix and the plaintext parameter matrix equal to the result of multiplying the plaintext activation matrix and the plaintext parameter matrix and then performing homomorphic encryption.

[0034] In addition, in the process of homomorphic matrix multiplication, operations such as multiplication and addition are relatively time-consuming. Therefore, single instruction multiple data (SIMD) instructions are generally used to implement matrix addition and multiplication. Specifically, in the activation value matrix, multiple elements of the matrix are encoded into a plaintext polynomial and further encrypted into a ciphertext polynomial. This encoding method enables a ciphertext polynomial operation to process the addition / multiplication of multiple data at the same time, thereby improving efficiency. When performing addition or multiplication, part of the data in the plaintext parameter matrix is ​​loaded into one register, and multiple elements in the ciphertext are loaded into another register. When implementing matrix multiplication, one instruction is used to simultaneously control the data in the two registers to perform bit-by-bit multiplication or addition operations, thereby processing the addition or multiplication of multiple data in parallel.

[0035] In the above case, in order to facilitate the calculation, the diagonal coding method is generally used for calculation.

[0036] Specifically, if Figure 2 As shown, we take the multiplication of the parameter matrix and the activation value matrix (vector in the figure) as an example. It should be noted that Figure 2 The numbers shown in do not represent the actual values ​​in the parameter matrix or activation value matrix, but only represent the serial number. The parameters are encoded in a diagonal loop, such as Figure 2 As shown in , the elements of the same color in the parameter matrix are encoded together, and the activation value is encoded according to the vector column. The plaintext of each parameter encoding is multiplied by the activation value ciphertext. Figure 2 As shown, when performing multiplication operations, the last three multiplication operations require a rotation operation on the activation value matrix.

[0037] After obtaining the four vectors, the last three vectors of the four vectors are rotated and then added in position. Specifically, after the rotation process, the elements with the same number in the four vectors should be added. The result of the addition can be transposed to obtain the result of the operation. And the result of the operation is equivalent to the result of the matrix multiplication. In a neural network, the activation value matrix often contains multiple vectors, and this calculation can be repeated.

[0038] In the above case, if we still follow the pruning method for plaintext in the related art, we will not be able to convert the pruning ratio into the acceleration of model inference. In the above homomorphic matrix multiplication, since it is necessary to implement matrix multiplication through SIMD processing and diagonal encoding, in order to reduce the number of calculations, it is necessary to prune in a diagonal manner, such as pruning the data on a diagonal, that is, Figure 2 Elements of the same color in the parameter matrix .

[0039] If pruning is performed along the diagonal line, the pruning granularity is larger. However, the pruning granularity is negatively correlated with the pruning ratio. Pruning along the diagonal line can only achieve a pruning ratio of less than 30%. It is impossible to achieve a good acceleration effect through pruning.

[0040] Based on this, this specification provides a model reasoning acceleration method. The method is applied to a first device, and is used to perform reasoning operations on any target layer of a neural network model. When performing reasoning, for each column of the Q×N dimensional parameter matrix of the target layer: when the j-th row element in the i-th column is 0, set the j-th row of the intermediate matrix to 0. When the j-th row element in the column is not 0, copy it P times and load it into the first vector register. The second vector register stores the i-th row elements in the N×P dimensional activation value matrix. Through the SIMD instruction, the first vector register and the second vector register are bitwise multiplied, and the result is the j-th row of the intermediate matrix. Through the above operation, N intermediate matrices can be obtained, and the N intermediate matrices are summed to obtain the operation result of this layer.

[0041] In the above method, during the multiplication process, each operation is to copy each element in the parameter matrix into P copies and multiply it with a row in the activation value matrix. Therefore, as long as one element in the parameter matrix is ​​0, one homomorphic multiplication operation can be reduced. On this basis, the pruning ratio can be converted into model acceleration to a large extent.

[0042] Moreover, on this basis, pruning can be performed according to the fine-grained pruning method, thereby greatly improving the reasoning efficiency.

[0043] In addition, compared with the diagonal encoding scheme in the related art, this method does not require rotation operations when performing matrix multiplication or addition. Rotation operations are more time-consuming than homomorphic multiplication or homomorphic addition operations. The method of this specification also speeds up the reasoning efficiency by reducing rotation operations.

[0044] Next, the method shown in this specification will be described in detail.

[0045] First of all, it should be noted that although the above description of the method shown in this specification is based on the problem of the MPC scenario, the method shown in this specification can be applied not only to the MPC scenario, but also to the scenario of multiplying a plaintext parameter matrix and a plaintext activation value matrix.

[0046] For the scenario of plaintext matrix multiplication, this method can still speed up the reasoning to a certain extent by reducing the number of multiplications.

[0047] Compared with the scenario applied to plaintext matrix multiplication, the method shown in this specification has a better combination with the ciphertext matrix multiplication using the SIMD method when applied to ciphertext matrix multiplication, thereby having a better effect of accelerating model reasoning.

[0048] Next, combine Figure 3 , a model reasoning acceleration method shown in this specification is described. The method is applied to a first device and is used to perform reasoning operations on any target layer in a neural network model.

[0049] The neural network model can be any neural network model including matrix multiplication operations. In an optional embodiment, the neural network model is a Transformer neural network model. Since there are more matrix multiplication operations in the Transformer neural network model, and the matrix multiplication operation has more parameters and a larger amount of calculation, the method shown in this specification can play a better role in improving the model reasoning speed.

[0050] The target layer is a layer that includes matrix multiplication operations, such as a linear layer of a neural network model.

[0051] As mentioned above, the method can be applied to a variety of scenarios. Correspondingly, when the method of this specification is applied to the plaintext matrix multiplication scenario, the first device can have all the layers of the neural network model.

[0052] In the scenario where the method of this specification is applied to ciphertext matrix multiplication, the method may also involve a second device. The first device may have all or part of the layers of the neural network model, but at least includes the target layer. The second device has private data and needs to perform multi-party joint computing with the first device.

[0053] For example, the second device has transaction information such as the user's transfer record. The first device has a neural network model that determines whether the user is a high-risk user based on the user's transaction information. The first device and the second device can perform multi-party secure computing, and the user transaction information of the second device's ciphertext can be input into the neural network model owned by the first device to determine whether the user is a high-risk user.

[0054] Before executing the method, the neural network model may be pre-trained. In an optional implementation, during or after the pre-training process, that is, before performing the inference operation of the target layer, the target layer of the neural network may be finely pruned.

[0055] As mentioned above, through the method shown in this specification, one operation can be reduced for each element in the parameter matrix that is 0. Therefore, fine-grained pruning with a larger pruning ratio can be used for pruning processing. In this way, more SIMD multiplication operations can be reduced in subsequent operations, thereby better accelerating model reasoning.

[0056] After pruning is completed, the neural network model can also be fine-tuned so that the reasoning results of the neural network model are not affected by the pruning operation.

[0057] In addition, when the method of this specification is applied to the ciphertext matrix multiplication scenario, the first device may also receive ciphertext data sent from the second device. The ciphertext data may be an activation value matrix input into the target layer reasoning process. The ciphertext data may also be ciphertext user privacy data, or ciphertext data of intermediate results input through multiple layers of a neural network. In this case, the first device may also input the user privacy data into the neural network model, and obtain the activation value matrix input into the target layer through processing of several layers of the neural network model.

[0058] In other words, the method also involves a second device, and the first device and the second device jointly perform multi-party secure computing MPC; the activation value matrix is ​​obtained based on the ciphertext data sent by the second device and the neural network model.

[0059] Next, we will combine Figure 3 , the specific steps of the model reasoning acceleration method shown in this specification are described. Figure 3 As shown, the method includes:

[0060] Step 301 : Perform the first operation in sequence on each column of the Q×N dimensional parameter matrix corresponding to the target layer to obtain N intermediate matrices.

[0061] The first operation for the i-th column includes:

[0062] a. If the j-th row element in the column is zero, set the j-th row of the intermediate matrix to all 0s.

[0063] b. If the element in the j-th row is not zero, copy it P times into a vector and load it into the first vector register; use the single instruction multiple data SIMD instruction to perform bitwise multiplication on the data in the first vector register and the second vector register, and use the result vector as the vector of the j-th row of the intermediate matrix; wherein the second vector register stores the i-th row element in the N×P-dimensional activation value matrix corresponding to the target layer.

[0064] Among them, Q, N and P can be any positive integers. The Q×N dimensional parameter matrix includes the parameters of the target layer. The sizes of Q and N can be the same or different, and this specification does not limit this. Correspondingly, the N×P dimensional activation value matrix is ​​the input of the target layer, and the sizes of N and P can be the same or different. In addition, according to the limitations of the dimensions of the activation value matrix and the parameter matrix, it can be understood that the value range of i is 1-N, and the value range of j is 1-Q.

[0065] As mentioned above, the method of this specification can be applied to a variety of scenarios. Correspondingly, when the method of this specification is applied to the scenario of ciphertext matrix multiplication, the parameter matrix is ​​plaintext and is held by the first device, and the activation value matrix is ​​ciphertext data processed by homomorphic encryption.

[0066] When applied to the ciphertext matrix multiplication scenario, the bitwise multiplication in step 301 is not the direct multiplication of the plaintext and the ciphertext, but the homomorphic multiplication of the plaintext and the ciphertext, and the result is equivalent to: the data obtained by homomorphically encrypting the plaintext after multiplication. For the convenience of description below, the above process is also referred to as multiplication.

[0067] For ease of understanding, this will be combined Figure 4 The first operation of step 301 is specifically described with reference to an example. Figure 4 In the example, P, Q and N are all taken as 4, that is, the parameter matrix W is a 4×4 dimensional plaintext matrix, and the activation value matrix X is a 4×4 dimensional ciphertext matrix. Figure 4 middle, , , and represents the element in the i-th column of the parameter matrix, represents the i-th row of the activation value matrix, Represents the i-th intermediate matrix.

[0068] When i takes values ​​from 1 to N, the following is executed: Figure 4 The first operation shown. Then the first operation needs to be performed N times, that is, 4 times in this example. The object of each first operation is the i-th column of the parameter matrix and the i-th row of the activation value matrix. Figure 4 In the figure, only the i-th first operation is exemplified.

[0069] Specifically, in the first operation, each element in the i-th column of the parameter matrix is ​​copied into P copies to form Q vectors. Figure 4In the example, P and Q are both 4, and the first column is used as an example for explanation, where the four colors represent the four elements of the column. Then the Q vectors are SIMD multiplied with the i-th row of the activation value matrix respectively. Correspondingly, each first operation includes Q SIMD multiplications, that is, 4 SIMD multiplications. In the first operation, the data obtained by multiplying the element of the j-th row and the i-th column of the parameter matrix with the data of the i-th row of the activation value matrix can be used as The element in the j-th row of the matrix.

[0070] Since the parameter matrix is ​​encoded element by element and the activation value matrix is ​​encoded row by row during calculation, when there is an element of 0 in the i-th column of the parameter matrix, the vector obtained by copying the element is a zero vector. Accordingly, the row corresponding to the element in the intermediate matrix can be directly set to zero. That is, when any element in the parameter matrix is ​​0, a SIMD multiplication operation can be skipped and the corresponding row of the intermediate matrix can be directly set to 0. For example Figure 5 middle, If is 0, the SIMD multiplication operation corresponding to the second line can be skipped and the The elements in the second row of the matrix are set to 0.

[0071] Thus, when performing matrix multiplication operations using the method of this specification, a fine-grained pruning method can be used to increase the number of elements in the parameter matrix that are 0. Through common fine-grained pruning methods, a pruning rate of nearly 90% can be achieved, greatly reducing the number of SIMD multiplications.

[0072] Step 303: sum the N intermediate matrices to obtain the calculation result of this layer.

[0073] Specifically, the several intermediate matrices obtained in step 301 may be added to obtain a calculation result.

[0074] In an optional embodiment, when executing step 301, in order to improve processing efficiency, SIMD encoding may also be used, and each addition instruction operation adds the same rows of two matrices.

[0075] Specifically, step 303 is implemented by loading the elements of the same row in the first matrix and the second matrix into the third vector register and the fourth vector register respectively; and using SIMD instructions to perform bitwise addition on the data in the third vector register and the fourth vector register.

[0076] like Figure 4 In this example, the operation result C of this layer can be obtained by formula (1), where C is a Q×P dimensional matrix. Here, it is a 4×4 matrix.

[0077] (1)

[0078] In order to improve the efficiency during the operation, the SIMD method can be used to perform the operation. For each row of the intermediate matrix, SIMD addition operation is used to accumulate and obtain the final result.

[0079] The calculation results of the calculation method in steps 301-303 are equivalent to the matrix multiplication results, and there is no additional calculation in the total multiplication and addition operations.

[0080] As for the number of multiplications, N first operations are performed, and each first operation performs at most Q SIMD multiplication operations, and correspondingly at most N*Q SIMD multiplication operations are performed (calculated in this way when there are no non-zero elements in the parameter matrix).

[0081] As for the number of additions, N intermediate matrices need to be added. If the accumulation method is used, each row of the final calculation result needs to be accumulated from the same row of N intermediate matrices. In the process of adding N intermediate matrices, each row in Q rows needs to be added N-1 times to get the final result. Therefore, Q*(N-1) SIMD addition operations are required.

[0082] The correctness of the above calculation method is demonstrated below.

[0083] Specifically, the above calculation results are explained by taking Q, N and P as 2 as an example. The matrix D and the matrix E are multiplied, and the calculation result is shown in formula (2):

[0084] [ d 11 d 12 d 21 d 22 ] [ e 11 e 12 e 21 e 22 ] = [ d 11 e 11 + d 12 e 21 d 11 e 12 + d 12 e 22 d 21 e 11 + d 22 e 21 d 21 e 12 + d 22 e 22 ] (2)

[0085] The method shown in this specification requires two first operations to obtain two intermediate matrices. Assuming that there are no non-zero elements in D and E, the process of obtaining the two intermediate matrices is as follows: Figure 6 As shown. Figure 6 The intermediate matrix shown and After that, the addition shown in formula (3) is performed, and the result obtained is the same as the result shown in formula (2).

[0086] f 1 + f 2 = [ d 11 e 11 d 11 e 12 d 21 e 11 d 21 e 12 ] + [ d 12 e 21 d 12 e 22 d 22 e 21 d 22 e 22 ] = [ d 11 e 11 + d 12 e 21 d 11 e 12 + d 12 e 22 d 21 e 11 + d 22 e 21 d 21 e 12 + d 22 e 22 ] (3)

[0087] In the above method, the parameters are encoded element by element during the inference process, while the activation values ​​are encoded row by row, which is different from the scheme in which the parameters are encoded diagonally and the activation values ​​are encoded column by column in the diagonal encoding. In this way, each element that is pruned or 0 can reduce one SIMD multiplication operation in the calculation process during each calculation. Therefore, based on the above characteristics, a fine-grained pruning method can be used. Under the premise of lossless inference accuracy, a pruning rate of 85% can be achieved, which is much higher than the pruning rate of 30% under diagonal encoding. This can reduce more SIMD multiplication operations and speed up the model inference.

[0088] In addition, compared to diagonal coding, which requires rotation operations during multiplication and addition operations, the method shown in this specification does not require rotation operations. In the ciphertext matrix multiplication operation scenario, the consumption caused by the rotation operation is relatively high. By reducing the number of rotations, the reasoning speed of the model can be accelerated.

[0089] Corresponding to the embodiments of the aforementioned method, this specification also provides embodiments of a device and a terminal to which it is applied.

[0090] like Figure 7 As shown, Figure 7 This is a block diagram of a model reasoning acceleration device according to an exemplary embodiment of the present specification, which is applied to a first device and is used to perform reasoning operations at any target layer in a neural network model. The device includes:

[0091] The matrix multiplication module 710 is used to perform the first operation on each column of the Q×N dimensional parameter matrix corresponding to the target layer in sequence to obtain N intermediate matrices; wherein the first operation on the i-th column includes:

[0092] If the j-th row element in the column is zero, set the j-th row of the intermediate matrix to all 0s;

[0093] If the j-th row element is not zero, copy it P times to form a vector and load it into the first vector register; use the single instruction multiple data SIMD instruction to perform bitwise multiplication on the data in the first vector register and the second vector register, and use the result vector as the vector of the j-th row of the intermediate matrix; wherein the second vector register stores the i-th row element in the N×P-dimensional activation value matrix corresponding to the target layer;

[0094] The matrix addition module 720 sums the N intermediate matrices to obtain the operation result of this layer.

[0095] In an optional implementation, the matrix addition module 720 is specifically used to: load the elements of the same row in the first matrix and the second matrix into the third vector register and the fourth vector register, respectively; and use SIMD instructions to perform bitwise addition on the data in the third vector register and the fourth vector register.

[0096] In an optional implementation, the activation value matrix is ​​ciphertext data that has been homomorphically encrypted.

[0097] In an optional implementation, the method further involves a second device, and the first device and the second device jointly perform multi-party secure computing MPC; the activation value matrix is ​​obtained based on the encrypted data sent by the second device and the neural network model.

[0098] In an optional implementation, the apparatus further includes a pruning module 730 (not shown in the figure) for performing fine-grained pruning on the target layer of the neural network.

[0099] In an optional implementation, the neural network model is a Transformer neural network model.

[0100] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.

[0101] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying creative labor.

[0102] like Figure 8 As shown, Figure 8 A hardware structure diagram of a computer device in which the model reasoning acceleration device of the embodiment is located is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.

[0103] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification. The processor implements the above method by running executable instructions.

[0104] The memory 1020 for storing processor executable instructions can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020.

[0105] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.

[0106] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0107] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010 , the memory 1020 , the input / output interface 1030 , and the communication interface 1040 ).

[0108] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0109] The embodiments of this specification also provide a computer-readable storage medium having a computer program stored thereon, which implements the above-mentioned model reasoning acceleration device method when executed by a processor.

[0110] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0111] The embodiments of this specification also provide a computer program product, which implements the above-mentioned model reasoning acceleration device method when executed by a processor.

[0112] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0113] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0114] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

Claims

1. A model inference acceleration method, applied to a first device, for performing an inference operation of any target layer in a neural network model, the method include: For each column of the Q×N dimensional parameter matrix corresponding to the target layer, the first operation is performed in sequence to obtain N intermediate matrices; The first operation for the i-th column includes: If the j-th row element in the column is zero, set the j-th row of the intermediate matrix to all 0s; If the j-th row element is not zero, copy it P times to form a vector and load it into the first vector register; use the single instruction multiple data SIMD instruction to perform bitwise multiplication on the data in the first vector register and the second vector register, and use the result vector as the vector of the j-th row of the intermediate matrix; wherein the second vector register stores the i-th row element in the N×P-dimensional activation value matrix corresponding to the target layer; The N intermediate matrices are summed to obtain the operation result of this layer.

2. According to the method of claim 1, the N intermediate matrices are summed to obtain the operation result of this layer, include: Loading the elements of the same row in the first matrix and the second matrix into the third vector register and the fourth vector register respectively; Using SIMD instructions, bitwise addition is performed on the data in the third vector register and the data in the fourth vector register.

3. The method according to claim 1, in, The activation value matrix is ​​ciphertext data processed by homomorphic encryption.

4. The method according to claim 3, in, The method also involves a second device, wherein the first device and the second device jointly perform multi-party secure computing (MPC); the activation value matrix is ​​obtained based on the ciphertext data sent by the second device and the neural network model.

5. The method according to claim 1, before performing the inference operation of any target layer in the neural network model, the method further include: The target layer of the neural network is fine-grainedly pruned.

6. The method according to claim 1, in, The neural network model is a Transformer neural network model.

7. A model reasoning acceleration device, applied to a first device, for performing reasoning operations at any target layer in a neural network model, wherein the device include: A matrix multiplication module, used for sequentially performing the first operation on each column of the Q×N dimensional parameter matrix corresponding to the target layer to obtain N intermediate matrices; The first operation for the i-th column includes: If the j-th row element in the column is zero, set the j-th row of the intermediate matrix to all 0s; If the j-th row element is not zero, copy it P times to form a vector and load it into the first vector register; use the single instruction multiple data SIMD instruction to perform bitwise multiplication on the data in the first vector register and the second vector register, and use the result vector as the vector of the j-th row of the intermediate matrix; wherein the second vector register stores the i-th row element in the N×P-dimensional activation value matrix corresponding to the target layer; The matrix addition module sums the N intermediate matrices to obtain the operation result of this layer.

8. A computer program product, which, when executed by a processor, implements the model reasoning acceleration method as described in any one of claims 1 to 6.

9. A computer device, include: processor; A memory for storing processor executable instructions; wherein, the processor implements the model reasoning acceleration method as described in any one of claims 1-6 by running the executable instructions.

10. A computer-readable storage medium having computer instructions stored thereon, wherein the computer instructions, when executed by a processor, implement the model reasoning acceleration method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Systems and methods for providing block-wise sparsity in a neural network

    CN113906448A

  • Neural network model reasoning system based on secure multi-party computing

    CN115526290A

  • Matrix calculation method and device

    CN117407640A

  • System and method of accelerating execution of a neural network

    US20210042624A1

Cited By

  • Hybrid multiplication encryption method and device based on homomorphic encryption matrix-vector plaintext and ciphertext

    CN119420466A