Name Date Size #Lines LOC

..--

runner/H25-Apr-2025-760620

CMakeLists.txtH A D25-Apr-20251 KiB3734

README.mdH A D25-Apr-20252.2 KiB3626

install_requirements.shH A D25-Apr-202581 42

qaihub_stable_diffusion.pyH A D25-Apr-202513.2 KiB416344

qaihub_stable_diffusion_runner.cppH A D25-Apr-20255.4 KiB142119

stable_diffusion_lib.pyH A D25-Apr-2025782 2318

README.md

1# Summary
2
3## Overview
4This file provides you the instructions to run Stable-Diffusion-v2.1 with different parameters via Qualcomm HTP backend. We will demonstrate how to run Stable Diffusion v2.1 on mobile devices using context binaries from Qualcomm AI Hub’s Stable Diffusion v2.1
5
6Please check corresponding section for more information.
7
8## Stable-Diffusion-v2.1
9The model architecture, scheduler, and time embedding are from the [stabilityai/stable-diffusion-2-1-base](https://huggingface.co/stabilityai/stable-diffusion-2-1-base).
10
11### Instructions
12#### Step 1: Setup
131. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch.
142. Follow the [tutorial](https://pytorch.org/executorch/stable/build-run-qualcomm-ai-engine-direct-backend.html) to build Qualcomm AI Engine Direct Backend.
15
16#### Step2: Prepare Model
171. Download the context binaries for TextEncoder, UNet, and VAEDecoder under https://huggingface.co/qualcomm/Stable-Diffusion-v2.1/tree/main
182. Download vocab.json under https://huggingface.co/openai/clip-vit-base-patch32/tree/main
19
20
21#### Step3: Install Requirements
22Before running the code, you need to install the necessary Python packages.
23
24We have verified the code with `diffusers`==0.29.0 and `piq`==0.8.0. Please follow the instructions here to install the required items:
25```bash
26sh examples/qualcomm/qaihub_scripts/stable_diffusion/install_requirements.sh
27```
28
29#### Step4: Run default example
30In this example, we execute the script for 20 time steps with the `prompt` 'a photo of an astronaut riding a horse on mars':
31```bash
32python examples/qualcomm/qaihub_scripts/stable_diffusion/qaihub_stable_diffusion.py -b build-android -m ${SOC_MODEL} --s ${SERIAL_NUM} --text_encoder_bin ${PATH_TO_TEXT_ENCODER_CONTEXT_BINARY} --unet_bin ${PATH_TO_UNET_CONTEXT_BINARY} --vae_bin ${PATH_TO_VAE_CONTEXT_BINARY} --vocab_json  ${PATH_TO_VOCAB_JSON_FILE} --num_time_steps 20 --prompt "a photo of an astronaut riding a horse on mars"
33```
34- Please replace `${PATH_TO_TEXT_ENCODER_CONTEXT_BINARY}`, `${PATH_TO_UNET_CONTEXT_BINARY}`, and `${PATH_TO_VAE_CONTEXT_BINARY}` with the actual paths to your AI Hub context binary files.
35- Please replace `${PATH_TO_VOCAB_JSON_FILE}` with the actual path to your vocab.json file.
36