Single-file Stable Diffusion re-implementation for mobile deployment
Top 67.3% on sourcepulse
This repository provides a single-file Swift re-implementation of the Stable Diffusion model, including CLIP, UNet, and decoder components, along with PLMS inference. It targets developers and researchers aiming to understand diffusion models or enable Stable Diffusion on Apple mobile devices, offering a path for highly optimized, on-device execution without relying on external runtimes like ONNX.
How It Works
The project meticulously re-implements Stable Diffusion's components in Swift, aiming for layer-by-layer output parity with the original PyTorch implementation. This approach facilitates deep understanding and enables custom, low-level optimizations crucial for resource-constrained mobile environments. The use of a custom framework (s4nnc) allows for fine-grained control over memory usage and kernel selection, potentially surpassing the capabilities of more general-purpose mobile ML frameworks.
Quick Start & Requirements
sd-v1.4.ckpt
) must be downloaded separately.apt
. macOS requires modifying the WORKSPACE
file and adding a .bazelrc.local
configuration for MPS.bazel run examples:txt2img --compilation_mode=opt -- /path/to/sd-v1.4.ckpt "prompt"
Highlighted Details
txt2img
, img2img
, and inpainting
use cases.Maintenance & Community
The project appears to be a personal educational effort by a single developer, with no explicit mention of community channels, roadmap, or other contributors in the README.
Licensing & Compatibility
The README does not specify a license. This is a critical omission for evaluating commercial use or integration into closed-source projects.
Limitations & Caveats
The setup process is complex, requiring Bazel and specific system dependencies. Inpainting functionality is noted as not working without prompt guidance. The lack of a specified license presents a significant adoption blocker.
1 month ago
1 day