apple-aiml-research /ml-stable-diffusion

Stable Diffusion with Core ML on Apple Silicon

★ 17,958⑂ 1,076👁 138⑃ 0● 0▤ 7
PythonMITCreated 2022-11-16
下载:1.1.11.1.1 ↓1.1.12024-05-04
+0
日增长
17,958
stars
1,076
forks
138
watchers
0
prs
0
issues
7
releases

README

Core ML Stable Diffusion

Run Stable Diffusion on Apple Silicon with Core ML

[\[Blog Post\]](https://machinelearning.apple.com/research/stable-diffusion-coreml-apple-silicon) [\[BibTeX\]](bibtex)


This repository comprises:

- python_coreml_stable_diffusion, a Python package for converting PyTorch models to Core ML format and performing image generation with Hugging Face diffusers in Python
- StableDiffusion, a Swift package that developers can add to their Xcode projects as a dependency to deploy image generation capabilities in their apps. The Swift package relies on the Core ML model files generated by python_coreml_stable_diffusion

If you run into issues during installation or runtime, please refer to the FAQ section. Please refer to the System Requirements section before getting started.



  System Requirements


   Details (Click to expand) 

Model Conversion:

 macOS  | Python | coremltools |
:------:|:------:|:-----------:|
  13.1  | 3.8    |    7.0      |

Project Build:

  macOS | Xcode | Swift |
:------:|:-----:|:-----:|
  13.1  | 14.3  |  5.8  |

Target Device Runtime:

  macOS | iPadOS, iOS |
:------:|:-----------:|
  13.1  |     16.2    |

Target Device Runtime (With Memory Improvements):

  macOS | iPadOS, iOS |
:------:|:-----------:|
  14.0  |     17.0    |

Target Device Hardware Generation:

  Mac   |  iPad   | iPhone  |
:------:|:-------:|:-------:|
   M1   |   M1    |  A14    |




  Performance Benchmarks


   Details (Click to expand) 


stabilityai/stable-diffusion-2-1-base (512x512)



|        Device         | --compute-unit| --attention-implementation | End-to-End Latency (s) | Diffusion Speed (iter/s) |
| --------------------- | --------------- | ---------------------------- | ---------------------- | ------------------------ |
| iPhone 12 Mini        | CPU_AND_NE    |      SPLIT_EINSUM_V2       |      18.5             |        1.44              |
| iPhone 12 Pro Max     | CPU_AND_NE    |      SPLIT_EINSUM_V2       |      15.4              |        1.45              |
| iPhone 13             | CPU_AND_NE    |      SPLIT_EINSUM_V2       |      10.8             |        2.53              |
| iPhone 13 Pro Max     | CPU_AND_NE    |      SPLIT_EINSUM_V2       |      10.4              |        2.55              |
| iPhone 14             | CPU_AND_NE    |      SPLIT_EINSUM_V2       |      8.6               |        2.57              |
| iPhone 14 Pro Max     | CPU_AND_NE    |      SPLIT_EINSUM_V2       |      7.9               |        2.69              |
| iPad Pro (M1)         | CPU_AND_NE    |      SPLIT_EINSUM_V2       |      11.2              |        2.19              |
| iPad Pro (M2)         | CPU_AND_NE    |      SPLIT_EINSUM_V2       |      7.0               |        3.07              |


   Details (Click to expand) 

- This benchmark was conducted by Apple and Hugging Face using public beta versions of iOS 17.0, iPadOS 17.0 and macOS 14.0 Seed 8 in August 2023.
- The performance data was collected using the b

Latest release

1.1.1 1.1.1 2024-05-04
Changed the license to MIT

 What else has Changed
 Fix safety_checker dtype  by @ZachNagengast in https://github.com/apple/ml-stable-diffusion/pull/276
 Fix  missing parameters ('mixed_bit_compression_apply', ) &  import pkg (mixed_bit_compression_pre_analysis) issues by @jiangdi0924 in https://github.com/apple/ml-stable-diffusion/pull/279
 Fix pipeline.py for Python 3.8 by @TobyRoseman in https://github.com/apple/ml-stable-diffusion/pull/287
 Compiled Models in Python by @TobyRoseman in https://github.com/apple/ml-stable-diffusion/pull/296
 Use sRGB if available by @stuartjmoore in ht

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON