explaingit

apple/ml-stable-diffusion

17,850PythonAudience · developerComplexity · 4/5Setup · hard

TLDR

Apple's toolkit for converting Stable Diffusion image-generation models to run entirely on iPhones, iPads, and Macs using Apple's own chips, no cloud server or internet connection required.

Mindmap

mindmap
  root((ml-stable-diffusion))
    What it does
      On-device image generation
      Model format conversion
      No server required
    Tech stack
      Python
      Swift
      Core ML
      PyTorch
    Platforms
      Mac
      iPhone
      iPad
    Use cases
      Privacy-first apps
      Offline generation
      iOS app development
    Features
      Weight compression
      Neural Engine support
      Performance benchmarks
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Ship an iOS or macOS app that generates images from text prompts entirely on-device, with no internet connection needed.

USE CASE 2

Convert a Stable Diffusion checkpoint from Hugging Face into a Core ML model file for Mac or iPhone.

USE CASE 3

Build an iPad app with private, offline AI image generation using Swift and Apple's Neural Engine.

Tech stack

PythonSwiftCore MLPyTorchHugging FaceXcode

Getting it running

Difficulty · hard Time to first run · 1day+

Requires a Mac with Apple Silicon, Xcode, and a Stable Diffusion checkpoint downloaded from Hugging Face before conversion can begin.

License terms not described in the explanation.

In plain English

Core ML Stable Diffusion is Apple's project for running Stable Diffusion image generation on Apple Silicon devices using Core ML, the framework Apple uses to run machine-learning models efficiently on its own chips. Stable Diffusion normally runs in PyTorch on big GPUs in the cloud, this repository provides the pieces needed to take that model, convert it into Core ML format, and run it directly on a Mac, iPad, or iPhone, including using the Neural Engine for acceleration. The repository has two main parts. The first is a Python package called python_coreml_stable_diffusion that converts PyTorch Stable Diffusion checkpoints, sourced via the Hugging Face diffusers library, into Core ML model files, and can also run image generation from Python. The second is a Swift package called StableDiffusion, which app developers add to an Xcode project so their own application can generate images using the converted Core ML models, without a server. The README documents tunables like compute-unit and attention-implementation choices that trade off latency, memory, and accuracy on different hardware, and weight compression techniques such as 6-bit and lower mixed-bit palettization to make the model small enough to fit on a phone. You would reach for this to ship an app that generates images on-device for privacy or offline use, or to experiment with Stable Diffusion performance on Mac hardware. The README lists system requirements including macOS, Xcode, Swift, and target Apple device generations, and includes performance benchmarks measured by Apple and Hugging Face across various iPhones and iPads. The Python side is Python, the on-device runtime is Swift, inference uses Core ML.

Copy-paste prompts

Prompt 1
Using Apple's ml-stable-diffusion Swift package, show me the Xcode setup steps and minimal Swift code to generate an image from a text prompt on an iPhone.
Prompt 2
Show me how to convert a Stable Diffusion v1.5 checkpoint from Hugging Face to Core ML format using the python_coreml_stable_diffusion Python tool.
Prompt 3
What compute-unit settings in ml-stable-diffusion should I choose for an iPhone 15 Pro to balance speed and memory?
Prompt 4
Write a Python script using python_coreml_stable_diffusion to generate an image from a prompt and save it to disk.
Prompt 5
How do I apply 6-bit palettization in ml-stable-diffusion to shrink the model so it fits on a phone?
Open on GitHub → Explain another repo

← apple on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.