QLoRA: Efficient Finetuning of Quantized LLMs

TL;DR

QLoRA combines 4-bit quantization, LoRA, and paging to finetune 65B models on a single GPU, achieving near ChatGPT performance.

cs.LG 🔴 Advanced 2023-05-24 53 views
Tim Dettmers Artidoro Pagnoni Ari Holtzman Luke Zettlemoyer
large-scale models quantization parameter-efficient finetuning memory optimization NLP

Key Findings

Methodology

QLoRA integrates NF4 (NormalFloat4) quantization, double quantization, and paged optimizers to enable high-fidelity finetuning of massive models with minimal memory. It freezes the pretrained weights, adds low-rank adapters (LoRA), and quantizes weights to 4-bit NF4, which is optimal for normally distributed parameters. Double quantization compresses quantization constants further, reducing storage. Paged optimizers leverage NVIDIA unified memory to handle memory spikes during long-sequence training. Experiments show that 65B models can be finetuned in 48GB GPU memory within 24 hours, with performance close to full-precision finetuning.

Key Results

  • Guanaco models on Vicuna reach 99.3% of ChatGPT's performance, trained in under 24 hours on a single GPU.
  • NF4 and double quantization reduce model storage to approximately 0.37 bits per parameter, enabling large model finetuning on commodity hardware.
  • Over 1000 models across architectures and sizes (7B-65B) demonstrate that QLoRA matches or exceeds full-precision finetuning in instruction-following and chatbot benchmarks, with significant efficiency gains.

Significance

This work dramatically lowers the hardware barrier for large model finetuning, democratizing access and accelerating research and deployment. By enabling high-performance training on modest hardware, it fosters broader adoption of large language models in industry and academia, addressing longstanding resource constraints.

Technical Contribution

The paper introduces NF4, an information-theoretically optimal 4-bit data type for normal distributions, combined with double quantization of quantization constants and paged optimizers. These innovations collectively enable high-fidelity, memory-efficient finetuning of models previously limited by hardware. The approach maintains performance parity with full-precision methods, opening new engineering possibilities for large-scale NLP.

Novelty

This is the first demonstration that 4-bit quantized models can be finetuned without performance loss, leveraging NF4 and double quantization. It extends quantization from inference-only to training, combined with LoRA, creating a new paradigm for resource-efficient large model training.

Limitations

  • While performance is close to full-precision, some tasks or extreme scenarios may still see minor gaps. Further optimization is needed for certain applications.
  • The approach relies heavily on CUDA kernels and GPU paging features, which may limit hardware compatibility.
  • Long-sequence training and very large models still face challenges in memory management and efficiency, requiring ongoing research.

Future Work

Future directions include refining quantization algorithms for even lower bit-widths, integrating sparsity and pruning, and extending the method to multi-modal models. Improving hardware support and optimizing for diverse platforms will further broaden applicability.

AI Executive Summary

The rapid growth of large-scale pretrained language models (LLMs) has revolutionized NLP, yet their training and fine-tuning demand enormous computational resources. Traditional full-precision methods require hundreds of gigabytes of GPU memory, making it infeasible for most researchers and organizations. This bottleneck has limited the democratization of state-of-the-art models, confining their use to well-funded labs with access to massive hardware.

In response, this work introduces QLoRA, an innovative approach that combines 4-bit quantization, low-rank adapters (LoRA), and memory-efficient optimization techniques. The key breakthrough is the development of NF4, a data type based on the statistical properties of neural network weights, which allows the model's parameters to be stored at a fraction of their original size without performance loss. Complemented by double quantization of quantization constants and NVIDIA’s unified memory-based paged optimizers, QLoRA effectively manages memory spikes during training, enabling the fine-tuning of models with up to 65 billion parameters on a single GPU.

Experimental results demonstrate that Guanaco models trained with QLoRA achieve performance levels within 0.7% of ChatGPT on the Vicuna benchmark, with training times under 24 hours. The storage footprint is reduced to about 0.37 bits per parameter, making large models accessible to a broader community. Extensive testing across multiple datasets, architectures, and model scales confirms the robustness and generality of the approach. The authors also analyze instruction-following and chatbot capabilities, showing that smaller models fine-tuned with QLoRA can outperform larger, less efficient counterparts.

This advancement signifies a major step toward democratizing large language models, lowering hardware barriers, and accelerating research. By enabling high-fidelity finetuning on commodity hardware, QLoRA opens new horizons for deploying sophisticated NLP systems in real-world applications, from personalized assistants to enterprise AI solutions. Despite some remaining challenges, such as hardware dependency and long-sequence memory management, the method sets a new standard for resource-efficient large model training and fine-tuning.

Deep Analysis

Background

Large-scale pretrained language models(如GPT、LLaMA、T5)在自然语言处理领域取得巨大成功,但其微调成本极高。传统微调依赖全参数更新,需大量显存和计算资源,限制了模型的普及。量化技术在推理阶段已被广泛应用,显著降低存储和推理成本,但在训练中仍存在性能下降的问题。近年来,LoRA等参数高效微调方法出现,减少了参数更新量,但在超大模型上依然受硬件限制。本文结合量化和参数高效微调,试图突破硬件瓶颈,实现单GPU微调超大模型的目标。

Core Problem

核心问题在于如何在极低存储精度(4-bit)下实现高性能微调,尤其是对超大模型(如65B参数)而言。传统量化方法在训练中会引入性能损失,难以保证模型的表达能力。同时,长序列训练的内存管理也是一大难题。如何在保证模型性能的同时,显著降低硬件需求,成为亟待解决的难题。

Innovation

本文提出NF4(NormalFloat4)量化方案,基于正态分布参数的最优信息编码,优于传统的INT4和FP4。双重量化技术对量化常数进行二次压缩,减少存储空间。分页优化器利用GPU的统一内存技术,有效管理长序列训练中的内存突增。结合LoRA的低秩适配器,实现在极低存储条件下微调超大模型,性能几乎不受影响。这些创新共同推动了大模型微调的技术边界。

Methodology

  • �� 预训练模型参数通过NF4进行量化,利用正态分布的统计特性实现信息最优存储。
  • �� 采用双重量化,将量化常数再压缩,降低存储成本。
  • �� 在训练中冻结预训练模型参数,仅更新低秩适配器(LoRA),减少梯度存储需求。
  • �� 使用分页优化器,通过GPU的统一内存技术,动态管理长序列训练中的内存突增。
  • �� 反向传播时,将量化参数反量化到16-bit进行矩阵乘法,保证梯度计算的精度。
  • �� 实验中,微调65B模型仅需48GB显存,训练时间缩短至24小时,性能与全精度微调相当。

Experiments

采用Vicuna、MMLU、GLUE等多个公开数据集,比较不同模型大小(7B、13B、33B、65B)在指令跟随、问答和推理任务中的表现。对比全参数微调、LoRA和QLoRA的性能差异,验证NF4和双重量化的有效性。通过GPT-4和人类评审的模型排名,分析模型的实际应用能力。实验还包括长序列训练的内存管理测试,确保优化器的稳定性。

Results

QLoRA在65B模型上实现了与16-bit全微调几乎一致的性能,Vicuna测试中达99.3%的ChatGPT水平。存储需求从780GB降低到48GB,训练时间缩短至24小时。NF4数据类型优于FP4,双重量化无性能损失。超过1000个模型验证了其在多任务、多架构中的普适性。模型在指令跟随和聊天任务中表现优异,验证了方法的实用性和有效性。

Applications

该技术可广泛应用于企业和研究机构,快速定制大规模模型,降低硬件门槛,推动AI民主化。在实际场景中,可用于快速部署定制化聊天机器人、问答系统和多任务模型,尤其适合资源有限的环境。未来还可结合稀疏化、剪枝等技术,进一步提升模型效率。

Limitations & Outlook

目前方法对硬件支持要求较高,依赖CUDA核和GPU分页机制,可能限制在某些平台的应用。长序列训练中的内存管理仍有优化空间,极端模型规模和复杂任务中可能出现性能瓶颈。此外,量化在某些任务中仍存在微小性能差距,未来需持续优化算法和硬件适配。

Plain Language Accessible to non-experts

想象你在厨房做饭,平时用的厨具都很大很重,搬来搬去很麻烦。现在你用一种特别的折叠刀,只用很少的空间就能切菜,还能做出和大刀一样的效果。这就像QLoRA用4个比特的“折叠刀”把大模型变得轻巧又强大。它把模型的“数据”压缩得很小,但仍能保持原来的“味道”和“效果”。这样,你就可以用普通的厨房(电脑)轻松完成大厨(大模型)的工作,不再需要昂贵的厨房设备(超级GPU)。这让更多人都能享受到做大菜的乐趣,也让大模型变得更普及、更实用。

ELI14 Explained like you're 14

想象你有一台超级大的游戏机,但它太重、太大,搬不动。平时玩游戏需要很多空间和电力,太麻烦了。现在,有个聪明的办法,把游戏机的“内部零件”用特别的方法压缩成很小的“迷你版”,还能让游戏运行得和大机器一样快。这就像QLoRA用特殊的“压缩技术”把大模型变得很小,但还保持原来的“强大”。这样,你只用一台普通的电脑,就能让它像专业的游戏机一样厉害,甚至还能自己调节和改进。是不是很酷?这让更多人都能用上强大的AI,不再受限于昂贵的设备,就像用迷你版的游戏机也能打出高分一样!

Abstract

We present QLoRA, an efficient finetuning approach that reduces memory usage enough to finetune a 65B parameter model on a single 48GB GPU while preserving full 16-bit finetuning task performance. QLoRA backpropagates gradients through a frozen, 4-bit quantized pretrained language model into Low Rank Adapters~(LoRA). Our best model family, which we name Guanaco, outperforms all previous openly released models on the Vicuna benchmark, reaching 99.3% of the performance level of ChatGPT while only requiring 24 hours of finetuning on a single GPU. QLoRA introduces a number of innovations to save memory without sacrificing performance: (a) 4-bit NormalFloat (NF4), a new data type that is information theoretically optimal for normally distributed weights (b) double quantization to reduce the average memory footprint by quantizing the quantization constants, and (c) paged optimziers to manage memory spikes. We use QLoRA to finetune more than 1,000 models, providing a detailed analysis of instruction following and chatbot performance across 8 instruction datasets, multiple model types (LLaMA, T5), and model scales that would be infeasible to run with regular finetuning (e.g. 33B and 65B parameter models). Our results show that QLoRA finetuning on a small high-quality dataset leads to state-of-the-art results, even when using smaller models than the previous SoTA. We provide a detailed analysis of chatbot performance based on both human and GPT-4 evaluations showing that GPT-4 evaluations are a cheap and reasonable alternative to human evaluation. Furthermore, we find that current chatbot benchmarks are not trustworthy to accurately evaluate the performance levels of chatbots. A lemon-picked analysis demonstrates where Guanaco fails compared to ChatGPT. We release all of our models and code, including CUDA kernels for 4-bit training.

cs.LG