---
title: "Accelerating Stable Diffusion Inference on Intel CPUs"
description: "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."
url: "https://swe.quest/articles/accelerating-stable-diffusion-inference-on-intel-cpus-b246e61d473debb6"
canonical: "https://huggingface.co/blog/stable-diffusion-inference-intel"
source: "Hugging Face"
published: "2023-03-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["inference","performance","hardware","python"]
---

# Accelerating Stable Diffusion Inference on Intel CPUs

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-03-28, 6 min read, How-to. Original: [https://huggingface.co/blog/stable-diffusion-inference-intel](https://huggingface.co/blog/stable-diffusion-inference-intel)

## Summary

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.

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)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- PyTorch basics
- Stable Diffusion pipelines

## Keywords

Stable Diffusion, Diffusers, OpenVINO, Optimum Intel, Intel Extension for PyTorch, Sapphire Rapids, AMX, jemalloc

## Related posts

- [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.
- [Optimizing Stable Diffusion for Intel CPUs with NNCF and 🤗 Optimum](https://swe.quest/articles/optimizing-stable-diffusion-for-intel-cpus-with-nncf-and-optimum-4e8b23fd42b05887.md): Hugging Face · 2023-05-25 · Hard · 7 min read · Inference & serving, Computer vision, Model training, Performance engineering
  Post-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.
- [🧨 Accelerating Stable Diffusion XL Inference with JAX on Cloud TPU v5e](https://swe.quest/articles/accelerating-stable-diffusion-xl-inference-with-jax-on-cloud-tpu-v5e-70ca37a9ec6835bd.md): Hugging Face · 2023-10-03 · Medium · 8 min read · Inference & serving, Computer vision, Hardware, Python, Performance engineering
  Hugging Face Diffusers can now serve Stable Diffusion XL with JAX on Cloud TPU v5e.
- [🧨 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 PyTorch Transformers with Intel Sapphire Rapids - part 2](https://swe.quest/articles/accelerating-pytorch-transformers-with-intel-sapphire-rapids-part-2-c41ef6f6c233e349.md): Hugging Face · 2023-02-06 · Medium · 6 min read · Inference & serving, Hardware, Performance engineering, Python
  Intel 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.

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)
