knowledge base · entry 17
A 65B fine-tune on the GPU you already have
A read-through of QLoRA: Efficient Finetuning of Quantized LLMs. Entry 09 shrank the update; this paper shrinks the base model under it to four bits without losing fine-tuning quality — collapsing a 780GB training job onto a single 48GB card. It is the reason “fine-tune a 65B at home” stopped being a joke, and it is the default hardware recipe of the post-training arc.
every figure zooms — click it, scroll to magnify, drag to pan
part one
The problem, in gigabytes
figure 1 · the memory wall
Where 780 gigabytes actually go
Fine-tuning is memory-hungry far beyond the weights themselves: 16-bit weights, then gradients of the same size, then Adam’s two optimizer states on top — before any activations. For a 65B model the full-fine-tune bill exceeds 780GB — a rack of A100s to change the tone of a chatbot. LoRA already deleted the gradient and optimizer cost for the base weights; the weights themselves, 130GB in 16-bit, remained the floor.
click any figure to zoom · scroll to magnify · drag to pan
QLoRA’s question: how far down can the frozen base go — without the fine-tune noticing?
part two · the scheme
Freeze it at 4 bits, learn beside it
figure 2 · the architecture
A 4-bit statue with 16-bit hands
The recipe: quantize the entire frozen base model to 4 bits, and train ordinary 16-bit LoRA adapters on top. On each forward pass, weights are dequantized block-by-block to BFloat16 just long enough to multiply, so gradients flow through the frozen 4-bit weights into the adapters — only the adapters (a fraction of a percent of parameters) ever have gradients or optimizer states.
Nothing about LoRA changes — same low-rank update, same mergeability. QLoRA is a storage claim: the fine-tune’s signal lives in the adapters, so the base can be compressed brutally as long as compute happens in 16-bit.
figure 3 · innovation one
NF4 — bins shaped like the weights
Four bits buy sixteen values, so the question is which sixteen. Uniform bins (INT4/FP4) waste levels where weights rarely fall. Pretrained weights are approximately zero-centered normal — so 4-bit NormalFloat places its sixteen levels at the quantiles of that normal distribution: equal mass per bin, dense near zero where the weights crowd, sparse in the tails. Information-theoretically, for normal data, that is the optimal spend of sixteen values.
Empirically the shaping is worth about a percentage point on MMLU over FP4 — the difference between “quantization degraded it” and “matches 16-bit.”
figure 4 · innovations two & three
Quantize the bookkeeping, page the spikes
Two supporting tricks. Each block of 64 weights carries a 32-bit scaling constant — half a bit per parameter of pure bookkeeping. Double quantization quantizes those constants themselves (8-bit, blocks of 256), cutting the overhead to 0.127 bits per parameter. And paged optimizers use NVIDIA unified memory to spill optimizer states to CPU RAM during the rare long-sequence memory spikes that would otherwise kill the run.
figure 5 · worked by hand
The 65B memory bill, line by line
Add it up for 65 billion parameters: 4-bit weights are 32.5GB; double-quantized constants add about 1GB (instead of ~4GB); LoRA adapters and their optimizer states are a rounding error; what remains is activations and cache. Under 48GB, with ~3GB saved by double quantization alone — against 780GB for the full fine-tune.
part three · the evidence
Did four bits cost anything?
results · fidelity and Guanaco
Matches 16-bit — and the fine-tune proves it
The fidelity claim is tested across sizes and benchmarks: 4-bit NF4 QLoRA matches 16-bit full fine-tuning and 16-bit LoRA — provided adapters go on all linear layers, not just attention (the finding that became the modern default). As a demonstration, the authors fine-tune Guanaco on the OASST1 dataset: the 65B model reaches 99.3% of ChatGPT’s Vicuna-benchmark score after 24 hours on one GPU.
| model | 4-bit memory | Vicuna Elo | note |
|---|---|---|---|
| Guanaco 65B | 41 GB | 1022 | 99.3% of ChatGPT, 24h on one GPU |
| Guanaco 33B | 21 GB | 992 | — |
| Guanaco 13B | 10 GB | 916 | — |
| Guanaco 7B | 5 GB | 879 | fits on a phone; ~20 points over Alpaca 13B |
figure 7 · the data echo
9,000 beats 450,000 — LIMA, re-proven by accident
Buried in the evaluation is the arc’s recurring lesson, found independently: Guanaco trained on 9k curated OASST1 conversations beat models trained on the 450k-example FLAN v2 mixture at chat — a 50× smaller dataset, better suited to the target behavior. Dataset suitability dominated dataset size; the effect dwarfed everything scaling the data bought.
the caveat we would flag QLoRA democratizes the compute; it does nothing about the data. After this paper the binding constraint on a small team’s fine-tune is entirely entry 14’s problem — a thousand excellent examples — which is exactly the division of labor the arc’s capstone (entry 18) industrializes.
the math · in the paper's notation
The forward pass, a block by hand, and the bit ledger
QLoRA's math is bookkeeping done carefully: one forward-pass equation, one rounding scheme, and an accounting identity for the overhead. Each decoded, with a real block quantized by hand.
the equations · worked
Dequantize, multiply, and count the bits
§3, eq. (5) · the QLoRA forward pass
YBF16 = XBF16 · doubleDequant( c1FP32, c2k-bit, WNF4 ) + XBF16 L1 L2
read aloud: rebuild each block of frozen weights to 16-bit just long enough to multiply, and add the LoRA path, which was 16-bit all along. The superscripts are the paper's storage-format annotations — the whole design is in them: weights rest in NF4, arithmetic happens in BF16, and only L1, L2 ever see a gradient.
- WNF4the frozen base weights, stored as 4-bit NormalFloat codes
- c1, c2the two tiers of scaling constants — c2 per 64-weight block, themselves quantized against c1 (that's the "double")
- L1, L2the LoRA factors — entry 09's B and A, in the paper's own renaming
§3 · block quantization, one block by hand
c = absmax(block), qi = nearest NF4 level to wic, ŵi = c · NF4[ qi ]
read aloud: scale the block so its biggest weight is ±1, snap every weight to the nearest of the sixteen NF4 levels, and store the 4-bit index plus one constant per block. The sixteen levels sit at the quantiles of a normal distribution — dense near zero where weights crowd — which is the entire NF4 idea from figure 3.
- cthe block's absmax — the one number that survives at full precision
- NF4[·]the fixed table of sixteen normal-quantile levels, shared by every block in every model
§3 · the bit ledger — what double quantization saves
plain: 4 + 3264 = 4.5 bits/param double: 4 + 864 + 3264·256 ≈ 4.127 bits/param
read aloud: each weight costs its 4 bits plus its share of the block's constant; quantizing the constants themselves to 8-bit (in super-blocks of 256) cuts the bookkeeping from half a bit to an eighth of a bit per parameter.
part four
What we take from it
applied · our reading
The default hardware recipe
- Start every fine-tune as QLoRA. NF4 base, adapters on all linear layers, rank 8–16, BF16 compute. Escalate to full precision only when an eval — not a feeling — shows the 4-bit run leaving quality on the table. For most domain work, it never does.
- Sovereignty runs through this paper. A regulated-domain model that must train on-premise no longer needs a rack: one workstation GPU fine-tunes a 33B–65B base. The hardware excuse for shipping data to someone else’s cloud is gone.
- Adapters compose with the whole arc. The frozen 4-bit base plus swappable LoRA adapters is an architecture: one base model, one adapter per behavior or client, hot-swapped at serve time — and the same trick runs DPO (entry 16) on the pairs your review queue emits.
source
Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, Luke Zettlemoyer. QLoRA: Efficient Finetuning of Quantized LLMs. arXiv:2305.14314. Figures on this page are our own; the memory figures, NF4/double-quantization design, fidelity results and Guanaco numbers are the paper’s, and any other plotted values are illustrative.
← back to the knowledge base · ← entry 16 · DPO · entry 18 · Tulu 3 →
attention.sh — a division of Jinacode Systems. Transformers,
fine-tuning, and sovereign LLMs.
we're hiring the curious — hello@attention.sh