Skip to main content

Overview

Stable Diffusion XL (SDXL) is Stability AI’s flagship text-to-image model, offering exceptional quality and versatility. It’s the most widely-used and well-supported diffusion model, with excellent community support and thousands of fine-tuned variants available.
SDXL is the recommended starting point for most users due to its excellent balance of quality, speed, and VRAM requirements.

Model Variants

SDXL Base 1.0

The standard SDXL model optimized for high-quality image generation.
Key Features:
  • Resolution: Native 1024x1024 (can generate up to 2048x2048)
  • Quality: Excellent detail and composition
  • VRAM: 8GB minimum, 12GB recommended
  • Speed: ~4 seconds per image (RTX 4090, 50 steps)

SDXL Turbo

A distilled variant optimized for ultra-fast generation (1-4 steps).
Key Features:
  • Speed: 3-4x faster than base (1-4 inference steps)
  • Quality: Very good (slightly below base)
  • VRAM: 8GB minimum
  • Use Case: Rapid prototyping, real-time applications

SDXL Refiner

A specialized model for refining SDXL base outputs (optional).
The refiner is optional and typically used for professional workflows. Most users don’t need it.

Loading SDXL with HyperGen

Basic Loading

Optimized Loading

For better performance and lower VRAM usage:
Using torch_dtype="float16" reduces VRAM usage by ~50% with minimal quality loss.

Memory-Optimized Loading

For GPUs with 8GB VRAM:

Training LoRAs with SDXL

SDXL is the most popular model for LoRA training due to its excellent quality and wide compatibility.

Basic LoRA Training

For fast iteration and testing:
Settings:
  • Lower rank (8) for faster training
  • Fewer steps for quick results
  • Works on 8GB VRAM
  • Training time: ~10 minutes (50 images)

Training for Different Use Cases

Learning an artistic style or aesthetic:
Dataset:
  • 50-200 images in the target style
  • Consistent aesthetic across all images
  • Captions describing content, not style
  • High resolution (1024x1024+)
Example caption:
(Describe what you see, not “in artistic style”)
Learning a specific person, character, or object:
Dataset:
  • 20-100 images of the subject
  • Variety of poses, angles, and expressions
  • Different lighting conditions
  • Detailed captions
Example caption:
Learning a new concept or composition style:
Dataset:
  • 30-150 images demonstrating the concept
  • Varied examples showing different aspects
  • Captions focusing on composition and elements

Inference Parameters

Basic Generation

Parameter Guide

str
required
Text description of the desired image
str
default:""
What to avoid in the generated imageCommon negative prompts:
int
default:50
Number of denoising steps
  • 20-30: Fast, good quality
  • 40-50: Better quality (recommended)
  • 50-100: Highest quality, diminishing returns
float
default:7.5
How closely to follow the prompt
  • 5-6: More creative, less literal
  • 7-8: Balanced (recommended)
  • 9-12: Very literal, can be oversaturated
int
default:1024
Image height in pixels (must be multiple of 8)
  • 1024: Standard (recommended)
  • 768: Faster, lower quality
  • 1536-2048: Higher detail, slower
int
default:1024
Image width in pixels (must be multiple of 8)

Speed Priority

Generation time: ~1.5s

Balanced

Generation time: ~3.5s

Quality Priority

Generation time: ~4.5s

Advanced Generation

Performance Benchmarks

Generation Performance

Based on NVIDIA RTX 4090, 1024x1024 resolution:

Training Performance

LoRA training on RTX 4090, 50 images:

VRAM Requirements

1

8GB VRAM

GPUs: RTX 3060 12GB, RTX 2080 TiCapabilities:
  • Generation: 1024x1024 
  • Training: Rank 8-16 
  • Batch size: 1 
2

12GB VRAM

GPUs: RTX 3060, RTX 4070 TiCapabilities:
  • Generation: 1024x1024 
  • Training: Rank 16-32 
  • Batch size: 1-2 
3

16GB+ VRAM

GPUs: RTX 4080, RTX 4090, A100Capabilities:
  • Generation: Up to 2048x2048 
  • Training: Rank 32-64 
  • Batch size: 2-4 

Best Practices

Prompt Engineering

Good prompt structure:
Examples: Good:
L Poor:

Training Best Practices

1

Dataset Quality

Prepare high-quality training data: Do:
  • Use high-resolution images (1024x1024 or higher)
  • Ensure consistent quality
  • Include variety (poses, angles, lighting)
  • Write detailed captions
  • 20-150 images is usually sufficient
L Don’t:
  • Use low-resolution or blurry images
  • Include duplicates
  • Mix different subjects in same dataset
  • Leave images uncaptioned
2

Caption Writing

Write effective captions: Good caption:
L Poor caption:
Tips:
  • Describe what you see objectively
  • Include composition, lighting, colors
  • Be consistent in style
  • Don’t describe what you want to learn
3

Hyperparameter Selection

Choose appropriate hyperparameters:Start with defaults:
Adjust based on results:
  • Underfitting? Increase steps, rank, or learning rate
  • Overfitting? Decrease steps, add more data
  • Out of memory? Reduce rank or batch size
4

Checkpoint Management

Save and test checkpoints:
Test checkpoints at 500, 1000, 1500, and 2000 steps to find the best one.

Memory Optimization

Reduce VAE memory usage:
  • Reduces VRAM by ~10%
  • Minimal performance impact
  • Recommended for all users
Reduce attention memory usage:
  • Reduces VRAM by ~15-20%
  • Small performance impact (~5% slower)
  • Useful for 8GB GPUs
Offload to CPU when not in use:
  • Reduces VRAM by ~40-50%
  • Significant performance impact (~20% slower)
  • Use only if necessary
Use float16 instead of float32:
  • Reduces VRAM by ~50%
  • Minimal quality impact
  • Strongly recommended

Troubleshooting

Common Issues

Error: CUDA out of memory during image generationSolutions:
  1. Enable memory optimizations:
  2. Reduce image resolution:
  3. Use float16 precision:
  4. Generate fewer images:
Error: CUDA out of memory during LoRA trainingSolutions:
  1. Reduce LoRA rank:
  2. Use batch size 1:
  3. Use gradient accumulation:
  4. Use float16 precision:
Issue: Generated images are low quality or don’t match promptSolutions:
  1. Increase inference steps:
  2. Adjust guidance scale:
  3. Improve prompt:
  4. Use negative prompts:
Issue: Trained LoRA doesn’t work wellSolutions:
  1. Increase training steps:
  2. Improve dataset:
    • Add more images
    • Improve caption quality
    • Use higher resolution images
    • Add more variety
  3. Adjust hyperparameters:
  4. Check earlier checkpoints:
    • Model might be overfitting
    • Try checkpoint-500 or checkpoint-1000
Issue: Image generation is very slowSolutions:
  1. Reduce inference steps:
  2. Use SDXL Turbo:
  3. Reduce resolution:
  4. Disable CPU offload if enabled:

Example Workflows

Basic Image Generation

LoRA Training Pipeline

Batch Generation

Community Fine-Tunes

SDXL has thousands of community fine-tunes available. Here are some popular ones:
Browse HuggingFace’s SDXL models for more options.

Next Steps

Training Guide

Complete LoRA training documentation

Dataset Preparation

Learn how to prepare training data

Serving SDXL

Deploy SDXL with the API

Supported Models

View all compatible models

Additional Resources