Topic 3 of 5 · 5 min read
PEFT, TRL, Unsloth and Axolotl
Goal: Read a PEFT or Axolotl config and say which layers are trained, at what rank, and what files the run will save.
PEFT defines the adapter, TRL runs the training loop, and Unsloth and Axolotl wrap both so you write less code; learn what each layer does and you can read any LoRA config.
Check yourself · 1 of 3
In a PEFT LoraConfig, what does target_modules control?
Why it matters
Most LoRA problems are config problems: the wrong layers adapted, the wrong rank, the wrong base model, or a file saved where you did not expect it. If you can read the config, you can tell what a run will do before you spend GPU hours on it.
The tools
- PEFT (Hugging Face) holds the adapter methods.
LoraConfigsays which modules to adapt and how big the adapters are.get_peft_modelwraps a model with them, andsave_pretrainedwrites the adapter. - TRL (Hugging Face) provides trainers such as
SFTTrainer. You hand it a model, a dataset and a PEFT config, and it runs the loop. - Unsloth is a library with optimized kernels and ready notebooks for common open models. It aims for faster tuning and lower memory with the same adapter format.
- Axolotl is driven by a YAML file. You list the base model, dataset, adapter settings and hyperparameters, then launch it from the command line. It is a good fit when you want runs that are reproducible from one file.
The settings to read first
- Base model. The exact checkpoint the adapter belongs to.
randlora_alpha. Capacity and scale, from the last topic.target_modules. Which layers get adapters. Attention only (q_proj,v_proj) is the smallest choice. Addingk_proj,o_projand the MLP projections (gate_proj,up_proj,down_proj) trains more and usually helps. Many tools can also adapt all linear layers.use_dora. DoRA splits each weight into magnitude and direction and adapts both. PEFT exposes it as one flag. It costs some speed.- Quantization. A 4-bit load makes it QLoRA.
What the run saves
An adapter run saves adapter_config.json, which records the base model name and the settings, and adapter_model.safetensors, the trained weights. It does not save a full model unless you merge.
Before and after
Weak: reading only the learning rate and epochs in a config. Better: read this first.
base_model: meta-llama/Llama-3.1-8B
load_in_4bit: true
adapter: qlora
lora_r: 16
lora_alpha: 32
lora_target_modules: [q_proj, k_proj, v_proj, o_proj]
output_dir: ./out/support-v1
This is QLoRA at rank 16 on the four attention projections of an 8B base. It saves an adapter into ./out/support-v1, not a full model.
What goes wrong
- Wrong module names. Names differ between architectures, and a typo can adapt nothing or raise an error.
- Mixing up the output. Teams ship the adapter file expecting a standalone model.
- Library version drift. Pin PEFT, TRL and Transformers versions with the run so it can be repeated.
Examples
Reading a PEFT config
LoraConfig(
r=32,
lora_alpha=64,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"],
lora_dropout=0.05,
use_dora=True,
task_type="CAUSAL_LM",
)
Rank 32, scale 2, every attention and MLP projection adapted, DoRA on. This trains many times more parameters than a q_proj/v_proj run at rank 8, and DoRA makes each step a bit slower.
Choosing a tool
A solo engineer wants a quick first tune of an open model on a free notebook GPU and picks Unsloth for its memory savings. A team that must repeat the same run next month stores an Axolotl YAML in the repo. Someone writing a custom training loop uses PEFT directly with their own trainer.
Key points
- PEFT defines and saves adapters, while TRL, Unsloth and Axolotl run the training around it.
- target_modules decides which layers are trained, and MLP projections add capacity beyond attention-only.
- A 4-bit load plus a LoRA adapter is QLoRA; use_dora switches to the DoRA variant in PEFT.
- A run saves adapter_config.json and adapter_model.safetensors, not a full model, unless you merge.
- Pin library versions and record the base model name so a run can be reproduced.
Common mistakes
- Reading only the learning rate and ignoring target_modules, so nobody notices only two projections are adapted.
- Treating the adapter output folder as a complete model and shipping it without the base.
- Copying a target_modules list from a different architecture and getting an error or an empty adapter.
- Letting library versions float between runs, which makes results hard to reproduce.
Check yourself · 2 of 3
A finished Axolotl run with adapter: lora leaves a folder with adapter_config.json and adapter_model.safetensors. What do you have?
Check yourself · 3 of 3
A config sets target_modules to [q_proj, v_proj] and you want the adapter to learn more. Which change adds trainable layers?
Practice items, not counted towards your mastery.
Start here
- LoRA: Low-Rank Adaptation of Large Language Models (opens in a new tab)PaperFree
The original method: frozen weights, low-rank update matrices and why no inference latency is added.
- QLoRA: Efficient Finetuning of Quantized LLMs (Dettmers et al.) (opens in a new tab)PaperFree
Four-bit NF4 base weights, double quantization and paged optimizers, with the single-GPU memory results.
- PEFT documentation (Hugging Face) (opens in a new tab)DocsFree
LoraConfig fields, target modules, DoRA, merging and saving adapters.
More for this topic
- Axolotl documentation (opens in a new tab)DocsFree
YAML-config tuning for LoRA and QLoRA, including dataset formats and adapter options.
- DoRA: Weight-Decomposed Low-Rank Adaptation (opens in a new tab)PaperFree
The weight-decomposed variant that PEFT exposes as use_dora.