Large language model low-rank approximate pruning method and device based on input activation

By considering the weight importance index of input activation in the large language model for pruning, and using the low-rank approximation method to fine-tune the model, the problem of ignoring input activation and high pruning cost in the existing technology is solved, and an efficient and concise model is achieved. Model compression and performance recovery.

CN118627581APending Publication Date: 2024-09-10NAT COMP NETWORK & INFORMATION SECURITY MANAGEMENT CENT
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410753364.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

Existing large language model pruning methods ignore the importance of input activations, resulting in computationally intensive weight updates and high pruning costs, and require iterative training to restore performance.

Method used

A low-rank approximation pruning method for large language models based on input activation is used. By designing activation-aware weight importance indicators, calculating the product of weight and input activation, pruning is performed in one go, and the low-rank approximation method is used to prun the pruned results. The model is fine-tuned to reduce computational overhead and training complexity.

Benefits of technology

It achieves efficient model compression, reduces computational costs and memory overhead, maintains the same simplicity as amplitude pruning, and shows better performance recovery than existing methods in experiments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118627581A
    Figure CN118627581A
Patent Text Reader

Abstract

The invention belongs to the technical field of artificial intelligence, and relates to a large language model low-rank approximate pruning method and device based on input activation. The method comprises the following steps: calculating a pruning index according to a weight and input activation; performing local weight comparison and pruning on each output of the linear layer of the large language model according to a pruning index; and performing fine tuning on the pruned large language model by using a low-rank approximation method to promote the recovery of the performance of the large language model. According to the method, the LLMs can be effectively compressed, relatively high calculation efficiency is realized, execution is performed in single forward propagation, and only very small memory overhead is realized, so that calculation of an inverse matrix in a local layered reconstruction process is avoided, and the same conciseness as amplitude pruning is kept.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence and deep learning technology, and relates to large language model compression, and specifically to a large language model low-rank approximate pruning method and device based on input activation. Background Art

[0002] Recently, large language models (LLMs) have shown remarkable performance in different natural language processing tasks. The emergence of LLMs has triggered unprecedented competition among technology giants and academic institutions. As the model size increases, they are able to handle complex tasks better. However, these models with parameter sizes exceeding billions impose huge computational demands on inference, leading to the problem of excessive latency. In the context of LLMs, some model compression methods have been proposed to address these problems, such as SparseGPT, Wanda, LESS, etc. Among them, model pruning, as an easy-to-use model compression method, can effectively compress LLMs.

[0003] Model pruning reduces the size of the network by removing specific weights from the model. Directly pruning LLMs is very challenging. This is very expensive for the GPT series of models. In order to alleviate the high computational cost of LLMs, pruning methods tailored for LLMs have been proposed one after another. These methods either formalize the pruning problem of LLMs as a weight reconstruction problem or perform updates on the relevant weights after pruning. They usually require retraining after pruning, involving a large number of iterations and subsequent training. Existing LLMs pruning methods are mainly divided into structured methods and unstructured methods.

[0004] Structured pruning methods refer to removing entire structured components from a model to speed up inference. Recently, researchers have studied structured pruning of LLMs. It is shown that there is cue-dependent and task-related sparsity in the structured components of LLMs (e.g., attention heads and MLP neurons). Unstructured pruning methods, such as amplitude pruning at the individual weight level, can maintain performance even in the presence of high sparsity. These methods usually require modifying the training process, retraining the pruned network to restore performance, or involve computationally intensive iterative training procedures.

[0005] Existing pruning methods for LLMs ignore the importance of input activations and still require computationally intensive weight updates. For example, consider a neuron with two inputs and their respective weights, and an output y = w1x1 + w2x2, where |w1| ≤ |w2|. Suppose the goal is to select a weight to remove while minimizing the change in the output. The standard approach is to remove weight w1. This may be a good strategy if the input features x1 and x2 have similar magnitudes. In fact, as recently observed in LLMs, the scales of these two input features can be very different. It is possible that |x1| >> |x2|, resulting in |w1x1| >> |w2x2|. In this case, it is clear that removing weight w2 is a better choice, as this removal has less impact on the neuron's output y than removing weight w1. The example using the simplest linear layer mentioned above reveals the limitation of current pruning methods, namely, ignoring the input activations. In fact, these input activations may play an equally important role in determining the neuron's output. Given the large-scale emergent features found in LLMs, the importance of input activations becomes particularly prominent when pruning LLMs. Summary of the invention

[0006] In order to solve the above problems, the present invention proposes a large language model pruning method based on input activation to effectively compress LLMs. Specifically, first, an activation-aware weight importance indicator is designed to perform one-time pruning. Secondly, from the perspective of weight importance, the weight is evaluated by the product of the weight size and the norm of the corresponding input activation. Correspondingly, for weight comparison grouping, the weights are locally compared in each output of the linear layer to remove weights with lower priority. Finally, a low-rank approximation method is used to promote the performance recovery of the pruned model. In general, the present invention achieves high computational efficiency, is executed in a single forward propagation, and has only a small memory overhead. The present invention not only avoids the calculation of the inverse matrix during local hierarchical reconstruction, but also maintains the same simplicity as amplitude pruning.

[0007] The technical solution adopted by the present invention is as follows:

[0008] A low-rank approximate pruning method for a large language model based on input activation, comprising the following steps:

[0009] Calculate pruning metrics based on weights and input activations;

[0010] Compare and prune the local weights of each output of the linear layer of the large language model according to the pruning index;

[0011] The pruned large language model is fine-tuned using a low-rank approximation method to facilitate the recovery of the performance of the large language model.

[0012] Furthermore, the pruning index is simplified by the following formula:

[0013] S ij =|W ij | 2 ·|X j |

[0014] Among them, W ij represents the weight in the linear layer connecting input j and output i, |X j |Yes The simplified value of; Given a pre-trained large language model, its pruning index is calculated from the initial layer to the last layer. After pruning the previous layer, the subsequent layers receive the updated input activations and calculate their pruning indexes accordingly.

[0015] Furthermore, the comparing and pruning of the local weights of each output of the linear layer of the large language model according to the pruning index includes:

[0016] Assigning an importance score to each weight according to the pruning metric;

[0017] Divide the weights into multiple comparison groups according to the output;

[0018] The weights within each comparison group are compared to each other, and the weights with lower importance scores within each comparison group are pruned.

[0019] Furthermore, the step of dividing the weights into a plurality of comparison groups according to the outputs includes: for the weight W in the linear layer connecting the input j and the output i ij , defining the comparison group for this weight as all weights connected to output i.

[0020] Further, the pruning of weights with lower importance scores within each comparison group includes: for a predefined sparsity percentage s%, eliminating s% of weights connected to each output.

[0021] Furthermore, the method of fine-tuning the pruned large language model using the low-rank approximation method includes:

[0022] The update value ΔW of the learnable weight matrix W in the large language model is decomposed into in and And use the following formula for forward calculation:

[0023] f(x)=(W+ΔW)X+b=(WX+b)+(PQ)X

[0024] Where b represents the bias of the fully connected layer; by only training parameters P and Q, the overall training complexity is reduced, thereby reducing the need for a large amount of training data.

[0025] Furthermore, the unstructured pruning mode is extended to the semi-structured sparse mode to meet different compression requirements; for the N:M sparse mode, each consecutive M weights contains N zeros, and for all weights connected to the output, the same pruning metric is used when comparing the weights within each consecutive M weights.

[0026] A low-rank approximate pruning device for a large language model based on input activation, comprising:

[0027] A pruning module is used to calculate pruning indicators based on weights and input activations, and compare and prune the local weights of each output of the linear layer of the large language model according to the pruning indicators;

[0028] The recovery module is used to fine-tune the pruned large language model using a low-rank approximation method to promote the recovery of the performance of the large language model.

[0029] The beneficial effects of the present invention are as follows:

[0030] The present invention studies the problem of compressing large language models by pruning. Model pruning, as an effective method for compressing large language models, has recently attracted much attention in the field of natural language processing. However, existing large language model pruning methods have two major disadvantages: (1) For models with more than one billion parameters, iterative pruning requires retraining, which leads to significant pruning costs. (2) Large language model pruning is formalized as a weight reconstruction problem, which requires second-order information and incurs expensive computational overhead. To address these problems, the present invention proposes a novel pruning method, named Aplra: Input Activation-Based Low-Rank Approximate Pruning of Large Language Models, which can efficiently identify sparse networks in large language models. Specifically, the present invention designs an input activation-based pruning metric for fast one-shot compression of large language models. First, the input activation is incorporated into the calculation of weight importance to facilitate accurate pruning of low-priority weights. Then, local weight comparison is performed between each output of the linear layer to produce the same sparsity. Next, Aplra is extended to a semi-structured pruning mode to adapt to various acceleration scenarios. Finally, a low-rank parameterized update matrix is ​​used to fine-tune the pruned model to promote rapid recovery of model performance. Experimental results on various language benchmark datasets show that Aplra outperforms the most competitive existing pruning methods. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 It is a framework diagram of the method of the present invention.

[0032] Figure 2 This is the perplexity comparison of Aplra and SparseGPT under different calibration samples. DETAILED DESCRIPTION

[0033] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below through specific embodiments and drawings.

[0034] The low-rank approximate pruning method for a large language model based on input activation proposed in the present invention mainly includes two stages: a pruning stage and a recovery stage. In the pruning stage, a new pruning metric is designed to integrate weights and input activations into the calculation of weight importance. Weights are compared based on each output to achieve effective pruning. In addition, the present invention can also be extended to semi-structured sparse patterns to meet different compression requirements. In the recovery stage, fast fine-tuning is performed to mitigate potential performance degradation caused by pruning. The framework of the present invention is as follows Figure 1 As shown. Regarding the "input activation" in the present invention, assuming that a neuron with two inputs and their respective weights is considered, its output y = w1x1 + w2x2, then the input activation X refers to the general term for the input feature values ​​x1 and x2.

[0035] Next, we will describe the two stages of pruning and recovery.

[0036] 1. Pruning stage.

[0037] (1) Pruning index. The pruning index of the present invention is simplified based on SparseGPT (Frantar, E., Alistarh, D.: Sparsegpt: Massive language models can be accurately pruned in one-shot. In: International Conference on Machine Learning, ICML 2023. vol. 202, pp. 10323–10337 (2023).). SparseGPT converts LLMs pruning into solving the local hierarchical reconstruction problem. The pruning index and weight update process are inspired by OBS (Hassibi, B., Stork, DG, Wolff, GJ: Optimal brainsurgeon and general network pruning. In: IEEE international conference on neural networks. pp. 293–299. IEEE (1993).). Consider a linear layer with a weight matrix W, the shape of W is (C out ,C in ), where C out represents the number of output features of the linear layer, that is, the dimension of the output of this layer, Cin Indicates the number of input features of the linear layer, that is, the input dimension received by the layer. For a language model, its linear layer adopts a shape of (N×L,C in ), where N and L are the batch size and sequence dimension respectively. Using i to represent the output and j to represent the input, then the pruning index S for input j and output i is ij The calculation is as follows:

[0038] S ij =[|W| 2 / diag((X T X+λI) -1 )] ij

[0039] The X in the denominator T X+λI represents the Hessian matrix H of the hierarchical reconstruction problem. λ is the Hessian matrix damping factor, which is used to prevent the failure of the inverse calculation. It is easy to observe that when λ is 0 and only the Hessian matrix X is retained T When the diagonal elements of X+λI are ij Can be transformed as follows:

[0040]

[0041] Due to X T The diagonal of X corresponds to The denominator of the above formula can be simplified to Where j represents the input, X j represents the eigenvalue of the input activation. Therefore, S ij Simplified to:

[0042]

[0043] Among them, W ij represents the weight in the linear layer connecting input j and output i, |X j |Yes This simplification greatly reduces the amount of computation required to calculate the importance of the weights, without having to compute any matrix inverses.

[0044] The present invention is seamlessly implemented and integrated in a single forward propagation process of LLMs, where S ij The estimation is done using a set of calibration data. The calibration data sets are representative of the typical inputs that the model will process in real applications, which means that they cover a variety of tasks and language phenomena that the model will solve. The pruning metric S is calculated on these data. ij, determine which weights need to be pruned. Given a pre-trained LLM, its pruning index is calculated from the initial layer to the last layer of the network. After pruning the previous layer, the subsequent layers receive the updated input activations and calculate their pruning indexes accordingly. The prior art requires a complex weight update process during the iterative pruning process, while the present invention does not introduce any additional weight updates.

[0045] (2) Weight comparison and grouping. During the pruning process, it is usually necessary to assign an importance score to each weight, which is the pruning index mentioned above. Then, these weights are grouped into multiple comparison groups, where the weights in each comparison group are compared with each other. In each comparison group, weights with lower importance scores (i.e., those with lower S ij The weights of the values ​​of the outputs are pruned. Many existing pruning methods default to comparing weights within each layer or across the entire network. While layer-by-layer and network-wide comparisons are common choices, the present invention finds that grouping in a more localized manner can bring greater benefits. In the present invention, weights are compared and pruned based on each output ( Figure 1 Each row of the matrix in represents an output), which means locally comparing the weight importance scores within each output neuron. Specifically, for the weight W in the linear layer connecting input j and output i ij , defining the comparison group of this weight as all weights connected to output i:

[0046] G ij = {W uv |u=i}

[0047] Among them, G ij Denote the representation and weight W ij The relevant comparison group contains all the weights connected to output i. In other words, G ij is a set containing all weights of the i-th row of the weight matrix W, W uv Denotes the weight connecting any two nodes in the weight matrix W, where u is the index of the output node and v is the index of the input node.

[0048] In this comparison group, for a predefined sparsity percentage s%, the present invention eliminates s% of the weights connected to each output. Practice has shown that this approach is always better than layer-by-layer pruning. It is worth noting that uniform sparsity applies not only to the pruning metric proposed by the present invention, but also to the standard amplitude pruning metric. This shows that it is crucial to maintain a balanced pruning ratio between output features when pruning LLMs.

[0049] (3) Extension to semistructured sparsity. Although only unstructured pruning has been discussed so far, the present invention can be easily extended to semistructured N:M mode. For the N:M sparse format, it can take advantage of NVIDIA's sparse tensor cores to accelerate matrix multiplication. Specifically, each consecutive M weights should contain exactly N zeros. After extension to the semistructured N:M sparse mode, for all weights connected to the output, the same pruning metric is used when comparing weights within each consecutive M weights.

[0050] 2. Recovery phase

[0051] In order to speed up the model recovery, the number of parameters that need to be optimized during the recovery phase must be minimized. To this end, the pruned model is fine-tuned using low-rank approximation (LoRA). Each learnable weight matrix in the model (denoted by W) contains the pruned and unpruned linear projections in LLMs. The update value ΔW of W can be decomposed into in and Among them, d represents the original dimension of the weight matrix W, d + Denotes a higher dimension, d - represents a lower dimension, represents the set of real numbers, d - ×d represents the dimension of the first matrix P, where d - is the number of rows, and d is the number of columns. This dimension indicates that P is a d - A matrix with d rows and d columns. d×d + represents the dimension of the second matrix Q, where d is the number of rows and d + is the number of columns. This dimension means that Q is a d-row d + The forward calculation then becomes:

[0052] f(x)=(W+ΔW)X+b=(WX+b)+(PQ)X

[0053] Among them, f(x) represents the forward pass result of the model for the input x, and b represents the bias of the fully connected layer. describes how the elements of the matrix Q are generated, where represents a normal distribution (also called a Gaussian distribution), meaning that all elements in Q are independently distributed from a mean of 0 and a variance of σ 2 The training of only P and Q helps to reduce the overall training complexity, thereby reducing the need for a large amount of training data. In addition, the additional parameters P and Q can be reparameterized as ΔW without introducing additional parameters in the final compressed model.

[0054] The following is an in-depth description of the specific implementation details of the invention. First, the datasets, evaluation indicators, comparison algorithms, and implementation details used in the experiment are introduced; then experiments are conducted on recognized benchmark datasets and the experimental results are presented; finally, model analysis is performed, including analysis of pruning configurations and the number of calibration samples, so as to obtain the optimal pruning configuration.

[0055] 1. Dataset Introduction

[0056] The performance of the pruned model is evaluated by its language modeling ability and zero-shot learning ability. In terms of language modeling ability, the perplexity indicator on the WikiText validation set is mainly displayed. Among them, the lower the perplexity of the model, the better the performance. In order to evaluate the zero-shot learning ability, seven common sense benchmarks are selected from the EleutherAI LM Harness: BoolQ, RTE, HellaSwag, WinoGrande, ARC Easy, ARC Challenge, and Open bookQA. In the experiment, the accuracy of each benchmark dataset and the overall average accuracy are given.

[0057] 2. Comparison of algorithms

[0058] The present invention is compared with three representative pruning methods: Magnitude pruning, SparseGPT and Wanda. Magnitude pruning is a standard layer-by-layer pruning benchmark method that can be extended to large models. SparseGPT is a second-order pruning method based on solving the layer-by-layer reconstruction problem, which can work efficiently on models with tens to hundreds of billions of parameters. Wanda is a direct pruning method that can prune LLMs to very high sparsity without any modification of the remaining weights.

[0059] 3. Implementation details

[0060] In the pruning phase, the present invention uses the same calibration dataset as SparseGPT, which contains 128 context length sequences sampled from the C4 training set. In the recovery phase, the present invention uses a cleaned version of Alpaca, which contains about 50,000 samples. The settings of the present invention refer to LoRA in the recovery phase. In the experiment, the rank d is set to 8, the learning rate is set to 1e-4, the batch size is set to 4, the number of training rounds is set to 2, and AdamW is selected as the optimizer. For all experiments, the average results of five runs using different random seeds are shown.

[0061] In the setting of sparsity, for all methods, the configuration of SparseGPT is mainly referred to, in which the same sparsity is applied in all layers. The present invention excludes the first embedding layer and the last classification head, which is a common practice in pruned Transformer models. The present invention not only generates a sparse network through unstructured pruning, but also compares the performance of all methods under semi-structured N:M sparsity. Here, the present invention provides a comparison of 4:8 and 2:4 sparsity modes.

[0062] 4. Experimental Results

[0063] (1) Language modeling capability. The first is the analysis of unstructured sparse patterns. For the LLaMA and OPT models, they are pruned to an unstructured sparsity of 50% in all methods. The experimental results are shown in Table 1, from which it can be seen that the Aplra pruning proposed in the present invention is improved compared with the amplitude pruning. In the absence of any weight updates, the performance of Aplra is far superior to the existing amplitude pruning methods. For example, based on the OPT-6.7B model, the perplexity of Aplra is 11.19, which is significantly lower than the perplexity of amplitude pruning, 968.75. It is worth noting that Aplra also surpasses the most competitive SparseGPT method currently. This highlights the importance of accurate pruning methods for large language models.

[0064] Table 1 WikiText perplexity of pruned LLaMA and OPT models

[0065] Method Weight Update Sparsity LLaMA-7B OPT-6.7B Mean Dense - 0% 5.68 10.86 8.27 Magnitude × 50% 17.29 968.75 493.02 SparseGPT √ 50% 7.24 11.60 9.42 Wanda × 50% 7.27 12.01 9.64 Aplra(Ours) × 50% 7.17 11.19 9.18 Magnitude × 4:8 16.83 196.16 106.50 SparseGPT √ 4:8 8.75 12.61 10.68 Wanda × 4:8 8.62 13.65 11.14 Aplra(Ours) × 4:8 7.80 12.20 10.00 Magnitude × 2:4 42.54 264.09 153.32 SparseGPT √ 2:4 11.09 14.43 12.76 Wanda × 2:4 11.59 15.94 13.77 Aplra(Ours) × 2:4 8.63 13.48 11.06

[0066] Then comes the analysis of semi-structured N:M sparsity. N:M sparsity is a stricter sparsity pattern compared to the unstructured sparsity pattern. Therefore, it is expected that this semi-structured sparsity pattern may lead to inferior results. The results of semi-structured 4:8 and 2:4 sparsity are given in the lower part of Table 1, respectively. It can be found that Aplra is easily generalized to the sparse scenario of N:M. In both 4:8 and 2:4 sparsity cases, Aplra can identify efficient sparse subnetworks and outperforms the baseline methods in most cases.

[0067] (2) Zero-shot tasks. The pruned model was evaluated on downstream zero-shot tasks with prompting, and the results are shown in Table 2. The comparison methods uniformly pruned to 50% sparsity in an unstructured manner. From the average accuracy of the seven tasks, the Aplra method successfully identified effective pruned networks and outperformed the baseline method. In terms of single task performance, it can be observed that in most tasks, Aplra's results are always better than all comparison methods.

[0068] Table 2 Accuracy of seven zero-shot tasks under unstructured 50% sparsity conditions (%)

[0069]

[0070] 5. Model Analysis

[0071] This section analyzes Aplra from two aspects: pruning configuration and calibration samples. In this section, the LLaMA-7B model is pruned to an unstructured 50% sparsity and the perplexity results on WikiText are given.

[0072] (1) Pruning configuration. Aplra is different from previous methods in both pruning indicators and pruning granularity. The effectiveness of Aplra is verified by comparing various pruning indicators and granularity. Aplra groups weights connected to a single output channel together. SparseGPT adopts a local granularity level within the model layer, that is, weights connected to 128 consecutive input channels form a group. Therefore, this section adopts two options: (input or output), (128 or 1). For simplicity, (input / output, block size) is used to represent the local pruning granularity level, such as (input, 1).

[0073] Table 3 shows the results of different pruning configurations, with bold values ​​indicating the best comparison group for each pruning metric, and underlined results indicating the default pruning configuration for each method. Aplra's pruning configuration produced the best pruned model with a perplexity of 7.17. It is worth noting that in the magnitude pruning metric, comparing the weights of the same input neuron (input, 1) produces a perplexity of 8.86, which is significantly better than other granularity scenarios. At this granularity, the four methods also produced the same pruning results. Since the inputs are the same, the weight ranking depends entirely on the weight size. This finding further emphasizes the importance of using the appropriate pruning granularity, even when performing magnitude pruning in LLMs.

[0074] Table 3 Different pruning configurations

[0075]

[0076] (2) Calibration samples. The number of calibration samples can be adjusted by selecting different sample sizes from 1 to 128. The results are shown in Figure 2 As shown in Figure 2. It can be observed that the trend of Aplra is significantly different with the change of calibration data size: Aplra shows robustness when there are fewer calibration samples. It is worth noting that even with only one sample, the perplexity of the pruned network obtained using Aplra is only 7.33. This may be due to the fact that the input norm statistic |X j | than the inverse Hessian matrix H of the local hierarchical reconstruction problem-1 Easier to estimate.

[0077] The key points of the present invention are:

[0078] 1. This invention proposes a new weight importance calculation method in the model pruning stage, which does not require gradient calculation through back propagation or any second-order Hessian inverse transform. At each layer, the pruning weight can be determined once and for all without the need for an iterative process.

[0079] 2. A low-rank approximation mechanism is introduced in the model recovery phase to help quickly restore the performance of the pruned model. This method does not require weight updates for the pruned model.

[0080] 3. Experimental results on different language benchmark datasets show that the Aplra method proposed in this paper outperforms the most advanced methods and achieves fast one-time pruning.

[0081] Another embodiment of the present invention provides a large language model low-rank approximate pruning device based on input activation, comprising:

[0082] A pruning module is used to calculate pruning indicators based on weights and input activations, and compare and prune the local weights of each output of the linear layer of the large language model according to the pruning indicators;

[0083] The recovery module is used to fine-tune the pruned large language model using a low-rank approximation method to promote the recovery of the performance of the large language model.

[0084] The specific implementation process of each module refers to the above description of the method of the present invention.

[0085] Another embodiment of the present invention provides a computer device (computer, server, smart phone, etc.), which includes a memory and a processor, the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program includes instructions for executing each step in the method of the present invention.

[0086] Another embodiment of the present invention provides a computer-readable storage medium (such as ROM / RAM, magnetic disk, optical disk), wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the steps of the method of the present invention are implemented.

[0087] The specific embodiments of the present invention disclosed above are intended to help understand the content of the present invention and implement it accordingly. It can be understood by those skilled in the art that various replacements, changes and modifications are possible without departing from the spirit and scope of the present invention. The present invention should not be limited to the contents disclosed in the embodiments of this specification, and the scope of protection of the present invention shall be subject to the scope defined in the claims.

Claims

1. A low-rank approximate pruning method for a large language model based on input activation, characterized in that: The following steps are involved: Calculate pruning metrics based on weights and input activations; Compare and prune the local weights of each output of the linear layer of the large language model according to the pruning index; The pruned large language model is fine-tuned using a low-rank approximation method to facilitate the recovery of the performance of the large language model.

2. The method according to claim 1, characterized in that The pruning index is simplified by the following formula: S ij =|W ij | 2 ·|X j | Among them, W ij represents the weight in the linear layer connecting input j and output i, |X j |Yes The simplified value of; Given a pre-trained large language model, its pruning index is calculated from the initial layer to the last layer. After pruning the previous layer, the subsequent layers receive the updated input activations and calculate their pruning indexes accordingly.

3. The method according to claim 1, characterized in that The comparing and pruning of the local weights of each output of the linear layer of the large language model according to the pruning index includes: Assigning an importance score to each weight according to the pruning metric; Divide the weights into multiple comparison groups according to the output; The weights within each comparison group are compared to each other, and the weights with lower importance scores within each comparison group are pruned.

4. The method according to claim 3, characterized in that The weights are divided into multiple comparison groups according to the outputs, including: For the weight W in the linear layer connecting input j and output i ij , defining the comparison group for this weight as all weights connected to output i.

5. The method according to claim 3, characterized in that: The pruning of weights with lower importance scores within each comparison group includes: for a predefined sparsity percentage s%, eliminating s% of weights connected to each output.

6. The method according to claim 1, characterized in that The method of fine-tuning the pruned large language model using the low-rank approximation method includes: The update value ΔW of the learnable weight matrix W in the large language model is decomposed into in and And use the following formula for forward calculation: f(x)=(W+ΔW)X+b=(WX+b)+(PQ)X Where b represents the bias of the fully connected layer; by only training parameters P and Q, the overall training complexity is reduced, thereby reducing the need for a large amount of training data.

7. The method according to claim 1, characterized in that The unstructured pruning mode is extended to the semi-structured sparse mode to meet different compression requirements; for the N:M sparse mode, each consecutive M weights contains N zeros, and for all weights connected to the output, the same pruning metric is used when comparing weights within each consecutive M weights.

8. A low-rank approximate pruning device for a large language model based on input activation, characterized in that: include: A pruning module is used to calculate pruning indicators based on weights and input activations, and compare and prune the local weights of each output of the linear layer of the large language model according to the pruning indicators; The recovery module is used to fine-tune the pruned large language model using a low-rank approximation method to promote the recovery of the performance of the large language model.

9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program comprises instructions for executing the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Large model hierarchical pruning method based on pruning influence rate and application

    CN119849577A

  • Voice model compression method, electronic equipment and storage medium

    CN119905087A

  • Federal large language model training method, device and equipment

    CN121052335A