Large language model acceleration method and device

Through multiple matrix compression decomposition and adaptive rank parameterization update, it solves the problem of high resource demand of large language models, achieves efficient deployment and inference acceleration of large language models, and improves its application universality.

CN118569324AActive Publication Date: 2024-08-30INSPUR SOFTWARE TECH CO LTD

Patent Information

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

AI Technical Summary

Technical Problem

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

Method used

Multi-matrix compression decomposition technology is used to compress and decompose the pre-trained weight matrix of the large language model, combined with QR decomposition and singular value decomposition, to reduce storage resource requirements and computational complexity, and adaptively adjust the rank parameterized update matrix during the fine-tuning process.

Benefits of technology

Compress the weight matrix of large language models to the greatest extent within the allowable error range, reduce storage and computational complexity, improve application universality, and reduce the computational complexity of the inference process after fine-tuning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118569324A
    Figure CN118569324A
Patent Text Reader

Abstract

The invention relates to the field of artificial intelligence, and aims to solve the technical problem of how to simplify storage resources and computing resources and popularize a large language model. According to the technical scheme, the large language model acceleration method and device comprise the following steps that S1, a pre-training weight matrix W of a large language model is compressed and decomposed; s2, performing QR decomposition on the U matrix and the VT matrix to obtain QU, RU, QV and RV; s3, performing compression decomposition on the matrix product by using a singular value decomposition algorithm; s4, respectively combining the matrixes; s5, replacing the weight matrix W with the obtained matrix for storage; s6, performing reasoning acceleration by using the stored matrix; s7, setting the obtained rank r to be a rank of a low-rank parameterization updating matrix delta W corresponding to the weight matrix W; and S8, performing inference acceleration of the fine-tuned large language model by using the stored matrix.
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: A large language model acceleration method has the following steps: 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 ; S2, the second matrix compression decomposition, respectively for U and The matrix is ​​decomposed by QR, and we get , , , ; 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 , , ; S4, the matrix , , and , Merge into matrices and , so that ; 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 low-rank parameterized update matrix corresponding to the weight matrix W The rank of The dimension is ; 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.

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

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

[0009] 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 ; At this point, the pre-trained weight matrix W of the large language model is decomposed into dimensions: , , , , The five matrices are .

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

[0011] 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).

[0012] 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)).

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

[0014] 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: .

[0015] 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; The matrix compression decomposition module is used to convert the dimension The weight matrix W is compressed and decomposed to obtain the 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 ; The QR decomposition module is used to respectively The matrix is ​​decomposed by QR, and we get , , , , whose dimensions are , , , ,Right now , ; 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 ; The matrix processing storage module is used to convert 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.

[0016] 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 ; 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: .

[0017] Compared with the prior art, the large language model acceleration method and device of the present invention have the following outstanding beneficial effects: 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 LoRA-based fine-tuning process 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 large language model inference process after fine-tuning.

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

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

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

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

[0022] A best embodiment is given below: like Figure 1 As shown, a large language model acceleration method in this embodiment has the following steps: 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 .

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

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

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

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

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

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

[0029] 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 ; 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.

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

[0031] 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; The matrix compression decomposition module is used to convert the dimension The weight matrix W is compressed and decomposed to obtain the 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 ; The QR decomposition module is used to separate U and The matrix is ​​decomposed by QR, and we get , , , , whose dimensions are , , , ,Right now , ; 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 ; 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.

[0032] 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 ; 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: .

[0033] The above-mentioned specific implementation modes 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 implementation modes. Any technical solutions that conform to 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.

[0034] 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: The steps are as follows: 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 ; S2, the second matrix compression decomposition, respectively for U and The matrix is ​​decomposed by QR, and we get , , , ; 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 , , ; S4, the matrix , , and , Merge into matrices and , so that ; 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 low-rank parameterized update matrix corresponding to the weight matrix W The rank of The dimension is ; 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.

2. A large language model acceleration method according to claim 1, characterized in that: In step S1, the first matrix compression decomposition is performed 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 .

3. A large language model acceleration method according to claim 2, characterized in that: In step S2, the second matrix compression decomposition is performed to 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 .

4. A large language model acceleration method according to claim 3, characterized in that: 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 ; At this point, the pre-trained weight matrix W of the large language model is decomposed into dimensions: , , , , The five matrices are .

5. A large language model acceleration method according to claim 4, characterized in that: 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 .

6. A large language model acceleration method according to claim 5, characterized in that: 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).

7. A large language model acceleration method according to claim 6, 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)).

8. A large language model acceleration method according to claim 7, characterized in that: 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 is, where 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.

9. A large language model acceleration method according to claim 8, 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: .

10. A large language model acceleration device, characterized in that: It includes matrix compression decomposition module, QR decomposition module, singular value decomposition module, matrix processing storage module, model fine-tuning module and model reasoning module; 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 ; The QR decomposition module is used to respectively The matrix is ​​decomposed by QR, and we get , , , , whose dimensions are , , , ,Right now , ; 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 ; 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 , while storing the matrices A and B after fine-tuning training; 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 ; 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: .

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

  • Large language model acceleration method based on low-rank compression and implementation device

    CN118396068A

  • System and Method for Low Rank Training of Neural Networks

    US20230057387A1

Cited By

  • MOOC stop prediction method and system based on large language model auxiliary graph node classification

    CN119323293A

  • MOOC Dropout Prediction Method and System for Graph Node Classification Assisted by Large Language Model

    CN119323293B

  • Artificial intelligence model accelerated training reasoning method and device

    CN119884575A

  • A method and device for accelerating training and reasoning of artificial intelligence models

    CN119884575B

  • Large language model optimization system and method based on low-rank adaptive technology

    CN119886279A