NF4 Quantization
NF4 is a information-theoretically optimal 4-bit data type for normally distributed weights. The quantization steps are:- Quantize pretrained weights W to 4-bit NF4.
- Store quantized weights in a blockwise format with 64-element blocks.
- Dequantize on-the-fly during the forward pass to 16-bit or 32-bit compute.
- Apply LoRA to the dequantized weights.
Memory Savings
QLoRA reduces memory compared to full-precision LoRA by quantizing the base model weights. The exact savings depend on model size, sequence length, batch size, and optimizer state. Memory for adapter parameters and gradients remains full precision.QLoRA Training Flowchart
Hyperparameters
QLoRA inherits all LoRA hyperparameters and adds quantization-specific settings:Integration Points
- QuantizationEngine: handles NF4 quantization and dequantization.
- ModelLoader: loads quantized base model and attaches LoRA adapters.
- GPU Orchestration: allocates adapters and optimizer state in full precision, base weights in NF4.
- ArtifactStore: stores quantized base reference and adapter checkpoints separately.