QLoRA › Paged Optimizers

Michael BrenndoerferDecember 4, 20252 min read
Language AI HandbookAll chapters
Part 35 of 67Parameter-Efficient Fine-tuning
Chapter 259QLoRA › Paged Optimizers
Reading section 9 of 15 · Paged Optimizers · 2 minSection 9 of 15 · 2 min

Book contents

Section 9 of 15 · 2 min read

QLoRA › Paged OptimizersOne section · Sections in this chapter9 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

QLoRA introduces one additional innovation beyond quantization: paged optimizers using NVIDIA's unified memory. During training, memory usage can spike unpredictably due to long sequences or unusual batch compositions. These spikes are difficult to predict in advance because they depend on the specific data being processed. When GPU memory is exhausted, the training process crashes, potentially hours into a long fine-tuning run. This is particularly problematic with QLoRA because we're already operating close to the GPU's memory limit to maximize the model size we can fit.

Think of paged optimizers as an overflow drain in a bathtub. Normally, you fill the bathtub to a comfortable level and it stays there. But if a sudden surge of water comes in (an unusually long sequence or complex batch), the drain prevents overflow by routing the excess away. When the surge passes, the water level returns to normal. Paged optimizers do the same with GPU memory: they maintain a target occupancy level and automatically spill any excess to CPU memory, retrieving it as needed.

Paged optimizers handle this by automatically transferring optimizer states between GPU and CPU memory as needed. When GPU memory runs low, inactive optimizer states are paged to CPU memory. When they're needed for a parameter update step, they're paged back to GPU memory. This enables training to continue even when memory demand temporarily exceeds GPU capacity, at the cost of some speed overhead during memory transfers. The implementation uses CUDA's unified memory system, which manages CPU-GPU memory transfers at the hardware level and is therefore more efficient than manual data movement.

This technique is particularly valuable for QLoRA because the memory savings already put us at the edge of what fits on a given GPU. We're deliberately operating close to the memory limit to maximize model size. Paged optimizers provide a safety margin against memory spikes that would otherwise crash training. The additional speed overhead from occasional paging events is typically small relative to the cost of handling such spikes manually or reducing batch size preemptively. In practice, paging events are rare enough during stable training that the throughput impact is negligible.