Stable-Diffusion-v2.1 Example
This document explains how to use the QAI AppBuilder Python API to perform inference with the Stable-Diffusion-v2.1 text-to-image model using the Qualcomm® Hexagon™ Processor (NPU).
Supported Devices
| Device | SoC |
|---|---|
| Fogwise® AIRbox Q900 | QCS9075 |
Install QAI AppBuilder
tip
-
Please install QAI AppBuilder according to the QAI AppBuilder Installation Guide.
-
Please configure the ADSP environment variables according to Configuring ADSP Environment Variables.
Run Example
Install Dependencies
Device
pip3 install requests tqdm qai-hub py3_wget opencv-python torch torchvision matplotlib easyocr qai_hub_models transformers diffusers
Run the Script
-
Navigate to the example directory
- QCS9075
Devicecd ai-engine-direct-helper/samples/python -
Execute inference
Devicepython3 stable_diffusion_v2_1/stable_diffusion_v2_1.py --prompt spectacular view of northern lights from Alaskapython3 stable_diffusion_v2_1/stable_diffusion_v2_1.py --prompt spectacular view of northern lights from Alaska
/prj/qct/webtech_scratch20/mlg_user_admin/qaisw_source_repo/rel/qairt-2.37.1/point_release/SNPE_SRC/avante-tools/prebuilt/dsp/hexagon-sdk-5.5.5/ipc/fastrpc/rpcmem/src/rpcmem_android.c:38:dummy call to rpcmem_init, rpcmem APIs will be used from libxdsprpc
Step 0 Running...
Step 1 Running...
Step 2 Running...
Step 3 Running...
Step 4 Running...
Step 5 Running...
Step 6 Running...
Step 7 Running...
Step 8 Running...
Step 9 Running...
Step 10 Running...
Step 11 Running...
Step 12 Running...
Step 13 Running...
Step 14 Running...
Step 15 Running...
Step 16 Running...
Step 17 Running...
Step 18 Running...
Step 19 Running...
/mnt/ssd/qualcomm/702/zzf_fork/test/ai-engine-direct-helper/samples/python/stable_diffusion_v2_1/stable_diffusion_v2_1.py:275: DeprecationWarning: 'mode' parameter is deprecated and will be removed in Pillow 13 (2026-10-15)
output_image = Image.fromarray(output_image, mode="RGB")
Image saved to '/mnt/ssd/qualcomm/702/zzf_fork/test/ai-engine-direct-helper/samples/python/stable_diffusion_v2_1/images/2025_10_30_05_46_28_2081127356_512.jpg'
time consumes for inference 4.454082250595093(s)
/usr/bin/xdg-open: 882: www-browser: not found
/usr/bin/xdg-open: 882: links2: not found
<W> Logs will be sent to the system's default channel
/usr/bin/xdg-open: 882: elinks: not found
/usr/bin/xdg-open: 882: links: not found
/usr/bin/xdg-open: 882: lynx: not found
/usr/bin/xdg-open: 882: w3m: not found
xdg-open: no method available for opening '/tmp/tmp0ci7lglx.PNG'
<W> Logs will be sent to the system's default channel
/prj/qct/webtech_scratch20/mlg_user_admin/qaisw_source_repo/rel/qairt-2.37.1/point_release/SNPE_SRC/avante-tools/prebuilt/dsp/hexagon-sdk-5.5.5/ipc/fastrpc/rpcmem/src/rpcmem_android.c:42:dummy call to rpcmem_deinit, rpcmem APIs will be used from libxdsprpc
Output image