---
title: "🧨 Accelerating Stable Diffusion XL Inference with JAX on Cloud TPU v5e"
description: "Hugging Face Diffusers can now serve Stable Diffusion XL with JAX on Cloud TPU v5e."
url: "https://swe.quest/articles/accelerating-stable-diffusion-xl-inference-with-jax-on-cloud-tpu-v5e-70ca37a9ec6835bd"
canonical: "https://huggingface.co/blog/sdxl_jax"
source: "Hugging Face"
published: "2023-10-03"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["inference","computer-vision","hardware","python","performance"]
---

# 🧨 Accelerating Stable Diffusion XL Inference with JAX on Cloud TPU v5e

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-10-03, 8 min read, How-to. Original: [https://huggingface.co/blog/sdxl\_jax](https://huggingface.co/blog/sdxl_jax)

## Summary

Hugging Face Diffusers can now serve Stable Diffusion XL with JAX on Cloud TPU v5e. JIT compilation over static shapes plus pmap data parallelism lets a v5e-4 produce four 1024×1024 images in about 2.3s of generation time, after a one-time compile of roughly three minutes. A step-by-step pipeline converts parameters to bfloat16 while keeping scheduler state in float32 to avoid degraded or black images, then replicates inputs with per-device RNG seeds. Benchmarks show TPU v5e delivering up to 2.4x better performance per dollar than TPU v4 at similar latency.

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)
- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- JAX basics
- diffusion models
- Python ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))

## Keywords

Stable Diffusion XL, JAX, Cloud TPU v5e, Diffusers, XLA, pmap, bfloat16, Flax

## Related posts

- [🧨 Stable Diffusion in JAX / Flax !](https://swe.quest/articles/stable-diffusion-in-jax-flax-24ee6f1fbf14e9db.md): Hugging Face · 2022-10-13 · Medium · 9 min read · Inference & serving, Computer vision, Python, Hardware
  Hugging Face Diffusers 0.5.1 adds Flax support, enabling Stable Diffusion inference on Google TPUs.
- [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.
- [Diffusers welcomes Stable Diffusion 3](https://swe.quest/articles/diffusers-welcomes-stable-diffusion-3-f6ced777e2fcbd47.md): Hugging Face · 2024-06-12 · Medium · 7 min read · Computer vision, Inference & serving, Model training, Python
  Stable Diffusion 3 Medium (2B parameters) is now usable through Diffusers.
- [Fine-tuning Stable Diffusion models on Intel CPUs](https://swe.quest/articles/fine-tuning-stable-diffusion-models-on-intel-cpus-a7b97eec2af1f8ba.md): Hugging Face · 2023-07-14 · Medium · 7 min read · Model training, Hardware, Inference & serving, Computer vision
  Stable Diffusion v1.5 can be fine-tuned with textual inversion on a four-node Intel Sapphire Rapids Xeon cluster, using AMX acceleration via Intel Extension for PyTorch, oneCCL for distributed communication, and Accelerate launched under mpirun with 16 tasks.
- [State of open video generation models in Diffusers](https://swe.quest/articles/state-of-open-video-generation-models-in-diffusers-9770186e8fdb5a0a.md): Hugging Face · 2025-01-27 · Medium · 16 min read · Inference & serving, Computer vision, Video & media, Performance engineering, Model training
  Open video generation models such as HunyuanVideo, CogVideoX, LTX-Video, Mochi-1 and Allegro share a common architecture: T5-style text encoders, a DiT-based denoiser over 3D spatio-temporal tokens, a spatially and temporally compressing VAE, and a scheduler.

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)
