AlgoViz

Latent diffusion and generative media systems

easy 6 min

A latent diffusion system represents an image in a compressed space.

Video lesson · Chapter 1 of 4

A lantern and a bicycle

0:00 / 3:33

Theory

Read or listen first. About 2 min.

What it is

A latent diffusion system represents an image in a compressed space. During training, the model learns to predict a target related to noise added at different levels. During generation, a scheduler and denoiser progressively turn a noisy latent into a sample conditioned on a prompt. A decoder maps the final latent back into pixels. A diffusion transformer can serve as the denoising backbone.

Why it exists

The image is refined over iterations, which gives a different latency profile from token-by-token text generation. Resolution changes latent dimensions and compute. Step count changes the number of denoiser evaluations; guidance and solver choice also affect work and fidelity. Benchmark fixed prompts and seeds alongside diverse seeds so a fast setting does not win by sacrificing the requested subject.

Reduce image-generation latency without losing the subject

Prompt encoder → Denoiser (prompt condition). Noisy latent → Denoiser (starting latent). Denoiser → Denoiser (next noise level). Denoiser → Image decoder (final latent)
Prompt encoder → Denoiser (prompt condition). Noisy latent → Denoiser (starting latent). Denoiser → Denoiser (next noise level). Denoiser → Image decoder (final latent)

Inside this chapter

Chapter sources
Conditioning and latents
Encode text into a conditioning representation and initialize a latent using the selected noise and seed. An autoencoder compresses geometry and appearance, so very fine detail can already be difficult to represent.

Working in a latent space is what makes these systems affordable: an autoencoder squeezes the image into a much smaller grid, and the expensive denoising happens there. The seed fixes the starting noise, and the prompt's conditioning steers every denoising step. The price of compression is that very fine detail, such as small text, may be hard for the autoencoder to represent at all, so no amount of denoising recovers it.

Example. Two prompts use the same initial seed. Differences in conditioning alter the denoising trajectory even with an identical scheduler.

Another example. A product-shot generator keeps the seed fixed while changing red kettle to blue kettle. The composition stays broadly similar, which makes A/B comparison of prompts much easier.

Two inputs meet in the denoiser
  1. 1Prompta red kettle beside a cat
  2. 2Text encoderconditioning vectors
  3. 3Seedfixes the starting noise
  4. 4Noisy latentsmall grid, not full pixels
  5. 5Denoise, then decodelatent becomes an image

Same seed, different prompt: the start is identical but the path diverges.

Denoiser and scheduler
The denoiser predicts an update target and the scheduler determines how to move between noise levels. A step is not necessarily one forward pass for every solver or guidance configuration. Compare actual model evaluations when estimating latency.

The denoiser is the large network: given a noisy latent, the noise level and the conditioning, it predicts something like the noise to remove. The scheduler (or solver) is a small piece of maths that decides how far to move and which noise levels to visit. Some solvers call the denoiser more than once per step, and guidance can double calls, so the step count alone is a poor latency estimate. Profile the actual number of denoiser calls.

Example. A 20-step configuration can use more than twenty evaluations. Measure calls rather than assuming a step count equals an exact time budget.

The generation loop

Every pass through the denoiser is a model call. Count calls, not steps.
Visual quality and reproducibility
Evaluate subject adherence, artifacts and consistency on a prompt set under fixed settings. Record seed, scheduler, model revision, resolution and runtime. Across hardware, identical seeds need not produce bit-identical images.

Image quality needs measures tied to the request: is every requested object there, are there artefacts, does the style match? Run the same prompts and seeds through each configuration and record the seed, scheduler, model revision, resolution and runtime with every image. Use several seeds per prompt because one lucky seed can hide a systematic loss. Do not expect identical pixels across different GPUs or library versions even with the same seed.

Example. A faster configuration keeps the background intact but drops the second object in paired prompts. Track object coverage alongside wall time.

Another example. A greeting-card app tracks objects present per prompt. A faster setting passes visual review on sample images but fails on prompts with two named subjects.

Paired comparison on fixed prompts

ConfigurationStepsBoth objects presentBackground intact
Baseline4076 of 8078 of 80
Fast2058 of 8078 of 80
Illustrative counts for 20 prompts times 4 seeds. The fast setting keeps the background but drops the second object.
Classifier-free guidance
Classifier-free guidance runs the denoiser with and without the prompt conditioning and pushes the prediction further in the direction the prompt suggests. A larger guidance scale usually follows the prompt more closely at some cost to variety and natural appearance.

The model is trained with the prompt sometimes dropped, so it learns both a conditioned and an unconditioned prediction. At generation time the difference between the two is the direction the prompt pulls in, and the guidance scale amplifies it. This is a direct cost lever: guidance roughly doubles denoiser work per step, which is easy to miss when someone quotes only the step count.

Example. At guidance scale 1 the image follows the prompt loosely. At a higher scale the requested red kettle is more reliably red, but colours can look oversaturated.

Guided prediction

ϵ^=ϵuncond+w (ϵcond−ϵuncond)\hat\epsilon=\epsilon_{\text{uncond}}+w\,(\epsilon_{\text{cond}}-\epsilon_{\text{uncond}})
w is the guidance scale. Two predictions per step means roughly two denoiser evaluations, unless they are batched together.

How it works

Step through the idea, or press Play.

Step 1 of 4

Prompt encoder. Represent two requested objects

Understand it

Worked example

Reduce image-generation latency without losing the subject

  1. 1

    Represent two requested objects

    Encode the prompt and retain the generation settings and seed.

  2. 2

    Initialize the image representation

    Sample a latent at the requested resolution and conditioning configuration.

  3. 3

    Refine over the chosen schedule

    Repeat updates at successive noise levels. Profile real model calls and intermediate memory.

  4. 4

    Inspect pixels and prompt fidelity

    Decode the image and grade both requested objects over multiple seeds against the latency target.

Follow the handoffs

The image is refined over iterations, which gives a different latency profile from token-by-token text generation. Resolution changes latent dimensions and compute. Step count changes the number of denoiser evaluations; guidance and solver choice also affect work and fidelity. Benchmark fixed prompts and seeds alongside diverse seeds so a fast setting does not win by sacrificing the requested subject.

Steps versus denoiser calls

SettingStepsCalls per stepDenoiser calls
No guidance, first-order solver20120
Guidance, separate passes20240
Guidance, halved steps10220
Illustrative counts. Second-order solvers can add further calls per step, so profile the real number.

Release decision for a faster setting

Speed alone does not decide: the requested subject must survive.

Summary

The whole topic in one minute.

A valid performance comparison measures whether the output still satisfies the intended prompt.

The image is refined over iterations, which gives a different latency profile from token-by-token text generation. Resolution changes latent dimensions and compute. Step count changes the number of denoiser evaluations; guidance and solver choice also affect work and fidelity. Benchmark fixed prompts and seeds alongside diverse seeds so a fast setting does not win by sacrificing the requested subject.

Sources