A large language model acceleration method and device

Through multi-matrix compression and decomposition and singular value decomposition technology, the weight matrix is ​​compressed on the large language model, solving the problems of resource requirements and computational complexity of large language model, realizing the reduction of storage resources and the acceleration of the inference process.

CN118569324BActive Publication Date: 2025-01-07INSPUR SOFTWARE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411045654.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2025-01-07
Estimated Expiration
2044-08-01

AI Technical Summary

Technical Problem

Due to large parameters, large training data and high computing power requirements, large language models require a large amount of storage resources and computing resources for deployment, training and reasoning, which limits their promotion and application.

Method used

The multi-matrix compression and decomposition technology is used to compress and decompose the pre-trained weight matrix of large language models, combining QR decomposition and singular value decomposition to reduce the dimension of the weight matrix, and set the low-rank parameterization update matrix rank during the fine-tuning process to reduce storage Resource requirements and computational complexity.

Benefits of technology

The pre-trained weight matrix of large language models is compressed to the greatest extent within the range of error permitted, reducing storage resource requirements and computational complexity, improving application universality, and reducing the computational complexity of the inference process after fine-tuning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118569324B_ABST
    Figure CN118569324B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of artificial intelligence. The technical problem to be solved by the present invention is how to simplify storage resources and computing resources and promote large language models. The technical solution adopted is a large language model acceleration method and device, which has the following steps: S1, compress and decompose the pre-trained weight matrix W of the large language model; S2, respectively decompose U and V T The matrix is ​​decomposed by QR to obtain Q U , R U , Q V , R V ; S3. Use the singular value decomposition algorithm to compress and decompose the matrix product; S4. Merge the matrices separately; S5. Replace the weight matrix W with the obtained matrix for storage; S6. Use the stored matrix to accelerate reasoning; S7. Set the obtained rank r to the rank of the low-rank parameterized update matrix ΔW corresponding to the weight matrix W; S8. Use the stored matrix to accelerate reasoning of the large language model after fine-tuning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence, and specifically provides a large language model acceleration method and device. Background Art

[0002] The rapid development of generative artificial intelligence technology has brought about the rapid popularization of artificial intelligence applications, especially the large language model based on generative artificial intelligence technology, which has demonstrated amazing language understanding, text generation and knowledge reasoning capabilities. It can well understand user intentions, conduct effective multi-round communication, and provide substantial, well-organized and logical answers, which has greatly improved people's understanding of artificial intelligence technology. At the same time, it has also brought new opportunities for cost reduction and efficiency improvement to all walks of life. Therefore, all walks of life have begun to explore the application of large language models in their own industry.

[0003] However, large language models have the characteristics of large parameters, large training data, and high computing power requirements. Their deployment, training, and inference require a large amount of storage and computing resources, which greatly restricts the promotion and application of large language models. Summary of the invention

[0004] The present invention aims to address the deficiencies of the above-mentioned prior art and provides a practical large language model acceleration method.

[0005] A further technical task of the present invention is to provide a large language model acceleration device that is reasonably designed, safe and applicable.

[0006] The technical solution adopted by the present invention to solve its technical problem is:

[0007] A large language model acceleration method has the following steps:

[0008] S1. The first matrix compression decomposition is to compress and decompose the pre-trained weight matrix W of the large language model to obtain U and V, so that ;

[0009] S2, the second matrix compression decomposition, respectively for U and The matrix is ​​decomposed by QR to obtain , , , ;

[0010] S3, the third matrix compression decomposition, using the singular value decomposition algorithm to decompose the matrix and The product of is compressed and decomposed to obtain , , ;

[0011] S4, the matrix , , and , Merge into matrices and , so that ;

[0012] S5. The obtained matrix and Replace the weight matrix W for storage;

[0013] S6. When a large language model needs to use a pre-trained weight matrix for inference, use the stored matrix and Perform reasoning acceleration;

[0014] S7. When fine-tuning of the large language model is required, before fine-tuning based on LoRA, the rank r obtained in step S3 is set to the low-rank parameterized update matrix corresponding to the weight matrix W The rank of The dimension is ;

[0015] S8. When using the fine-tuned large language model for inference, use the stored matrix , ,A,B,Inference acceleration of large language models after fine-tuning.

[0016] Furthermore, in step S1, the first matrix compression decomposition is performed using the matrix compression decomposition technique to decompose the matrix with a dimension of The pre-trained weight matrix W of the large language model is compressed and decomposed to obtain dimensions and The two matrices U and V of , where k is the rank of the weight matrix after the first compression decomposition, that is .

[0017] Furthermore, in step S2, the second matrix compression decomposition is performed to respectively decompose U and The matrix is ​​QR decomposed to obtain the matrix , , , , whose dimensions are , , , ,Right now , , so far the pre-trained weight matrix W of the large language model is decomposed into four matrices, namely .

[0018] Further, in step S3, the third compression decomposition is performed using the singular value decomposition algorithm to decompose the matrix and The product of is compressed and decomposed to obtain , , , whose dimensions are , , , where r is the final rank of the weight matrix and ,Right now ;

[0019] At this point, the pre-trained weight matrix W of the large language model is decomposed into dimensions: , , , , The five matrices are .

[0020] Further, in step S4, the matrix , , Multiply and merge into dimensions The matrix , the matrix , Multiply and merge into dimensions The matrix , so far the pre-trained weight matrix of the large language model is decomposed into dimensions , Multiply the two matrices of .

[0021] Further, in step S5, the obtained matrix and Replace the large language model pre-trained weight matrix W for storage, where The dimensions of the matrix are , The dimensions of the matrix are , so store and The storage size of the two matrices is r(m+n).

[0022] Furthermore, in step S6, when the large language model needs to use the pre-trained weight matrix for inference, for the input vector x, the corresponding output h is: , the computational complexity of this reasoning process is O(r(m+n)).

[0023] Furthermore, in step S7, when the large language model needs to be fine-tuned, before fine-tuning based on LoRA, the rank r obtained in step S3 is set to the low-rank parameterized update matrix corresponding to the weight matrix W The rank of The dimension is , fine-tuning training is performed to obtain matrices A and B, the dimension of A is , the dimension of B is ,in , store matrices A and B as the update matrices of the large language model after fine-tuning.

[0024] Furthermore, in step S8, when the fine-tuned large language model is used for inference, for the input vector x, the corresponding output h is: .

[0025] A large language model acceleration device, comprising a matrix compression decomposition module, a QR decomposition module, a singular value decomposition module, a matrix processing storage module, a model fine-tuning module and a model reasoning module;

[0026] The matrix compression decomposition module is used to convert the dimension The weight matrix W is compressed and decomposed to obtain the dimensions respectively and The two matrices U and V of , where k is the rank of the weight matrix after the first compression decomposition, that is ;

[0027] The QR decomposition module is used to respectively The matrix is ​​decomposed by QR to obtain , , , , whose dimensions are , , , ,Right now , ;

[0028] The singular value decomposition module is used to use the singular value decomposition algorithm to decompose the matrix and The product of is compressed and decomposed to obtain , , , whose dimensions are , , , where r is the final rank of the weight matrix, and ,Right now ;

[0029] The matrix processing storage module is used to store the matrix , , Multiply and merge to become dimension The matrix , the matrix , Multiply and merge to become dimension The matrix , and replace the weight matrix W storage matrix and , and store the fine-tuned training matrices A and B at the same time.

[0030] The model fine-tuning module is used to fine-tune the large language model based on LoRA, where the rank r obtained in the singular value decomposition module is set to the low-rank parameterized update matrix corresponding to the weight matrix W The rank of The dimension is , fine-tune the training to get matrices A and B, the dimension of A is , B dimension is ,in ;

[0031] The model inference module is used to complete the inference of the large language model. For the input vector x, the corresponding output h when using the pre-trained weight matrix inference is: , the corresponding output h when using the fine-tuned large language model for inference is: .

[0032] Compared with the prior art, the large language model acceleration method and device of the present invention have the following outstanding beneficial effects:

[0033] The present invention utilizes multiple matrix compression decomposition technology to perform multiple matrix compression decomposition on the large-dimensional weight matrix of a large language model, and realizes the compression of the pre-trained weight matrix of the large language model to the greatest extent within the allowable error range, thereby reducing the storage resource requirements of the large language model during the deployment process and the computational complexity of the model inference process. The rank r obtained based on matrix compression is adaptively determined to update the rank of the low-rank parameterized update matrix in the fine-tuning process based on LoRA for fine-tuning training, thereby realizing adaptive matching of the entire process, improving the universality of the application, and also reducing the computational complexity of the inference process of the large language model after fine-tuning.

[0034] The method and device of the present invention are suitable for accelerating applications of all types of artificial intelligence models with large-dimensional dense layer deep neural networks. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0036] Attached Figure 1 The figure is a flowchart of a large language model acceleration method. DETAILED DESCRIPTION

[0037] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0038] A best embodiment is given below:

[0039] like Figure 1 As shown, a large language model acceleration method in this embodiment has the following steps:

[0040] S1, the first matrix compression decomposition, using matrix compression decomposition technology to decompose the dimension The pre-trained weight matrix W of the large language model is compressed and decomposed to obtain dimensions and The two matrices U and V of , where k is the rank of the weight matrix after the first compression decomposition, that is .

[0041] S2, the second matrix compression decomposition, respectively for U and The matrix is ​​QR decomposed to obtain the matrix , , , , whose dimensions are , , , ,Right now , , so far the pre-trained weight matrix W of the large language model is decomposed into four matrices, namely .

[0042] S3, the third matrix compression decomposition, using the singular value decomposition algorithm to decompose the matrix and The product of is compressed and decomposed to obtain , , , whose dimensions are , , , where r is the final rank of the weight matrix and ,Right now .

[0043] At this point, the pre-trained weight matrix W of the large language model is decomposed into dimensions: , , , , The five matrices are .

[0044] S4, the matrix , , Multiply and merge into dimensions The matrix , the matrix , Multiply and merge into dimensions The matrix , so far the pre-trained weight matrix of the large language model is decomposed into dimensions , Multiply the two matrices of .

[0045] S5. The obtained matrix and Replace the large language model pre-trained weight matrix W for storage, where The dimensions of the matrix are , The dimensions of the matrix are , so store and The storage size of the two matrices is r(m+n), because Therefore, compared with the weight matrix W with a storage scale of mn or the matrices U and V with a storage scale of k(m+n) in step S1, the required storage resources are reduced, reducing the storage resource requirements for large language model deployment.

[0046] S6. When a large language model needs to use a pre-trained weight matrix for inference, for the input vector x, the corresponding output h is: , the computational complexity of this reasoning process is O(r(m+n)). In this case, the computational complexity is much smaller than the original O(mn) and the O(k(m+n)) computational complexity after the first matrix compression decomposition, which reduces the computing power threshold for the reasoning process of large language models and accelerates the reasoning process of large language models.

[0047] S7. When fine-tuning of the large language model is required, before fine-tuning based on LoRA, the rank r obtained in step S3 is set to the low-rank parameterized update matrix corresponding to the weight matrix W The rank of The dimension is ;

[0048] Fine-tune the training to get the matrix A (dimension is ) and B (dimension is ),in . Store matrices A and B as update matrices for the large language model after fine-tuning.

[0049] S8. When using the fine-tuned large language model for inference, for the input vector x, the corresponding output h is: , it is also possible to reduce the computational complexity of the reasoning process as described in step S6, and accelerate the reasoning process of the fine-tuned large language model.

[0050] Based on the above method, a large language model acceleration device in this embodiment includes a matrix compression decomposition module, a QR decomposition module, a singular value decomposition module, a matrix processing and storage module, a model fine-tuning module and a model reasoning module;

[0051] The matrix compression decomposition module is used to convert the dimension The weight matrix W is compressed and decomposed to obtain the dimensions respectively and The two matrices U and V of , where k is the rank of the weight matrix after the first compression decomposition, that is ;

[0052] The QR decomposition module is used to separate U and The matrix is ​​decomposed by QR to obtain , , , , whose dimensions are , , , ,Right now , ;

[0053] The singular value decomposition module is used to use the singular value decomposition algorithm to perform and The product of is compressed and decomposed to obtain , , , whose dimensions are , , , where r is the final rank of the weight matrix, and ,Right now ;

[0054] The matrix processing storage module is used to store the matrix , , Multiply and merge to become dimension The matrix , the matrix , Multiply and merge to become dimension The matrix , and replace the weight matrix W storage matrix and , and store the fine-tuned training matrices A and B at the same time.

[0055] The model fine-tuning module is used to fine-tune the large language model based on LoRA, where the rank r obtained in the singular value decomposition module is set to the low-rank parameterized update matrix corresponding to the weight matrix W The rank of The dimension is , fine-tune the training to get matrices A and B, the dimension of A is , B dimension is ,in ;

[0056] The model inference module is used to complete the inference of the large language model. For the input vector x, the corresponding output h when using the pre-trained weight matrix inference is: , the corresponding output h when using the fine-tuned large language model for inference is: .

[0057] The above-mentioned specific implementations are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementations. Any technical solutions that comply with the claims of the present invention and any appropriate changes or substitutions made by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.

[0058] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A large language model acceleration method, characterized in that: This method is suitable for text generation. It uses multiple matrix compression decomposition technology to perform multiple matrix compression decomposition on the large-dimensional weight matrix of the large language model, and maximizes the compression of the pre-trained weight matrix of the large language model within the allowable error range, reducing the storage resource requirements of the large language model during deployment and the computational complexity of the model inference process. In addition, the rank r obtained based on matrix compression is adaptively determined to determine the rank of the low-rank parameterized update matrix in the fine-tuning process based on LoRA for fine-tuning training, thereby achieving adaptive matching of the entire process. The steps are as follows: S1, the first matrix compression decomposition, compressing and decomposing the pre-trained weight matrix W of the large language model to obtain U and V, so that W = U·V; The pre-trained weight matrix W of the large language model with a dimension of m×n is compressed and decomposed using matrix compression decomposition technology to obtain two matrices U and V with dimensions of m×k and k×n respectively, where k is the rank of the weight matrix after the first compression decomposition, that is, W=U·V; S2, the second matrix compression decomposition, respectively for U and V T The matrix is ​​decomposed by QR to obtain Q U , R U , Q V , R V ; The second matrix compression decomposition is to decompose U and V respectively. T The matrix is ​​decomposed by QR to obtain the matrix Q U , R U , Q V , R V , whose dimensions are m×k, k×k, n×k, k×k, that is, U=Q U ·R U , V T =Q V ·R V , so far the pre-trained weight matrix W of the large language model is decomposed into four matrices, namely S3, the third matrix compression decomposition, using the singular value decomposition algorithm to decompose the matrix RU and The product of is compressed and decomposed to obtain Third compression and decomposition, using the singular value decomposition algorithm to perform compression and decomposition on the product of matrix R U and to obtain whose dimensions are k×r, r×r, and r×k respectively, where r is the final rank of the weight matrix and r < k << min(m, n), that is At this point, the pre-trained weight matrix W of the large language model is decomposed into five matrices with dimensions of m×k, k×r, r×r, r×k, and k×n, namely S4, the matrix Q U , and Merge into matrices and Make S5. The obtained matrix and Replace the weight matrix W for storage; S6. When a large language model needs to use a pre-trained weight matrix for inference, use the stored matrix and Perform reasoning acceleration; S7. When fine-tuning of the large language model is required, before fine-tuning based on LoRA, the rank r obtained in step S3 is set to the rank of the low-rank parameterized update matrix ΔW corresponding to the weight matrix W, where the dimension of ΔW is m×n; Perform fine-tuning training to obtain matrices A and B, where the dimensions of A are m×r and the dimensions of B are r×n, where ΔW = A·B. Store matrices A and B as update matrices for the large language model after fine-tuning. S8. When using the fine-tuned large language model for inference, use the stored matrix A, B, Inference speedup of large language models after fine-tuning.

2. A large language model acceleration method according to claim 1, characterized in that: In step S5, the obtained matrix and Replace the large language model pre-trained weight matrix W for storage, where The dimension of the matrix is ​​m×r, The dimensions of the matrix are r×n, so the storage and The storage size of the two matrices is r(m+n).

3. A large language model acceleration method according to claim 2, characterized in that: In step S6, when the large language model needs to use the pre-trained weight matrix for inference, for the input vector x, the corresponding output h is: The computational complexity of this reasoning process is O(r(m+n)).

4. A large language model acceleration method according to claim 3, characterized in that: In step S8, when the fine-tuned large language model is used for inference, for the input vector x, the corresponding output h is:

5. A large language model acceleration device, characterized in that: The device is suitable for text generation, and uses multiple matrix compression decomposition technology to perform multiple matrix compression decomposition on the large-dimensional weight matrix of the large language model, and realizes the compression of the pre-trained weight matrix of the large language model to the greatest extent within the allowable error range, thereby reducing the storage resource requirements of the large language model during the deployment process and the computational complexity of the model inference process. In addition, the rank r obtained based on matrix compression is adaptively determined to update the rank of the low-rank parameterized update matrix in the fine-tuning process based on LoRA for fine-tuning training, thereby realizing adaptive matching of the entire process; The device includes a matrix compression decomposition module, a QR decomposition module, a singular value decomposition module, a matrix processing storage module, a model fine-tuning module and a model reasoning module; The matrix compression decomposition module is used to compress and decompose the weight matrix W with a dimension of m×n using the matrix compression decomposition technology to obtain two matrices U and V with dimensions of m×k and k×n respectively, where k is the rank of the weight matrix after the first compression decomposition, that is, W=U·V; The QR decomposition module is used to decompose U and V respectively. T The matrix is ​​decomposed by QR to obtain Q U , R U , Q V , R V , whose dimensions are m×k, k×k, n×k, k×k, that is, U=Q U ·R U , V T =Q V ·R V , the pre-trained weight matrix W of the large language model is decomposed into four matrices, namely The singular value decomposition module is used to perform compression decomposition on the product of matrix R U and using the singular value decomposition algorithm to obtain whose dimensions are k×r, r×r, and r×k respectively, where r is the final rank of the weight matrix, and r < k << min(m, n), that is The pre-trained weight matrix W of the large language model is decomposed into five matrices with dimensions of m×k, k×r, r×r, r×k, and k×n, namely The matrix processing storage module is used to convert the matrix Q U , Multiply and merge into a matrix of dimension m×r The matrix Multiply and merge into a matrix of dimension r×n The pre-trained weight matrix of the large language model is decomposed into two matrices with dimensions of m×r and r×n, and the two matrices are multiplied, that is, The resulting matrix and Replace the weight matrix W for storage; When a large language model needs to use a pre-trained weight matrix for inference, use the stored matrix and Perform reasoning acceleration; The model fine-tuning module is used to set the obtained rank r to the rank of the low-rank parameterized update matrix ΔW corresponding to the weight matrix W before performing LoRA-based fine-tuning, where the dimension of ΔW is m×n; Perform fine-tuning training to obtain matrices A and B, where the dimensions of A are m×r and the dimensions of B are r×n, where ΔW = A·B. Store matrices A and B as update matrices for the large language model after fine-tuning. The model inference module is used to use the stored matrix A, B, Inference speedup of large language models after fine-tuning.

Citation Information

Patent Citations

  • Network structure optimization fine tuning method for large pre-training language model

    CN117033641A

  • Dialogue model training method, dialogue processing method and device

    CN117951264A