Skip to main content
TRL supports PEFT (Parameter-Efficient Fine-Tuning) methods for memory-efficient model training. PEFT enables fine-tuning large language models by training only a small number of additional parameters while keeping the base model frozen, significantly reducing computational costs and memory requirements.

Installation

For QLoRA support (4-bit and 8-bit quantization), also install:

Quick start

All TRL trainers support PEFT through the peft_config argument. The simplest way to enable PEFT is via the CLI with the --use_peft flag:
Alternatively, pass a PEFT config directly in Python:

Three ways to configure PEFT

Use the --use_peft flag with TRL scripts. Best for quick experiments and standard LoRA configurations.
Available CLI flags:
  • --use_peft — enable PEFT
  • --lora_r — LoRA rank (default: 16)
  • --lora_alpha — LoRA alpha (default: 32)
  • --lora_dropout — LoRA dropout (default: 0.05)
  • --lora_target_modules — target modules (space-separated)
  • --lora_modules_to_save — additional modules to train
  • --use_rslora — enable Rank-Stabilized LoRA
  • --use_dora — enable Weight-Decomposed LoRA (DoRA)
  • --load_in_4bit — enable 4-bit quantization (QLoRA)
  • --load_in_8bit — enable 8-bit quantization
Apply PEFT to the model before passing it to the trainer. Useful for custom architectures or complex setups.

Using ModelConfig and get_peft_config

For script-based workflows, TRL provides ModelConfig and the helper functions get_peft_config and get_quantization_config to build PEFT and quantization configs directly from CLI arguments.
get_peft_config reads the following ModelConfig fields:

get_kbit_device_map

get_kbit_device_map() returns a device map appropriate for k-bit (4-bit or 8-bit) quantized models in multi-GPU environments. Returns {"": local_process_index} when a GPU is available, or None when running on CPU.
Always pass device_map=get_kbit_device_map() when using 4-bit or 8-bit quantization in multi-GPU setups. This ensures each process loads its shard onto the correct GPU.

PEFT with different trainers

Learning rate considerations

When using LoRA or other PEFT methods, use a higher learning rate (approximately 10x) compared to full fine-tuning. PEFT methods train only a small fraction of parameters, requiring a larger learning rate to achieve comparable updates.

QLoRA: quantized low-rank adaptation

QLoRA combines 4-bit quantization with LoRA to enable fine-tuning of very large models on consumer hardware. This can reduce memory requirements by up to 4x compared to standard LoRA.
1

Install bitsandbytes

2

Load the model in 4-bit

3

Attach a LoRA adapter and train

The equivalent via CLI:

BitsAndBytesConfig parameters

8-bit quantization

For slightly higher precision at reduced memory savings:

LoRA configuration reference

Target module selection

Prompt tuning

Prompt tuning learns soft prompts (continuous embeddings) prepended to the input while keeping the entire model frozen. It is particularly parameter-efficient for large models.

Saving and loading PEFT models

Pushing to Hub

Multi-GPU training

PEFT works with TRL’s multi-GPU support through Accelerate:
For QLoRA across multiple GPUs, the quantized base model is automatically sharded:

Resources

SFT with LoRA/QLoRA notebook

Complete working example with both LoRA and QLoRA.

PEFT documentation

Official PEFT library documentation.

LoRA paper

Original LoRA methodology and results.

QLoRA paper

Efficient finetuning of quantized language models.