image = pipe(prompt, num_inference_steps=30).images[0] Scaled dot product attention improves the latency from 4.63 seconds to 3.31 seconds.   torch.compile PyTorch 2 includes torch.compile which uses fast and optimized kernels. In Diffusers, the UNet and VAE are usually compiled because these are the most compute-intensive modules. First, configure a few compiler flags (refer to the full list for more options):   Copied from diffusers import StableDiffusionXLPipeline