Master LoRA Training: The Ultimate Guide to Custom Stable Diffusion Models

8 min read

Make this article actionable

Send the article context into Vife Agent and turn it into a plan, checklist, or draft you can keep working on.

Open in Agent

In the rapidly evolving world of Generative AI, Stable Diffusion has democratized art creation. However, the real magic happens when you stop using generic models and start creating your own. Enter LoRA (Low-Rank Adaptation).

If you have ever wanted to insert yourself, a specific art style, or a unique product into an AI generator without retraining a massive model from scratch, this LoRA training tutorial is for you.

In this comprehensive guide, we will walk through exactly how to train LoRA models, the best practices for dataset preparation, and the specific settings you need to master in tools like Kohya_ss to achieve professional results.

What is LoRA and Why Should You Care?

Before we dive into the technical steps, it is crucial to understand what we are building.

Technically, LoRA stands for Low-Rank Adaptation. In the context of LoRA Stable Diffusion, think of a standard checkpoint model (like SD 1.5 or SDXL) as a massive encyclopedia of the world.

Prior to LoRA, if you wanted to teach the AI a new concept (like your face), you had to use a method called Dreambooth, which essentially rewrote the whole encyclopedia. This resulted in massive file sizes (2GB - 6GB) and required heavy GPU power.

LoRA, on the other hand, is like inserting a few sticky notes into that encyclopedia. It doesn't change the underlying model; it just adds a small layer of new information on top.

The benefits are massive:

  • File Size: LoRAs are tiny (typically 18MB to 144MB).
  • Speed: Training takes minutes to an hour, not days.
  • Flexibility: You can mix and match multiple LoRAs (e.g., a "Pixel Art" LoRA + a "Celebrity" LoRA).
Mid-read shortcut

Turn the useful parts into next steps

Vife Agent can convert this guide into a prioritized workflow with tasks, risks, and reusable prompts.

Create a brief

Prerequisites: What You Need

To follow this LoRA training tutorial, you will need a few things set up:

  1. Hardware: An NVIDIA GPU is highly recommended.
    • For SD 1.5 training: Minimum 6GB VRAM (8GB recommended).
    • For SDXL training: Minimum 12GB VRAM (24GB recommended).
  2. Software: We will use Kohya_ss, the industry-standard GUI for training. You can install it locally or use a cloud notebook (like Google Colab or RunPod) if your hardware isn't powerful enough.
  3. Base Model: You need a checkpoint to train against (e.g., runwayml/stable-diffusion-v1-5 or stabilityai/stable-diffusion-xl-base-1.0).

Step 1: The Art of Dataset Preparation

If you take one thing away from this guide, let it be this: Your model is only as good as your data. 90% of training failures happen because of poor dataset preparation, not bad settings.

Image Selection

How many images do you need? Less than you think, but quality matters.

  • For a Character/Person: 15–25 high-quality images.
  • For a Style: 20–50 images that distinctly represent that style.
  • For an Object/Concept: 15–30 images.

Critical Tips:

  • Variety is Key: If training a person, use different angles (close-up, full body, side profile), different lighting, and different backgrounds. If you only provide selfies, the AI will only generate selfies.
  • Consistency: If training a style, ensure the style is consistent across all images.
  • Resolution: Crop your images to 512x512 (for SD 1.5) or 1024x1024 (for SDXL). While Kohya can handle bucketing (different aspect ratios), uniform crops often yield more stable results for beginners.

Captioning Your Images

To teach the AI what is in your image, you need to caption it. You can do this manually or use auto-captioning tools within Kohya_ss (using BLIP or WD14 Tagger).

The Golden Rule of Captioning: If you want the LoRA to absorb a feature, do not caption it. If you want the LoRA to be flexible about a feature, caption it.

Example: You are training a LoRA on a character named "Jane" who has blue hair.

  • Scenario A (Caption: "Jane, woman"): Since you didn't mention the blue hair in the caption, the AI assumes "Jane" implies blue hair. The LoRA will always generate her with blue hair.
  • Scenario B (Caption: "Jane, woman, blue hair"): Since you explicitly described the hair, the AI learns that "Jane" is the face structure, but the hair color is a variable. You can later prompt "Jane with red hair" more easily.

Step 2: Folder Structure

Kohya_ss requires a very specific folder structure to understand your training parameters automatically. Create a main folder (e.g., lora_training) and inside it, create a folder named img.

Inside img, create a folder with this naming convention:

{Repeats}_{Instance Prompt} {Class Prompt}

Example: 10_sks woman

  • 10 (Repeats): The trainer will look at each image in this folder 10 times per epoch.
  • sks (Instance Token): A unique trigger word. "sks" is a classic, but you can use anything unique like "ohwx".
  • woman (Class Token): A general description of what the thing is.

So, if you have 20 images and set repeats to 10, one epoch equals 200 steps (20 * 10).

Step 3: Configuring Kohya_ss for Success

Once you launch the Kohya_ss GUI, navigate to the LoRA tab. Here is a breakdown of the critical settings for a standard SD 1.5 training run.

Source Model

Select the path to your base model. Use the standard SD 1.5 pruned checkpoint for maximum compatibility. Do not train on top of heavily stylized custom models unless you know exactly what you are doing.

Folders

Point the Image folder to the parent directory of your 10_sks woman folder (not the numbered folder itself).

Training Parameters

This is where the "black magic" of how to train LoRA happens. Here are the recommended "safe" settings for a beginner:

  • Train Batch Size: 1 (Use 2 or higher only if you have a powerful GPU like a 3090/4090).
  • Epochs: 2 to 4. (It is better to overtrain slightly and choose an earlier save state).
  • Mixed Precision: fp16 (Save VRAM).
  • Save Precision: fp16.
  • Learning Rate: 0.0001 (1e-4). This is the standard speed limit for learning.
  • LR Scheduler: constant or cosine.
  • Optimizer: AdamW8bit (Great balance of speed and memory efficiency).

Network Rank (Dimension) and Alpha

These two settings determine the "capacity" of your LoRA model.

  • Network Rank (Dim): 128 is the modern standard.
    • Low (8-32): Good for simple styles, very small file size.
    • High (128-256): Good for complex faces and details.
  • Network Alpha: Set this to roughly half of your Rank, or equal to it.
    • Recommendation: Rank 128 / Alpha 128 (or Alpha 64).
    • A lower Alpha makes the training more subtle; a higher Alpha makes it learn faster and more aggressively.

Step 4: The Training Process

Click "Start Training". Watch your console (terminal).

As the training progresses, you will see a "Loss" value.

  • High Loss: The AI is confused.
  • Low Loss: The AI is learning.

However, do not obsess over the number. The lowest loss isn't always the best; sometimes it means the AI has memorized your images (overfitting) rather than learning the concept.

Pro Tip: Set Kohya to save a backup of the model every epoch. This allows you to test the model at different stages of "cookedness." The version from Epoch 2 might be flexible and creative, while Epoch 10 might be rigid and burnt.

Step 5: Testing and Inference

Once training is complete, you will find .safetensors files in your output folder.

  1. Move the file to your WebUI folder: stable-diffusion-webui/models/Lora.
  2. Open Automatic1111 or ComfyUI.
  3. Construct a prompt: Photo of sks woman, walking in a park, <lora:my_model_name:1>.

Troubleshooting Your Results

  • The LoRA does nothing: Did you use the trigger word (sks)? Is the weight set to 1?
  • The images look fried/distorted: The model is overtrained. Try lowering the weight to 0.7 or use an earlier epoch save.
  • The face doesn't look like the subject: You might need more repeats or a higher network rank. Alternatively, your dataset might lack close-ups.

Advanced Tips for Power Users

1. Regularization Images

If you are training a concept like "dog" and you don't want the model to forget what a normal dog looks like, you use Regularization Images. These are generic images of the class provided to the trainer so it learns the difference between your specific dog and dogs in general. For LoRA, this is optional but recommended for versatility.

2. Block Weighting

Sometimes you want a LoRA to affect the style (background/colors) but not the composition. Advanced users can use "Block Weighting" during inference to apply the LoRA only to specific layers of the neural network.

3. SDXL Training

Training LoRA Stable Diffusion for SDXL requires significantly more VRAM. However, the process is nearly identical. The main difference is the resolution (1024x1024) and the need for a lower learning rate (try 4e-7 for SDXL).

Conclusion

Learning how to train LoRA models is a superpower in the world of AI art. It bridges the gap between prompting random seeds and achieving consistent, professional artistic control.

The first time you see your custom character appear perfectly in a generated image is a moment of pure delight. Remember, the settings provided here are a starting point. Every dataset is unique, so do not be afraid to experiment with Learning Rates and Network Ranks.

Ready to start? Gather your images, fire up Kohya_ss, and begin building your own custom AI library today.