The Problem
A team is choosing between SDXL and FLUX for their image generation pipeline. They look at sample outputs and pick FLUX because "it looks better." But they can't explain why FLUX is better — they don't know it uses a Diffusion Transformer while SDXL uses a UNet. When the interviewer asks "why did you choose FLUX over SDXL?", "it looks better" is not a sufficient answer.
Understanding the architecture behind generative models is what separates engineers from API callers. You don't need to implement these architectures from scratch, but you need to know what they are, how they differ, and why one scales better than the other.
What you'll build
Load both a UNet-based model (SDXL) and a DiT-based model (FLUX.1 Schnell), generate images with both, measure inference time, and compare output quality. Write a comparison report documenting the architecture differences and practical trade-offs.
The Concept
UNet architecture
The UNet was the original architecture for diffusion models, used in DDPM, Stable Diffusion 1.x, and SDXL.
Structure: Encoder-decoder with skip connections
Encoder (downsampling) Decoder (upsampling)
[64x64] ──→ [32x32] ──→ [16x16] ──→ [8x8] (bottleneck)
│ │ │
│skip │skip │skip
│ │ │
[64x64] ←── [32x32] ←── [16x16] ←── [8x8]
Key features:
- Skip connections: connect encoder layers to corresponding decoder layers, preserving spatial detail
- Attention mechanisms: self-attention at lower resolutions (16x16, 8x8) for global context
- Convolutional: primarily conv-based, with attention layers at key points
- Resolution processing: processes the image at multiple resolutions through down/up sampling
Models using UNet:
- Stable Diffusion 1.5 (256x256 / 512x512)
- Stable Diffusion XL (1024x1024)
- DeepFloyd IF
# SDXL uses a UNet
from diffusers import StableDiffusionXLPipeline
pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
# pipe.unet is a UNet2DConditionModel
Diffusion transformers (DiTs)
DiTs replace the convolutional UNet with a transformer architecture. Instead of processing at multiple resolutions with convolutions, the image is patched and processed with self-attention.
Structure: Patchify → Transformer blocks → Unpatchify
Input latent (e.g., 64x64x4)
↓
Patchify: split into patches (e.g., 2x2 → 32x32 patches)
↓
Transformer blocks (self-attention + MLP) × N
↓
Unpatchify: reconstruct to latent shape
↓
Output predicted noise
Key features:
- Patch-based: image is split into patches, each treated as a token
- Full self-attention: every patch attends to every other patch (global context at all layers)
- Scalable: architecture scales predictably with parameters and compute
- No convolutions: purely attention-based (with MLPs)
Models using DiT:
- FLUX.1 (Schnell, Dev, Pro) — Black Forest Labs
- Sora — OpenAI
- Veo — Google
- Stable Diffusion 3 / 3.5
# FLUX uses a DiT
from diffusers import FluxPipeline
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell")
# pipe.transformer is a FluxTransformer2DModel (DiT-based)
Why DiTs scale better
The key insight from the DiT paper (Peebles & Xie, 2022): transformers scale more predictably than UNets.
| Property | UNet | DiT |
|---|
| Scaling | Empirical (hard to predict) | Predictable (follows scaling laws) |
| Parallelism | Limited (multi-resolution) | Excellent (uniform blocks) |
| Training efficiency | Good | Better (especially at scale) |
| Global context | Only at low resolutions | At all layers (full attention) |
| Hardware utilization | Good | Better (transformer-friendly) |
This is why the frontier models (FLUX, Sora, Veo) all use DiTs — they scale better with more compute and data. The UNet isn't bad, but it doesn't scale as cleanly.
Why do frontier models like FLUX and Sora use DiT instead of UNet?
DiTs scale more predictably than UNets — transformer architectures follow known scaling laws, making it easier to plan training runs. Full self-attention at all layers provides global context that UNets only get at low resolutions. This is why FLUX, Sora, and Veo all use DiT. UNets are still good (SDXL), but DiTs are better at the frontier.
Practical comparison
| Factor | SDXL (UNet) | FLUX.1 (DiT) |
|---|
| Quality | High (with LoRAs) | Higher (better base quality) |
| Speed | 20-30 steps, ~5s | 4 steps (Schnell), ~2s |
| VRAM | ~8GB (fp16) | ~12GB (fp16) |
| Ecosystem | Massive (thousands of LoRAs, ControlNets) | Growing (newer, fewer LoRAs) |
| Resolution | 1024x1024 native | 1024x1024 native |
| Text rendering | Poor | Good (FLUX.1 Pro excellent) |
| Prompt adherence | Good | Better |
| LoRA support | Thousands on Civitai | Growing |
| ControlNet | Mature (depth, pose, canny, etc.) | Emerging |
| License | CreativeML Open RAIL-M | Apache 2.0 (Schnell) |
When to use each
Use SDXL when:
- You need a specific LoRA style from Civitai's massive ecosystem
- You need ControlNet (depth, pose, canny, openpose)
- You need inpainting with mature tooling
- VRAM is limited (< 12GB)
Use FLUX when:
- You need the best base quality without LoRAs
- You need fast generation (Schnell: 4 steps, 2 seconds)
- You need good text rendering in images
- You need strong prompt adherence
- You're building a pipeline where quality matters more than ecosystem
The hybrid approach
Production systems often use both:
- SDXL with LoRAs for brand-specific styles (thousands of community LoRAs)
- FLUX Schnell for rapid prototyping and high-volume generation (4 steps, $0.003)
- FLUX Pro for final quality when cost is less important
# Hybrid routing
def select_model(use_case: str) -> str:
if use_case == "brand_marketing":
return "sdxl" # Has brand LoRA
elif use_case == "bulk_product":
return "flux-schnell" # Fast, cheap
elif use_case == "hero_image":
return "flux-pro" # Best quality
else:
return "flux-schnell" # Default