apple-aiml-research/ml-stable-diffusion
Core ML conversion and Swift inference for on-device Stable Diffusion on Apple Silicon
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
The framework separates model preparation from application inference. python_coreml_stable_diffusion converts PyTorch components into Core ML artifacts through torch2coreml and offers a Python generation path using Hugging Face Diffusers. The dependency manifest specifies coremltools>=8.0, diffusers[torch]==0.30.2, transformers==4.44.2, and diffusionkit==0.4.0; PyTorch is also listed separately without a version pin.
Package.swift defines the Swift integration side: add StableDiffusion to an Xcode project or exercise the model with StableDiffusionSample. The handoff is a model resource bundle, not a Python service or network API. The artifacts depend on the model family: SDXL conversion can include a base and optional refiner, whereas SD3 Medium uses DiffusionKit-assisted tooling for an MMDiT denoiser and a 16-channel VAE decoder, with an option to bundle a preconverted T5 encoder alongside the converted text encoders.
Key Capabilities & Differentiators
Preconverted weights cover SD 1.4, 1.5, 2 Base, 2.1 Base, and SDXL Base, with six-bit variants for the listed SD 1.x and 2.x models and mixed-bit variants for SDXL. SDXL has a Swift refiner path, and SD3 Medium has a conversion recipe for 1024×1024 and a Swift --sd3 inference mode. Custom conversion can apply fixed-bit palettization to the UNet and text encoder; mixed-bit palettization instead chooses bit widths layer by layer using denoised-latent PSNR. Calibrated UNet activation quantization selectively uses W8A8 on less sensitive layers and W8A16 on more sensitive ones.
The 512×512 SD 2.1 Base benchmark paired CPU_AND_NE with SPLIT_EINSUM_V2, recording median end-to-end latencies of 18.5 s on iPhone 12 Mini, 7.9 s on iPhone 14 Pro Max, and 7.0 s on M2 iPad Pro. These were medians of five back-to-back runs on 2023 beta software, not current performance guarantees or estimates for SDXL or SD3.
Trade-offs & Limitations
Compared with direct PyTorch/Diffusers execution, this stack gives Apple applications a native Core ML runtime but makes checkpoint changes a conversion and validation task. Compared with hosted inference, it can keep prompts and images on-device, at the cost of distributing model resources and operating within client memory and compute limits. For SDXL, ORIGINAL is recommended for CPU plus GPU on Mac, and SPLIT_EINSUM for CPU plus Neural Engine on iPhone and iPad. The V2 attention path that performs well in the SD 2.1 benchmark is discouraged for XL because compilation takes too long.
The mobile SDXL recommendation is 768×768 rather than the default 1024×1024. The converter also forces float32 for the original SDXL VAE to avoid known float16 overflow; account for that precision choice in device tests. Mixed-bit pre-analysis can take hours on one MPS or CUDA GPU, and latent PSNR is not a substitute for inspecting images from representative prompts. In a deployment review, measure both first-run and repeated-run latency and peak memory for the exact artifact you will ship. The repository's MIT license does not settle the licensing of separately distributed weights.
Hardware & Deployment Guide
For an initial app test, use matching Core ML weights from Hugging Face and validate the resources with the Swift CLI before integrating the package into Xcode. For a custom checkpoint, install the Python project with pip install -e ., convert with the flags for its model family, and use --bundle-resources-for-swift-cli to prepare the Swift resources. Downloads and conversion are setup steps; once the model resources are in place, generation can run on-device without a hosted inference endpoint or a Python runtime in the Swift app.
The baseline runtime minima are macOS 13.1 and iOS/iPadOS 16.2. The memory-improved compressed-weight path targets macOS 14 and iOS/iPadOS 17, where compressed weights can be decompressed at execution time rather than in advance when the model loads. These OS floors do not guarantee that every model fits on every supported device. Release 1.0.0 introduced six-bit compression and SPLIT_EINSUM_V2; 1.1.0 added Swift SDXL refiner inference and Python SDXL base inference; 1.1.1 switched the code to MIT and fixed safety-checker dtype and mixed-bit tooling issues.
StableDiffusion and StableDiffusionSample consume bundled resources on the Swift side.--sd3 mode.--latent-h 96 --latent-w 96 targets 768×768; SPLIT_EINSUM is recommended for CPU plus Neural Engine, while V2 is discouraged for XL compilation.SPLIT_EINSUM_V2 yielded median end-to-end times of 7.9 s on iPhone 14 Pro Max and 7.0 s on M2 iPad Pro.Apple-platform teams shipping local image generation in a Swift app or testing Core ML model bundles from the CLI on target devices.
You need one inference runtime across Apple and non-Apple platforms, frequently change model components without a conversion step, or cannot budget client storage and memory for model assets.
Quick Start & Installation
conda create -n coreml_stable_diffusion python=3.8 -y conda activate coreml_stable_diffusion cd /path/to/cloned/ml-stable-diffusion/repository pip install -e .
Comparison vs. Top Voice, Vision & Video Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| ml-stable-diffusion ★ | 18k | +1 | Python | MIT | Core ML conversion and Swift inference for on-device Stable Diffusion on Apple S |
| whisperX | 26.5k | +677 | Python | BSD-2-Clause | Batched Whisper with forced alignment for word timings and optional speaker labe |
| hypit | 32.4k | +731 | TypeScript | — | An SVML framework and CLI for turning video references into reusable workflows |
| diffusers | 35k | +36 | Python | Apache-2.0 | A modular PyTorch SDK for running and customizing multimodal diffusion pipelines |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/apple-aiml-research/ml-stable-diffusion.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about ml-stable-diffusion
How do I move a checkpoint from Python into a Swift app?
python_coreml_stable_diffusion.torch2coreml. For your own conversion, --bundle-resources-for-swift-cli packages the resources consumed by StableDiffusionSample. Test that bundle with the CLI, then add the StableDiffusion Swift package to your Xcode project and provide the corresponding model resources. The Swift runtime does not need the Python conversion environment.How should I size memory and test runtime overhead?
Does MIT cover commercial deployment and redistribution of the weights?
When is Core ML a better fit than direct Diffusers or a hosted API?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy