native-diffusion  by mortenjust

Swift package for native Stable Diffusion inference on Apple devices

Created 2 years ago
503 stars

Top 61.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

Inactive

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

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Tomas Valenta Tomas Valenta(Cofounder of E2B), and
12 more.

diffusionbee-stable-diffusion-ui by divamgupta

0.1%
13k
GUI app for local Stable Diffusion on MacOS
Created 3 years ago
Updated 10 months ago
Feedback? Help us improve.