ANTIGRAVITY LABJP
Articles/AI Tools
AI Tools/2026-04-08Intermediate

Stable Diffusion & ComfyUI Not Working: A Complete Error Troubleshooting Guide

Fix common Stable Diffusion and ComfyUI errors including installation failures, VRAM issues, model loading problems, and broken custom nodes with step-by-step solutions.

troubleshooting105error12fix8stable-diffusioncomfyuiai-imagepython26

Struggling with Stable Diffusion or ComfyUI Errors?

Stable Diffusion and ComfyUI are among the most powerful open-source AI image generation tools available today, but getting them to run smoothly can be surprisingly frustrating. "It won't start after installation," "nothing happens when I click Generate," "I'm suddenly getting CUDA errors" — if any of these sound familiar, you're not alone.

This guide covers the most common errors you'll encounter with Stable Diffusion WebUI (AUTOMATIC1111 / Forge) and ComfyUI, organized by symptom. For each issue, we'll walk through the root causes, step-by-step fixes, and verification methods so you can get back to generating images as quickly as possible.

If you're stuck at the Python or PyTorch installation stage, check out our PyTorch & CUDA Installation Error Fix Guide first.


Issue 1: Installation and Startup Errors

Common Error Messages

These errors typically appear when running the startup script (webui.sh / run_nvidia.bat / main.py):

  • ModuleNotFoundError: No module named 'xxx'
  • RuntimeError: CUDA out of memory
  • OSError: Can't load tokenizer for 'openai/clip-vit-large-patch14'
  • torch.cuda.is_available() returns False

Root Cause Analysis

Python version mismatch: Stable Diffusion WebUI recommends Python 3.10.x. Python 3.12 and later can cause build failures with certain dependency libraries.

Missing or corrupted virtual environment: If the venv folder wasn't properly created, you'll get module-not-found errors due to conflicts with your system Python installation.

CUDA toolkit version mismatch: When the CUDA version that PyTorch was built against doesn't match your NVIDIA driver's CUDA version, the GPU won't be detected.

Step-by-Step Fix

# Step 1: Check your Python version
python --version
# Recommended: Python 3.10.x (3.10.6 through 3.10.14)
 
# Step 2: Verify CUDA detection
python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}'); print(f'CUDA version: {torch.version.cuda}'); print(f'GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"None\"}')"
# Expected output:
# CUDA available: True
# CUDA version: 12.4
# GPU: NVIDIA GeForce RTX 4090
 
# Step 3: Recreate the venv (for Stable Diffusion WebUI)
cd stable-diffusion-webui
rm -rf venv
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
 
# Step 4: For ComfyUI, reinstall requirements
cd ComfyUI
pip install -r requirements.txt
# Explicitly install GPU-enabled PyTorch
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124

Verification

# Final check that GPU is properly detected
python -c "
import torch
assert torch.cuda.is_available(), 'CUDA is not available!'
print(f'✅ GPU: {torch.cuda.get_device_name(0)}')
print(f'✅ VRAM: {torch.cuda.get_device_properties(0).total_mem / 1024**3:.1f} GB')
print(f'✅ PyTorch: {torch.__version__}')
"
# Expected output:
# ✅ GPU: NVIDIA GeForce RTX 4090
# ✅ VRAM: 24.0 GB
# ✅ PyTorch: 2.5.1+cu124

Issue 2: VRAM Out-of-Memory Errors

Common Error Messages

  • RuntimeError: CUDA out of memory. Tried to allocate X MiB
  • torch.cuda.OutOfMemoryError
  • Screen freezes and the system becomes unresponsive

Root Cause Analysis

Large models like SDXL and Flux require a minimum of 8GB VRAM, with 12GB or more recommended for comfortable use. Running high-resolution generation on a GPU with 6GB or less VRAM will cause memory allocation failures. Background applications consuming VRAM can also trigger this error.

Step-by-Step Fix

# Check current VRAM usage
nvidia-smi
# If VRAM usage is near the limit, close other GPU-intensive apps
 
# Stable Diffusion WebUI: Low-VRAM launch options
# Add to webui-user.sh (Linux/Mac) or webui-user.bat (Windows)
export COMMANDLINE_ARGS="--medvram-sdxl --xformers"
# For 6GB or less:
export COMMANDLINE_ARGS="--lowvram --xformers"
 
# ComfyUI: Low-VRAM launch
python main.py --lowvram
# For extreme cases:
python main.py --novram  # Uses CPU offloading (very slow)

In ComfyUI, you can also reduce VRAM consumption by removing unnecessary nodes from your workflow or adopting a "Hires Fix" approach where you generate at a smaller resolution first, then upscale.

# ComfyUI workflow configuration example (JSON excerpt)
# Generate at 512x512, then upscale 2x
{
    "KSampler": {
        "seed": 42,
        "steps": 20,
        "cfg": 7.0,
        "sampler_name": "euler_ancestral",
        "denoise": 1.0
    },
    "EmptyLatentImage": {
        "width": 512,   # Generate at small size first
        "height": 512,
        "batch_size": 1
    }
}

Issue 3: Model File Loading Errors

Common Error Messages

  • SafetensorError: Error reading file: not a safetensors file
  • RuntimeError: Error(s) in loading state_dict
  • ValueError: Checkpoint has unexpected keys
  • Model file not found in ComfyUI

Root Cause Analysis

Corrupted files: Interrupted downloads leave incomplete files behind. This is especially common with large model files (2GB–10GB) on unstable connections.

Wrong directory placement: Different model types need to go in different folders. Placing a checkpoint in the LoRA folder or a VAE in the checkpoints directory is a frequent mistake.

Format incompatibility: .ckpt and .safetensors formats have different loading mechanisms. Some older extensions don't support .safetensors.

Step-by-Step Fix

# Step 1: Verify file integrity (hash comparison)
sha256sum models/Stable-diffusion/your-model.safetensors
# Compare with the SHA256 listed on Civitai or Hugging Face
 
# Step 2: Check file sizes
ls -lh models/Stable-diffusion/
# SD 1.5 models: ~2GB / SDXL models: ~6.5GB / Flux: ~12GB
# If the file is significantly smaller, the download was incomplete
 
# Step 3: Correct directory structure
# Stable Diffusion WebUI
# models/Stable-diffusion/  <- Checkpoints (.safetensors, .ckpt)
# models/Lora/              <- LoRA models
# models/VAE/               <- VAE models
# extensions/               <- Extensions
 
# ComfyUI
# models/checkpoints/       <- Checkpoints
# models/loras/             <- LoRA
# models/vae/               <- VAE
# models/clip/              <- CLIP models
# custom_nodes/             <- Custom nodes
 
# Step 4: Re-download corrupted files
# Using Hugging Face CLI
pip install huggingface_hub
huggingface-cli download stabilityai/stable-diffusion-xl-base-1.0 \
  sd_xl_base_1.0.safetensors \
  --local-dir models/Stable-diffusion/

Issue 4: ComfyUI Custom Node Errors

Common Error Messages

  • Cannot import name 'xxx' from 'comfy.xxx'
  • Node class not found: 'XXXNode'
  • ImportError: cannot import name 'xxx'
  • Red nodes appearing when loading a workflow

Root Cause Analysis

ComfyUI's extensibility through custom nodes is one of its greatest strengths, but core API updates can break custom node compatibility. When ComfyUI changes internal structures in modules like comfy.model_management or comfy.samplers, older custom nodes may stop working entirely.

Step-by-Step Fix

# Step 1: Check node status via ComfyUI Manager
# After launching ComfyUI, open the Manager menu
# Click "Install Missing Custom Nodes"
 
# Step 2: Identify the problematic custom node
# Check ComfyUI startup logs for errors
python main.py 2>&1 | grep -i "error\|failed\|cannot"
 
# Step 3: Update individual custom nodes
cd custom_nodes/ComfyUI-Impact-Pack
git pull origin main
pip install -r requirements.txt
 
# Step 4: Batch update all custom nodes (via ComfyUI Manager)
cd custom_nodes/ComfyUI-Manager
git pull origin main
# Restart ComfyUI, then Manager -> Update All
 
# Step 5: If all else fails, temporarily disable the problematic node
cd custom_nodes
mv problematic-node problematic-node.bak
# Restart ComfyUI to verify other nodes work correctly

When sharing workflows, always document the custom node versions you're using. This prevents reproducibility issues for anyone trying to run your workflow.


Issue 5: Black or Noisy Output Images

Symptoms

No error message appears, but generated images are completely black, full of noise, or have distorted colors.

Root Cause Analysis

Missing or mismatched VAE: Without the correct VAE for your model, the image won't decode properly during the final step. SDXL models in particular require their dedicated VAE.

NaN propagation: During FP16 (half-precision) computation, numerical overflow can produce NaN values that propagate through the entire image, resulting in a black output.

Extreme CFG scale: A CFG (Classifier-Free Guidance) scale that's too high causes image saturation, while too low means the prompt is essentially ignored.

Step-by-Step Fix

# For Stable Diffusion WebUI
# Go to Settings -> Stable Diffusion -> SD VAE and set to "Automatic"
# Or explicitly specify the SDXL VAE:
# Place sdxl_vae.safetensors in models/VAE/
 
# Fix NaN issues (add to webui-user.sh)
export COMMANDLINE_ARGS="--no-half-vae --xformers"
# --no-half-vae: Runs VAE in FP32 to prevent NaN
 
# For ComfyUI
# Ensure the VAEDecode node has the correct VAE connected
# CheckpointLoaderSimple VAE output -> VAEDecode vae input

Recommended CFG scale ranges vary by model, but these are generally stable starting points:

  • SD 1.5 models: CFG 7–12
  • SDXL models: CFG 5–9
  • Flux models: CFG 1–3.5 (Flux works best with low CFG)

Prevention: Best Practices for a Stable Environment

Building good habits will save you hours of debugging down the road. Here are the key practices we recommend:

1. Always use a Python virtual environment: Using your system Python directly invites dependency conflicts with other projects. Set up a dedicated environment with venv or conda.

2. Record model file hashes: Save the SHA256 hash of every model you download. This lets you instantly detect corruption if something goes wrong.

3. Use Git for version control: Before updating ComfyUI custom nodes, create a rollback point with git stash or git tag. When something breaks, you can revert in seconds.

4. Check VRAM headroom before generating: Make a habit of running nvidia-smi before starting generation. Closing unnecessary background processes that consume VRAM can dramatically reduce OOM errors.

5. Clean up regularly: Removing unused models and custom nodes doesn't just free up disk space — it also speeds up startup times and reduces compatibility issues.

For more on managing Python dependencies in AI projects, see our LangChain & LlamaIndex Version Dependency Error Fix guide.


Looking back

Stable Diffusion and ComfyUI errors fall into five main categories: environment setup, VRAM management, model management, node compatibility, and generation parameters. By following the diagnostic steps in this guide, you should be able to resolve the vast majority of issues on your own.

The single most important skill is learning to read error messages carefully. Python tracebacks can look intimidating, but the last few lines contain the essential clue. ModuleNotFoundError points to dependencies, CUDA out of memory to VRAM, SafetensorError to file corruption — once you develop the ability to quickly map messages to causes, even new errors won't throw you off.

For more environment setup guidance, check out the Antigravity Install & Setup Troubleshooting Guide as well.

If you'd like to deepen your understanding of the topics covered here,

Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

AI Tools2026-06-17
Fix PyTorch CUDA Errors: torch.cuda.is_available() False & Version Mismatches (2026)
Struggling with PyTorch or CUDA installation errors? This guide covers version mismatches, dependency conflicts, and GPU detection failures with step-by-step solutions.
AI Tools2026-04-09
Fixing Hugging Face Transformers Errors — Identifying the Cause and Resolving It
Hugging Face Transformers errors sorted by symptom: ImportError, CUDA OOM, bf16 on unsupported GPUs, gated-model 401s, and cache bloat. How to identify the cause and work through the fix.
AI Tools2026-04-07
How to Fix LangChain and LlamaIndex Version Mismatch and Dependency Errors
Struggling with LangChain or LlamaIndex version conflicts and dependency errors? This guide covers the 5 most common error patterns, their root causes, and step-by-step solutions to get your AI development environment back on track.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →