AI intermediate ⏱ 60 minutes

Stable Diffusion: Image Generation with Automatic1111 and ComfyUI

Self-hosted image generation. Setup AUTOMATIC1111, ComfyUI, and model management.

By homelabbing.io • 2025-12-17
#stable-diffusion#automatic1111#comfyui#image-generation#gpu

Generate stunning AI images in your homelab with Stable Diffusion. No cloud dependencies, no per-image costs, complete creative control - all running on your hardware.

What is Stable Diffusion?

Stable Diffusion is an open-source, deep learning text-to-image model that generates photo-realistic images from text descriptions. Unlike DALL-E or Midjourney which require cloud subscriptions, Stable Diffusion runs entirely on your hardware.

Key Capabilities:

  • Text-to-image generation
  • Image-to-image transformation
  • Inpainting and outpainting
  • Upscaling and enhancement
  • ControlNet for precise control
  • Custom model training (LoRAs, embeddings)
  • Unlimited generation with no costs

Why Self-Host:

  • Privacy: Images and prompts never leave your network
  • Cost: Zero per-image costs after hardware investment
  • Freedom: No content filters or restrictions
  • Customization: Install any model, extension, or modification
  • Speed: Local generation (2-10 seconds per image with GPU)

Hardware Requirements

Minimum Configuration

  • GPU: NVIDIA RTX 3060 (12GB VRAM) or equivalent
  • RAM: 16GB system memory
  • Storage: 50GB for models and generated images
  • CPU: Modern 4-core processor
  • GPU: NVIDIA RTX 4070 (12GB), 4080 (16GB), or 4090 (24GB VRAM)
  • RAM: 32GB system memory
  • Storage: 200GB+ NVMe SSD
  • CPU: 6+ core processor

VRAM Requirements by Resolution

ResolutionMinimum VRAMRecommended VRAM
512x5124GB6GB
768x7686GB8GB
1024x10248GB12GB
1536x153612GB16GB
2048x204816GB24GB

GPU Recommendations:

  • Budget: RTX 3060 12GB (under $300) - 512x512 @ 15-20s
  • Mid-Range: RTX 4060 Ti 16GB or 4070 12GB - 768x768 @ 8-12s
  • High-End: RTX 4080 16GB - 1024x1024 @ 5-8s
  • Professional: RTX 4090 24GB - 1536x1536 @ 4-6s

AMD GPUs: Supported via ROCm but with reduced performance and compatibility. NVIDIA strongly recommended.

Installation Methods

Automatic1111 (A1111) is the most popular Stable Diffusion interface with extensive community support.

Features:

  • User-friendly web interface
  • Extensive extension ecosystem
  • Strong community support
  • Regular updates
  • Comprehensive model support

Docker Installation:

Create project directory:

mkdir -p ~/homelab/stable-diffusion
cd ~/homelab/stable-diffusion

Create docker-compose.yml:

version: '3.8'

services:
  automatic1111:
    image: universonic/automatic1111:latest
    container_name: stable-diffusion-webui
    restart: unless-stopped
    ports:
      - "7860:7860"
    volumes:
      - ./models:/app/models
      - ./outputs:/app/outputs
      - ./extensions:/app/extensions
      - ./embeddings:/app/embeddings
      - ./config:/app/config
    environment:
      - CLI_ARGS=--allow-code --xformers --enable-insecure-extension-access --api
      - NVIDIA_VISIBLE_DEVICES=all
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

Start the container:

docker compose up -d

# Watch startup logs (first run downloads dependencies)
docker compose logs -f

# Wait for message: "Running on local URL: http://0.0.0.0:7860"

Access at: http://YOUR-SERVER-IP:7860

Native Installation (Linux):

# Install dependencies
sudo apt update
sudo apt install -y wget git python3 python3-venv libgl1 libglib2.0-0

# Clone repository
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui

# Run installation script
./webui.sh --xformers --enable-insecure-extension-access --api

# Access at http://localhost:7860

Windows Installation:

  1. Download sd.webui.zip from GitHub releases
  2. Extract to desired location
  3. Run webui-user.bat
  4. Wait for installation to complete
  5. Access at http://localhost:7860

Method 2: ComfyUI (Advanced Workflows)

ComfyUI uses node-based workflow design, offering more control for complex image generation pipelines.

Features:

  • Node-based visual workflow
  • Lower VRAM usage
  • Faster iteration
  • Advanced chaining capabilities
  • Growing ecosystem

Docker Installation:

Create docker-compose-comfy.yml:

version: '3.8'

services:
  comfyui:
    image: yanwk/comfyui-boot:latest
    container_name: comfyui
    restart: unless-stopped
    ports:
      - "8188:8188"
    volumes:
      - ./comfy-models:/opt/ComfyUI/models
      - ./comfy-output:/opt/ComfyUI/output
      - ./comfy-input:/opt/ComfyUI/input
      - ./comfy-custom-nodes:/opt/ComfyUI/custom_nodes
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

Start ComfyUI:

docker compose -f docker-compose-comfy.yml up -d

Access at: http://YOUR-SERVER-IP:8188

When to Choose Each:

  • Automatic1111: Easy to learn, great for general use, huge extension library
  • ComfyUI: Advanced workflows, better performance, complex multi-step generation

GPU Configuration

NVIDIA Setup

Install NVIDIA Container Toolkit:

# Add repository
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey |   sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg]   https://nvidia.github.io/libnvidia-container/stable/deb/$(ARCH) /" |   sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

# Install
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit

# Configure Docker
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Test GPU access:

docker run --rm --gpus all nvidia/cuda:12.0.0-base-ubuntu22.04 nvidia-smi

Monitor GPU during generation:

watch -n 1 nvidia-smi

Performance Optimization

Enable xFormers (Faster generation, lower VRAM):

Already enabled in Docker config via --xformers flag.

For native installation, install with:

pip install xformers

Optimized Settings for Different GPUs:

RTX 3060 12GB:

CLI_ARGS="--xformers --medvram --opt-split-attention"
# Enables memory optimizations for 12GB cards

RTX 4070 12GB:

CLI_ARGS="--xformers --no-half-vae"
# Optimal for 12GB with quality preservation

RTX 4090 24GB:

CLI_ARGS="--xformers --precision full --no-half"
# Maximum quality mode

AMD GPU (ROCm):

services:
  automatic1111:
    image: rocm/pytorch:latest
    devices:
      - /dev/kfd
      - /dev/dri
    environment:
      - HSA_OVERRIDE_GFX_VERSION=10.3.0
      - CLI_ARGS=--precision full --no-half

Downloading Models

Understanding Model Types

Checkpoint Models (.safetensors, .ckpt):

  • Main model file containing trained weights
  • Size: 2-7GB each
  • Different models excel at different styles

LoRAs (Low-Rank Adaptations):

  • Small model modifications (10-200MB)
  • Add specific styles, characters, or concepts
  • Used with base checkpoint

Embeddings (Textual Inversions):

  • Small files (under 100KB)
  • Add specific concepts to prompts
  • Lightweight customization

VAE (Variational Autoencoders):

  • Improves color and detail
  • Size: ~300MB
  • Shared across models

For Automatic1111:

1. Realistic Vision V5.1 (Photorealism):

mkdir -p ~/homelab/stable-diffusion/models/Stable-diffusion

# Download via browser or wget
wget -O ~/homelab/stable-diffusion/models/Stable-diffusion/realisticVision_v51.safetensors   "https://civitai.com/api/download/models/130072"

2. DreamShaper 8 (All-purpose):

wget -O ~/homelab/stable-diffusion/models/Stable-diffusion/dreamshaper_8.safetensors   "https://civitai.com/api/download/models/128713"

3. AbsoluteReality V1.8 (Portraits):

wget -O ~/homelab/stable-diffusion/models/Stable-diffusion/absolutereality_v181.safetensors   "https://civitai.com/api/download/models/132760"

Model Sources:

Download via WebUI:

  1. Open Automatic1111 web interface
  2. Go to “Checkpoints” dropdown
  3. Click refresh icon
  4. Select downloaded model

Installing LoRAs and Embeddings

LoRAs directory:

mkdir -p ~/homelab/stable-diffusion/models/Lora

Download popular LoRAs:

# Detail enhancement LoRA
wget -O ~/homelab/stable-diffusion/models/Lora/add_detail.safetensors   "https://civitai.com/api/download/models/87153"

# Better hands LoRA
wget -O ~/homelab/stable-diffusion/models/Lora/BadHands.safetensors   "https://civitai.com/api/download/models/16993"

Embeddings directory:

mkdir -p ~/homelab/stable-diffusion/embeddings

Use in prompts:

Prompt: beautiful landscape, detailed trees, flowing river <lora:add_detail:0.8>

Negative: (low quality, blurry), BadHands

VAE Installation

Download recommended VAE:

mkdir -p ~/homelab/stable-diffusion/models/VAE

wget -O ~/homelab/stable-diffusion/models/VAE/vae-ft-mse-840000-ema-pruned.safetensors   "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors"

Apply VAE:

Settings → Stable Diffusion → SD VAE → Select vae-ft-mse-840000-ema-pruned.safetensors

Using Automatic1111 WebUI

Basic Text-to-Image Generation

Step 1: Select Model

Checkpoint dropdown → Select model (e.g., “dreamshaper_8”)

Step 2: Write Prompt

Positive prompt:
a beautiful sunset over mountains, highly detailed, 4k, photorealistic,
vibrant colors, dramatic lighting, golden hour

Negative prompt:
low quality, blurry, distorted, watermark, text, signature,
bad anatomy, deformed

Step 3: Configure Settings

  • Sampling Method: DPM++ 2M Karras (good balance)
  • Sampling Steps: 20-30 (more = better quality, slower)
  • Width: 512 or 768
  • Height: 512 or 768
  • CFG Scale: 7-8 (how closely to follow prompt)
  • Seed: -1 (random) or specific number (reproducible)

Step 4: Generate

Click “Generate” and wait 5-15 seconds for result.

Advanced Settings

Batch Generation:

  • Batch Count: Generate multiple images sequentially
  • Batch Size: Generate multiple images simultaneously (uses more VRAM)

Resolution:

  • Start with 512x512 for testing
  • Use 768x768 or 1024x1024 for final outputs
  • Higher resolution = more VRAM and time

Sampling Methods:

  • DPM++ 2M Karras: Fast, high quality (recommended)
  • Euler a: Classic, good for creative outputs
  • DDIM: Fast but lower quality
  • DPM++ SDE Karras: Highest quality, slower

CFG Scale (Prompt Guidance):

  • 1-5: Loose interpretation, more creative
  • 7-10: Balanced (recommended)
  • 12-20: Strict adherence, can over-saturate

Image-to-Image Transformation

Use Cases:

  • Apply different styles to existing images
  • Refine AI-generated images
  • Transform photos with AI effects

Process:

  1. Switch to “img2img” tab
  2. Upload source image
  3. Write transformation prompt
  4. Set Denoising Strength: 0.3-0.7
    • Low (0.3): Subtle changes
    • Medium (0.5): Balanced transformation
    • High (0.7): Major changes
  5. Generate

Example:

Source: Photo of a house
Prompt: the same house but in cyberpunk style, neon lights, futuristic
Denoising: 0.6

Inpainting (Selective Editing)

Process:

  1. Go to “Inpaint” tab
  2. Upload image
  3. Use brush tool to mask area to regenerate
  4. Write prompt describing desired content
  5. Inpaint Area: “Only masked” or “Whole picture”
  6. Generate

Example Use:

  • Remove objects from photos
  • Change backgrounds
  • Fix specific image regions
  • Add elements to existing images

Upscaling Images

Built-in Upscaling:

  1. Generate image at 512x512
  2. Send to “Extras” tab
  3. Select upscaler: “R-ESRGAN 4x+” (general) or “4x-UltraSharp” (details)
  4. Set resize factor: 2x or 4x
  5. Click “Generate”

Hires Fix (Better quality):

In txt2img:

  1. Enable “Hires. fix”
  2. Set upscale factor: 2x
  3. Upscaler: Latent or R-ESRGAN
  4. Hires steps: 15-20
  5. Denoising strength: 0.4-0.6

Generates at low resolution first, then upscales with refinement.

Essential Extensions

Installing Extensions

Via WebUI:

  1. Go to “Extensions” tab
  2. Click “Available” sub-tab
  3. Click “Load from:” to refresh list
  4. Search for extension
  5. Click “Install”
  6. Restart WebUI

Manual Installation:

cd ~/homelab/stable-diffusion/extensions
git clone https://github.com/EXTENSION-REPO-URL
docker compose restart

ControlNet (Essential for Precision):

Allows precise control over composition using reference images.

Installation:

cd ~/homelab/stable-diffusion/extensions
git clone https://github.com/Mikubill/sd-webui-controlnet

Download ControlNet models:

mkdir -p ~/homelab/stable-diffusion/models/ControlNet

# Canny edge detection
wget -O ~/homelab/stable-diffusion/models/ControlNet/control_v11p_sd15_canny.pth   "https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth"

# Depth map
wget -O ~/homelab/stable-diffusion/models/ControlNet/control_v11f1p_sd15_depth.pth   "https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth"

# Pose detection
wget -O ~/homelab/stable-diffusion/models/ControlNet/control_v11p_sd15_openpose.pth   "https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth"

Use:

  1. Enable ControlNet in img2img or txt2img
  2. Upload reference image
  3. Select preprocessor (e.g., “Canny” for edges)
  4. Select model
  5. Generate with precise composition control

Deforum (Animation):

Create video animations with Stable Diffusion.

cd ~/homelab/stable-diffusion/extensions
git clone https://github.com/deforum-art/deforum-for-automatic1111-webui

Ultimate SD Upscale:

Better upscaling for large images.

cd ~/homelab/stable-diffusion/extensions
git clone https://github.com/Coyote-A/ultimate-upscale-for-automatic1111

Regional Prompter:

Different prompts for different image regions.

cd ~/homelab/stable-diffusion/extensions
git clone https://github.com/hako-mikan/sd-webui-regional-prompter

Civitai Helper:

Browse and download models directly from Civitai within WebUI.

cd ~/homelab/stable-diffusion/extensions
git clone https://github.com/butaixianran/Stable-Diffusion-Webui-Civitai-Helper

API Usage and Automation

Enable API Access

Already enabled in Docker config with --api flag.

For native installation, add to launch args:

./webui.sh --api

API documentation available at: http://YOUR-SERVER-IP:7860/docs

Basic API Usage

Generate Image via API:

curl -X POST "http://localhost:7860/sdapi/v1/txt2img"   -H "Content-Type: application/json"   -d '{
    "prompt": "a beautiful landscape, mountains, sunset, 4k",
    "negative_prompt": "low quality, blurry",
    "steps": 25,
    "width": 512,
    "height": 512,
    "cfg_scale": 7,
    "sampler_name": "DPM++ 2M Karras"
  }'

Response includes base64-encoded image:

{
  "images": ["base64_encoded_image_data"],
  "parameters": {...},
  "info": "{}"
}

Python Integration

Install SDK:

pip install requests pillow

Basic example:

import requests
import base64
from PIL import Image
from io import BytesIO

# API endpoint
url = "http://localhost:7860/sdapi/v1/txt2img"

# Request payload
payload = {
    "prompt": "cyberpunk city at night, neon lights, highly detailed",
    "negative_prompt": "low quality, blurry, distorted",
    "steps": 25,
    "width": 768,
    "height": 768,
    "cfg_scale": 7.5,
    "sampler_name": "DPM++ 2M Karras",
    "batch_size": 1
}

# Generate image
response = requests.post(url, json=payload)
result = response.json()

# Decode and save image
image_data = base64.b64decode(result['images'][0])
image = Image.open(BytesIO(image_data))
image.save("generated_image.png")

print("Image saved as generated_image.png")

Batch generation script:

import requests
import base64
from PIL import Image
from io import BytesIO
import time

url = "http://localhost:7860/sdapi/v1/txt2img"

prompts = [
    "a serene forest with sunlight filtering through trees",
    "futuristic city skyline at sunset",
    "cozy coffee shop interior, warm lighting",
    "mountain landscape with snow-capped peaks",
    "tropical beach at golden hour"
]

for i, prompt in enumerate(prompts):
    payload = {
        "prompt": f"{prompt}, highly detailed, 4k, professional photography",
        "negative_prompt": "low quality, blurry, watermark",
        "steps": 20,
        "width": 768,
        "height": 512,
        "cfg_scale": 7,
        "sampler_name": "DPM++ 2M Karras"
    }

    print(f"Generating image {i+1}/5: {prompt[:50]}...")

    response = requests.post(url, json=payload)
    result = response.json()

    image_data = base64.b64decode(result['images'][0])
    image = Image.open(BytesIO(image_data))
    image.save(f"batch_{i+1}.png")

    print(f"Saved: batch_{i+1}.png")
    time.sleep(2)  # Prevent overload

print("Batch generation complete!")

Automated Workflows

Daily wallpaper generator:

#!/usr/bin/env python3
import requests
import base64
from PIL import Image
from io import BytesIO
from datetime import datetime
import random

def generate_wallpaper():
    themes = [
        "serene mountain landscape at sunrise",
        "peaceful ocean waves at sunset",
        "misty forest with morning light",
        "starry night sky over hills",
        "autumn leaves in a park"
    ]

    prompt = random.choice(themes)

    payload = {
        "prompt": f"{prompt}, ultra high quality, 4k wallpaper, cinematic lighting",
        "negative_prompt": "low quality, blurry, distorted, watermark, text",
        "steps": 30,
        "width": 1920,
        "height": 1080,
        "cfg_scale": 8,
        "sampler_name": "DPM++ 2M Karras"
    }

    response = requests.post("http://localhost:7860/sdapi/v1/txt2img", json=payload)
    result = response.json()

    image_data = base64.b64decode(result['images'][0])
    image = Image.open(BytesIO(image_data))

    filename = f"/home/user/wallpapers/wallpaper_{datetime.now().strftime('%Y%m%d')}.png"
    image.save(filename)

    print(f"Wallpaper saved: {filename}")

if __name__ == "__main__":
    generate_wallpaper()

Schedule with cron:

0 6 * * * /usr/bin/python3 /opt/scripts/daily_wallpaper.py

Prompt Engineering

Anatomy of a Good Prompt

Structure:

[Main Subject] + [Style/Quality] + [Details] + [Lighting] + [Camera/Perspective]

Example:

Positive:
portrait of a woman, photorealistic, highly detailed face, natural skin texture,
soft lighting, bokeh background, professional photography, 85mm lens, f/1.8

Negative:
low quality, blurry, distorted, deformed, bad anatomy, watermark, text,
cartoon, 3d render

Effective Prompt Techniques

1. Specificity:

Bad: “a landscape” Good: “mountain landscape with pine trees, lake in foreground, snow-capped peaks, golden hour lighting”

2. Quality modifiers:

masterpiece, best quality, highly detailed, 4k, 8k, ultra high resolution,
professional photography, award winning

3. Artist styles:

in the style of Greg Rutkowski, Artgerm, alphonse mucha, trending on artstation

4. Weight adjustment:

(keyword:1.2) - Increase emphasis by 20%
(keyword:0.8) - Decrease emphasis by 20%
(keyword:1.5) - Strong emphasis

Example:

a (highly detailed:1.3) cyberpunk city, (neon lights:1.2), rainy streets,
(blurry background:0.7)

Negative Prompt Best Practices

Standard negative prompt:

low quality, blurry, pixelated, jpeg artifacts, watermark, text, signature,
username, bad anatomy, bad proportions, deformed, distorted, disfigured,
poorly drawn, bad hands, missing fingers, extra digits, fewer digits

For photorealistic images:

cartoon, 3d render, cgi, anime, painting, drawing, illustration, sketch,
unrealistic, oversaturated, low contrast

For portraits:

bad anatomy, bad hands, missing fingers, extra fingers, three hands,
bad face, bad eyes, cross-eyed, asymmetric eyes, fused fingers

Homelab Use Cases

1. Custom Content Creation

Blog headers and thumbnails:

def generate_blog_header(topic, style="professional"):
    styles = {
        "professional": "clean, modern, minimalist, corporate aesthetic",
        "tech": "futuristic, high-tech, circuit boards, digital",
        "nature": "organic, natural lighting, earth tones"
    }

    prompt = f"blog header image for {topic}, {styles[style]}, 16:9 aspect ratio, high quality"

    # Generate via API...

Social media graphics:

# Automated Instagram post generator
./generate_image.py --prompt "motivational quote background, inspiring, uplifting"   --width 1080 --height 1080 --output instagram_post.png

2. Home Automation Integration

Dynamic smart home displays:

Generate personalized artwork for digital displays based on time, weather, or events.

import requests
from datetime import datetime

def generate_seasonal_art():
    season = get_current_season()
    weather = get_weather()

    prompts = {
        "spring_sunny": "blooming cherry blossoms, bright sunlight",
        "summer_rainy": "rain on tropical leaves, water droplets",
        "autumn_cloudy": "fall foliage, misty forest",
        "winter_snowy": "snow-covered pine trees, serene winter"
    }

    prompt_key = f"{season}_{weather}"
    # Generate and display on smart frame

3. Documentation and Tutorials

Generate example images for guides:

# Technical diagrams
prompt="network diagram showing router, switch, and connected devices, clean schematic style"

# UI mockups
prompt="modern web dashboard interface, dark mode, professional design"

# Before/after comparisons
# Generate transformation examples

4. Creative Projects

Book cover designs:

a mysterious forest path at twilight, ethereal fog, fantasy book cover style,
title space at top, professional typography placement

Concept art:

futuristic space station orbiting a planet, detailed architecture,
science fiction concept art, trending on artstation

Custom wallpapers:

Generate personalized desktop backgrounds for each family member or workspace.

5. Product Mockups

Visualize ideas before implementation:

modern smart home control panel, touchscreen interface, mounted on wall,
minimalist design, realistic product photography

Performance Optimization

Generation Speed Tips

1. Resolution strategy:

- Generate at 512x512 (fast)
- Upscale to desired resolution (Hires fix or Extras)
- Faster than direct high-res generation

2. Sampling steps:

- Testing: 15-20 steps
- Final output: 25-35 steps
- Diminishing returns above 40 steps

3. Batch processing:

Generate multiple images sequentially rather than parallel to avoid VRAM overload.

4. Model selection:

Smaller models = faster generation:

  • SD 1.5 models: Faster (2GB checkpoint)
  • SDXL models: Slower but higher quality (6GB checkpoint)

VRAM Optimization

Settings → System:

# For 8GB VRAM
--medvram --opt-split-attention

# For 6GB VRAM
--lowvram --opt-split-attention-v1

# For 4GB VRAM (slow but works)
--lowvram --always-batch-cond-uncond

Docker environment:

environment:
  - CLI_ARGS=--xformers --medvram --opt-split-attention

Disk Space Management

Automatic cleanup script:

#!/bin/bash
# cleanup-sd-outputs.sh

OUTPUT_DIR=~/homelab/stable-diffusion/outputs
MAX_AGE_DAYS=30

# Delete images older than 30 days
find "$OUTPUT_DIR" -name "*.png" -mtime +$MAX_AGE_DAYS -delete

# Keep total outputs under 50GB
du -sh "$OUTPUT_DIR" | awk '{if ($1 ~ /G/) print $1}' | sed 's/G//' |   awk '{if ($1 > 50) system("find '"$OUTPUT_DIR"' -name "*.png" -type f -printf "%T@ %p\n" | sort -n | head -n 100 | cut -d" " -f2- | xargs rm")}'

echo "Cleanup completed"

Schedule weekly:

0 2 * * 0 /opt/scripts/cleanup-sd-outputs.sh

Security and Privacy

Network Security

Restrict to local network:

ports:
  - "127.0.0.1:7860:7860"  # Localhost only
  # Or specific IP:
  - "192.168.1.100:7860:7860"

Reverse proxy with authentication:

server {
    listen 443 ssl;
    server_name sd.homelab.local;

    ssl_certificate /etc/ssl/certs/homelab.crt;
    ssl_certificate_key /etc/ssl/private/homelab.key;

    auth_basic "Stable Diffusion Access";
    auth_basic_user_file /etc/nginx/.htpasswd;

    location / {
        proxy_pass http://localhost:7860;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Content Safety

Enable safe mode (optional):

Settings → User Interface → Enable “Safe Mode”

Prevents generation of NSFW content (not foolproof).

Private deployment benefits:

  • No external logging of prompts or images
  • Full control over generated content
  • No cloud provider terms of service restrictions

Troubleshooting

Common Issues

Problem: “CUDA out of memory”

Solutions:

# Reduce resolution
width: 512
height: 512

# Enable memory optimization
CLI_ARGS="--medvram --opt-split-attention"

# Reduce batch size
batch_size: 1

Problem: Slow generation (30+ seconds per image)

Check:

# Verify GPU is being used
nvidia-smi

# Should show python process using GPU

# Check xFormers is enabled
docker logs stable-diffusion-webui | grep xformers

Problem: Green/black images

Solution: Disable half precision

environment:
  - CLI_ARGS=--no-half --precision full

Problem: Model won’t load

# Check model format (.safetensors preferred over .ckpt)
# Verify model is in correct directory
ls -lh ~/homelab/stable-diffusion/models/Stable-diffusion/

# Check file permissions
chmod 644 ~/homelab/stable-diffusion/models/Stable-diffusion/*.safetensors

Problem: Extensions not working

# Restart WebUI after installing extensions
docker compose restart

# Check extension compatibility
# Some extensions may not work with latest WebUI version

Performance Benchmarking

Test your setup:

import requests
import time

url = "http://localhost:7860/sdapi/v1/txt2img"

payload = {
    "prompt": "test image, simple",
    "steps": 20,
    "width": 512,
    "height": 512
}

start = time.time()
response = requests.post(url, json=payload)
duration = time.time() - start

print(f"Generation time: {duration:.2f} seconds")

Expected performance:

GPU512x512 (20 steps)768x768 (25 steps)
RTX 3060 12GB8-12s15-20s
RTX 4060 Ti 16GB6-10s12-16s
RTX 4070 12GB5-8s10-14s
RTX 4080 16GB3-6s7-10s
RTX 4090 24GB2-4s5-8s

Advanced Topics

Training Custom Models (LoRAs)

Train models on your own images:

Requirements:

  • 10-50 high-quality images of subject
  • Consistent lighting and angles
  • Properly tagged captions

Training via Kohya SS:

git clone https://github.com/bmaltais/kohya_ss
cd kohya_ss
./setup.sh

# Follow GUI for LoRA training
./gui.sh

Training time: 30 minutes to 3 hours depending on dataset size and GPU.

Stable Diffusion XL (SDXL)

Next-generation model with better quality:

Download SDXL base:

wget -O ~/homelab/stable-diffusion/models/Stable-diffusion/sd_xl_base_1.0.safetensors   "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors"

SDXL requirements:

  • Minimum 12GB VRAM
  • Slower generation (2-3x)
  • Higher quality output
  • Better text rendering
  • More coherent composition

Multi-GPU Setup

Distribute workload across multiple GPUs:

deploy:
  resources:
    reservations:
      devices:
        - driver: nvidia
          device_ids: ['0', '1']
          capabilities: [gpu]

Configure in WebUI settings to utilize multiple GPUs for parallel batch generation.

Conclusion

Stable Diffusion brings professional-grade AI image generation to your homelab. With proper GPU hardware, you can generate unlimited high-quality images with complete privacy and creative freedom.

Key Takeaways:

  • GPU essential (12GB VRAM recommended minimum)
  • Automatic1111 best for beginners, ComfyUI for advanced workflows
  • Model selection critical for desired output style
  • Extensions massively expand capabilities
  • API enables automation and integration
  • Prompt engineering significantly impacts quality

Next Steps:

  1. Download 2-3 different checkpoint models
  2. Experiment with various prompts and settings
  3. Install essential extensions (ControlNet, upscalers)
  4. Build automated workflows via API
  5. Join community for tips and model recommendations

Your homelab is now an unlimited AI art studio.

Related Guides:

  • Ollama for text generation
  • LocalAI for multi-modal AI
  • Open WebUI for ChatGPT-like interface
  • ComfyUI advanced workflows

Resources: