Stable Diffusion

Stable Diffusion Explained: Architecture, SDXL & Local Setup

The Open-Source Vanguard: Why Stable Diffusion Matters

While proprietary AI services like Midjourney and DALL-E 3 operate behind closed cloud paywalls and strict content filters, Stable Diffusion democratized generative AI by releasing its neural network weights publicly to the global open-source community. Originally developed through a collaboration between Stability AI, RunwayML, and the CompVis research group at Ludwig Maximilian University of Munich, Stable Diffusion sparked a revolution in consumer machine learning.

Because the weights are open, anyone with a modern desktop GPU can run Stable Diffusion completely offline: with zero subscription fees, absolute data privacy, no cloud latency, and uncapped generation potential. More importantly, open weights gave birth to an unprecedented developer ecosystem—giving rise to precision tools like ControlNet, LoRA (Low-Rank Adaptation), and modular node-based interfaces like ComfyUI.

In this technical guide, we break down how Stable Diffusion operates under the hood: analyzing the latent diffusion pipeline (VAE, CLIP, U-Net), comparing model generations from SD 1.5 to SDXL and SD 3.5, and exploring precision control mechanisms for production workflows.


The Latent Diffusion Pipeline: VAE, CLIP, and U-Net

Generating high-resolution images directly in raw pixel space (RGB) requires prohibitive amounts of GPU compute. Stable Diffusion solves this by executing the entire diffusion process inside a compressed mathematical space called Latent Space:

Text Prompt ──► [CLIP Text Encoder] ────────┐ (77 Token Vectors)
                                            │
Gaussian Noise ──► [Denoising U-Net] ◄──────┴ (Cross-Attention)
(Latent Space)          │ (Iterative Step Loop)
                        ▼
                Denoised Latents
                        │
                        ▼
              [VAE Decoder Network] ────────► Final High-Res Image (RGB)

1. Variational Autoencoder (VAE)

The VAE is composed of an Encoder and a Decoder. The encoder compresses a 512×512 RGB pixel image (3 color channels) into a compact 64×64 latent tensor (4 channels), achieving an 8x spatial compression factor (64x fewer values). The denoising computation occurs entirely within this lightweight latent representation. Once denoised, the VAE Decoder transforms the latent tensor back into a full-resolution RGB image.

2. Text Conditioning with CLIP

Stable Diffusion uses OpenAI’s open-source CLIP (Contrastive Language-Image Pre-training) text encoder. Prompts are tokenized into 77-token chunks and converted into 768-dimensional embedding vectors. These text embeddings guide the denoising network through Cross-Attention layers distributed throughout the U-Net.

3. The Denoising U-Net

The core engine is a U-Net neural network with residual blocks and cross-attention mechanisms. At each step of the diffusion schedule (e.g., using samplers like Euler, DPM++ 2M Karras, or UniPC), the U-Net predicts the noise component present in the latent tensor, subtracting a fraction of the noise to reveal structured imagery.


Model Evolution: SD 1.5 vs. SDXL vs. SD 3.5

Stable Diffusion has evolved across several distinct architectural generations:

Model VersionNative Canvas ResolutionText EncodersVRAM RequirementsCore Architectural Strength
Stable Diffusion 1.5512 x 512 pxSingle CLIP ViT-L/144GB – 6GB VRAMMassive community adoption. Tens of thousands of custom fine-tuned checkpoints, LoRAs, and ControlNets. Extremely fast inference.
SDXL 1.0 (Stable Diffusion XL)1024 x 1024 pxDual Encoders (OpenCLIP ViT-bigG + CLIP ViT-L)8GB – 12GB VRAM3x larger U-Net parameter count. Native 1-megapixel generation, superior human anatomy, richer cinematic lighting, and base/refiner two-stage architecture.
SD 3 / 3.5 (Large)1024 x 1024 pxTriple Encoders (CLIP L + OpenCLIP G + T5-XXL)12GB – 16GB+ VRAMMultimodal Diffusion Transformer (MMDiT) replacing the U-Net. Unmatched multi-clause prompt adherence and legible typographic rendering.

Precision Control: ControlNet and LoRA Fine-Tuning

In commercial design and game asset production, standard text prompting is too unpredictable. Stable Diffusion achieved dominance because developers can exert pixel-perfect spatial control:

1. ControlNet (Spatial Conditioning)

ControlNet attaches an auxiliary neural network to the frozen U-Net, conditioning generation on geometric guides:

  • OpenPose: Forces characters to adopt the exact skeletal pose detected from a source photograph.
  • Canny / Lineart: Renders realistic artwork conforming precisely to an architectural blueprint or line sketch.
  • Depth: Extracts 3D depth maps to preserve camera perspective and foreground/background separation.

2. LoRA (Low-Rank Adaptation)

Training an entire 6GB checkpoint requires enterprise GPU clusters. LoRA freezes the base model and injects tiny low-rank mathematical matrices (10MB to 150MB) into the attention layers. Designers can download or train custom LoRAs to render specific company mascots, proprietary product models, or unique digital art aesthetics on top of any base model instantly.


Local User Interfaces: ComfyUI vs. Automatic1111

When running Stable Diffusion on a local workstation, the community relies on two primary graphical frontends:

  • AUTOMATIC1111 (Stable Diffusion WebUI): A traditional form-based web dashboard. Excellent for beginners, with straightforward sliders for CFG Scale, Sampler selection, and Denoising strength.
  • ComfyUI (Node-Based Visual Graph): The modern industry standard for power users and pipeline automation. Visual nodes represent each model component (Checkpoints, VAE, CLIP, Samplers, ControlNets). ComfyUI optimizes GPU memory caching, executes workflows asynchronously, and allows developers to construct complex, multi-stage generation pipelines with zero memory waste.

Continue exploring modern artificial intelligence architectures and machine learning tools with our related guides:


Frequently Asked Questions

Can I run Stable Diffusion on an AMD or Apple Silicon GPU?

Yes. While Stable Diffusion is optimized primarily for NVIDIA CUDA architectures, modern backends support Apple Silicon via PyTorch MPS (Metal Performance Shaders) and AMD GPUs on Windows/Linux via DirectML and ROCm. However, NVIDIA GPUs (RTX 3060, 4070, 4090) remain the fastest due to dedicated Tensor Cores and xFormers / TensorRT acceleration.

What does CFG Scale mean in Stable Diffusion?

CFG (Classifier-Free Guidance) Scale controls how strictly the model adheres to your text prompt versus exploring random creative variations. A CFG of 1 allows the model to ignore your prompt almost entirely; a CFG between 6 and 8 is standard for high quality; CFG values above 12 often cause “overcooked”, high-contrast, or distorted artifacts.

Are images generated by Stable Diffusion copyrighted?

Under Stability AI’s permissive CreativeML Open RAIL-M and Community licenses, creators have full commercial rights to use, sell, and monetize outputs generated with Stable Diffusion. However, as with all AI-generated imagery, purely algorithmic outputs without substantial human creative input generally cannot receive traditional copyright protection under current US and international copyright law.

Article maintained by Mohit Kumar, Senior Full Stack & Cloud Architect. Have technical questions or architecture suggestions? Feel free to reach out via our Contact Us page.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top