Skip to content

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

Hugging Face 9 min read How-to mediumAdept

🧨 Stable Diffusion in JAX / Flax !

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.

Assumes: Pythonbasic JAXdiffusion models basics

Related posts

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

    Hugging Face mediumAdept

    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.

  • 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.

  • 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.5 Large

    Hugging Face mediumAdept

    Stable Diffusion 3.5 Large (8B) and a timestep-distilled Turbo variant are now usable in Diffusers. The architecture matches SD3 Medium except for QK normalization and dual attention layers in the MMDiT blocks. Code covers bf16 inference, few-step (4-8 step) Turbo generation without classifier-free guidance, NF4 quantization via bitsandbytes with CPU offload for consumer GPUs, and single-file checkpoint loading. LoRA fine-tuning on 24GB GPUs works with the existing SD3 DreamBooth script, combined with peft's k-bit training preparation.

  • 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.

The quest for software engineering knowledge.

Look:
Layout: