QLoRA (Dettmers et al. 2023) kết hợp: quantization (nén base model) + LoRA (chỉ train adapter nhỏ). Mục tiêu: fine-tune model rất lớn trên GPU tiêu dùng.
3 đóng góp chính:
1. 4-bit NormalFloat (NF4) — data type 4-bit được thiết kế cho distribution normal (giống phân bố weights pre-trained). Chính xác hơn INT4/FP4 thông thường với cùng số bit.
2. Double Quantization — quantize luôn các quantization constants (mỗi block cần scale + zero point). Tiết kiệm thêm ~0.37 bit/param.
3. Paged Optimizers — dùng NVIDIA unified memory để "page" optimizer state giữa GPU và CPU RAM, tránh OOM trong memory spike.
Quy trình: base weights được quantize xuống NF4 (freeze), gradient chỉ flow qua LoRA adapter ở FP16/BF16. Forward: dequantize NF4 → matmul FP16 → cộng LoRA output. Backward: chỉ update LoRA. Kết quả: chất lượng gần ngang full FT 16-bit (paper 2023 — Guanaco 65B đạt 99.3% ChatGPT trên Vicuna; so sánh này mang tính lịch sử vì ChatGPT đã thay đổi nhiều kể từ đó).
Memory math (LLaMA-65B): full BF16 ~130GB; QLoRA 4-bit model ~35GB + LoRA adapter ~0.5GB + gradient/optimizer ~5GB = ~40GB → chạy được trên 1 A100 80GB hoặc 2 RTX 4090 48GB total.
Trade-off: latency training chậm hơn ~30% vì dequantize on-the-fly; chất lượng giảm nhẹ vs full FT (~1-2%). Thư viện: bitsandbytes (4-bit kernel), PEFT (wrapper), Unsloth (tối ưu tốc độ 2x).
QLoRA (Dettmers et al. 2023) combines: quantization (compress base model) + LoRA (train only small adapters). Goal: fine-tune very large models on consumer GPUs.
3 main contributions:
1. 4-bit NormalFloat (NF4) — a 4-bit data type designed for normal distributions (matching pre-trained weights). More accurate than INT4/FP4 at the same bit budget.
2. Double Quantization — quantize the quantization constants themselves (each block needs a scale + zero point). Saves an extra ~0.37 bits/param.
3. Paged Optimizers — use NVIDIA unified memory to "page" optimizer state between GPU and CPU RAM, avoiding OOM during memory spikes.
Flow: base weights quantized to NF4 (frozen), gradients flow only through LoRA adapters in FP16/BF16. Forward: dequantize NF4 → FP16 matmul → add LoRA. Backward: only update LoRA. Result: quality is close to full 16-bit FT (2023 paper — Guanaco 65B hits 99.3% of ChatGPT on Vicuna; a historical comparison, as ChatGPT has evolved significantly since).
Memory math (LLaMA-65B): full BF16 ~130GB; QLoRA 4-bit model ~35GB + LoRA adapter ~0.5GB + gradient/optimizer ~5GB = ~40GB → fits on 1 A100 80GB or 2× RTX 4090 (48GB total).
Trade-offs: training ~30% slower due to on-the-fly dequantization; quality slightly below full FT (~1–2%). Libraries: bitsandbytes (4-bit kernels), PEFT (wrapper), Unsloth (2x speedup).