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
-
Install QAI AppBuilder by following the QAI AppBuilder installation guide.
-
Configure ADSP environment variables as described in Create ADSP environment variables.
Run the sample
Install dependencies
Install sample dependencies in the activated virtual environment:
pip3 install requests tqdm qai-hub py3-wget Pillow torch torchvision opencv-python-headless transformers diffusers
Run the script
-
Enter the upstream samples directory
Devicecd qai-appbuilder/samples -
Prepare input data (use the sample input if provided, or pass script arguments)

Output image
-
Run inference
Devicepython3 GenerativeAI/Image_Generation/stable_diffusion_v2_1/stable_diffusion_v2_1.py --chipset 9075 --prompt "a cat"
On success an image is written under the sample directory, for example:
GenerativeAI/Image_Generation/stable_diffusion_v2_1/images/<timestamp>_512.jpg
On AIRbox Q900 the first run downloads Text Encoder / UNet / VAE (on the order of ~1.2 GB total). Slow networks may take tens of minutes to hours.
Requires transformers and diffusers. Prefer running the script directly (avoids run_inference.py --args quoting issues with spaces in prompts):
python3 GenerativeAI/Image_Generation/stable_diffusion_v2_1/stable_diffusion_v2_1.py --chipset 9075 --prompt "a cat"