AI Hints
Home›Fine-Tuning LLMs Tutorial›Beyond LoRA: PEFT, Distillation and Prompting
Fine-Tuning LLMs · Lesson 94 of 120

Other PEFT Methods

Beyond LoRA.

⏱ 2 min read▶ Video at 2:23:03🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

LoRA is the most popular way to fine-tune efficiently. But it's not the only one. The PEFT library has several other methods. Let's meet the main ones.

  • LoRA is the most popular
  • Not the only one
  • Meet the others

The PEFT family

DoRA splits each weight into a size, and a direction, and adapts both. It's often a little better than LoRA. IA three learns tiny scaling vectors, that multiply the activations. And prompt tuning learns a few virtual tokens, that are added in front of every input.

MethodWhat it learns
LoRAsmall matrices B·A per layer
DoRALoRA + a size per weight
IA3scaling vectors
Prompt tuninga few virtual tokens

Counting parameters

Let's compare their sizes. We build each config, wrap the same model, and count the trainable parameters. Use dora equals true turns LoRA into DoRA. Run it. LoRA and DoRA train about five million parameters. IA three trains fifty seven thousand. And prompt tuning, only eleven thousand. Fewer parameters means less to store, but usually less power to learn.

methods.pypython
from transformers import AutoModelForCausalLM
from peft import get_peft_model, LoraConfig, IA3Config, PromptTuningConfig

NAME = "HuggingFaceTB/SmolLM2-135M-Instruct"
configs = {
    "LoRA r=16":     LoraConfig(r=16, target_modules="all-linear", task_type="CAUSAL_LM"),
    "DoRA r=16":     LoraConfig(r=16, target_modules="all-linear", use_dora=True,
                                task_type="CAUSAL_LM"),
    "IA3":           IA3Config(task_type="CAUSAL_LM"),
    "Prompt tuning": PromptTuningConfig(num_virtual_tokens=20, task_type="CAUSAL_LM"),
}
for name, config in configs.items():
    model = get_peft_model(AutoModelForCausalLM.from_pretrained(NAME), config)
    trainable, total = model.get_nb_trainable_parameters()
    print(f"{name:14} {trainable:>10,} trainable  ({trainable / total:.3%})")
Output
LoRA r=16       4,884,480 trainable  (3.504%)
DoRA r=16       5,040,000 trainable  (3.611%)
IA3                57,600 trainable  (0.043%)
Prompt tuning      11,520 trainable  (0.009%)

Which should you use?

In practice, start with LoRA. It works well, and every tool supports it. Try DoRA if you want a little extra quality. And use IA three, or prompt tuning, only when storage is extremely tight, like thousands of adapters.

keyvalue
DefaultLoRA
A bit betterDoRA, use_dora=True
TinyIA3, prompt tuning
SupportLoRA works everywhere

Summary

Let's recap. DoRA improves LoRA a little. IA three, and prompt tuning, are tiny, but weaker. And LoRA is the best default. Next, distillation.

Key takeaways
  • LoRA: default
  • DoRA: a bit better
  • IA3, prompt tuning: tiny
Next up: Distillation — a big model teaches a small one