Classifier-free guidance (CFG)
Classifier-free guidance is a sampling technique for diffusion models that pushes each output towards the prompt by comparing the model's predictions with and without it, controlled by a setting called the guidance scale.
A diffusion model builds an image by removing noise step by step. Classifier-free guidance changes how each step is taken. The model is trained to make predictions both with the conditioning, usually the text prompt, and without it. When generating, it makes both predictions at every step and looks at the difference between them, which points in the direction the prompt is pulling. That difference is multiplied by the guidance scale and added on, so the image is pushed harder towards what the prompt describes than the model would go on its own.
The name comes from what it replaced. Earlier classifier guidance steered a diffusion model with a separate image classifier, which had to be trained on noisy images and added complexity. Jonathan Ho and Tim Salimans showed that the same effect could be achieved without any classifier by combining the conditional and unconditional predictions of one jointly trained model; their paper, Classifier-Free Diffusion Guidance, was posted to arXiv in July 2022. OpenAI's GLIDE paper of December 2021 compared this approach with guidance from the CLIP model and found human evaluators preferred classifier-free guidance for both photorealism and match to the caption.
The setting is a trade-off between following the prompt and variety. The Hugging Face Diffusers documentation explains that a low guidance scale gives the model more freedom to produce images loosely related to the prompt, while a high value makes it follow the prompt more closely, and a value that is too high introduces visible artefacts. Its Stable Diffusion examples compare values of 2.5, 7.5 and 10.5. In the paper's terms, guidance trades sample diversity for sample fidelity.
Many image apps expose the setting as the guidance scale or CFG scale. The technique is not limited to pictures: the AudioGen text-to-audio model, for example, used classifier-free guidance to make its sounds match their text descriptions more closely.
In practice, classifier-free guidance is one of the main reasons modern text-to-image models do what they are asked. When a model ignores part of a prompt, raising the guidance scale is often the first fix, and when images look overcooked or samey, lowering it is. The best value depends on the model.
It controls how strongly a diffusion model follows the prompt. Higher values make the output stick more closely to the prompt but reduce variety and, if pushed too far, cause artefacts. Lower values give looser, more varied results. It depends on the model. The Hugging Face Diffusers guide shows Stable Diffusion examples at 2.5, 7.5 and 10.5. Start with the model's documented default and change it in small steps. Before it, the standard way to steer a diffusion model was classifier guidance, which needed a separate classifier trained on noisy images. Classifier-free guidance gets the same steering effect from the diffusion model itself, by comparing its predictions with and without the prompt. It usually means computing two predictions at each denoising step, one with the prompt and one without, so it adds work compared with sampling without guidance. The extra cost is usually accepted because the gain in prompt following is large.Common questions
What does the guidance scale or CFG scale do?
What is a good CFG value?
Why is it called classifier-free?
Does classifier-free guidance slow generation down?
Search for "classifier-free guidance", "guidance scale diffusion" or "CFG scale Stable Diffusion" to learn how the setting behaves. Reliable sources include the original paper by Ho and Salimans on arXiv, the documentation of open diffusion libraries such as Hugging Face Diffusers, and the model cards of specific image models, which often state a recommended value. Treat forum recipes for a single best value with care, because the right setting changes from model to model.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.