Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 7 min read How-to mediumAdept

Using LoRA for Efficient Stable Diffusion Fine-Tuning

LoRA freezes pretrained weights and trains small rank-decomposition matrices, and diffusers now supports applying it to Stable Diffusion's cross-attention layers for both full fine-tuning and Dreambooth. Training fits in 11 GB of VRAM (a 2080 Ti) without 8-bit optimizers, uses a much higher learning rate (1e-4 vs ~1e-6), and produces ~3 MB weight files, roughly 1000x smaller than the UNet. A walkthrough covers the training script on a Pokémon dataset, looking up the base model from Hub metadata, and loading LoRA weights at inference with load_attn_procs. LoRA is also compared with Textual Inversion and Pivotal Tuning.

Assumes: Stable Diffusion basicsPyTorchfine-tuning neural networks

Related posts

  • (LoRA) Fine-Tuning FLUX.1-dev on Consumer Hardware

    Hugging Face hardMaster

    FLUX.1-dev can be LoRA fine-tuned on a single consumer GPU by combining QLoRA (4-bit NF4 base transformer via bitsandbytes), 8-bit AdamW, gradient checkpointing, cached VAE latents and precomputed CLIP/T5 text embeddings, so that only the quantized transformer plus adapters sit in GPU memory. On an RTX 4090, a rank-4 LoRA at 512x768 peaked around 9 GB VRAM, compared with 26 GB for BF16 LoRA and an estimated ~120 GB for full fine-tuning, and 700 steps took about 41 minutes to learn Alphonse Mucha's style. The guide includes the diffusers training script settings, an embedding precompute script, FP8 training with torchao for faster runs on compatible hardware, and options for loading or merging the trained adapters at inference.

  • Training Stable Diffusion with Dreambooth using Diffusers

    Hugging Face mediumAdept

    Dreambooth fine-tuning of Stable Diffusion overfits quickly, so learning rate and step count must be tuned together. Experiments on 2x A100s found low learning rates (2e-6 for objects at ~400 steps, 1e-6 to 2e-6 with 800-1200 steps for faces) work best. Prior preservation matters mainly for faces, and the DDIM scheduler with ~100 inference steps cleans up noise from overfit models. Fine-tuning the text encoder alongside the UNet gave the biggest quality gain but needs ~24 GB of GPU memory; 8-bit Adam, fp16 or gradient accumulation bring training down to 16 GB.

  • LoRA training scripts of the world, unite!

    Hugging Face hardMaster

    Combining Pivotal Tuning (textual inversion of newly inserted tokens, then LoRA fine-tuning) with the adaptive Prodigy optimizer produces strong SDXL Dreambooth LoRA results, and both are now available in a diffusers training script. The guide covers the relevant flags and recommended values: stopping textual inversion halfway through training, Prodigy with learning_rate=1.0 and bias correction, and separate text encoder and UNet learning rates. It also covers custom BLIP captions, Min-SNR gamma of 5.0, image repeats, prior preservation loss and dataset curation tips for faces and objects. Experiments on a 31-image Huggy mascot dataset compare batch sizes, optimizers and text encoder training modes.

  • Goodbye cold boot - how we made LoRA Inference 300% faster

    Hugging Face mediumAdept

    Hugging Face's Inference API now keeps Stable Diffusion base models warm and swaps LoRA adapters per request, so hundreds of distinct LoRAs share a few GPUs instead of each getting a dedicated deployment. Requests carrying a base_model attribute and a lora tag are routed to a shared backend that uses Diffusers' load_lora_weights/fuse_lora and unfuse_lora/unload_lora_weights to swap adapters in 2-4 seconds. Warm-up dropped from 25s to 3s and cold request latency from 35s to 13s, with hundreds of LoRAs served on fewer than 5 A10G GPUs. Fusing weights cuts inference time by 30%, and batched LoRA inference was skipped because diffusion throughput rose only 25% at batch size 8 while latency grew sixfold.

  • Diffusers welcomes Stable Diffusion 3.5 Large

    Hugging Face mediumAdept

    Stable Diffusion 3.5 Large (8B) and a timestep-distilled Turbo variant are now usable in Diffusers. The architecture matches SD3 Medium except for QK normalization and dual attention layers in the MMDiT blocks. Code covers bf16 inference, few-step (4-8 step) Turbo generation without classifier-free guidance, NF4 quantization via bitsandbytes with CPU offload for consumer GPUs, and single-file checkpoint loading. LoRA fine-tuning on 24GB GPUs works with the existing SD3 DreamBooth script, combined with peft's k-bit training preparation.

The quest for software engineering knowledge.

Look:
Layout: