---
title: "Stable Diffusion XL on Mac with Advanced Core ML Quantization"
description: "Stable Diffusion XL base has been ported to Core ML for Apple Silicon Macs (macOS 14 beta), with end-to-end latency ranging from 46 s on an M1 Max to 20 s on an M2 Ultra using CPU+GPU and the ORIGINAL attention implementation."
url: "https://swe.quest/articles/stable-diffusion-xl-on-mac-with-advanced-core-ml-quantization-eb7e4e62c0405a93"
canonical: "https://huggingface.co/blog/stable-diffusion-xl-coreml"
source: "Hugging Face"
published: "2023-07-27"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 8
tags: ["inference","computer-vision","mobile","swift"]
---

# Stable Diffusion XL on Mac with Advanced Core ML Quantization

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-07-27, 8 min read, Deep dive. Original: [https://huggingface.co/blog/stable-diffusion-xl-coreml](https://huggingface.co/blog/stable-diffusion-xl-coreml)

## Summary

Stable Diffusion XL base has been ported to Core ML for Apple Silicon Macs (macOS 14 beta), with end-to-end latency ranging from 46 s on an M1 Max to 20 s on an M2 Ultra using CPU+GPU and the ORIGINAL attention implementation. The main technique is mixed-bit palettization, a post-training quantization method that picks a bit depth per layer (1, 2, 4, 8 or float16) based on each layer's measured PSNR impact against the float16 model. Recipes at 6.55, 4.50 and 3.41 bits per parameter all beat naive 8-bit linear quantization on PSNR, and the 4.5-bit recipe shrinks the UNet from 4.8 GB to 1.4 GB. Aggressive compression can degrade prompt adherence in ways PSNR does not capture. Analysis and apply scripts plus precomputed recipes for SD 1.5, 2.1 and XL are published.

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)
- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [Mobile](https://swe.quest/tags/mobile.md) (Web & mobile)
- [Swift](https://swe.quest/tags/swift.md) (Languages)

## Prerequisites

- diffusion models basics
- weight quantization ([easy posts on Inference & serving](https://swe.quest/tags/inference.md?difficulty=easy))
- Core ML ([easy posts on Machine learning](https://swe.quest/tags/machine-learning.md?difficulty=easy))

## Keywords

Stable Diffusion XL, Core ML, mixed-bit palettization, Apple Silicon, diffusers, PSNR, ml-stable-diffusion

## Related posts

- [Faster Stable Diffusion with Core ML on iPhone, iPad, and Mac](https://swe.quest/articles/faster-stable-diffusion-with-core-ml-on-iphone-ipad-and-mac-5c3ad0b6711e28d5.md): Hugging Face · 2023-06-15 · Medium · 9 min read · Inference & serving, Mobile, Computer vision, Hardware
  Core ML in iOS 17 and macOS 14 adds 6-bit weight palettization for running Stable Diffusion faster and with less memory.
- [Using Stable Diffusion with Core ML on Apple Silicon](https://swe.quest/articles/using-stable-diffusion-with-core-ml-on-apple-silicon-ec28c0373922e17b.md): Hugging Face · 2022-12-01 · Medium · 6 min read · Inference & serving, Computer vision, Swift, Python
  Stable Diffusion can run on Apple Silicon via Core ML using Apple's ml-stable-diffusion repo, with pre-converted checkpoints for v1.4, v1.5, v2 base and v2.1 base hosted on the Hugging Face Hub.
- [WWDC 24: Running Mistral 7B with Core ML](https://swe.quest/articles/wwdc-24-running-mistral-7b-with-core-ml-8ff5ba3b889a9bf2.md): Hugging Face · 2024-07-22 · Medium · 13 min read · Inference & serving, LLMs, Swift, Mobile
  Mistral 7B Instruct can run on a Mac with Core ML using features new in iOS 18 and macOS Sequoia: the MLTensor Swift type for tensor pre- and post-processing, stateful buffers that keep the kv-cache on the GPU instead of passing it in and out on every call, and block-wise 4-bit quantization.
- [Swift 🧨Diffusers - Fast Stable Diffusion for Mac](https://swe.quest/articles/swift-diffusers-fast-stable-diffusion-for-mac-9aed97f099aa5274.md): Hugging Face · 2023-02-24 · Medium · 5 min read · Inference & serving, Performance engineering, Hardware, Swift, Machine learning
  Diffusers for Mac 1.1, an open-source SwiftUI app that runs Core ML-converted Stable Diffusion models locally, can generate images up to twice as fast as the previous version by automatically picking the best compute unit for each machine.
- [Using LoRA for Efficient Stable Diffusion Fine-Tuning](https://swe.quest/articles/using-lora-for-efficient-stable-diffusion-fine-tuning-7bd5416d145ae531.md): Hugging Face · 2023-01-26 · Medium · 7 min read · Model training, Computer vision, Python
  LoRA freezes pretrained weights and trains small rank-decomposition matrices, and diffusers now supports applying it to Stable Diffusion's cross-attention layers for both full fine-tuning and Dreambooth.

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)
