out.images[0].save("out_custom_cfg.png") The callback function is executed at the end of each denoising step, and modifies the pipeline attributes and tensor variables for the next denoising step. With callbacks, you can implement features such as dynamic CFG without having to modify the underlying code at all! 🤗 Diffusers currently only supports callback_on_step_end, but feel free to open a feature request if you have a cool use-case and require a callback function with a different execution point!  Using Callbacks to interrupt the Diffusion Process The following Pipelines support interrupting the diffusion process via callback StableDiffusionPipeline StableDiffusionImg2ImgPipeline StableDiffusionInpaintPipeline StableDiffusionXLPipeline StableDiffusionXLImg2ImgPipeline StableDiffusionXLInpaintPipeline Interrupting the diffusion process is particularly useful when building UIs that work with Diffusers because it allows users to stop the generation process if they’re unhappy with the intermediate results. You can incorporate this into your pipeline with a callback. This callback function should take the following arguments: pipe, i, t, and callback_kwargs (this must be returned). Set the pipeline’s _interrupt attribute to True to stop the diffusion process after a certain number of steps. You are also free to implement your own custom stopping logic inside the callback. In this example, the diffusion process is stopped after 10 steps even though num_inference_steps is set to 50.   Copied from diffusers import StableDiffusionPipeline