---
title: "Exploring simple optimizations for SDXL"
description: "Running SDXL out of the box in fp32 on an A100 takes about 28GB and 72 seconds for 4 images."
url: "https://swe.quest/articles/exploring-simple-optimizations-for-sdxl-b199204d28422c69"
canonical: "https://huggingface.co/blog/simple_sdxl_optimizations"
source: "Hugging Face"
published: "2023-10-24"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["inference","performance","computer-vision","python"]
---

# Exploring simple optimizations for SDXL

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-10-24, 8 min read, How-to. Original: [https://huggingface.co/blog/simple\_sdxl\_optimizations](https://huggingface.co/blog/simple_sdxl_optimizations)

## Summary

Running SDXL out of the box in fp32 on an A100 takes about 28GB and 72 seconds for 4 images. A series of Diffusers and PyTorch 2 optimizations, each benchmarked on that setup, cuts both. Switching to fp16 brings latency to 14.8s, SDPA attention (on by default) to 11.4s, and torch.compile to 10.3s. Memory drops with model or sequential CPU offloading (sequential is much slower), VAE slicing (15.4GB, or 11.5GB combined with sequential offload), precomputed text embeddings, and the Tiny Autoencoder (15.5GB and faster, at some cost in fine detail). The gains depend on hardware; torch.compile, for example, only appears to help modern GPUs.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- PyTorch basics
- diffusion models
- GPU memory concepts ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))

## Keywords

SDXL, Diffusers, PyTorch 2.0, torch.compile, scaled dot product attention, Tiny Autoencoder, Stable Diffusion

## Related posts

- [Run FLUX.1-dev three times faster](https://swe.quest/articles/run-flux-1-dev-three-times-faster-ae60b80e0a362206.md): Modal · 2025-06-18 · Medium · 9 min read · Inference & serving, Performance engineering, Python, Computer vision, Serverless
  FLUX.1-dev image generation on Modal drops from ~6.75s to under three seconds per 1024x1024 image.
- [Make your ZeroGPU Spaces go brrr with ahead-of-time compilation](https://swe.quest/articles/make-your-zerogpu-spaces-go-brrr-with-ahead-of-time-compilation-51092e3d8eed121c.md): Hugging Face · 2025-09-02 · Medium · 13 min read · Inference & serving, Performance engineering, Compilers, Python
  PyTorch ahead-of-time compilation (torch.export plus AOTInductor) suits ZeroGPU Spaces, where each GPU task runs in a short-lived forked process and torch.compile's just-in-time caching costs tens of seconds to minutes per task.
- [Fast LoRA inference for Flux with Diffusers and PEFT](https://swe.quest/articles/fast-lora-inference-for-flux-with-diffusers-and-peft-adf61d95e12cb0a4.md): Hugging Face · 2025-07-23 · Hard · 9 min read · Inference & serving, Performance engineering, Computer vision, Python
  Combining Flash Attention 3, torch.compile and TorchAO FP8 quantization with PEFT's LoRA hotswapping speeds up Flux.1-Dev LoRA inference by 2.23x on an H100, and swapping adapters does not trigger recompilation.
- [Accelerating Stable Diffusion Inference on Intel CPUs](https://swe.quest/articles/accelerating-stable-diffusion-inference-on-intel-cpus-b246e61d473debb6.md): Hugging Face · 2023-03-28 · Medium · 6 min read · Inference & serving, Performance engineering, Hardware, Python
  Stable Diffusion v1.5 inference on Sapphire Rapids Xeon CPUs (EC2 r7iz) can be cut from a 32.3s baseline to a few seconds per image with a stack of optimizations.
- [Accelerating SD Turbo and SDXL Turbo Inference with ONNX Runtime and Olive](https://swe.quest/articles/accelerating-sd-turbo-and-sdxl-turbo-inference-with-onnx-runtime-and-olive-c7ff7774ed240b5b.md): Hugging Face · 2024-01-15 · Medium · 8 min read · Inference & serving, Performance engineering, Computer vision, Hardware
  ONNX Runtime's CUDA and TensorRT execution providers run SD Turbo and SDXL Turbo faster than PyTorch on NVIDIA A100 and RTX 4090 GPUs for every batch-size and step combination tested.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
