Large language models (LLMs) have shown remarkable capabilities in language understanding and generation. However, such impressive capability typically comes with a substantial model size, which presents significant challenges in both the deployment, inference, and training stages. With LLM being a general-purpose task solver, we explore its compression in a task-agnostic manner, which aims to preserve the multi-task solving and language generation ability of the original LLM. One challenge to achieving this is the enormous size of the training corpus of LLM, which makes both data transfer and model post-training over-burdensome. Thus, we tackle the compression of LLMs within the bound of two constraints: being task-agnostic and minimizing the reliance on the original training dataset. Our method, named LLM-Pruner, adopts structural pruning that selectively removes non-critical coupled structures based on gradient information, maximally preserving the majority of the LLM's functionality. To this end, the performance of pruned models can be efficiently recovered through tuning techniques, LoRA, in merely 3 hours, requiring only 50K data. We validate the LLM-Pruner on three LLMs, including LLaMA, Vicuna, and ChatGLM, and demonstrate that the compressed models still exhibit satisfactory capabilities in zero-shot classification and generation. The code is available at: https://github.com/horseee/LLM-Pruner
翻译:大型语言模型(LLMs)在语言理解与生成方面展现出卓越的能力。然而,这种令人瞩目的能力通常伴随着巨大的模型规模,给部署、推理和训练阶段带来了重大挑战。鉴于LLM作为通用任务求解器的特性,我们探索以任务无关的方式进行压缩,旨在保留原始LLM的多任务求解和语言生成能力。实现这一目标的一个挑战在于LLM训练语料库规模庞大,导致数据传输和模型后训练负担过重。因此,我们在两项约束条件下开展LLM压缩:任务无关性以及对原始训练数据集的最小依赖。我们提出的方法名为LLM-Pruner,采用结构性剪枝,基于梯度信息选择性移除非关键的耦合结构,从而最大程度保留LLM的大部分功能。通过微调技术LoRA,剪枝后模型的性能可在仅需5万数据、3小时内高效恢复。我们在LLaMA、Vicuna和ChatGLM三个LLM上验证了LLM-Pruner的有效性,结果表明压缩后的模型在零样本分类和生成任务中仍能展现令人满意的能力。代码已开源:https://github.com/horseee/LLM-Pruner