native-diffusion  by mortenjust

Swift package for native Stable Diffusion inference on Apple devices

created 2 years ago
501 stars

Top 62.9% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

Native Diffusion enables local Stable Diffusion inference on iOS and macOS using Swift and Apple's MPSGraph framework, eliminating the need for Python environments. It offers a simple, flexible API for developers targeting Apple platforms, allowing for image generation and image-to-image transformations with minimal setup.

How It Works

This project leverages MPSGraph, Apple's Metal Performance Shaders Graph API, to execute Stable Diffusion models natively on Apple silicon. It converts standard .ckpt model files into a memory-optimized format, utilizing FP16 tensors and operator fusion for efficient execution. This approach aims for performance comparable to or exceeding cloud-based solutions while ensuring a seamless, zero-dependency user experience on end-user devices.

Quick Start & Requirements

  • Install: Add https://github.com/mortenjust/native-diffusion to Xcode's Swift Package Manager.
  • Prerequisites: macOS or iOS device. Python 3.10 with torch, typing_extensions, numpy, Pillow, requests, and pytorch_lightning is required for model conversion.
  • Model Conversion: A Python script (maple-convert.py) is provided to convert .ckpt files to the native format.
  • Resources: Model files can be downloaded from a URL or included in the app bundle.
  • Docs: https://github.com/mortenjust/native-diffusion

Highlighted Details

  • 100% native Swift implementation, no Python dependencies for inference.
  • Supports image-to-image transformations and Dreambooth models.
  • Offers Combine publishers and async/await for integration.
  • Claims performance faster than Python/PyTorch/Tensorflow on M1 Max Macs.

Maintenance & Community

  • Active development with a roadmap including Stable Diffusion 2.0, in-painting, and on-device training.
  • Community engagement via Discord.

Licensing & Compatibility

  • Code is MIT Licensed.
  • Generated images are under the CreativeML Open RAIL-M license, permitting commercial use.

Limitations & Caveats

  • Stable Diffusion 2.0 and certain advanced features like in-painting are not yet supported.
  • The project is described as largely proof-of-concept, with ongoing efforts to improve code quality.
Health Check
Last commit

2 years ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
3 stars in the last 90 days

Explore Similar Projects

Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Georgios Konstantopoulos Georgios Konstantopoulos(CTO, General Partner at Paradigm), and
2 more.

mflux by filipstrand

0.7%
2k
MLX port of FLUX for local image generation on Macs
created 11 months ago
updated 17 hours ago
Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Anil Dash Anil Dash(Former CEO of Glitch), and
8 more.

diffusionbee-stable-diffusion-ui by divamgupta

0.1%
13k
GUI app for local Stable Diffusion on MacOS
created 2 years ago
updated 9 months ago
Starred by Georgios Konstantopoulos Georgios Konstantopoulos(CTO, General Partner at Paradigm), Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), and
9 more.

ml-stable-diffusion by apple

0.1%
18k
Core ML Stable Diffusion for Apple Silicon devices
created 2 years ago
updated 1 month ago
Feedback? Help us improve.