Guide

An LLM decodes one token at a time, and each token reads the weights and the KV cache. A diffusion model does something else. It runs the whole network over the whole latent, once per denoising step. Serving diffusion therefore needs its own arithmetic, and LLM folklore about batching and caching does not carry over unchanged.

LLM decoding versus diffusion

Typical LLM decodingTypical diffusion image
Sequential dependencyOne token after anotherMany full-network steps on the whole latent
BottleneckMemory bandwidth, for weights and KV cacheCompute, for repeated dense forward passes
BatchingPaged attention and continuous batchingBatched UNet or DiT forward passes, step by step
Latency knobTokens, speculative decodingStep count, distillation, resolution

Walking through a latency estimate

Suppose one forward pass of a diffusion transformer costs F FLOPs at your latent resolution. The sampler runs 30 steps, and classifier-free guidance needs two passes per step if you run the conditional and unconditional branches separately:

30 steps × 2 passes = 60 forward passes ≈ 60 F per image

Distilled to 4 steps with the same two-pass guidance, the count drops to 4 × 2 = 8 forward passes, about 8 F. Batching the conditional and unconditional branches into one call does not reduce the FLOPs, but it can reduce the overhead.

Example

If F is comparable to a 1-billion-parameter transformer's forward pass on the latent grid, the 30-step version costs tens of LLM-sized forward passes per picture. Step count and guidance dominate image API cost in the same way that batch size and the KV cache dominate chat API cost.

Do not forget the autoencoder

Measure end to end, including the VAE encode and decode. People often attribute all the latency to the sampler and miss the cost of decoding the latent back to pixels. Profile the whole pipeline, not just the denoising loop.

Common mistakes

  • Porting LLM batching unchanged. A denoiser batch is a batch of whole-image forward passes, with its own memory profile.
  • Counting one forward pass per image. Multiply by the number of steps, and by two when guidance uses separate branches.
  • Measuring only the sampler. The VAE decode is part of what the user waits for.

Check yourself

  1. With 30 steps and two passes per step, how many forward passes does one image need? 30 × 2 = 60.
  2. Why profile the VAE as well as the sampler? Decoding the latent back to pixels is part of the wait, and profiling the sampler alone can send you to the wrong fix.

Key takeaways

  • Diffusion cost is roughly steps times denoiser cost, times the guidance passes.
  • Diffusion is compute-bound and repeated, while LLM decoding is sequential and memory-bound.
  • Step count, distillation and resolution are the main latency levers.
  • Measure the whole pipeline, including encode and decode.

Further learning

The serving other models page covers how these workloads are run in production.