# Repository Briefing: apple-aiml-research/ml-stable-diffusion
> Source: https://repoforai.com/repo/apple-aiml-research/ml-stable-diffusion (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/apple-aiml-research/ml-stable-diffusion
- **Category**: Voice, Vision & Video (语音 / 视觉 / 视频生成)
- **Primary Language**: Python
- **License**: MIT
- **Engineering Health**: B+ (70/100 · Maintenance 20/35 · Adoption 19/25 · Releases 11/20 · License 20/20)
- **Latest Release**: 1.1.1 (2024-05-04) — https://github.com/apple-aiml-research/ml-stable-diffusion/releases
- **Review Snapshot**: 2026-12-01
- **Deployment / Stack Signals**: Local AI, CLI
- **Momentum**: 17,956 ★ total (+0 24h / +1 7d) · 1,073 forks
- **When to Use**: Best for: Apple-platform teams shipping local image generation in a Swift app or testing Core ML model bundles from the CLI on target devices. Skip if: 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.

## Overview
```text
### Architecture & 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.
```

## Key Capabilities
```text
- Integration boundary: Python exports Core ML artifacts; `StableDiffusion` and `StableDiffusionSample` consume bundled resources on the Swift side.
- Model coverage: Preconverted SD 1.x, SD 2.x, and SDXL weights are available; SD3 Medium has a DiffusionKit-assisted conversion path and Swift `--sd3` mode.
- Mobile SDXL: `--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.
- Compression: Fixed-bit palettization targets the UNet and text encoder; mixed-bit analysis selects per-layer bit widths using denoised-latent PSNR.
- Activation quantization: Calibrated UNet sensitivity analysis supports selective W8A8 versus W8A16 for Neural Engine optimization on hardware such as A17 Pro and M4.
- Measured baseline: At 512×512 with SD 2.1 Base, CPU plus Neural Engine and `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.
```

## Quick Start / Clone
```bash
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 .
```
