Skip to content
HasanAI
Log in Sign up

πŸ”§ PEFT: Parameter-Efficient Fine-Tuning

Adapters, prefix and prompt tuning, BitFit, (IA)^3 and LoRA - one frozen model, six ways in
Ten Landmark Papers Intermediate
Contents

    PEFT: Parameter-Efficient Fine-Tuning

    LoRA is the best-known way to adapt a large model without training all of it, but it is one of a family. Every member makes the same trade. Freeze the pre-trained weights, add or unfreeze a small set of parameters, and train only those. They differ in where the new parameters go:

    Method Paper What is trained
    Adapters Houlsby et al., 2019 small bottleneck MLPs inserted after sub-layers
    BitFit Ben Zaken et al., 2022 only the bias terms
    Prefix tuning Li & Liang, 2021 learned key/value vectors prepended in every layer
    Prompt tuning Lester et al., 2021 learned input embeddings prepended to the input only
    LoRA Hu et al., 2021 low-rank updates to weight matrices
    (IA)Β³ Liu et al., 2022 vectors that rescale keys, values and FFN activations

    This page implements all six, plus head-only and full fine-tuning, inside one small transformer. Each method adapts the same pre-trained model to the same new task, and the page measures how many parameters each trains and how well each does. It also counts what each would cost on a 7B-parameter model.

    helpers ready

    1. One transformer with every insertion point

    The model treats an 8Γ—8 handwritten digit as a sequence of 8 tokens, one per pixel row, plus a [CLS] token whose final state is classified. It has two transformer blocks, $d = 48$, and 4 heads.

    The block below is an ordinary pre-LN transformer block. The only unusual thing is that it carries the hooks each PEFT method needs, and every hook is off by default.

    backbone parameters: 38,928

    2. Pre-train, then adapt to classes it has never seen

    The backbone is pre-trained on digits 0 to 4. The new task is digits 5 to 9, with only 150 labelled images. Every method gets a fresh 5-way head, and otherwise trains only its own parameters.

    ==============================================================================
      PRE-TRAINING ON DIGITS 0-4
    ==============================================================================
      accuracy on 0-4 (train): 1.000
    ==============================================================================
      EIGHT WAYS TO ADAPT
    ==============================================================================
      head only          new non-head params      0 ( 0.00% of backbone)   accuracy 0.835 Β± 0.002
      prompt tuning      new non-head params    288 ( 0.74% of backbone)   accuracy 0.842 Β± 0.020
      prefix tuning      new non-head params  1,152 ( 2.96% of backbone)   accuracy 0.872 Β± 0.005
      (IA)^3             new non-head params    384 ( 0.99% of backbone)   accuracy 0.923 Β± 0.009
      BitFit             new non-head params    960 ( 2.47% of backbone)   accuracy 0.879 Β± 0.008
      LoRA r=4 (q, v)    new non-head params  1,536 ( 3.95% of backbone)   accuracy 0.911 Β± 0.009
      adapters (m=8)     new non-head params  3,296 ( 8.47% of backbone)   accuracy 0.899 Β± 0.007
      full fine-tune     new non-head params 38,928 (100.00% of backbone)   accuracy 0.943 Β± 0.001
    
    Checks
    ------------------------------------------------------------------------------
      [PASS] LoRA, adapters and (IA)^3 start as exact no-ops (identical outputs before training)
      [PASS] every PEFT method beats training the head alone

    3. Reading the results

    • Head only leaves the backbone's features exactly as they were. They were learned for 0 to 4, so they are the floor.
    • Prompt tuning trains the fewest parameters, six input vectors. On a small model it is the weakest PEFT method. Lester et al. found the gap closes only as models grow, and above about 10B parameters prompt tuning matches full fine-tuning.
    • Prefix tuning reaches every layer, not just the input, and does better.
    • BitFit, (IA)Β³, LoRA and adapters change how the backbone transforms its input, inside every block. Measured against the gap between head-only and full fine-tuning, they recover between about 40% (BitFit) and 80% ((IA)Β³) of it. (IA)Β³ does best here with only 384 trainable numbers.

    The exact ranking on a toy problem should not be taken too seriously. The pattern that recurs at every scale is that methods which touch every layer beat methods which only touch the input.

    4. What each costs on a 7B model

    At scale the counts matter more than the toy accuracies. For a Llama-2-7B-shaped model ($d = 4096$, 32 layers, FFN width 11,008, 6.74B parameters):

    ==============================================================================
      TRAINABLE PARAMETERS ON A 7B-SHAPED MODEL
    ==============================================================================
      total parameters: 6,738,415,616 (6.74B)
    
      prompt tuning (20 tokens)                 81,920     0.00122%   fp16 file        0.2 MB
      (IA)^3 (k, v, ffn)                       614,400     0.00912%   fp16 file        1.2 MB
      LoRA r=8 on q, v                       4,194,304     0.06224%   fp16 file        8.4 MB
      prefix tuning (20 per layer)           5,242,880     0.07781%   fp16 file       10.5 MB
      LoRA r=8, all 7 linear layers         19,988,480     0.29663%   fp16 file       40.0 MB
      adapters (2 per layer, m=64)          33,820,672     0.50191%   fp16 file       67.6 MB
      full fine-tuning                   6,738,415,616   100.00000%   fp16 file   13,476.8 MB
    
      BitFit is not listed: Llama-style models have no bias terms to train.

    The same block, with each method's parameters dropped in where they live. The counts are for the 7B-shaped model.

    5. Choosing between them

    Trainable share (7B) Extra inference cost Notes
    Prompt tuning ~0.001% longer input weak below ~10B parameters
    Prefix tuning ~0.08% longer K/V unstable to train; usually reparameterised by an MLP
    (IA)Β³ ~0.01% none once merged into weights strong for few-shot
    LoRA 0.06% (q, v) – 0.3% (all) none once merged the default today
    Adapters ~0.5% extra layers in series the original PEFT method
    BitFit ~0.1% (models with biases) none Llama-style models have no biases

    LoRA became the default because it adds nothing at inference time, works at any scale, and stacks with 4-bit quantisation (QLoRA). The Hugging Face peft library implements all of the methods above behind one interface.

    Summary

    • Every PEFT method freezes the pre-trained model and trains a small set of parameters. They differ in where those parameters go: input (prompt), every layer's keys and values (prefix), per-channel scales ((IA)Β³), biases (BitFit), weight updates (LoRA), or new modules (adapters).
    • On the same frozen transformer, every method beat training the head alone. Methods that act inside every block recovered 40–80% of the gap to full fine-tuning with 1–8% of its parameters. Prompt tuning, which acts only at the input, was the weakest at this size.
    • LoRA, adapters and (IA)Β³ start as exact no-ops, so step 0 is the pre-trained model. This was verified.
    • At 7B scale, the trainable share ranges from about 0.001% (prompt tuning) to about 0.5% (adapters).