Maple Diffusion runs Stable Diffusion models locally on macOS / iOS devices, in Swift, using the MPSGraph framework (not Python).
Maple Diffusion should be capable of generating a reasonable image in a minute or two on a recent iPhone (I get around ~2.3s / step on an iPhone 13 Pro).
To attain usable performance without tripping over iOS’s 4GB memory limit, Maple Diffusion relies internally on FP16 (NHWC) tensors, operator fusion from MPSGraph, and a truly pitiable degree of swapping models to device storage.
On macOS, Maple Diffusion uses slightly more memory (~6GB), to reach <1s / step.
Projects using Maple Diffusion
- https://github.com/mortenjust/maple-diffusion/ is a fork with several improvements
Maple Diffusion should run on any Apple Silicon Mac (M1, M2, etc.). Intel Macs should also work now thanks to this PR.
Maple Diffusion should run on any iOS device with sufficient RAM (≥6144MB RAM definitely works; 4096MB might but I wouldn’t bet on it; anything lower than that won’t work). That means recent iPads should work out of the box, and recent iPhones should work if you can get the
Increase Memory Limit capability working (to unlock 4GB of RAM). Unfortunately, iPhone 14 variants seemingly do not honor the increased memory limit, so they won’t work yet.
Maple Diffusion currently expects Xcode 14 and iOS 16; other versions may require changing build settings or just not work. iOS 16.1 (beta) is reportedly broken and always generating a gray image.
To build and run Maple Diffusion:
Download a Stable Diffusion PyTorch model checkpoint (
sd-v1-4.ckpt, or some derivation thereof)
Download this repo
git clone https://github.com/madebyollin/maple-diffusion.git && cd maple-diffusion
Setup & install Python with PyTorch, if you haven’t already.
# may need to install conda first https://github.com/conda-forge/miniforge#homebrew conda deactivate conda remove -n maple-diffusion --all conda create -n maple-diffusion python=3.10 conda activate maple-diffusion pip install torch typing_extensions numpy Pillow requests pytorch_lightning
Convert the PyTorch model checkpoint into a bunch of fp16 binary blobs.
maple-diffusionXcode project. Select the device you want to run on from the
Product > Destinationmenu.
Manually add the
Increased Memory Limitcapability to the
maple-diffusiontarget (this step might not be needed on iPads, but it’s definitely needed on iPhones – the default limit is 3GB).
Build & run the project on your device with the
Product > Runmenu.
Mobile App Development Best Practices – 03.10
iOS MetaCodable – Supercharge Swift’s Codable implementations with macros meta-programming How to build a Tuist plugin and publish it using...
How to make and use BOM (Bill of Materials) dependencies in Android projects
By using a BOM dependency, you can avoid specifying the versions of each individual library in your app, and let...
Telegram turns 10 years old and revenues stagnate
Telegram seems to want to grow not only through messaging but also through communities, which pretty much means it wants...
MetaCodable – Supercharge Swift’s Codable implementations with macros meta-programming
Supercharge Swift‘s Codable implementations with macros. Overview MetaCodable framework exposes custom macros which can be used to generate dynamic Codable implementations. The core of the framework...
How to get started with Swift Concurrency 🧵 (Beginner Tutorial)
Swift has built-in support for writing asynchronous and parallel code in a structured way. Asynchronous code can be suspended and resumed later,...
Mobile App Development Best Practices – 02.10
Data.ai has summarized the interim results of the year – and once again we have a record. Annual consumer spending...