The Math Behind Diffusion Image Synthesis
Have you ever wondered what actually happens when you hit "Generate"? Generative diffusion models do not "paint"—they start with a canvas of random gaussian static noise and systematically subtract that noise over 20 to 50 iterations (sampling steps) guided by your text tokens.
Understanding the interaction between CFG Scale, Sampling Algorithms, and Denoising gives you granular control over image quality.
1. What is CFG Scale (Classifier-Free Guidance)?
Classifier-Free Guidance measures how forcefully the AI prioritizes your prompt versus its own unconditional aesthetic prior:
- CFG 1.0 - 2.5: The model barely listens to you, generating generic pretty pictures.
- CFG 4.0 - 7.0 (The Standard Sweet Spot): Balanced prompt adherence and natural image contrast.
- CFG 8.0 - 12.0: Highly obedient, but colors become heavily saturated and edges can develop harsh ringing artifacts.
- CFG 15.0+ (Fried Pixels): Severe chromatic burn, color banding, and deep posterization.
2. Choosing the Right Sampling Method
Diffusion samplers are ordinary differential equation (ODE) solvers. Different samplers balance speed and convergence:
| Sampler | Characteristics | Best Use Cases |
|---|---|---|
| Euler | Direct, deterministic, fast | Clean minimalist scenes, line art |
| Euler Ancestral (Euler A) | Stochastic noise injection at every step | Creative concepts, painterly visuals |
| DPM++ 2M Karras | Superior convergence at 20-25 steps | High-detail photorealism, portraits |
| DPM++ SDE Karras | Photorealistic micro-textures, slower | Film grain, skin pores, fabric weaves |
| FlowMatch Euler (Flux) | Tailored for Rectified Flow Transformers | Modern Flux.1 architecture |