Stable Diffusion XL on Mac with Advanced Core ML Quantization
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.
Related posts
- Faster Stable Diffusion with Core ML on iPhone, iPad, and Mac
Hugging Face mediumAdeptCore ML in iOS 17 and macOS 14 adds 6-bit weight palettization for running Stable Diffusion faster and with less memory. Weights are indices into a lookup table and are decompressed layer by layer during inference rather than at load time, which cuts memory transfer on the critical path. Apple's ml-stable-diffusion now supports a --quantize-nbits conversion flag (8/6/4/2 bits) and a SPLIT_EINSUM_V2 attention variant that chunks queries into 512-length pieces for 10–30% Neural Engine speedups. Pre-converted 6-bit models for SD 1.4–2.1 are on the Hub, alongside conversion commands for custom models and a note that training-time compression can reach 4 or 2 bits with less quality loss.
- Using Stable Diffusion with Core ML on Apple Silicon
Hugging Face mediumAdeptStable 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. Each model comes in 'original' attention (CPU/GPU only, sometimes faster) or 'split_einsum' attention (also runs on the Neural Engine), packaged either as ML Packages for Python or compiled mlmodelc bundles for Swift. The best result on an M1 Max was 18s per image, using original attention with all compute units on macOS Ventura 13.1, which is required to avoid black images. Step-by-step download and inference commands are given for Python and Swift, plus a pointer to Apple's conversion script for custom fine-tuned models.
- WWDC 24: Running Mistral 7B with Core ML
Hugging Face mediumAdeptMistral 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. The conversion patches the transformers Mistral attention to use a pre-allocated, in-place kv-cache, traces it with torch.jit, and converts it with coremltools RangeDim inputs and StateType caches. Int4 per-block linear quantization (block size 32) shrinks the model from about 14GB in float16 to about 3.8GB. Inference then runs through the preview branch of swift-transformers.
- Swift 🧨Diffusers - Fast Stable Diffusion for Mac
Hugging Face mediumAdeptDiffusers 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. Benchmarks across M1, M2 and M1 Max show base M1/M2 chips run roughly twice as fast on the Neural Engine as on the GPU, while the M1 Max is much faster on the GPU because it has four times as many GPU cores. Memory size barely affects speed, and combining GPU and ANE did not beat the faster of the two alone. The release also adds guidance scale, seed reuse, cancellation and model download indicators, and asks the community for benchmark data from Pro and Max chips.
- Using LoRA for Efficient Stable Diffusion Fine-Tuning
Hugging Face mediumAdeptLoRA 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. Training fits in 11 GB of VRAM (a 2080 Ti) without 8-bit optimizers, uses a much higher learning rate (1e-4 vs ~1e-6), and produces ~3 MB weight files, roughly 1000x smaller than the UNet. A walkthrough covers the training script on a Pokémon dataset, looking up the base model from Hub metadata, and loading LoRA weights at inference with load_attn_procs. LoRA is also compared with Textual Inversion and Pivotal Tuning.