This Skill guides users in configuring a HuggingFace Diffusers development environment on Huawei Ascend NPU.
Quick Start
Complete the environment setup in 4 steps:
# 1. 激活 CANN 环境(自动检测版本)
if [ -d "/usr/local/Ascend/cann" ]; then
source /usr/local/Ascend/cann/set_env.sh
else
source /usr/local/Ascend/ascend-toolkit/set_env.sh
fi
# 2. 安装 PyTorch + torch_npu(版本自动匹配)
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install torch-npu # 自动匹配已安装的 PyTorch 版本
3. Install Diffusers
pip install diffusers["torch"] transformers
4. Verify the environmentpython scripts/validate_environment.py
## 安装概览
| 步骤 | 详细指南 |
|------|----------|
| CANN 验证 | [references/cann-versions.md](references/cann-versions.md) |
| PyTorch + torch_npu | [references/installation.md](references/installation.md) |
| Diffusers 安装 | [references/installation.md](references/installation.md) |
## 版本兼容性
| 组件 | 版本 | 说明 |
|------|------|------|
| CANN | 8.0.RC1+ | NPU 支持必需 |
| PyTorch | 2.1.0 - 2.8.0 | 含 torch_npu 扩展 |
| Diffusers | 0.28.0+ | 支持 SDXL、SD3、Flux |
**torch_npu 版本匹配**:
- 默认安装与 PyTorch 版本相同的 torch_npu:`pip install torch-npu`
- 如安装失败,请参考 [torch_npu Release](https://gitcode.com/Ascend/pytorch/README.md) 查看完整版本配套表
**示例**(CANN 8.3.RC1):
| PyTorch | torch_npu | Python |
|---------|-----------|--------|
| 2.8.0 | 2.8.0 | 3.9 - 3.11 |
| 2.7.1 | 2.7.1 | 3.9 - 3.11 |
| 2.6.0 | 2.6.0.post3 | 3.9 - 3.11 |
## 环境验证
运行验证脚本:
```bash
python scripts/validate_environment.py
Check items:
| Check Item | Description |
|---|---|
| CANN installation | Directory exists and environment variables are set |
| PyTorch | import succeeds, versions match |
| torch_npu | import succeeds, NPU is visible |
| Diffusers | import succeeds |
| numpy | Version < 2.0 |
Reference Resources
- Detailed Installation Guide - Complete installation steps and commands
- CANN Version Notes - Version detection and difference notes
- Troubleshooting - Common issues and solutions
- Diffusers Official Documentation
- Ascend PyTorch Extension
- torch_npu Release