Parameter-Efficient Fine-Tuning using 🤗 PEFT
Hugging Face's PEFT library brings parameter-efficient fine-tuning methods (LoRA, Prefix Tuning, Prompt Tuning, P-Tuning) to Transformers and Accelerate. Most pretrained weights stay frozen and only a small set of extra parameters is trained, which gives performance comparable to full fine-tuning at a fraction of the compute and storage cost. A LoRA config on mt0-large trains about 0.19% of the parameters, and the saved adapters are only a few MB (19MB for T0_3B) instead of 40GB per-task checkpoints. Example use cases include tuning T0_3B on 11GB consumer GPUs with DeepSpeed offload, INT8 tuning of OPT-6.7b in Colab with bitsandbytes, and Stable Diffusion Dreambooth, plus code for training, saving and loading adapters.
Related posts
- Fine-tuning 20B LLMs with RLHF on a 24GB consumer GPU
Hugging Face hardMasterCombining trl with peft and bitsandbytes makes RLHF fine-tuning of a 20B-parameter LLM feasible on a single 24GB consumer GPU. The approach loads the active model in 8-bit using LLM.int8(), trains only small LoRA adapters to shrink optimizer state, and obtains reference logits for PPO from the same model by disabling the adapters, so no second model copy is needed. Memory rules of thumb are 4/2/1 GB per billion parameters in fp32/fp16/int8, plus 8 bytes per parameter for AdamW. A gpt-neox-20b model was fine-tuned on IMDB, its adapters were merged, and it was then RL-tuned to generate positive reviews. The main cost is speed, since adapters make forward and backward passes roughly twice as slow.
- Beyond LoRA: Can you beat the most popular fine-tuning technique?
Hugging Face mediumAdeptLoRA accounts for roughly 95–98% of PEFT usage across Hugging Face Hub model cards and image-generation checkpoints, but controlled benchmarks in the PEFT library show it is often not the best tradeoff. On a MetaMathQA/GSM8K fine-tune of Llama-3.2-3B, rs-LoRA (53.2%, 22.6 GB) sits on the accuracy–memory Pareto frontier alongside BEFT (32.9%, 20.2 GB) and Lily (54.9%, 25.6 GB), while vanilla LoRA (48.1%, 22.5 GB) is dominated. On a FLUX.2-klein-base-4B image concept-learning benchmark, OFT strictly beats LoRA on both DINO similarity and VRAM. To work around downstream tools like vLLM that only load LoRA, PEFT can now convert some other adapters to LoRA with near-identical scores, so switching techniques is mostly a matter of changing one config.
- What is LLM fine-tuning?
Modal mediumAdept
Fine-tuning adjusts a pretrained LLM's weights for a specific task or domain, often matching larger models' quality at lower cost and latency. One cited example puts a fine-tuned Llama 7B at roughly 50x cheaper per token than GPT-3.5. The guide compares where to fine-tune (OpenAI, Predibase, Modal, Colab, SageMaker) and which frameworks to use (HuggingFace transformers, TRL, Axolotl). It then walks through choosing a base model, formatting and tokenizing an instruction dataset with optional custom special tokens, training, and efficiency techniques such as LoRA-based PEFT and quantization.
- LoRA Explained: Faster, More Efficient Fine-Tuning with Docker
Docker mediumAdeptGemma 3 270M can be specialized into a compact PII-masking assistant using LoRA, which freezes the base weights and trains only small low-rank adapters, cutting compute and memory needs while avoiding catastrophic forgetting. The walkthrough covers formatting supervised examples with the model's chat template so training data matches inference input, configuring PEFT adapters (r=16, alpha=32 on q_proj/v_proj), training with TRL's SFTConfig via Unsloth, and merging adapters into a standalone 16-bit checkpoint. The merged model can then be packaged and shared through Docker Model Runner and Docker Hub.
- Make LLM Fine-tuning 2x faster with Unsloth and 🤗 TRL
Hugging Face mediumAdeptUnsloth speeds up QLoRA fine-tuning of Llama and Mistral-family models by rewriting PyTorch modules as Triton kernels with manually derived backpropagation. Because no approximations are made, it claims 0% accuracy loss relative to standard QLoRA. Across 59 benchmark runs on A100 and T4 GPUs, it ran 1.5–3.9x faster than Hugging Face transformers and used up to 74% less VRAM. Code examples show loading pre-quantized 4-bit models with FastLanguageModel, attaching LoRA adapters, and training with TRL's SFTTrainer or DPOTrainer.