A method and device for compressing a neural network model
By performing parameter upgrading and tensor decomposition on the embedding layer and feedforward network layer of the transformer translation model, the problem of large model size is solved, and the parameter amount is effectively reduced and the performance is improved.
Patent Information
- Application Number
- CN202010293700.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-15
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2040-04-15
AI Technical Summary
The existing transformer translation model has a large number of parameters and is redundant, making the model bulky and difficult to compress effectively.
By obtaining the parameter matrix of the embedding layer and feedforward network layer of the model, perform upgrading processing to obtain high-order tensors, and use tensor decomposition technology, such as continuous decomposition method and peeling decomposition method, to reduce the amount of parameters and update parameters. matrix to obtain a compressed model.
While maintaining model performance, the model volume is significantly reduced and the translation performance index BLEU value is improved.
Smart Images

Figure CN113537485B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and apparatus for compressing a neural network model, a computing device, and a computer-readable storage medium. Background Art
[0002] With the development of computer technology, neural network models are being used more and more widely, such as the transformer translation model. The transformer translation model includes an encoder and a decoder. The encoder and decoder each include an embedding layer and 6 network layers with the same structure, that is, the encoder includes 6 encoding layers, and the decoder includes 6 decoding layers. Each encoding layer or decoding layer contains a self-attention layer and a feedforward network layer. The 6 encoding layers are serially connected, and the 6 decoding layers are serially connected.
[0003] The number of parameters in the transformer translation model is mainly concentrated in the embedding layer. In order to improve the performance of the translation model, the vocabulary size in the embedding layer is mostly in the tens of thousands. As the vocabulary size increases, the number of parameters also increases linearly. At the same time, the feedforward network layer is composed of two linear layers and adopts a bottleneck network structure. The feedforward network layer in the transformer translation model has 25 million parameters. Therefore, the number of parameters in the transformer translation model is huge, and there is also a lot of redundancy, which makes the transformer translation model huge.
[0004] Therefore, how to effectively compress the model size of the transformer translation model has become an urgent problem for technicians to solve. Summary of the invention
[0005] In view of this, the embodiments of the present application provide a compression method and apparatus for a neural network model, a computing device, and a computer-readable storage medium to solve the technical defects existing in the prior art.
[0006] According to a first aspect of an embodiment of the present application, a method for compressing a neural network model is provided, comprising:
[0007] Get the parameter matrix in the embedding layer of the neural network model;
[0008] Receiving an order-up instruction, and performing order-up processing on the parameter matrix according to the order-up instruction to obtain a high-order tensor;
[0009] Decomposing the high-order tensor to obtain a decomposition result of the high-order tensor;
[0010] The parameter matrix is updated according to the decomposition result to obtain a compressed neural network model.
[0011] Optionally, the neural network model is a transformer translation model, and the transformer translation model includes a first embedding layer and a second embedding layer;
[0012] Get the parameter matrix in the embedding layer of the neural network model, including:
[0013] Get the parameter matrix in the first embedding layer and / or the second embedding layer.
[0014] Optionally, the upgrade instruction includes an upgrade value;
[0015] Performing an rank-raising process on the parameter matrix according to the rank-raising instruction to obtain a high-order tensor includes:
[0016] The parameter matrix is raised in rank according to the raised in rank value to obtain a high-order tensor with a dimension corresponding to the raised in rank value.
[0017] Optionally, performing an rank-raising process on the parameter matrix according to the rank-raising value to obtain a high-order tensor of a dimension corresponding to the rank-raising value includes:
[0018] Decomposing the rows of the parameter matrix according to the raised order value to obtain a continuous product of a plurality of row parameters, wherein the number of the row parameters corresponds to the raised order value;
[0019] Decomposing the columns of the parameter matrix according to the raised order value to obtain a continuous product of a plurality of column parameters, wherein the number of the column parameters corresponds to the raised order value;
[0020] A high-order tensor is generated according to the row parameters and the column parameters, wherein the dimension of the high-order tensor corresponds to the raised-order value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameters and column parameters.
[0021] Optionally, decomposing the high-order tensor to obtain a decomposition result of the high-order tensor includes:
[0022] The high-order tensor is decomposed by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional, and the other tensors are four-dimensional.
[0023] Optionally, decomposing the high-order tensor to obtain a decomposition result of the high-order tensor includes:
[0024] The high-order tensor is decomposed by a peeling decomposition method to obtain the product of a core tensor and multiple matrices.
[0025] According to a second aspect of an embodiment of the present application, a method for compressing a neural network model is provided, comprising:
[0026] Get the parameter matrix in the feedforward network layer of the neural network model;
[0027] Receiving an order-up instruction, and performing order-up processing on the parameter matrix according to the order-up instruction to obtain a high-order tensor;
[0028] Decomposing the high-order tensor to obtain a decomposition result of the high-order tensor;
[0029] The parameter matrix is updated according to the decomposition result to obtain a compressed neural network model.
[0030] Optionally, the neural network model is a transformer translation model, the transformer translation model includes 6 encoding layers and 6 decoding layers, each encoding layer and each decoding layer includes a feedforward network layer;
[0031] Get the parameter matrix in the feedforward network layer of the neural network model, including:
[0032] Obtain a parameter matrix in at least one of the feed-forward network layers.
[0033] Optionally, the upgrade instruction includes an upgrade value;
[0034] Performing an rank-raising process on the parameter matrix according to the rank-raising instruction to obtain a high-order tensor includes:
[0035] The parameter matrix is raised in rank according to the raised in rank value to obtain a high-order tensor with a dimension corresponding to the raised in rank value.
[0036] Optionally, performing an rank-raising process on the parameter matrix according to the rank-raising value to obtain a high-order tensor of a dimension corresponding to the rank-raising value includes:
[0037] Decomposing the rows of the parameter matrix according to the raised order value to obtain a continuous product of a plurality of row parameters, wherein the number of the row parameters corresponds to the raised order value;
[0038] Decomposing the columns of the parameter matrix according to the raised order value to obtain a continuous product of a plurality of column parameters, wherein the number of the column parameters corresponds to the raised order value;
[0039] A high-order tensor is generated according to the row parameters and the column parameters, wherein the dimension of the high-order tensor corresponds to the raised-order value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameters and column parameters.
[0040] Optionally, decomposing the high-order tensor to obtain a decomposition result of the high-order tensor includes:
[0041] The high-order tensor is decomposed by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional.
[0042] Optionally, decomposing the high-order tensor to obtain a decomposition result of the high-order tensor includes:
[0043] The high-order tensor is decomposed by a peeling decomposition method to obtain the product of a core tensor and multiple matrices.
[0044] According to a third aspect of an embodiment of the present application, a method for compressing a neural network model is provided, comprising:
[0045] Obtain a first parameter matrix in an embedding layer and a second parameter matrix in a feedforward network layer of a neural network model;
[0046] Receiving an order-raising instruction, and performing an order-raising process on the first parameter matrix according to the order-raising instruction to obtain a first high-order tensor, and performing an order-raising process on the second parameter matrix according to the order-raising instruction to obtain a second high-order tensor;
[0047] Decomposing the first high-order tensor to obtain a first decomposition result, and decomposing the second high-order tensor to obtain a second decomposition result;
[0048] The first parameter matrix is updated according to the first decomposition result, and the second parameter matrix is updated according to the second decomposition result to obtain a compressed neural network model.
[0049] Optionally, the neural network model is a transformer translation model, which includes a first embedding layer, a second embedding layer, 6 encoding layers and 6 decoding layers, the first embedding layer is connected to the 6 encoding layers in sequence, the second embedding layer is connected to the 6 decoding layers in sequence, and each of the encoding layers and each of the decoding layers includes a feedforward network layer;
[0050] Obtaining the first parameter matrix in the embedding layer and the second parameter matrix in the feedforward network layer of the neural network model includes:
[0051] Obtaining a first parameter matrix in the first embedding layer and / or the second embedding layer;
[0052] Obtain a second parameter matrix in at least one of the feed-forward network layers.
[0053] Optionally, the upgrade instruction includes an upgrade value;
[0054] Performing an rank-up process on the first parameter matrix according to the rank-up instruction to obtain a first high-order tensor, and performing an rank-up process on the second parameter matrix according to the rank-up instruction to obtain a second high-order tensor, including:
[0055] Performing an rank-raising process on the first parameter matrix according to the rank-raising value to obtain a first high-order tensor corresponding to the rank-raising value;
[0056] The second parameter matrix is raised in rank according to the raised in rank value to obtain a second high-order tensor corresponding to the raised in rank value.
[0057] Optionally, performing an rank-raising process on the first parameter matrix according to the rank-raising value to obtain a first high-order tensor of a dimension corresponding to the rank-raising value includes:
[0058] Decomposing the rows of the first parameter matrix according to the raised order value to obtain a plurality of continuous products of the first row parameters, wherein the number of the first row parameters corresponds to the raised order value;
[0059] Decomposing the columns of the first parameter matrix according to the raised order value to obtain a plurality of continuous products of the first column parameters, wherein the number of the first column parameters corresponds to the raised order value;
[0060] A first high-order tensor is generated according to the first row parameter and the first column parameter, wherein the dimension of the first high-order tensor corresponds to the raised-order value, and the size of each dimension of the first high-order tensor is determined by the corresponding first row parameter and first column parameter.
[0061] Optionally, performing an rank-raising process on the second parameter matrix according to the rank-raising value to obtain a second high-order tensor having a dimension corresponding to the rank-raising value includes:
[0062] Decomposing the rows of the second parameter matrix according to the raised order value to obtain a plurality of continuous products of second row parameters, wherein the number of the second row parameters corresponds to the raised order value;
[0063] Decomposing the columns of the second parameter matrix according to the raised order value to obtain a plurality of continuous products of the second column parameters, wherein the number of the second column parameters corresponds to the raised order value;
[0064] A second high-order tensor is generated according to the second row parameter and the second column parameter, wherein the dimension of the second high-order tensor corresponds to the raised-order value, and the size of each dimension of the second high-order tensor is determined by the corresponding second row parameter and second column parameter.
[0065] Optionally, decomposing the first high-order tensor to obtain a first decomposition result includes:
[0066] The first high-order tensor is decomposed by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional.
[0067] Optionally, decomposing the second high-order tensor to obtain a second decomposition result includes:
[0068] The second high-order tensor is decomposed by a peeling decomposition method to obtain the product of a core tensor and multiple matrices.
[0069] According to a fourth aspect of an embodiment of the present application, a compression device for a neural network model is provided, comprising:
[0070] A first acquisition module is configured to acquire a parameter matrix in an embedding layer of a neural network model;
[0071] A first order-raising module is configured to receive an order-raising instruction, and perform order-raising processing on the parameter matrix according to the order-raising instruction to obtain a high-order tensor;
[0072] A first decomposition module is configured to decompose the high-order tensor to obtain a decomposition result of the high-order tensor;
[0073] The first updating module is configured to update the parameter matrix according to the decomposition result to obtain a compressed neural network model.
[0074] According to a fifth aspect of an embodiment of the present application, a compression device for a neural network model is provided, comprising:
[0075] A second acquisition module is configured to acquire a parameter matrix in a feedforward network layer of the neural network model;
[0076] A second order-raising module is configured to receive an order-raising instruction, and perform order-raising processing on the parameter matrix according to the order-raising instruction to obtain a high-order tensor;
[0077] A second decomposition module is configured to decompose the high-order tensor to obtain a decomposition result of the high-order tensor;
[0078] The second updating module is configured to update the parameter matrix according to the decomposition result to obtain a compressed neural network model.
[0079] According to a sixth aspect of an embodiment of the present application, a compression device for a neural network model is provided, comprising:
[0080] A third acquisition module is configured to acquire a first parameter matrix in the embedding layer and a second parameter matrix in the feedforward network layer of the neural network model;
[0081] A third order-raising module is configured to receive an order-raising instruction, and to perform an order-raising process on the first parameter matrix according to the order-raising instruction to obtain a first high-order tensor, and to perform an order-raising process on the second parameter matrix according to the order-raising instruction to obtain a second high-order tensor;
[0082] a third decomposition module, configured to decompose the first high-order tensor to obtain a first decomposition result, and decompose the second high-order tensor to obtain a second decomposition result;
[0083] The third updating module is configured to update the first parameter matrix according to the first decomposition result, and update the second parameter matrix according to the second decomposition result to obtain a compressed neural network model.
[0084] According to the seventh aspect of the embodiment of the present application, a computing device is provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein the processor implements the steps of the compression method of the neural network model when executing the instructions.
[0085] According to an eighth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores computer instructions, and when the instructions are executed by a processor, the steps of the compression method of the neural network model are implemented.
[0086] According to a ninth aspect of an embodiment of the present application, a chip is provided, which stores computer instructions, and when the instructions are executed by the chip, the steps of the compression method of the neural network model are implemented.
[0087] In an embodiment of the present application, the parameters in the neural network model are compressed by using a tensor decomposition method. The parameter matrix is first upgraded to obtain a high-order tensor, and then the tensor decomposition technology is used to effectively reduce the number of parameters in the embedding layer and / or the feedforward network layer. Experiments have shown that performing a continuous decomposition on the high-order tensor in the embedding layer and a peeled decomposition on the high-order tensor in the feedforward network layer can effectively reduce the number of parameters of the model while maintaining the model performance, thereby significantly reducing the size of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0088] Figure 1 is a structural block diagram of a computing device provided in an embodiment of the present application;
[0089] Figure 2 is a flow chart of a method for compressing a neural network model provided in the first embodiment of the present application;
[0090] Figure 3 is a flow chart of a method for compressing a neural network model provided in the second embodiment of the present application;
[0091] Figure 4 is a flow chart of a method for compressing a neural network model provided in the third embodiment of the present application;
[0092] Figure 5 It is a structural schematic diagram of a compression device of a neural network model provided in an embodiment of the present application;
[0093] Figure 6 It is a structural schematic diagram of a compression device of a neural network model provided in an embodiment of the present application;
[0094] Figure 7 It is a structural schematic diagram of the compression device of the neural network model provided in an embodiment of the present application. DETAILED DESCRIPTION
[0095] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0096] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms of "a", "said" and "the" used in one or more embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more associated listed items.
[0097] It should be understood that, although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0098] First, the terms involved in one or more embodiments of the present invention are explained.
[0099] transformer: A translation model that replaces the long short-term memory model with a self-attention model structure, achieving better results on translation tasks, including encoder and decoder.
[0100] Embedding layer: Located at the input layer in the network model, it is used to embed the input text data and output text vectors; embed the input image data and output image features.
[0101] Parameter matrix: A matrix that describes network parameters. Model parameters expressed in matrix form are called parameter matrix. Each element in the parameter matrix has a fixed meaning.
[0102] Upgrade command: A command used to instruct to upgrade network parameters.
[0103] Upgrading: The operation of upgrading low-order parameters to high-order tensors according to the upgrading instruction.
[0104] High-order tensor: Tensors of rank three or above are called high-order tensors.
[0105] Compressed neural network model: a neural network model that has been compressed.
[0106] Row parameters: The number of rows of the parameter matrix is decomposed to obtain the product of multiple parameters. Each parameter is called a row parameter. For example, if the parameter matrix has 120 rows and is decomposed into 2*3*4*5, then 2, 3, 4, and 5 are called row parameters.
[0107] Column parameter: The columns of the parameter matrix are decomposed to obtain the product of multiple parameters. Each parameter is called a row parameter. For example, if the parameter matrix has 120 columns and is decomposed into 2*3*4*5, then 2, 3, 4, and 5 are called column parameters.
[0108] Continuous decomposition: A tensor decomposition method that decomposes a high-dimensional tensor into the product of multiple three-dimensional tensors (the first and last tensors are two-dimensional).
[0109] Peeling decomposition: A tensor decomposition method that decomposes a high-dimensional tensor into the product of a kernel tensor and a matrix for each dimension.
[0110] Feedforward network layer: The simplest neural network, where neurons are arranged in layers. Each neuron is only connected to the neurons in the previous layer. It receives the output of the previous layer and outputs it to the next layer, with no feedback between layers.
[0111] First parameter matrix: the parameter matrix in the embedding layer.
[0112] Second parameter matrix: parameter matrix in the feed-forward network layer.
[0113] First high-order tensor: The high-order tensor obtained after the first parameter matrix is upgraded.
[0114] Second high-order tensor: The high-order tensor obtained after the second parameter matrix is upgraded.
[0115] First decomposition result: the decomposition result obtained after the first high-order tensor is decomposed.
[0116] Second decomposition result: the decomposition result of the second high-order tensor after tensor decomposition.
[0117] First row parameters: row parameters corresponding to the first parameter matrix.
[0118] First column parameter: Column parameter corresponding to the first parameter matrix.
[0119] Second row parameter: row parameter corresponding to the second parameter matrix.
[0120] Second column parameter: Column parameter corresponding to the second parameter matrix.
[0121] In the present application, a compression method and apparatus for a neural network model, a computing device, and a computer-readable storage medium are provided, which are described in detail one by one in the following embodiments.
[0122] Figure 1 The structure block diagram of a computing device 100 according to an embodiment of the present application is shown. The components of the computing device 100 include but are not limited to a memory 110 and a processor 120. The processor 120 is connected to the memory 110 via a bus 130, and the database 150 is used to store data.
[0123] The computing device 100 also includes an access device 140 that enables the computing device 100 to communicate via one or more networks 160. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 140 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0124] In one embodiment of the present application, the above components of the computing device 100 and Figure 1 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 1 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of the present application. Those skilled in the art may add or replace other components as needed.
[0125] The computing device 100 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 100 may also be a mobile or stationary server.
[0126] The processor 120 may execute Figure 2 Steps in a compression method for the neural network model shown. Figure 2 A flowchart of a compression method for a neural network model according to the first embodiment of the present application is shown. This embodiment takes a transformer sentence translation model as an example, and the transformer sentence translation model includes a first embedding layer and a second embedding layer. The compression method for a neural network model provided in this embodiment is applicable to any embedding layer. For any embedding layer, the compression method for a neural network model includes steps 202 to 208.
[0127] Step 202: Obtain the parameter matrix in the embedding layer of the neural network model.
[0128] The embedding layer is located at the input layer of the neural network model, and is used to embed the input text data and output the text vector; embed the input image data and output the image features.
[0129] The parameter matrix is a matrix that describes the network parameters. The model parameters expressed in matrix form are called parameter matrix. Each element in the parameter matrix has a fixed meaning. The parameter matrix can be expressed as M*N, where M is the vocabulary size and N is the dimension of the embedding layer.
[0130] Obtaining the parameter matrix in the embedding layer of the neural network model is to obtain an M*N parameter matrix, the purpose of which is to compress the parameters in the embedding layer and reduce the volume of the neural network model.
[0131] In the first embodiment provided in the present application, the first parameter matrix is 120*48, where 120 is the vocabulary size and 48 is the dimension of the current embedding layer.
[0132] Step 204: receiving an order-up instruction, and performing order-up processing on the parameter matrix according to the order-up instruction to obtain a high-order tensor.
[0133] The upgrade instruction is used to instruct the upgrading of network parameters. Tensors of order three and above are called high-order tensors. The upgrade instruction includes an upgrade value P. According to the upgrade value P included in the upgrade instruction, the first parameter matrix is upgraded to a high-order tensor of order P.
[0134] Optionally, the parameter matrix is upgraded according to the upgraded value to obtain a high-order tensor of a dimension corresponding to the upgraded value, including: decomposing the rows of the parameter matrix according to the upgraded value to obtain a continuous product of multiple row parameters, wherein the number of the row parameters corresponds to the upgraded value; decomposing the columns of the parameter matrix according to the upgraded value to obtain a continuous product of multiple column parameters, wherein the number of the column parameters corresponds to the upgraded value; generating a high-order tensor according to the row parameters and the column parameters, wherein the dimension of the high-order tensor corresponds to the upgraded value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameter and column parameter.
[0135] The number of rows of the parameter matrix is decomposed to obtain the product of multiple parameters, each of which is called a row parameter; the number of columns of the parameter matrix is decomposed to obtain the product of multiple parameters, each of which is called a row parameter.
[0136] For the parameter matrix M*N, according to the order value P, the row M of the first parameter matrix is decomposed into That is, P row parameters I1, I2...I p The product of , decomposes the column N of the first parameter matrix into That is, P columns of parameters J1, J2, ... p The product of , the parameter matrix M*N can be transformed into a P solution tensor, that is Wherein, R represents the real number space. In the present application, the dimension of the high-order tensor is represented by the product of the row parameter and the column parameter at the corresponding position, which can quickly and accurately restore the original first parameter matrix when restoring the first parameter matrix.
[0137] In the first embodiment provided by the present application, a boost instruction is received, the boost value in the boost instruction is 3, the row 120 of the parameter matrix is decomposed into 4*5*6, the column 48 of the parameter matrix is decomposed into 4*3*4, and the parameter matrix 120*48 is boosted to obtain a high-order tensor R (4*4)*(5*3)*(6*4) .
[0138] Step 206: Decompose the high-order tensor to obtain a decomposition result of the high-order tensor.
[0139] There are many methods for tensor decomposition, such as CP decomposition, peeling decomposition, continuous decomposition, ring decomposition, etc. In practical applications, the method of tensor decomposition can be selected according to the actual situation. For example, the high-order tensor can be decomposed by the continuous decomposition method to obtain the product of multiple continuous tensors, where the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional; the high-order tensor can also be decomposed by the peeling decomposition method to obtain the product of a core tensor and multiple matrices.
[0140] In the first embodiment provided in the present application, the continuous decomposition method is selected to decompose the high-order tensor in the embedded layer. The order of the high-order tensor is P. For any element in the tensor, the decomposition formula of the continuous decomposition is shown in Formula 1:
[0141]
[0142] Where K is the index of the element, For tt-cores, The minimum values in are called tt-ranks.
[0143] Receive preset According to the preset For the first high-order tensor Decompose it, and the decomposition formula is shown in Formula 2 below:
[0144]
[0145] In the first embodiment provided in the present application, the step-up value in the step-up instruction is P=3, and the preset is (16, 8), then the first high-order tensor R (4*4)*(5*3)*(6*4) It can be decomposed into the following formula 3:
[0146]
[0147] Among them G 1 ∈R 4*4*16 , G 2 ∈R 16*5*3*8 , G 3 ∈R 8*6*4 .
[0148] Step 208: Update the parameter matrix according to the decomposition result to obtain a compressed neural network model.
[0149] The decomposition result is the result obtained after the high-order tensor is decomposed. The parameter matrix in the embedding layer of the neural network model is updated according to the decomposition result to obtain a compressed neural network model, so that the compressed translation model effectively reduces the amount of parameters in the embedding layer and reduces the model volume while maintaining the performance.
[0150] In the first embodiment provided in the present application, the decomposition results include preset tt-ranks=(16, 8), G 1 ∈R 4 *4*16 , G 2 ∈R 16*5*3*8 and G 3 ∈R 8*6*4 , use the decomposition results to update the parameter matrix 120*48 in the embedding layer to obtain the compressed translation model.
[0151] Optionally, the method further includes: using the compressed neural network model for training.
[0152] The compressed neural network model is used for model training. In practical applications, the parameter matrix in the embedding layer of the neural network model can be restored according to the saved decomposition results, that is, the vocabulary size and embedding layer dimension in the embedding layer can be restored to maintain the performance of the neural network model.
[0153] In the first embodiment provided in this application, according to tt-ranks=(16, 8), G 1 ∈R 4*4*16 , G 2 ∈R 16*5*3*8 and G 3 ∈R 8*6*4 The original two-dimensional parameter matrix 120*48 in the embedding layer is restored, and the two-dimensional parameter matrix is used to participate in the training of the neural network model.
[0154] The compression method of the neural network model provided in the first embodiment of the present application is applicable to the embedding layer of the neural network model. The parameters in the embedding layer are upgraded to high-order tensors and then the embedding layer can be effectively compressed based on the tensor decomposition technology. Experiments have shown that the continuous decomposition method is used to compress the model parameters in the embedding layer. In practical applications, the BLEU value of the evaluation index of the neural network model is higher, which can significantly reduce the size of the neural network model while ensuring the performance of the neural network model.
[0155] Figure 3 A flowchart of a compression method for a neural network model according to a second embodiment of the present application is shown. This embodiment takes a transformer translation model as an example. The transformer translation model includes 6 encoding layers and 6 decoding layers, and each of the encoding layers and each of the decoding layers includes a feedforward network layer. The compression method for a neural network model provided in this embodiment is applicable to any feedforward network layer. For any feedforward network layer, the compression method for a neural network model includes steps 302 to 308.
[0156] Step 302: Obtain the parameter matrix in the feedforward network layer of the neural network model.
[0157] The feedforward network layer is the simplest neural network, where neurons are arranged in layers. Each neuron is only connected to the neurons in the previous layer. It receives the output of the previous layer and outputs it to the next layer, with no feedback between layers.
[0158] The feedforward network layer consists of two linear layers and a Relu layer, as shown in Formula 4 below:
[0159] FFN(x)=max(0,xW1+b1)W2+b2 (4)
[0160] Among them, W1 and W2 are parameter matrices in the feedforward network layer, b1 and b2 are bias vectors. Any parameter matrix can be expressed as M*N, where M represents the length of the current training sentence and N represents the feature dimension.
[0161] In the second embodiment provided in the present application, the parameter matrix is 48*512, where 48 is the length of the current training sentence and 512 is the feature dimension.
[0162] Step 304: receiving an order-up instruction, and performing order-up processing on the parameter matrix according to the order-up instruction to obtain a high-order tensor.
[0163] Step 304 is consistent with the method of step 204 described above. For a specific explanation of step 304, please refer to the detailed content of step 204 in the first embodiment described above, which will not be repeated here.
[0164] In the second embodiment provided by the present application, the rank value in the rank-raising instruction is 3, the row 48 of the second parameter matrix is decomposed into 3*4*4, the column 512 of the second parameter matrix is decomposed into 8*8*8, and the second parameter matrix 48*512 is rank-raised to obtain the second high-order tensor R (3*8)*(4*8)*(4*8) .
[0165] Step 306: Decompose the high-order tensor to obtain a decomposition result of the high-order tensor.
[0166] There are many methods for tensor decomposition, such as CP decomposition, peeling decomposition, continuous decomposition, ring decomposition, etc. In practical applications, the method of tensor decomposition can be selected according to the actual situation. For example, the high-order tensor can be decomposed by the continuous decomposition method to obtain the product of multiple continuous tensors, where the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional; the high-order tensor can also be decomposed by the peeling decomposition method to obtain the product of a core tensor and multiple matrices.
[0167] In the second embodiment provided by the present application, the peeling decomposition method is selected to decompose the second high-order tensor in the feedforward network layer. P*Q*R Taking the third-order tensor as an example, receive the preset core tensor G∈R I*J*Z , the decomposition formula of peeling decomposition is shown in the following formula 5:
[0168]
[0169] Among them, A, B and C are factor matrices, and G is the preset core tensor. Any element in the tensor can be expressed as:
[0170] In the second embodiment provided in the present application, the second high-order tensor is R (3*8)*(4*8)*(4*8) , receiving the preset core tensor G∈R 2*2*2 , decompose the second high-order tensor into three factor matrices A, B, and C, where A∈R 3*8*2 , B∈R 4*8*2 , C∈R 4*8*2 .
[0171] Step 308: Update the parameter matrix according to the decomposition result to obtain a compressed neural network model.
[0172] The decomposition result is the result obtained after the high-order tensor is decomposed. The parameter matrix in the feedforward network layer of the neural network model is updated according to the decomposition result to obtain a compressed neural network model, so that the compressed translation model effectively reduces the amount of parameters in the feedforward network layer and reduces the model volume while maintaining the performance.
[0173] In the embodiment provided in the present application, the second decomposition result includes a core tensor G∈R 2*2*2 , and three factor matrices A∈R 3*8*2 , B∈R 4*8*2 , C∈R 4*8*2 , use the second decomposition result to update the second parameter matrix 48*512 in the transformer translation model to obtain a compressed translation model. The compressed translation model effectively reduces the amount of parameters in the feedforward network layer and reduces the model size while maintaining performance.
[0174] Optionally, the method further includes: using the compressed neural network model for training.
[0175] The compressed neural network model is used for model training. In practical applications, the parameter matrix in the feedforward network layer of the neural network model can be restored according to the saved decomposition results, that is, the length and feature dimension of the sentences in the feedforward network layer can be restored to maintain the performance of the neural network model.
[0176] The compression method of the neural network model provided in the second embodiment of the present application is applicable to the feedforward network layer of the neural network model. By upgrading the parameters in the feedforward network layer to high-order tensors and then effectively compressing the feedforward network layer based on tensor decomposition technology, experiments have shown that the use of peeling decomposition method to compress the model parameters in the feedforward network layer has a higher BLEU value, an evaluation index of the neural network model in actual applications, and can significantly reduce the size of the neural network model while ensuring the performance of the neural network model.
[0177] Figure 4A flowchart of a compression method for a neural network model according to a third embodiment of the present application is shown. This embodiment takes a transformer translation model as an example. The transformer translation model includes a first embedding layer, a second embedding layer, 6 encoding layers and 6 decoding layers, wherein the first embedding layer is serially connected to the 6 encoding layers in sequence, and the second embedding layer is serially connected to the 6 decoding layers in sequence, each embedding layer includes a first parameter matrix corresponding to the current embedding layer, and the first parameter matrix is the parameter matrix in the embedding layer. Each encoding layer and each decoding layer includes a feedforward network layer, that is, a total of 12 feedforward network layers, each feedforward network layer includes a second parameter matrix corresponding to the current feedforward network layer, and the second parameter matrix is the parameter matrix in the feedforward network layer. The compression method of the neural network model provided in this embodiment is applicable to any embedding layer and feedforward network layer. For any embedding layer and feedforward network layer, the compression method of the neural network model includes steps 402 to 408.
[0178] Step 402: Obtain a first parameter matrix in the embedding layer and a second parameter matrix in the feedforward network layer of the neural network model.
[0179] The first parameter matrix is the parameter matrix in the embedding layer, and the second parameter matrix is the parameter matrix in the feedforward network layer.
[0180] The step of obtaining the first parameter matrix in the embedding layer is consistent with the method of the above step 202. For a specific explanation of obtaining the first parameter matrix in the embedding layer, please refer to the detailed content of step 202 in the above first embodiment, which will not be repeated here.
[0181] The step of obtaining the second parameter matrix in the feedforward network layer is consistent with the above-mentioned step 302 method. For a specific explanation of obtaining the second parameter matrix in the feedforward network layer, please refer to the detailed content of step 302 in the above-mentioned second embodiment, which will not be repeated here.
[0182] Step 404: receiving an upgrade instruction, and performing upgrade processing on the first parameter matrix according to the upgrade instruction to obtain a first high-order tensor, and performing upgrade processing on the second parameter matrix according to the upgrade instruction to obtain a second high-order tensor.
[0183] In practical applications, the boost instruction may include a boost value P, or may include a boost value P1 for the first parameter matrix and a boost value P2 for the second parameter matrix, which is not limited in the present application.
[0184] The step of performing upgrading processing on the first parameter matrix according to the upgrading instruction to obtain the first high-order tensor is consistent with the method of the above-mentioned step 204. For the specific explanation of performing upgrading processing on the first parameter matrix according to the upgrading instruction to obtain the first high-order tensor, please refer to the detailed content of step 204 in the above-mentioned first embodiment, which will not be repeated here.
[0185] The step of performing upgrading processing on the second parameter matrix according to the upgrading instruction to obtain a second high-order tensor is consistent with the above-mentioned step 304 method. For the specific explanation of performing upgrading processing on the second parameter matrix according to the upgrading instruction to obtain a second high-order tensor, please refer to the detailed content of step 304 in the above-mentioned second embodiment, which will not be repeated here.
[0186] Step 406: decompose the first high-order tensor to obtain a first decomposition result, and decompose the second high-order tensor to obtain a second decomposition result.
[0187] The step of decomposing the first high-order tensor to obtain a first decomposition result is consistent with the above-mentioned step 206 method. For a specific explanation of decomposing the first high-order tensor to obtain a first decomposition result, please refer to the detailed content of step 206 in the above-mentioned first embodiment, which will not be repeated here.
[0188] The step of decomposing the second high-order tensor to obtain the second decomposition result is consistent with the above-mentioned step 306 method. For the specific explanation of decomposing the second high-order tensor to obtain the second decomposition result, please refer to the detailed content of step 306 in the above-mentioned second embodiment, which will not be repeated here.
[0189] Step 408: Update the first parameter matrix according to the first decomposition result, and update the second parameter matrix according to the second decomposition result to obtain a compressed neural network model.
[0190] The step of updating the first parameter matrix according to the first decomposition result is consistent with the method of the above-mentioned step 208. For the specific explanation of updating the first parameter matrix according to the first decomposition result, please refer to the detailed content of step 208 in the above-mentioned first embodiment, which will not be repeated here.
[0191] The step of updating the second parameter matrix according to the second decomposition result is consistent with the method of the above-mentioned step 308. For the specific explanation of updating the second parameter matrix according to the second decomposition result, please refer to the detailed content of step 308 in the above-mentioned second embodiment, which will not be repeated here.
[0192] Optionally, the method further includes: using the compressed neural network model for training.
[0193] The compressed neural network model is used for model training. In practical applications, the parameter matrix in the embedding layer of the neural network model is restored according to the saved first decomposition result, that is, the vocabulary size and the embedding layer dimension in the embedding layer are restored; the parameter matrix in the feedforward network layer of the neural network model is restored according to the saved second decomposition result, that is, the length and feature dimension of the sentences in the feedforward network layer are restored to maintain the performance of the neural network model.
[0194] The compression method of the neural network model provided in the third embodiment of the present application effectively reduces the number of parameters in the embedding layer and the feedforward network layer through tensor decomposition technology. The number of parameters in the embedding layer is huge and there is a lot of redundancy. The continuous decomposition method is used for the embedding layer, which effectively reduces the number of parameters in the model embedding layer while maintaining the model performance. At the same time, the parameters in the feedforward network layer are peeled off to reduce the number of parameters in the model feedforward network layer. The volume of the neural network model is significantly reduced while maintaining the model performance. Experiments have shown that the continuous decomposition method is used for high-order tensors in the embedding layer, and the peeling decomposition method is used for high-order tensors in the feedforward network layer. The evaluation index BLEU value in the application is higher, and the volume of the neural network model can be significantly reduced while maintaining the performance of the neural network model.
[0195] Corresponding to the above method embodiment, the present application also provides a compression device embodiment of a neural network model, Figure 5 A schematic diagram of the structure of a compression device for a neural network model according to an embodiment of the present application is shown.
[0196] like Figure 5 As shown, the device comprises:
[0197] The first acquisition module 502 is configured to acquire a parameter matrix in an embedding layer of a neural network model.
[0198] The first up-order module 504 is configured to receive an up-order instruction, and perform up-order processing on the parameter matrix according to the up-order instruction to obtain a high-order tensor.
[0199] The first decomposition module 506 is configured to decompose the high-order tensor to obtain a decomposition result of the high-order tensor.
[0200] The first updating module 508 is configured to update the parameter matrix according to the decomposition result to obtain a compressed neural network model.
[0201] Optionally, the neural network model is a transformer translation model, and the transformer translation model includes a first embedding layer and a second embedding layer;
[0202] The first acquisition module 502 is further configured to acquire a parameter matrix in the first embedding layer and / or the second embedding layer.
[0203] Optionally, the upgrade instruction includes an upgrade value;
[0204] The first rank-raising module 504 is further configured to perform rank-raising processing on the parameter matrix according to the rank-raising value to obtain a high-order tensor with a dimension corresponding to the rank-raising value.
[0205] Optionally, the first up-order module 504 is further configured to decompose the rows of the parameter matrix according to the up-order value to obtain a plurality of continuous products of row parameters, wherein the number of the row parameters corresponds to the up-order value; decompose the columns of the parameter matrix according to the up-order value to obtain a plurality of continuous products of column parameters, wherein the number of the column parameters corresponds to the up-order value; generate a high-order tensor according to the row parameters and the column parameters, wherein the dimension of the high-order tensor corresponds to the up-order value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameter and column parameter.
[0206] Optionally, the first decomposition module 506 is further configured to decompose the high-order tensor by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional.
[0207] Optionally, the first decomposition module 506 is further configured to decompose the high-order tensor by peeling decomposition to obtain the product of a core tensor and multiple matrices.
[0208] The compression device of the neural network model provided in the present application is suitable for the embedding layer of the neural network model. The parameters in the embedding layer are upgraded to high-order tensors and then the embedding layer can be effectively compressed based on the tensor decomposition technology. Experiments have shown that the continuous decomposition method is used to compress the model parameters in the embedding layer. In practical applications, the BLEU value of the evaluation index of the neural network model is higher, which can significantly reduce the size of the neural network model while ensuring the performance of the neural network model.
[0209] Corresponding to the above method embodiment, the present application also provides a compression device embodiment of a neural network model, Figure 6 A schematic diagram of the structure of a compression device for a neural network model according to an embodiment of the present application is shown.
[0210] like Figure 6 As shown, the device comprises:
[0211] The second acquisition module 602 is configured to acquire the parameter matrix in the feedforward network layer of the neural network model.
[0212] The second up-order module 604 is configured to receive an up-order instruction, and perform up-order processing on the parameter matrix according to the up-order instruction to obtain a high-order tensor.
[0213] The second decomposition module 606 is configured to decompose the high-order tensor to obtain a decomposition result of the high-order tensor.
[0214] The second updating module 608 is configured to update the parameter matrix according to the decomposition result to obtain a compressed neural network model.
[0215] Optionally, the neural network model is a transformer translation model, the transformer translation model includes 6 encoding layers and 6 decoding layers, each encoding layer and each decoding layer includes a feedforward network layer;
[0216] The second acquisition module 602 is further configured to acquire a parameter matrix in at least one of the feed-forward network layers.
[0217] Optionally, the upgrade instruction includes an upgrade value;
[0218] The second up-order module 604 is configured to perform up-order processing on the parameter matrix according to the up-order value to obtain a high-order tensor with a dimension corresponding to the up-order value.
[0219] Optionally, the second up-order module 604 is further configured to decompose the rows of the parameter matrix according to the up-order value to obtain a plurality of continuous products of row parameters, wherein the number of the row parameters corresponds to the up-order value; decompose the columns of the parameter matrix according to the up-order value to obtain a plurality of continuous products of column parameters, wherein the number of the column parameters corresponds to the up-order value; generate a high-order tensor according to the row parameters and the column parameters, wherein the dimension of the high-order tensor corresponds to the up-order value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameter and column parameter.
[0220] Optionally, the second decomposition module 606 is further configured to decompose the high-order tensor by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional.
[0221] Optionally, the second decomposition module 606 is further configured to decompose the high-order tensor by peeling decomposition to obtain the product of a core tensor and multiple matrices.
[0222] The compression device of the neural network model provided in the present application is suitable for the feedforward network layer of the neural network model. By upgrading the parameters in the feedforward network layer to high-order tensors, the feedforward network layer can be effectively compressed based on the tensor decomposition technology. Experiments have shown that the use of the peeling decomposition method to compress the model parameters in the feedforward network layer has a higher BLEU value, an evaluation index of the neural network model in actual applications, and can significantly reduce the size of the neural network model while ensuring the performance of the neural network model.
[0223] Corresponding to the above method embodiment, the present application also provides a compression device embodiment of a neural network model, Figure 7 A schematic diagram of the structure of a compression device for a neural network model according to an embodiment of the present application is shown.
[0224] like Figure 7 As shown, the device comprises:
[0225] The third acquisition module 702 is configured to acquire a first parameter matrix in the embedding layer and a second parameter matrix in the feedforward network layer of the neural network model.
[0226] The third up-order module 704 is configured to receive an up-order instruction, and perform up-order processing on the first parameter matrix according to the up-order instruction to obtain a first high-order tensor, and perform up-order processing on the second parameter matrix according to the up-order instruction to obtain a second high-order tensor.
[0227] The third decomposition module 706 is configured to decompose the first high-order tensor to obtain a first decomposition result, and decompose the second high-order tensor to obtain a second decomposition result.
[0228] The third updating module 708 is configured to update the first parameter matrix according to the first decomposition result, and update the second parameter matrix according to the second decomposition result to obtain a compressed neural network model.
[0229] Optionally, the neural network model is a transformer translation model, which includes a first embedding layer, a second embedding layer, 6 encoding layers and 6 decoding layers, the first embedding layer is connected to the 6 encoding layers in sequence, the second embedding layer is connected to the 6 decoding layers in sequence, and each of the encoding layers and each of the decoding layers includes a feedforward network layer;
[0230] The third acquisition module 702 is further configured to acquire a first parameter matrix in the first embedding layer and / or the second embedding layer; and acquire a second parameter matrix in at least one of the feedforward network layers.
[0231] Optionally, the upgrade instruction includes an upgrade value;
[0232] The third up-order module 704 is further configured to perform up-order processing on the first parameter matrix according to the up-order value to obtain a first high-order tensor corresponding to the up-order value; and perform up-order processing on the second parameter matrix according to the up-order value to obtain a second high-order tensor corresponding to the up-order value.
[0233] Optionally, the third up-order module 704 is further configured to decompose the rows of the first parameter matrix according to the up-order value to obtain a plurality of continuous products of first row parameters, wherein the number of the first row parameters corresponds to the up-order value; decompose the columns of the first parameter matrix according to the up-order value to obtain a plurality of continuous products of first column parameters, wherein the number of the first column parameters corresponds to the up-order value; generate a first high-order tensor according to the first row parameters and the first column parameters, wherein the dimension of the first high-order tensor corresponds to the up-order value, and the size of each dimension of the first high-order tensor is determined by the corresponding first row parameter and first column parameter.
[0234] Optionally, the third up-order module 704 is further configured to decompose the rows of the second parameter matrix according to the up-order value to obtain a plurality of continuous products of second row parameters, wherein the number of the second row parameters corresponds to the up-order value; decompose the columns of the second parameter matrix according to the up-order value to obtain a plurality of continuous products of second column parameters, wherein the number of the second column parameters corresponds to the up-order value; generate a second high-order tensor according to the second row parameters and the second column parameters, wherein the dimension of the second high-order tensor corresponds to the up-order value, and the size of each dimension of the second high-order tensor is determined by the corresponding second row parameter and second column parameter.
[0235] Optionally, the third decomposition module 706 is further configured to decompose the first high-order tensor by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional.
[0236] Optionally, the third decomposition module 706 is further configured to decompose the second high-order tensor by peeling decomposition to obtain a core tensor and the product of multiple matrices. The compression device of the neural network model provided in the embodiment of the present application effectively reduces the number of parameters in the embedding layer and the feedforward network layer through tensor decomposition technology. The number of parameters in the embedding layer is huge and there is a lot of redundancy. The continuous decomposition method is used for the embedding layer, which effectively reduces the number of parameters in the model embedding layer while maintaining the model performance. At the same time, the parameters in the feedforward network layer are peeled and decomposed to reduce the number of parameters in the model feedforward network layer. The volume of the neural network model is significantly reduced while maintaining the model performance. Experiments have shown that the continuous decomposition method is used for the high-order tensors in the embedding layer, and the peeling decomposition method is used for the high-order tensors in the feedforward network layer. The evaluation index BLEU value in the application is higher, and the volume of the neural network model can be significantly reduced while maintaining the performance of the neural network model.
[0237] In one embodiment of the present application, a computing device is also provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein when the processor executes the instructions, the steps of the compression method of the neural network model are implemented.
[0238] An embodiment of the present application also provides a computer-readable storage medium storing computer instructions, which, when executed by a processor, implement the steps of the compression method of the neural network model as described above.
[0239] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the compression method of the above-mentioned neural network model belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be found in the description of the technical scheme of the compression method of the above-mentioned neural network model.
[0240] An embodiment of the present application discloses a chip storing computer instructions, which, when executed by a processor, implement the steps of the neural network model compression method as described above.
[0241] The above describes specific embodiments of the present application. 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 accompanying 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.
[0242] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0243] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0244] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0245] The preferred embodiments of the present application disclosed above are only used to help explain the present application. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the present application. The present application selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present application, so that those skilled in the art can understand and use the present application well. The present application is only limited by the claims and their full scope and equivalents.
Claims
1. A compression method for a neural network translation model, characterized in that: include: Obtaining a parameter matrix in an embedding layer of a neural network translation model, wherein the embedding layer is used to perform embedding processing on input text data; Receive an order-raising instruction, and decompose the rows of the parameter matrix according to the order-raising value in the order-raising instruction to obtain a plurality of continuous products of row parameters, decompose the columns of the parameter matrix according to the order-raising value to obtain a plurality of continuous products of column parameters, and generate a high-order tensor according to the row parameters and the column parameters, wherein the number of the row parameters, the number of the column parameters, and the dimension of the high-order tensor correspond to the order-raising value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameter and column parameter; Decomposing the high-order tensor to obtain a decomposition result of the high-order tensor; The parameter matrix is updated according to the decomposition result to obtain a compressed neural network translation model.
2. The method for compressing a neural network translation model according to claim 1, wherein: The neural network translation model is a transformer translation model, and the transformer translation model includes a first embedding layer and a second embedding layer; Get the parameter matrix in the embedding layer of the neural network translation model, including: Get the parameter matrix in the first embedding layer and / or the second embedding layer.
3. The compression method of the neural network translation model according to claim 1, characterized in that: Decomposing the high-order tensor to obtain a decomposition result of the high-order tensor includes: The high-order tensor is decomposed by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional, and the other tensors are four-dimensional.
4. The method for compressing a neural network translation model according to claim 1, wherein: Decomposing the high-order tensor to obtain a decomposition result of the high-order tensor includes: The high-order tensor is decomposed by a peeling decomposition method to obtain the product of a core tensor and multiple matrices.
5. A compression method for a neural network translation model, characterized in that: include: Obtaining a parameter matrix in a feedforward network layer of a neural network translation model, wherein the neural network translation model includes an embedding layer, and the embedding layer is used to perform embedding processing on input text data; Receive an order-raising instruction, and decompose the rows of the parameter matrix according to the order-raising value in the order-raising instruction to obtain a plurality of continuous products of row parameters, decompose the columns of the parameter matrix according to the order-raising value to obtain a plurality of continuous products of column parameters, and generate a high-order tensor according to the row parameters and the column parameters, wherein the number of the row parameters, the number of the column parameters, and the dimension of the high-order tensor correspond to the order-raising value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameter and column parameter; Decomposing the high-order tensor to obtain a decomposition result of the high-order tensor; The parameter matrix is updated according to the decomposition result to obtain a compressed neural network translation model.
6. The method for compressing a neural network translation model as claimed in claim 5, characterized in that: The neural network translation model is a transformer translation model, and the transformer translation model includes 6 encoding layers and 6 decoding layers, and each encoding layer and each decoding layer includes a feedforward network layer; Get the parameter matrix in the feedforward network layer of the neural network translation model, including: Obtain a parameter matrix in at least one of the feed-forward network layers.
7. The method for compressing a neural network translation model as claimed in claim 5, characterized in that: Decomposing the high-order tensor to obtain a decomposition result of the high-order tensor includes: The high-order tensor is decomposed by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional.
8. The method for compressing a neural network translation model as claimed in claim 5, characterized in that: Decomposing the high-order tensor to obtain a decomposition result of the high-order tensor includes: The high-order tensor is decomposed by a peeling decomposition method to obtain the product of a core tensor and multiple matrices.
9. A compression method for a neural network translation model, characterized in that: include: Obtaining a first parameter matrix in an embedding layer and a second parameter matrix in a feedforward network layer of a neural network translation model, wherein the embedding layer is used to perform embedding processing on input text data; Receive an upgrade instruction, and decompose the rows of the first parameter matrix according to the upgrade value in the upgrade instruction to obtain a plurality of continuous products of first row parameters, decompose the columns of the first parameter matrix according to the upgrade value to obtain a plurality of continuous products of first column parameters, and generate a first high-order tensor according to the first row parameter and the first column parameter, wherein the number of the first row parameters, the number of the first column parameters, and the dimension of the first high-order tensor correspond to the upgrade value, and the size of each dimension of the first high-order tensor is determined by the corresponding first row parameter and first column parameter; decompose the rows of the second parameter matrix according to the upgrade value to obtain a plurality of continuous products of second row parameters, decompose the columns of the second parameter matrix according to the upgrade value to obtain a plurality of continuous products of second column parameters, and generate a second high-order tensor according to the second row parameter and the second column parameter, wherein the number of the second row parameters, the number of the second column parameters, and the dimension of the second high-order tensor correspond to the upgrade value, and the size of each dimension of the second high-order tensor is determined by the corresponding second row parameter and second column parameter; Decomposing the first high-order tensor to obtain a first decomposition result, and decomposing the second high-order tensor to obtain a second decomposition result; The first parameter matrix is updated according to the first decomposition result, and the second parameter matrix is updated according to the second decomposition result to obtain a compressed neural network translation model.
10. The method for compressing a neural network translation model according to claim 9, wherein: The neural network translation model is a transformer translation model, which includes a first embedding layer, a second embedding layer, 6 encoding layers and 6 decoding layers, the first embedding layer is connected to the 6 encoding layers in sequence, the second embedding layer is connected to the 6 decoding layers in sequence, and each of the encoding layers and each of the decoding layers includes a feedforward network layer; Obtaining a first parameter matrix in an embedding layer and a second parameter matrix in a feedforward network layer of a neural network translation model, including: Obtaining a first parameter matrix in the first embedding layer and / or the second embedding layer; Obtain a second parameter matrix in at least one of the feed-forward network layers.
11. The method for compressing a neural network translation model according to claim 9, wherein: Decomposing the first high-order tensor to obtain a first decomposition result includes: The first high-order tensor is decomposed by a continuous decomposition method to obtain the product of multiple continuous tensors, wherein the first and last tensors of the multiple continuous tensors are three-dimensional and the other tensors are four-dimensional.
12. The method for compressing a neural network translation model according to claim 9, wherein: Decomposing the second high-order tensor to obtain a second decomposition result includes: The second high-order tensor is decomposed by a peeling decomposition method to obtain the product of a core tensor and multiple matrices.
13. A compression device for a neural network translation model, characterized in that: include: A first acquisition module is configured to acquire a parameter matrix in an embedding layer of a neural network translation model, wherein the embedding layer is used to perform embedding processing on input text data; A first order-raising module is configured to receive an order-raising instruction, decompose the rows of the parameter matrix according to the order-raising value in the order-raising instruction, obtain a plurality of continuous products of row parameters, decompose the columns of the parameter matrix according to the order-raising value, obtain a plurality of continuous products of column parameters, and generate a high-order tensor according to the row parameters and the column parameters, wherein the number of the row parameters, the number of the column parameters, and the dimension of the high-order tensor correspond to the order-raising value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameter and column parameter; A first decomposition module is configured to decompose the high-order tensor to obtain a decomposition result of the high-order tensor; The first updating module is configured to update the parameter matrix according to the decomposition result to obtain a compressed neural network translation model.
14. A compression device for a neural network translation model, characterized in that: include: A second acquisition module is configured to acquire a parameter matrix in a feedforward network layer of a neural network translation model, wherein the neural network translation model includes an embedding layer, and the embedding layer is used to perform embedding processing on input text data; A second order-raising module is configured to receive an order-raising instruction, decompose the rows of the parameter matrix according to the order-raising value in the order-raising instruction, obtain a plurality of continuous products of row parameters, decompose the columns of the parameter matrix according to the order-raising value, obtain a plurality of continuous products of column parameters, and generate a high-order tensor according to the row parameters and the column parameters, wherein the number of the row parameters, the number of the column parameters, and the dimension of the high-order tensor correspond to the order-raising value, and the size of each dimension of the high-order tensor is determined by the corresponding row parameter and column parameter; A second decomposition module is configured to decompose the high-order tensor to obtain a decomposition result of the high-order tensor; The second updating module is configured to update the parameter matrix according to the decomposition result to obtain a compressed neural network translation model.
15. A compression device for a neural network translation model, characterized in that: include: A third acquisition module is configured to acquire a first parameter matrix in an embedding layer and a second parameter matrix in a feedforward network layer of a neural network translation model, wherein the embedding layer is used to perform embedding processing on input text data; A third order-raising module is configured to receive an order-raising instruction, and decompose the rows of the first parameter matrix according to the order-raising value in the order-raising instruction to obtain a plurality of continuous products of first row parameters, decompose the columns of the first parameter matrix according to the order-raising value to obtain a plurality of continuous products of first column parameters, and generate a first high-order tensor according to the first row parameters and the first column parameters, wherein the number of the first row parameters, the number of the first column parameters, and the dimension of the first high-order tensor correspond to the order-raising value, and the size of each dimension of the first high-order tensor is determined by the corresponding first row parameter and first column parameter; decompose the rows of the second parameter matrix according to the order-raising value to obtain a plurality of continuous products of second row parameters, decompose the columns of the second parameter matrix according to the order-raising value to obtain a plurality of continuous products of second column parameters, and generate a second high-order tensor according to the second row parameters and the second column parameters, wherein the number of the second row parameters, the number of the second column parameters, and the dimension of the second high-order tensor correspond to the order-raising value, and the size of each dimension of the second high-order tensor is determined by the corresponding second row parameter and second column parameter; a third decomposition module, configured to decompose the first high-order tensor to obtain a first decomposition result, and decompose the second high-order tensor to obtain a second decomposition result; The third updating module is configured to update the first parameter matrix according to the first decomposition result, and update the second parameter matrix according to the second decomposition result to obtain a compressed neural network translation model.
16. A computing device comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the instructions, the steps of the method described in any one of claims 1-4, 5-8 or 9-12 are implemented.
17. A computer-readable storage medium storing computer instructions, characterized in that: When the instruction is executed by the processor, the steps of the method described in any one of claims 1-4, 5-8 or 9-12 are implemented.
