Advanced level · Module 4: Parameter-Efficient Fine-Tuning · Lesson 2 of 3
Applying PEFT with Hugging Face
Learners wrap a model with a PEFT configuration, check how many parameters are trainable, and train it with the same trainer as before.
In this lesson you will
- Apply a PEFT configuration to a model
- Train and save a PEFT adapter
Key concepts
LoraConfigget_peft_modelprint_trainable_parametersadapter savingtraining with TRL
The lesson
The PEFT library (Apache-2.0) wraps a model: model = get_peft_model(base_model, LoraConfig(...)). model.print_trainable_parameters() shows how small the trainable part is.
Training then proceeds as usual, for example with TRL's SFTTrainer, which also accepts a PEFT configuration directly.
Saving writes only the adapter (a few megabytes), which can be loaded on top of the same base model later.
Step by step
- Wrap SmolLM2-135M-Instruct with a LoRA configuration.
- Print the trainable parameter share.
- Train on the instruction dataset.
- Save the adapter and check its file size.
Practice activity
Train and save a LoRA adapter for the narrow task.
Expected result: A trained adapter with its parameter share and size recorded.
Check your understanding
-
What does print_trainable_parameters show?
Show answer
How many parameters will be trained compared with the total.
-
What is saved after PEFT training?
Show answer
Only the small adapter weights.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.