Accelerating Stable Diffusion Inference on Intel CPUs
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.
Related posts
- Fine-tuning Stable Diffusion models on Intel CPUs
Hugging Face mediumAdeptStable 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.
- Optimizing Stable Diffusion for Intel CPUs with NNCF and 🤗 Optimum
Hugging Face hardMasterPost-training 8-bit quantization breaks Stable Diffusion's UNet, so this workflow uses NNCF quantization-aware training with knowledge distillation from the original model as teacher and EMA on non-quantizer weights. It is stacked with an OpenVINO-compatible Token Merging (merge ratio 0.4) to speed up inference on Intel CPUs. Fine-tuning a Pokemon-tuned model for 4096 iterations on a single 24 GB GPU takes under a day. Against PyTorch FP32 on a Xeon CPU, OpenVINO FP32 gives 1.9x, 8-bit QAT gives 3.9x with a 4x smaller footprint, and ToMe plus 8-bit reaches 5.1x. The resulting pipeline loads through Optimum Intel's OVStableDiffusionPipeline, and more complex datasets call for lower merging ratios.
- 🧨 Accelerating Stable Diffusion XL Inference with JAX on Cloud TPU v5e
Hugging Face mediumAdeptHugging 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.
- 🧨 Stable Diffusion in JAX / Flax !
Hugging Face mediumAdeptHugging 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 PyTorch Transformers with Intel Sapphire Rapids - part 2
Hugging Face mediumAdeptIntel Sapphire Rapids CPUs with AMX instructions, combined with Hugging Face Optimum Intel running in bfloat16 with JIT compilation, cut p99 inference latency for DistilBERT, BERT and RoBERTa text classification by roughly 3x compared with vanilla Transformers on Ice Lake. The benchmark uses EC2 c6i.16xlarge and r7iz.16xlarge-metal instances, short (16-token) and long (128-token) inputs, single and batch-of-8 predictions, and libtcmalloc. Optimum needs only a small wrapper around the existing pipeline code, and the results show single-digit millisecond latency on long sequences without a GPU.