Task processing method and device based on large language model
Through the joint sparsification and quantification (JSQ) framework, utilizing activation range saliency and activation editor, the problem of performance degradation of large language models under high compression ratios is solved, and resource optimization of computing and storage is achieved while maintaining model performance. and build quality.
Patent Information
- Application Number
- CN202410660117.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-10-01
AI Technical Summary
The problem of performance degradation of large language models under high compression ratios is that existing model compression methods only consider a single technology, resulting in low computational complexity and performance collapse.
The joint sparsification and quantification (JSQ) framework is adopted to smoothly remove outliers by introducing the activation range significance (SAR) metric and a search-based activation editor, combining sparsification and quantization techniques to achieve more effective model compression.
Significantly reduces the amount of computation and storage requirements at high compression ratios, while maintaining the performance of large language models and ensuring minimal loss in generation quality.
Smart Images

Figure CN118734909A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a task processing method based on a large language model, and also relates to a corresponding task processing device, belonging to the technical field of natural language processing. Background Art
[0002] Large Language Models refer to machine learning models with a large number of parameters, which are usually used to process and generate natural language text. These models are trained on massive text data to learn the complex structure and patterns of language, so that they can perform various language tasks such as text classification, sentiment analysis, machine translation, question-answering systems, and text generation. Due to the large number of parameters, large language models can capture rich language features and provide more accurate and humanized language processing capabilities. However, the scale of these models also brings some challenges, including high consumption of computing resources, large storage requirements, and difficulty in deployment.
[0003] To solve this problem, many model compression techniques have been proposed to compress large language models, including sparsification, quantization, etc. Since large language models are much larger than previous deep neural network models, they require a larger compression ratio in actual use. However, current model compression methods designed for large language models only consider using one specific technique to compress the model, and significant performance degradation occurs when the compression ratio increases. For example, the state-of-the-art method Omni Quant suffers from a collapse in accuracy because the computational complexity is too low. Therefore, a new question arises: Is it possible to maintain the performance of large language models at high compression ratios?
[0004] In a Chinese patent application with application number 202311280391.2, a model compression method is disclosed, and the specific implementation method is: in response to receiving the initial model parameters of the model to be compressed and the target compression accuracy set for the initial model parameters, the model weight matrix of the model to be compressed is read from the initial model parameters; the model weight matrix is sparsely processed to obtain a sparse weight matrix; the target weights in the sparse weight matrix are fused to obtain fused weights, and the target weights represent the model weights of the sub-networks with a coupling relationship in the model to be compressed; according to the target compression accuracy, the target model parameters including the fused weights are quantized to obtain quantized parameters, and the target model parameters include the model weights represented by the sparse weight matrix and the activation values determined based on the sparse weight matrix; and according to the quantization parameters, a compressed model corresponding to the model to be compressed is determined. Summary of the invention
[0005] The primary technical problem to be solved by the present invention is to provide a task processing method based on a large language model.
[0006] Another technical problem to be solved by the present invention is to provide a task processing device based on a large language model.
[0007] In order to achieve the above technical objectives, the present invention adopts the following technical methods:
[0008] According to a first aspect of an embodiment of the present invention, a task processing method based on a large language model is provided, comprising the following steps:
[0009] Get the target tasks to be processed;
[0010] Get the pre-trained target large language model;
[0011] Compressing the target large language model through a first sparsification quantization joint compression process;
[0012] Processing the target task using the compressed target large language model;
[0013] The first sparse quantization joint compression process includes the following sub-steps:
[0014] Filtering a target weight from the target large language model, wherein a value of the target weight after activation is less than a first preset threshold;
[0015] The importance of the target weight is adjusted according to a preset rule so that the activation value of the target weight after sparseness is adapted to the quantization requirement;
[0016] The adjusted target large language model is compressed layer by layer using sparsification and quantization.
[0017] Preferably, before compressing the target large language model through the first sparse quantization joint compression process, compressing the target large language model through the second sparse quantization joint compression process; the second sparse quantization joint compression process includes the following sub-steps:
[0018] Obtaining a target activation outlier value in the target large language model, wherein the target activation outlier value is greater than a second preset threshold;
[0019] Using an activation editor to remove the target activation outlier from the target large language model; wherein a simulated annealing algorithm is used to search for an optimal edit vector to determine an optimal edit strength;
[0020] The removed target large language model is compressed layer by layer using sparsification and quantization.
[0021] Preferably, in the first sparse quantization joint compression process,
[0022] The importance of each target weight is evaluated using activation range significance; wherein, the larger the activation range of the target weight, the lower the importance, so as to avoid adverse effects on the quantization process after sparsification.
[0023] Preferably, the activation range significance is obtained by the following steps:
[0024] Calculating the activation outlier significance of each weight in the target large language model; wherein the activation outlier significance is obtained by calculating the Frobenius norm of each channel aggregated along the token dimension and taking its absolute value;
[0025] Creating an auxiliary weight matrix in which selected weight elements are set to zero, calculating and comparing the changes in the maximum and minimum values of the output activation before and after the weight elements are removed, thereby determining the auxiliary significance of each weight;
[0026] The activation range significance of each weight is calculated by combining the activation outlier significance and the auxiliary significance.
[0027] Preferably, the activation outlier significance is obtained by the following steps:
[0028] The input activation of the target large language model is denoted as The weight is recorded as Where N, c in 、c out are the number of tokens, input dimension, and output dimension respectively; the activation outlier significance I ij The formula is as follows:
[0029] I ij =||X j ||2·|W ij |
[0030] Among them, ||X j ||2 represents the Frobenius norm of the j-th channel aggregated along the token dimension, |·| represents the absolute value, and the subscript ·ij represents the element in the i-th row and j-th column of the weight or input matrix.
[0031] Preferably, the auxiliary significance is obtained by the following formula:
[0032]
[0033] Among them, auxiliary significance c in 、c out are the input dimension and the output dimension respectively, Here φ(W; i; j) represents an auxiliary weight matrix; when the elements in the i-th row and j-th column in the weight W are set to 0, max(·) and min(·) represent the maximum and minimum values of the vector, respectively. is a matrix The i-th column of .
[0034] Preferably, in the second sparse quantization joint compression process,
[0035] First, a set of edit strength selections is designed for each activation layer to form an edit vector, and the edit strength of each weight element is selected from the edit vector;
[0036] Using the edit vector, the activation editor edits the activation value in the target large language model; during the editing process, the activation editor identifies the target activation outlier and removes the target activation outlier from the target large language model.
[0037] Preferably, during the editing process, the target activation outlier is removed from the target large language model by the following formula:
[0038] F edit = clamp(F, LB, HB)
[0039] LB=r·max(F)+(1-r)·min(F)
[0040] HB=(1-r)·max(F)+r·min(F)
[0041] Wherein, F is a layer of activation edited in the target large language model, clamp() represents a truncation operation on F, with a lower bound of LB and an upper bound of HB, and r∈[0,1] is the editing strength.
[0042] Preferably, a simulated annealing algorithm is used to search for an optimal edit vector to determine an optimal edit strength and smoothly remove target activation outliers in a target large language model; wherein the activation of each layer is edited according to the edit vector, and the edited target large language model is thinned and quantized using activation range significance; thereafter, the compressed model is tested on calibration data; an element in the edit vector is randomly changed, and this process is iteratively performed to search for the optimal edit vector.
[0043] According to a second aspect of an embodiment of the present invention, there is provided a task processing device based on a large language model, comprising a processor and a memory, wherein the memory is coupled to the processor; wherein:
[0044] The memory is used to store a computer program, and when the computer program is executed by the processor, it is used to implement the above-mentioned task processing method based on a large language model.
[0045] Compared with the prior art, the task processing method and device provided by the embodiment of the present invention propose an innovative joint sparsification and quantization (JSQ) framework, which effectively solves the computational and storage burden problems of large language models in practical applications. This method not only introduces a new sparsity indicator, activation range significance (SAR), to bridge the mismatch between sparsification and quantization, but also proposes a search-based activation editor that uses a simulated annealing algorithm to automatically remove outliers that are harmful to compression. Through comprehensive experimental verification, the JSQ framework significantly reduces the amount of computation at a high compression ratio while maintaining the performance of large language models. While reducing resource usage, computing and memory requirements, it ensures minimal loss in generation quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 A flowchart of a task processing method based on a large language model provided by an embodiment of the present invention;
[0047] Figure 2 A flowchart of another task processing method based on a large language model provided by an embodiment of the present invention;
[0048] Figure 3 Schematic diagram of a joint sparsification and quantization (JSQ) framework in an embodiment of the present invention;
[0049] Figure 4 A comparison diagram of activation ranges after sparse quantization between the task processing method provided by an embodiment of the present invention and other methods;
[0050] Figure 5 This is a schematic diagram of the effect of editing before compression in an embodiment of the present invention;
[0051] Figure 6 A schematic diagram of a task processing device based on a large language model provided by an embodiment of the present invention;
[0052] Figure 7 The zero-shot performance of the compression model is shown, and the performance of different compression methods under the same computing conditions is compared;
[0053] Figure 8 The performance of the JSQ framework is shown when using structured 2:4 and 4:8 sparsity in the sparsification process;
[0054] Fig. 9 The JSQ framework is shown to significantly speed up and reduce GPU memory usage on compressed models.
[0055] Fig.10 Shows the effects of the activation range significance (SAR) metric, activation editor, and simulated annealing search in ablation experiments;
[0056] Fig.11 The performance when using different subsequent quantization methods is shown, demonstrating the generalization ability of the JSQ framework;
[0057] Fig.12 Shows the impact of fine-tuning techniques on compression model performance, showing the performance improvement after fine-tuning using the C4 dataset;
[0058] Fig.13 The effect of different values of the factor λ used to weigh different items on the performance of the JSQ framework is shown;
[0059] Fig.14 The effect of the amount of calibration data on the performance of the JSQ framework is shown;
[0060] Fig.15 Examples of sentences generated by the original model and the compressed model are shown, demonstrating how the compressed model performs in terms of fluency, relevance, and informativeness. DETAILED DESCRIPTION
[0061] The technical content of the present invention is described in detail below with reference to the accompanying drawings and specific embodiments.
[0062] The technical concept of the embodiment of the present invention is to organically combine the two compression methods of sparsification and quantization, and propose an innovative joint sparsification and quantization (JSQ for short) framework, instead of using them separately like traditional methods. The JSQ framework bridges the mismatch between sparsification and quantization by introducing a new sparsity indicator, the activation range significance (SAR). The SAR indicator is designed to evaluate the range changes of weights after activation, helping to determine which weights are friendly to the quantization process and which may cause performance degradation, thereby achieving more effective model compression without sacrificing model performance. In addition, the JSQ framework also introduces a search-based activation editor, which uses a simulated annealing algorithm to automatically find the optimal editing ratio and smoothly remove outliers that are harmful to model compression. This method solves the problem of high coupling between the quantization process and the outlier processing in existing solutions, making the sparsification process more efficient.
[0063] like Figure 1 As shown, the task processing method based on the large language model provided by the embodiment of the present invention includes the following steps:
[0064] S11: Obtain the target task to be processed;
[0065] S12: Obtain a pre-trained target large language model;
[0066] S13: compressing the target large language model through a first sparsification quantization joint compression process;
[0067] S14: Use the compressed target large language model to process the target task.
[0068] Among them, S13 includes:
[0069] S131: Filtering a target weight from a target large language model, wherein a value of the target weight after activation is less than a first preset threshold;
[0070] S132: adjusting the importance of the target weight according to a preset rule so that the activation value after the target weight is sparsely converted meets the quantization requirement;
[0071] S133: Compress the adjusted target large language model layer by layer using sparsification and quantization.
[0072] like Figure 2 As shown, in another embodiment of the present invention, another task processing method based on a large language model is provided, comprising the following steps:
[0073] S21: Obtain the target task to be processed;
[0074] S22: Obtain a pre-trained target large language model;
[0075] S23: compressing the target large language model through a second sparsification quantization joint compression process;
[0076] S24: compressing the target large language model through a first sparsification quantization joint compression process;
[0077] S25: Use the compressed target large language model to process the target task.
[0078] In some optional embodiments, S23 may be implemented by, but not limited to, the following sub-steps:
[0079] S231: Obtain a target activation outlier value in the target large language model, where the target activation outlier value is greater than a second preset threshold;
[0080] S232: removing target activation outliers from the target large language model using an activation editor; wherein a simulated annealing algorithm is used to search for an optimal editing vector to determine an optimal editing strength;
[0081] S233: Compress the removed target large language model layer by layer using sparsification and quantization.
[0082] In some optional embodiments, S24 may be implemented by, but not limited to, the following sub-steps:
[0083] S241: Obtain activation outlier significance, where the activation outlier significance is used to determine the importance of each weight in the target large language model;
[0084] S242: Obtain auxiliary saliency, where the auxiliary saliency is used to characterize the influence of each weight on the output activation in the target large language model;
[0085] S243: determining activation range significance based on activation outlier significance and auxiliary significance;
[0086] S244: Filtering a target weight from the target large language model, wherein a value of the target weight after activation is less than a first preset threshold;
[0087] S245: adjusting the importance of the target weight according to a preset rule so that the activation value after the target weight is sparsely converted can meet the quantization needs;
[0088] S246: Compress the adjusted target large language model layer by layer using sparsification and quantization.
[0089] It should be noted that the “target weight” refers to the subset of weights selected and adjusted during the compression process, and is therefore different from the “weight” which is the original parameter in the large language model.
[0090] Below, some key details in the above task processing method are further described in detail.
[0091] First of all, it is important to note that utilizing both sparsification and quantization techniques simultaneously is not an easy task, as there are two major issues. First, sparsification and quantization contradict each other. Sparsification tends to retain parameters with large absolute values in large language models, while quantization prefers a small range of parameter values. Therefore, parameters retained in sparsification may degrade the performance of quantization. For example, a sparsified model may perform well if weights with very large absolute values are retained. However, the subsequent quantization process will encounter a large range of values, preventing promising quantization performance. On the other hand, retaining small-valued weights can lead to satisfactory quantization performance but poor sparsification results. Therefore, it is necessary to design a new mechanism to balance the effects of these two techniques.
[0092] To solve this problem, the embodiments of the present invention first proposed a new sparsity metric in the joint sparsification and quantization (JSQ) framework, called activation range significance (SAR), to bridge the mismatch between sparsification and quantization. Specifically, the SAR metric additionally considers the activation range after sparsification during the compression process. If the activation range becomes larger after removing these weights, the importance of specific weights will be reduced. Therefore, the sparse model after sparsification will have a small activation range, which is friendly to quantization.
[0093] In addition to the contradiction between sparsification and quantization, the second problem is how to deal with outliers. Existing technologies have proven that outliers play a vital role in large language models. However, these outliers make it difficult to sparsify or quantize large language models due to their extremely large values. Existing methods alleviate this problem through migration or clipping techniques. But these techniques are highly coupled with the quantization process. If these techniques are directly applied to joint sparsification and quantization, it can only follow the sparsification-clipping / migration-quantization process, in which these techniques do not work on the sparsification process, resulting in suboptimal problems.
[0094] To solve the second problem, an embodiment of the present invention further proposes a search-based activation editor that automatically removes relatively useless outliers before thinning. The inventors found that instead of elegantly incorporating migration or clipping into quantization, it is more effective to directly edit outliers in activation before thinning and quantization, where the core challenge is to find out which outliers should be edited and how to edit them. Therefore, an embodiment of the present invention proposes to use a simulated annealing algorithm to search for the optimal ratio of suppressing activations, allowing relatively useless outliers to be smoothly removed to enhance thinning and quantization.
[0095] like Figure 3 As shown, in the joint sparsification and quantization (JSQ) framework provided by an embodiment of the present invention, given a pre-trained large language model, an activation editor is first used to remove relatively useless outliers in the activation. After editing the activation, the weights and activations are sparsified and quantized in a layer-by-layer manner using the SAR indicator. This process is iteratively performed, and the simulated annealing algorithm is used to search for the optimal edit vector. After the search, the large language model is compressed using the optimal edit vector to obtain a compressed model.
[0096] In one embodiment of the present invention, a new sparsity metric, called Significant Activation Range (SAR), is proposed to take into account the subsequent quantization process during the sparsification process. Specifically, first consider a linear layer in a large language model. The input activation is recorded as The weight is recorded as Where N, c in 、c out are the number of tokens, input dimension, and output dimension respectively. The output Y of this layer can be written as:
[0097] Y=XW T (1)
[0098] in,
[0099] Here, the subscript ·ij represents the element in the i-th row and j-th column of the weight or input matrix.
[0100] When compressing a large language model, the goal is to sparse the weight matrix of each layer and then quantize the weights and activations to achieve a larger compression ratio. Since outliers play an important role in large language models, an embodiment of the present invention provides an activation outlier significance I ij , which can be expressed as follows:
[0101] I ij =||X j ||2·|W ij | (2)
[0102] Among them, ||X j ||2 represents the Frobenius norm of the jth channel aggregated along the token dimension, and |·| represents the absolute value. In this way, the importance can be calculated for each individual weight And thin them out based on importance.
[0103] This metric tends to retain outliers in large language models in order to retain more information, resulting in larger values for the output activations. However, it does not take into account the quantization process. Intuitively, quantization prefers activations with a smaller range, which is in conflict with the sparsity metric. To alleviate this problem, an embodiment of the present invention designs the SAR metric by simultaneously considering outliers and activity ranges in activations. The inventors observed that the per-channel quantization paradigm is more suitable for large language model compression. Therefore, the goal is to minimize the activation range of each output channel in the SAR metric.
[0104] To achieve the above goal, we need to design an indicator that can simulate the impact of each weight on the output activation. The intuitive idea is to measure the activation range of each channel after removing each individual weight and incorporate this measurement into the weight significance. From formula 1 and Figure 3 In the example, we can observe that the j-th output channel is only related to the j-th row in W (i.e., W T The jth column in .
[0105] Based on this observation, we first define an auxiliary saliency as follows:
[0106]
[0107] in,
[0108] Here, Φ(W;i;j) represents an auxiliary weight matrix when the elements in the i-th row and j-th column in W are set to 0. max(·) and min(·) represent the maximum and minimum values of the vector, respectively. is a matrix The i-th column of . Each element in the auxiliary matrix A reflects a simple feature: how the activation range will change if this weight element is sparse. In this way, the range significance can be used to measure the impact of each weight on the subsequent quantization process.
[0109] By jointly considering the significance of the activation outliers and the auxiliary significance, the activation range significance index in the embodiment of the present invention is It can be defined as:
[0110] S ij =I ij +λA ij (4)
[0111] Wherein, λ is a factor used to weigh different items. In one embodiment of the present invention, λ is set to 2 based on experience, but is not limited thereto.
[0112] The SAR metric reflects an intuitive design concept. If sparsifying a weight results in a large activation range (i.e., a large A ij ), a higher significance should be assigned to this weight to retain it, and vice versa. By using the SAR metric, a better trade-off can be achieved between retaining outliers to gain more information and minimizing the activation range for better quantization. In other words, the side effect of retaining outliers on quantization will be mitigated. The activation range after sparsification can be Figure 4 As can be seen in Figure 2, we can see that the activation range is reduced after taking auxiliary saliency into account.
[0113] It should be noted that the embodiment of the present invention can foresee and adapt to the needs of the quantization process in the sparsification stage by introducing the SAR indicator into the model compression process. This method not only solves the contradiction between sparsification and quantization, but also provides an effective strategy for maintaining the performance of large language models at high compression ratios. The SAR indicator determines which parameters are friendly to subsequent quantization and which parameters may cause quantization performance to degrade by evaluating the range of parameter changes after activation, thereby achieving more efficient and coordinated model compression without sacrificing model performance.
[0114] On the other hand, outliers are very important in large language models. To handle outliers, many compression methods design transfer or clipping strategies, which are elegantly combined with quantization. However, the inventors found that editing activations directly before compression is surprisingly effective, which can further strengthen the balance between outliers and compression. Figure 5 shows this finding. The inventors measured the perplexity of the compressed LLaMA-7B on the WikiText dataset at different editing intensities. Specifically, outliers in the activations are first suppressed, and then sparsification and quantization are used to compress the model. When outliers in the activations begin to be removed, the performance of the compressed large language model will first improve. The inventors therefore believe that when suppression begins, the benefits of sparsification and quantization will outweigh the performance degradation caused by outlier removal. As the editing intensity continues to increase, key outliers will also begin to be edited, so the disadvantages of activation editing will outweigh its benefits from sparsification and quantization. Therefore, it is very important to find a suitable activation editor to suppress outliers.
[0115] In order to solve this problem, an embodiment of the present invention further proposes a search-based activation editor (SAE).
[0116] Formally, we first represent a layer of activations to be edited in the large language model as F, and the activation edit can be written as:
[0117] F edit = clamp(F, LB, HB) (5)
[0118] Among them, LB = r·max(F)+(1-r)·min(F),
[0119] HB=(1-r)·max(F)+r·min(F).
[0120] Here, clamp() represents a truncation operation on F, with a lower bound of LB and an upper bound of HB. r∈[0, 1] is the editing strength. Formula 5 means limiting the activation range to [r, 1-r] of the original range to eliminate outliers.
[0121] It should be noted that it is not easy to determine the editing strength r, because the entire network may have a large number of possible combinations. Therefore, the embodiment of the present invention proposes to search for the optimal solution. In order to implement the search, the editing strength is encoded into a vector. For example, suppose there are L layers of activation layers that need to be edited, and a set of editing strength selections R = {r1, r2, ..., r n}, where n is the number of predefined choices, providing a good starting point for the search. Therefore, the edit strength of the entire network can be formed into an edit vector V = [v1, v2, ..., v L], each element v l You can choose from R.
[0122] After completing the activation encoding, the next goal is to search for the optimal edit vector V. Formally, the overall goal can be expressed as follows:
[0123]
[0124] Here, V is the edit vector of the entire network. COM(LLM; V) means compressing the large language model using the edit vector V. is the performance of the model. In Equation 6, the goal is to search for an edit vector that achieves the best performance of the large language model after compression.
[0125] To achieve this goal, the edit vector is first randomly initialized. Then, the simulated annealing algorithm is used to automatically search for the optimal edit vector. Specifically, the activations of each layer are edited according to the edit vector, and the edited model is sparsified and quantized using the SAR metric. After that, the compressed model is tested on the calibration data. An element in the edit vector V is randomly changed, and this process is iterated to search for the best edit vector V * In this way, relatively useless outliers can be smoothly edited out, ready for the subsequent thinning and quantization process.
[0126] By seamlessly combining activation range saliency and search-based activation editor, the embodiment of the present invention constructs a joint sparsification and quantization (JSQ) framework, and its workflow can be seen in the following table:
[0127]
[0128] As can be seen from the table above, the JSQ framework starts with initializing the pre-trained large language model and setting the initial temperature. First, the activation values in the large language model are edited using the activation editor based on the simulated annealing algorithm, with the goal of removing outliers that have little impact on model performance. Subsequently, the sparsification and quantization phase is entered, where the SAR indicator is used to guide the sparsification of weights and activations to ensure that the impact on model performance is minimized while reducing the model size. By testing the performance of the compressed model on the calibration dataset, the edit vector is continuously updated, and the temperature parameters are adjusted based on performance feedback to refine the search for the optimal solution. This process is repeated until the final temperature is reached, at which point the compressed and optimized large language model is output. The entire JSQ framework not only improves the compression efficiency of the large language model, but also ensures the stability and robustness of the model performance at a high compression ratio.
[0129] Based on the above-mentioned task processing method based on a large language model, the third embodiment of the present invention further provides a task processing device based on a large language model. Figure 6 As shown, the task processing device includes one or more processors and a memory. The memory is coupled to the processor and is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the task processing method based on the large language model in the above embodiment.
[0130] The processor is used to control the overall operation of the task processing device based on the large language model to complete all or part of the steps of the task processing method based on the large language model. In different embodiments of the present invention, the processor is preferably a GPU (graphics processing unit), but can also be an FPGA (field programmable gate array), ASIC (application-specific integrated circuit), DSP (digital signal processor), etc. The memory is used to store various types of data to support the operation of the task processing method based on the large language model. These data may include, for example, instructions for any application or method operating on the task processing device based on the large language model, as well as application-related data.
[0131] The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, etc.
[0132] In an exemplary embodiment, the above-mentioned task processing device based on the large language model can be specifically implemented by a computer chip or entity, or by a product with a certain function, for executing the above-mentioned task processing method based on the large language model, and achieving the same technical effect as the above-mentioned method. A typical embodiment is a computer. Specifically, the computer can be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a public security checkpoint inspection device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0133] In another exemplary embodiment, the present invention further provides a computer-readable storage medium including program instructions, which, when executed by a processor, implements the steps of the task processing method based on a large language model in any of the above embodiments. For example, the computer-readable storage medium may be a memory including program instructions, and the program instructions may be executed by a processor of a task processing device based on a large language model to complete the task processing method based on a large language model and achieve the same technical effect as the above method.
[0134] In order to verify the actual effects of the task processing method and apparatus provided by the embodiments of the present invention, the inventors conducted extensive experiments on the most widely used large language model family (including but not limited to LLaMA, LLaMA-2, and ChatGLM3). Figure 7 to Figure 15 The effectiveness and superiority of the entire JSQ framework in large language model compression tasks are verified from different perspectives, as follows:
[0135] Figure 7 The performance of the compression model using the JSQ framework on the zero-shot classification task is shown. The results show that under the same computing conditions, the quantization method performs better than the sparse method, especially under high compression ratios. The JSQ framework combines sparse and quantization methods to outperform a single method. For example, on the Hell laSwag dataset, JSQ's performance exceeds SmoothQuant by 22.04%.
[0136] Figure 8 The performance of the JSQ framework using structured 2:4 and 4:8 sparsity during the sparsification process is shown. Compared with unstructured sparsity, structured sparsity can achieve better actual speedup performance with only limited performance loss.
[0137] Fig. 9 The inference speedup and GPU memory reduction achieved by the JSQ framework on the compressed model are shown. The model using unstructured sparsity achieves a 23% inference speedup, while the structured 2:4 sparsity model achieves a 33% speedup while reducing GPU memory by 68%.
[0138] Fig.10 The results of the activation range significance (SAR) metric and the search-based activation editor in ablation experiments are shown. The SAR metric brings a 0.71 improvement in performance on the WikiText dataset, while the activation editor brings a 0.58 improvement. In addition, the activation editor with simulated annealing search brings an additional 0.25 improvement in performance.
[0139] Fig.11 The performance when using different quantization methods is shown. JSQ(GPTQ) uses GPTQ as the subsequent quantization method and shows comparable performance compared to standard JSQ, demonstrating the generalization ability of JSQ.
[0140] Fig.12 The effect of fine-tuning on the performance of the compression model is shown. After fine-tuning with the C4 dataset, JSQ can achieve further performance improvements.
[0141] Fig.13The effect of different λ values on performance is shown. The ideal range of λ is 1 to 3, and deviations from this range may lead to performance degradation.
[0142] Fig.14 The effect of the amount of calibration data on the performance of the JSQ framework is shown. It is found that the JSQ framework achieves the best performance when using 128 calibration data.
[0143] Fig.15 Examples of sentences generated by the original model and the compressed model are provided, showing how the compressed model compares to the original model in terms of fluency, relevance, and information content, while pointing out that the compressed model may occasionally generate meaningless or repetitive sentences.
[0144] Compared with the prior art, the task processing method and device provided by the embodiment of the present invention propose an innovative joint sparsification and quantization (JSQ) framework, which effectively solves the computational and storage burden problems of large language models in practical applications. This method not only introduces a new sparsity indicator, activation range significance (SAR), to bridge the mismatch between sparsification and quantization, but also proposes a search-based activation editor that uses a simulated annealing algorithm to automatically remove outliers that are harmful to compression. Through comprehensive experimental verification, the JSQ framework significantly reduces the amount of computation at a high compression ratio while maintaining the performance of large language models. While reducing resource usage, computing and memory requirements, it ensures minimal loss in generation quality.
[0145] It should be noted that the above-mentioned multiple embodiments are only examples, and the technical methods of each embodiment can be combined, all of which are within the protection scope of the present invention.
[0146] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0147] The above describes in detail the task processing method and device based on the large language model provided by the present invention. For those skilled in the art, any obvious changes made to it without departing from the essence of the present invention will constitute an infringement of the patent right of the present invention and will bear corresponding legal responsibilities.
Claims
1. A task processing method based on a large language model, characterized in that The steps include: Get the target tasks to be processed; Get the pre-trained target large language model; Compressing the target large language model through a first sparsification quantization joint compression process; Processing the target task using the compressed target large language model; The first sparse quantization joint compression process includes the following sub-steps: Filtering a target weight from the target large language model, wherein a value of the target weight after activation is less than a first preset threshold; The importance of the target weight is adjusted according to a preset rule so that the activation value of the target weight after sparseness is adapted to the quantization requirement; The adjusted target large language model is compressed layer by layer using sparsification and quantization.
2. The task processing method based on a large language model as claimed in claim 1, characterized in that Before compressing the target large language model through the first sparse quantization joint compression process, compressing the target large language model through the second sparse quantization joint compression process; the second sparse quantization joint compression process includes the following sub-steps: Obtaining a target activation outlier value in the target large language model, wherein the target activation outlier value is greater than a second preset threshold; Using an activation editor to remove the target activation outlier from the target large language model; wherein a simulated annealing algorithm is used to search for an optimal edit vector to determine an optimal edit strength; The removed target large language model is compressed layer by layer using sparsification and quantization.
3. The task processing method based on a large language model as claimed in claim 2, characterized in that In the first sparse quantization joint compression process, The importance of each target weight is evaluated using activation range significance; wherein, the larger the activation range of the target weight, the lower the importance, so as to avoid adverse effects on the quantization process after sparsification.
4. The task processing method based on a large language model as claimed in claim 3, characterized in that The activation range significance is obtained by the following steps: Calculating the activation outlier significance of each weight in the target large language model; wherein the activation outlier significance is obtained by calculating the Frobenius norm of each channel aggregated along the token dimension and taking its absolute value; Creating an auxiliary weight matrix in which selected weight elements are set to zero, calculating and comparing the changes in the maximum and minimum values of the output activation before and after the weight elements are removed, thereby determining the auxiliary significance of each weight; The activation range significance of each weight is calculated by combining the activation outlier significance and the auxiliary significance.
5. The task processing method based on a large language model as claimed in claim 4, characterized in that The activation outlier significance is obtained by the following steps: The input activation of the target large language model is denoted as The weight is recorded as Where N, c in 、c out are the number of tokens, input dimension, and output dimension respectively; the activation outlier significance I ij The formula is as follows: I ij =||X j ||2·|W ij | Among them, ||X j ||2 represents the Frobenius norm of the j-th channel aggregated along the token dimension, |·| represents the absolute value, and the subscript ·ij represents the element in the i-th row and j-th column of the weight or input matrix.
6. The task processing method based on a large language model as claimed in claim 4, characterized in that The auxiliary significance is obtained by the following formula: Among them, auxiliary significance c in 、c out are the input dimension and the output dimension respectively, Here Φ(W; i; j) represents an auxiliary weight matrix; when the elements in the i-th row and j-th column in the weight W are set to 0, max(·) and min(·) represent the maximum and minimum values of the vector, respectively. is a matrix The i-th column of .
7. The task processing method based on a large language model as claimed in claim 1, characterized in that In the second sparse quantization joint compression process, First, a set of edit strength selections is designed for each activation layer to form an edit vector, and the edit strength of each weight element is selected from the edit vector; Using the edit vector, activating the editor to edit the activation value in the target large language model; During the editing process, the activation editor identifies target activation outliers and removes the target activation outliers from the target large language model.
8. The task processing method based on a large language model as claimed in claim 7, characterized in that During the editing process, the target activation outlier is removed from the target large language model by the following formula: F edit =clamp(F,LB,HB) LB=r·max(F)+(1-r)·min(F) HB=(1-r)·max(F)+r·min(F) Wherein, F is a layer of activation edited in the target large language model, clamp() represents a truncation operation on F, with a lower bound of LB and an upper bound of HB, and r∈[0,1] is the editing strength.
9. The task processing method based on a large language model as claimed in claim 8, characterized in that A simulated annealing algorithm is used to search for an optimal edit vector to determine the best edit strength and smoothly remove target activation outliers in a target large language model; wherein the activation of each layer is edited according to the edit vector, and the edited target large language model is thinned and quantized using activation range significance; thereafter, the compressed model is tested on calibration data; an element in the edit vector is randomly changed, and this process is iteratively performed to search for the best edit vector.
10. A task processing device based on a large language model, characterized in that It includes a processor and a memory, wherein the memory is coupled to the processor; wherein, The memory is used to store a computer program, and when the computer program is executed by the processor, it is used to implement the task processing method based on a large language model as described in any one of claims 1 to 9.
Citation Information
Patent Citations
Pre-trained language model quantification method and device
CN111814448A
Combined model compression method and system for pre-training language model
CN114742036A
Model compression method and device, electronic equipment and storage medium
CN117371508A
Natural language processing method, system and device, and storage medium
WO2024077981A1
