Skip to content

Run Stable Diffusion on Android Devices with Snapdragon NPU acceleration. Also supports CPU inference.

License

Notifications You must be signed in to change notification settings

MicheleLopsDev/local-dream

 
 

Repository files navigation

Local Dream

Android Stable Diffusion with Snapdragon NPU acceleration. Also supports CPU inference.

About this Repo

This project is now open sourced and completely free. Hope you enjoy it!

If you like it, please consider sponsor this project.

Usage

  • Download the APK from the Releases page or Google Play.
  • Open the app and download the model(s) you want to use

Features

  • txt2img
  • img2img
  • inpaint

Build

It is recommended to build it on linux/wsl. Other platforms are not verified.

Rust, ninja, and cmake are needed for building. You should first install rustup, then "rustup default stable", and then "rustup target add aarch64-linux-android".

Clone this repo recursively

git clone --recursive https://github.com/xororz/local-dream.git

Prepare SDKs

  1. Download QNN_SDK_2.29 and extract
  2. Download Android NDK and extract
  3. Modify the QNN_SDK_ROOT in app/src/main/cpp/CMakeLists.txt
  4. Modify the ANDROID_NDK_ROOT in app/src/main/cpp/CMakePresets.json

Build and prepare libraries

Linux

cd app/src/main/cpp/
bash ./build.sh

Windows

# winget install Kitware.CMake (install CMake if you don't have it)
# winget install Ninja-build.Ninja (install Ninja if you don't have it)
# winget install Rustlang.Rustup (install Rust if you don't have it)
cd app\src\main\cpp\
# Convert patch file to Unix format (if you don't have dos2unix, install with: winget install -e --id waterlan.dos2unix)
dos2unix SampleApp.patch
.\build.bat

Mac OS

# brew install cmake rust ninja (If you are using homebrew)
sed -i '' '2s/$/ -DCMAKE_POLICY_VERSION_MINIMUM=3.5/' build.sh # The default version of homebrew is too high
bash ./build.sh

Build apk in android studio

open this project in android studio and click Build/Generate App Bundles or APKs/Generate APKs

Technical Implementation

NPU Acceleration

  • Utilizes Qualcomm QNN SDK to leverage Hexagon NPU
  • W8A16 static quantization for optimal performance
  • Fixed model shape at 512x512
  • Extremely fast inference speed

CPU Inference

  • Powered by MNN framework
  • W8 dynamic quantization
  • Flexible output sizes: 128x128, 256x256, 384x384, 512x512
  • Relatively slower processing speed with slightly lower accuracy

Supported Devices

NPU Acceleration Support

  • Devices with Snapdragon 8 Gen 1
  • Devices with Snapdragon 8+Gen 1
  • Devices with Snapdragon 8 Gen 2
  • Devices with Snapdragon 8 Gen 3
  • Devices with Snapdragon 8 Elite

Other devices are not able to download the npu models.

CPU Support

  • Requires approximately 2GB RAM
  • Compatible with most Android phones from recent years

Available Models

Model Type CPU NPU Clip Skip Source
Anything V5.0 SD1.5 2 Link
ChilloutMix SD1.5 1 Link
Absolute Reality SD1.5 2 Link
QteaMix SD1.5 2 Link
CuteYukiMix SD1.5 2 Link
Stable Diffusion 2.1 SD2.1 - 1 Link
Pony V5.5 SD2.1 - 1 Link

Seed Settings

The application supports custom seed settings for reproducible results:

  • CPU Mode: Seeds guarantee identical results across different devices with the same parameters
  • NPU Mode: Seeds ensure consistent results only on devices with identical chipsets

Credits

Cpp

Android

Sponsorship

If you like this project, please consider sponsoring it. Your support will help me implement:

  • Additional models
  • New features
  • Enhanced capabilities
Buy Me a Coffee at ko-fi.com 在爱发电支持我

Your sponsorship helps maintain and improve Local Dream for everyone!

About

Run Stable Diffusion on Android Devices with Snapdragon NPU acceleration. Also supports CPU inference.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 71.7%
  • C++ 26.1%
  • CMake 1.9%
  • Other 0.3%