Classifier-free Guidance Scale, also known as guidance scale, is a parameter that is passed to Stable Diffusion models to inform the model how closely it should follow the prompt when generating an image.
A lower number allows the model to be more “creative” or loosely follow the prompt whereas a higher number will force the model to be more strict. Stable Diffusion defaults to a value of 7.5 if the guidance scale is not provided.
Demonstrating the Difference in Values
To demonstrate how the guidance scale impacts the output of the Stable Diffusion model, we can use the X/Y/Z script in the Automatic1111 Stable Diffusion WebUI.
A lower guidance scale tends to be washed out and may or may not get all of the prompts correct. For example, in this image, at a CFG of 1.0, the person appears to be standing in New York City, but it isn’t nearly as well defined as those later down the list.
We also see that images higher on the scale, such as those greater than 15.0, start to become oversaturated, add in elements that we may or may not want, and in some cases, become so strict that the image is not recognizable.
Images between 6 and 12 tend to produce the best results:
Here are a couple of other examples of images that were generated on a wide range of guidance scale values:
When a Higher or Lower Guidance Scale Value May Make Sense
As the models improve, there may be instances where a higher or lower guidance scale value would make sense.
For example, if you are using a model trained on medical images, you may want to use a higher guidance scale value to ensure that the model does not generate images that are too far from the prompt (i.e. something that could be anatomically incorrect).
On the other hand, you may want to use a lower guidance scale value for images that are more artistic where creativity is required.
For example, if you are generating images for a logo, you may want to use a lower guidance scale value to ensure that the model does not generate images that are too close to the prompt (i.e. something that could be too similar to an existing logo and cause legal issues).
How to Choose a Guidance Scale Value
For better or worse there are a lot of levers that can be pulled to change the output of the Stable Diffusion model including the seed, the guidance scale, the number of steps, sampling method, steps, width, height, etc. This can make it difficult to know which adjustments are necessary to get the desired output.
The X/Y/Z script (Automatic 1111), or outputting your images into a grid with several different guidance scale values is a good way to see how the guidance scale impacts the output of the model.
You can find this in the scripts section of the Automatic 1111 Stable Diffusion WebUI: