Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 8 min read How-to mediumAdept

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

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.

Assumes: JAX basicsdiffusion modelsPython

Related posts

  • 🧨 Stable Diffusion in JAX / Flax !

    Hugging Face mediumAdept

    Hugging Face Diffusers 0.5.1 adds Flax support, enabling Stable Diffusion inference on Google TPUs. The walkthrough loads bf16 weights with FlaxStableDiffusionPipeline, then replicates parameters and shards prompts across 8 TPU devices to generate 8 images in parallel. It also covers PRNG key splitting for reproducibility and why input shapes must stay fixed to avoid recompilation. On a TPU v2-8, the first JIT compile takes over a minute, after which a batch of 8 images takes about 7 seconds. It closes by showing how jax.pmap compiles the generation function and runs it SPMD-style on each device.

  • Accelerating Stable Diffusion Inference on Intel CPUs

    Hugging Face mediumAdept

    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. OpenVINO via Optimum Intel gives a 2x speedup through automatic bfloat16, and reshaping the pipeline to a static 512x512 resolution brings it to 4.7s. Without OpenVINO, jemalloc, Intel OpenMP and numactl core pinning reach 11.8s with no code change. Adding IPEX with channels-last, bfloat16 and AMX gets to 5.4s, and the DPMSolverMultistep scheduler reaches 5.05s, about 6.5x faster than the baseline.

  • Diffusers welcomes Stable Diffusion 3

    Hugging Face mediumAdept

    Stable Diffusion 3 Medium (2B parameters) is now usable through Diffusers. Its architecture pairs three text encoders (two CLIP models and T5-XXL) with a Multimodal Diffusion Transformer that runs joint attention over text and image-patch sequences, and it is trained with rectified flow matching, served by a new FlowMatchEulerDiscreteScheduler (shift=3.0 recommended). Benchmarks on an A100 show the memory tradeoffs: CPU offloading cuts VRAM from 18.8GB to 12GB at roughly 6.8x latency, dropping T5 brings it to 4.3GB, and 8-bit T5 reaches 10.6GB with almost no slowdown. torch.compile delivers about a 4x speedup (0.585s), and a DreamBooth LoRA fine-tuning script is included.

  • Fine-tuning Stable Diffusion models on Intel CPUs

    Hugging Face mediumAdept

    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. With only five example images and bf16 mixed precision, 200 training steps take about five minutes; 3,000 steps take about an hour. The walkthrough covers environment setup, the IPEX patch to the diffusers script, oneCCL/tcmalloc environment variables, per-node troubleshooting, and exporting the result to OpenVINO via Optimum Intel for sub-5-second CPU inference.

  • State of open video generation models in Diffusers

    Hugging Face mediumAdept

    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. Diffusers runs them in a few lines of code but they need a lot of memory, about 60 GB for HunyuanVideo at default settings. Benchmarks combining bitsandbytes/FP8 quantization, CPU and group offloading, VAE tiling and layerwise casting bring HunyuanVideo down to about 6.6 GB with little extra latency. Timestep and guidance distillation speed up generation, and the finetrainers repo supports LoRA fine-tuning.

The quest for software engineering knowledge.

Look:
Layout: