$ attention.sh

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.

paper QLoRA: Efficient Finetuning of Quantized LLMs
authors Dettmers, Pagnoni, Holtzman, Zettlemoyer — University of Washington
source arXiv:2305.14314
why we read it it is the 2025-default starting point for applied fine-tuning — QLoRA plus the SFT→DPO recipe from entries 15–16 is the whole affordable pipeline, and its data findings independently re-prove LIMA

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.

model4-bit memoryVicuna Elonote
Guanaco 65B41 GB102299.3% of ChatGPT, 24h on one GPU
Guanaco 33B21 GB992
Guanaco 13B10 GB916
Guanaco 7B5 GB879fits 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
plug in → a block with absmax c = 0.8; take w = 0.31. normalize: 0.31/0.8 = 0.3875 → nearest NF4 levels are 0.3379 and 0.4407 → snap to 0.3379 → dequantized ŵ = 0.8 · 0.3379 ≈ 0.270. rounding error 0.04 — real, and the fine-tune's adapters learn around exactly this kind of noise.

§3 · the bit ledger — what double quantization saves

plain:   4 + 3264 = 4.5 bits/param      double:   4 + 864 + 3264·2564.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.

plug in → 65B parameters × 0.373 saved bits ÷ 8 ≈ 3.0GB — figure 5's "saved by double quantization alone", derived. and the headline: 65e9 × 4.127/8 ≈ 33.5GB resting weight memory, which is how a 780GB training job fits a 48GB card once adapters and paged optimizer states are the only other tenants.

part four

What we take from it

applied · our reading

The default hardware recipe

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