---
title: "Optimizing Stable Diffusion for Intel CPUs with NNCF and 🤗 Optimum"
description: "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."
url: "https://swe.quest/articles/optimizing-stable-diffusion-for-intel-cpus-with-nncf-and-optimum-4e8b23fd42b05887"
canonical: "https://huggingface.co/blog/train-optimize-sd-intel"
source: "Hugging Face"
published: "2023-05-25"
difficulty: "hard"
kind: "Case study"
reading_minutes: 7
tags: ["inference","computer-vision","model-training","performance"]
---

# Optimizing Stable Diffusion for Intel CPUs with NNCF and 🤗 Optimum

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-05-25, 7 min read, Case study. Original: [https://huggingface.co/blog/train-optimize-sd-intel](https://huggingface.co/blog/train-optimize-sd-intel)

## Summary

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

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- Stable Diffusion architecture ([easy posts on System design](https://swe.quest/tags/system-design.md?difficulty=easy))
- neural network quantization ([easy posts on Inference & serving](https://swe.quest/tags/inference.md?difficulty=easy))
- knowledge distillation

## Keywords

Stable Diffusion, OpenVINO, NNCF, Optimum Intel, Token Merging, Quantization-Aware Training, Diffusers, Intel Xeon

## Related posts

- [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.
- [Accelerate your models with 🤗 Optimum Intel and OpenVINO](https://swe.quest/articles/accelerate-your-models-with-optimum-intel-and-openvino-6481f69a8bf224aa.md): Hugging Face · 2022-11-02 · Medium · 5 min read · Inference & serving, Python, Hardware, Computer vision
  Optimum Intel now integrates OpenVINO, letting Transformers models run on OpenVINO Runtime across Intel processors and be quantized with the Neural Network Compression Framework (NNCF).
- [Exploring Quantization Backends in Diffusers](https://swe.quest/articles/exploring-quantization-backends-in-diffusers-11e0d1ba0cf15851.md): Hugging Face · 2025-05-21 · Medium · 11 min read · Inference & serving, Computer vision, Python, Performance engineering
  Hugging Face Diffusers supports several quantization backends (bitsandbytes, torchao, Quanto, GGUF and native FP8 layerwise casting) that shrink large diffusion models such as Flux-dev, whose full BF16 pipeline needs about 31 GB.
- [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.
- [Blazing Fast SetFit Inference with 🤗 Optimum Intel on Xeon](https://swe.quest/articles/blazing-fast-setfit-inference-with-optimum-intel-on-xeon-804c53c4c80ba1a3.md): Hugging Face · 2024-04-03 · Medium · 6 min read · Inference & serving, Performance engineering, Hardware, Python
  Post-training static int8 quantization of a SetFit model body with Optimum Intel and Intel Neural Compressor speeds up inference on Xeon CPUs by up to 7.8x in throughput with negligible accuracy loss.

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)
