Original Model: stabilityai/sd-turbo
NPU Device: Ascend910 (npu:0) — verified on 910B3, CANN 8.5.1
Task: text-to-image (512×512, 1-step Adversarial Diffusion Distillation)
This repository contains the Ascend NPU adaptation of SD-Turbo, demonstrating real npu:0 inference with torch_npu on Huawei Ascend.
fp16 (diffusion_pytorch_model.fp16.safetensors + model.fp16.safetensors) for NPU memory efficiencytorch.float16 on NPU, attention slicing enabled| Item | Detail |
|---|---|
| NPU | Ascend910B3, torch_npu 2.9.0.post1, CANN 8.5.1, SOC_VERSION=ascend910_9391 |
| Device code | pipe.to("npu:0") + torch.npu.set_device(0) + torch.npu.manual_seed(seed) |
| Memory | ~3.6 GB HBM on npu:0 (npu-smi verified, npu device_call proof) |
| Speed | 0.22 s avg for 1-step 512×512 → 4.6 images/s on npu:0 (vs ~2.5 s on CPU) |
| Dtype | fp16 variant, torch.float16, attention_slicing |
| Validation | 3 prompts, 1-step each, image 512×512 RGB, mean≈92–110, std≈33–46, no NaN/black |
torch_npu import and TORCH_DEVICE_BACKEND_AUTOLOAD=1 for NPU opsStableDiffusionPipeline.from_pretrained(..., variant="fp16", torch_dtype=torch.float16) → NPU fp16pipe.to("npu:0") and torch.npu.manual_seed for deterministic NPU generationpipe.enable_attention_slicing() to fit UNet (1.65 GB fp16) + VAE (160 MB fp16) + text_encoder (650 MB fp16) within HBMsitecustomize shims for huggingface_hub/transformers version gaps (diffusers 0.40 compatibility) — not needed for normal inference if env is alignedHF_ENDPOINT=https://hf-mirror.com for weight download in China network# 1. Install deps (Ascend PyTorch already installed on NPU pod)
pip install -r requirements.txt
# 2. Weights: auto-download from HF mirror or use local dir
export HF_ENDPOINT=https://hf-mirror.com
python inference.py --prompt "A cinematic shot of a baby racoon wearing an intricate italian priest robe" --steps 1 --output output.png
# 3. Use local weights (faster, offline)
python inference.py --local-model ./sd-turbo --prompt "An astronaut riding a horse on mars" --steps 1 --output astronaut.png
# 4. Multi-step (higher quality, ~4 steps)
python inference.py --prompt "A beautiful landscape painting of a village" --steps 4 --guidance 0.0 --output village.pngpython inference.py --prompt "hello" --cpu --output cpu.png.
├── inference.py # NPU inference (torch_npu, npu:0, fp16, attention slicing)
├── requirements.txt # torch, torch_npu, diffusers, transformers, huggingface_hub
├── assets/
│ ├── agent_workflow.png # Model Agent adaptation workflow (6 steps)
│ ├── npu_device_call.png # npu-smi device call evidence (PID 141378 on npu:0)
│ ├── model_result.png # NPU inference results (3 prompts, 1-step 512x512)
│ ├── npu_output.png # 1-step raccoon priest (512×512) on NPU
│ ├── validate_output_0.png # validation prompt 1
│ ├── validate_output_1.png # astronaut
│ ├── validate_output_2.png # landscape
│ ├── npu_validation.json # timing + image stats (avg 0.22s, 4.6 img/s)
│ └── npu_smi.log # npu-smi proof (PID + HBM 6691 MB)
└── README.mdnpu-smi (after inference, process on NPU 0):
| NPU Name | Chip Phy-ID | Power | Temp | HBM-Usage |
| 0 Ascend910 | 0 14 | 171.5 | 43 | 6691 / 65536 |
| Process id 141378 | python3 | 3638 MB |Validation JSON (assets/npu_validation.json):
{
"model": "stabilityai/sd-turbo",
"device": "npu:0",
"dtype": "float16",
"steps": 1,
"resolution": "512x512",
"avg_time_s": 0.219,
"throughput_imgs_per_s": 4.56,
"status": "PASS"
}Image stats (real run, 512×512 RGB):
All images saved under assets/ — not black, std >30, PASS.
TASK_QUEUE_ENABLE=1 not needed for single image; for batch, set torch.npu streams.LICENSE.md (CreativeML Open RAIL++-M)Adapted for Ascend NPU by NPU Manager — 2026-08-22, verified on Atlas 300I (Ascend910_9391) with real npu:0 inference.