Diffusion Inference Acceleration¶
There is no portable “speed-up factor” for diffusion inference. A technique can improve throughput for one checkpoint, resolution, hardware target, and pipeline while making another slower, less stable, or visually different. Treat acceleration as a controlled experiment, not as a list of interchangeable nodes.
Establish a baseline receipt¶
Before changing the runtime, record:
- exact model/checkpoint revision, pipeline version, scheduler, and adapters;
- prompt or input fixture, seed, dimensions, batch size, and number of steps;
- GPU, driver, CUDA/PyTorch/runtime versions, and precision;
- cold-start time, warm steady-state latency, peak device memory, and output files or hashes; and
- a task-specific fidelity check, including human review where visual correctness matters.
Report cold and warm behavior separately. Compilation and caching frequently move time into the first request, which may be unacceptable for interactive editing even when repeated jobs become faster.
Compatible optimization families¶
Use only a mechanism that is documented for the exact model/runtime pair, and add one family at a time.
Compilation¶
The Diffusers acceleration guide documents torch.compile for compute-heavy model components. Compilation can pay off for repeated, shape-stable work, but a changed image size or execution condition can trigger recompilation. Diffusers also documents regional compilation for repeated blocks; availability depends on the model implementation.
Precision and quantization¶
Reduced precision or quantized weights can alter memory use, latency, numerical behavior, and image details. Measure the result against representative inputs; do not infer fidelity from a precision label. Record the quantizer, base checkpoint, calibration path when applicable, and loader/runtime version.
Attention and memory placement¶
Attention backends may change speed and memory behavior on a particular hardware stack. CPU or disk offloading primarily solves a memory constraint, not an unconditional latency problem: the memory guide notes that sequential CPU offloading can be extremely slow. Treat offloading, VAE tiling, and sharding as capacity choices and benchmark them independently.
Scheduler, step count, and caching¶
Changing a scheduler or reducing steps changes the sampling procedure. Use the checkpoint publisher's supported route, then evaluate the requested task rather than assuming an arbitrary scheduler is compatible. Cache schemes are often architecture- and implementation-specific; verify their memory cost, invalidation behavior, and output effect on the target pipeline.
Control the random stream, not just the seed label¶
For reproducibility-sensitive Diffusers comparisons, use a CPU torch.Generator(device="cpu") and seed it explicitly. A generator is mutable: reusing an already-consumed object advances its random stream. Recreate it with the same seed for each controlled comparison, or save and restore its state. This does not promise identical images across releases, platforms or numerical backends. Diffusers reproducibility guide.
Bind the result to the recorded model/runtime/hardware tuple. When a benchmark changes an attention backend, precision, scheduler or step count, compare the output as well as speed; a matching integer seed does not isolate those changes. Use checkpoint-supported guidance settings, not a universal CFG range copied from another model family.
Measurement protocol¶
- Run a fixed baseline after sufficient warm-up and keep the raw receipt.
- Change one optimization family and repeat the same fixture.
- Compare median and tail latency, peak memory, output reproducibility, and visual/task fidelity.
- Keep the change only when its measured trade-off satisfies the deployment constraint; otherwise revert it.
- Repeat after changes to the checkpoint, adapters, resolution regime, driver, or runtime.
For a public workflow, publish the compatible version tuple and the benchmark fixture, not a generic performance claim. Do not combine percentage savings from separate experiments as if they multiply.
Gotchas¶
- Same generator object, different result: its state was consumed; recreate or restore it for the controlled comparison.
- Faster inference is declared equivalent from latency alone: retain the output and task-fidelity comparison for the exact changed runtime.
- Offloading is called an unconditional speed-up: measure host transfer and steady-state latency separately from the memory-capacity benefit.