g
gcw_coj3XaOd/qualcomm_ControlNet
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

qualcomm/ControlNet - 昇腾 NPU 推理部署

1. 模型简介

模型名称: qualcomm/ControlNet

模型链接: HuggingFace

模型描述: ControlNet 是一种神经网络结构,用于对扩散模型(diffusion model)添加额外的条件控制。ControlNet 可以接受条件输入(如边缘图、深度图、人体姿态等),引导扩散模型生成符合条件约束的图像。

重要声明: 该模型在 HuggingFace 上已标记为 deprecated。模型仓库中不包含任何模型权重文件(无 config.json、无 .safetensors、无 .bin)。原始 README 指向 Qualcomm AI Hub 获取最新模型和更新。

模型架构: ControlNet (基于 Stable Diffusion 的条件控制网络)

  • 编码器分支:处理控制条件(边缘图、深度图等)
  • 副本分支:锁定参数的 Stable Diffusion UNet 副本
  • 零卷积层(ZeroConv):连接两个分支

参数规模: ~1.2B(ControlNet for SD 1.5,含共享 UNet)

输入规格:

  • 文本 prompt:string
  • 控制条件图像:3通道 RGB 图像(如 canny 边缘图、深度图),shape=(H, W, 3)
  • 推理步数:int (默认 50)

输出规格:

  • 生成图像:RGB 图像,shape=(H, W, 3),像素值 [0, 255]

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
diffusers>= 0.25.0HuggingFace 扩散模型库
transformers>= 4.30.0文本编码器
accelerate>= 0.20.0设备映射和混合精度
Pillow>= 9.0.0图像处理
opencv-python>= 4.8.0控制条件预处理
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu>=2.1.0 torch>=2.1.0
pip install diffusers>=0.25.0 transformers>=4.30.0 accelerate>=0.20.0
pip install Pillow>=9.0.0 opencv-python>=4.8.0 numpy>=1.24.0

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; import torch; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型说明

qualcomm/ControlNet 模型已废弃,无可用权重。 以下推理方案使用替代模型。

3.3 推理方案

由于 qualcomm/ControlNet 已废弃,推荐以下替代方案:

方案一:使用 SD 1.5 ControlNet 模型

# 下载 ControlNet canny 模型
huggingface-cli download lllyasviel/sd-controlnet-canny --local-dir ./sd-controlnet-canny

方案二:使用 SDXL ControlNet 模型

huggingface-cli download diffusers/controlnet-sdxl --local-dir ./controlnet-sdxl

方案三:使用 Qualcomm AI Hub 优化模型

# 访问 https://aihub.qualcomm.com 获取 Qualcomm 优化的 ControlNet 模型

3.4 运行推理

# 使用参考推理脚本(需要有效模型权重)
python inference.py --model-path <模型路径> --control-type canny --prompt "a beautiful landscape"

3.5 推理参数说明

参数类型默认值说明
--model-pathstrNoneControlNet checkpoint 路径
--base-modelstrrunwayml/stable-diffusion-v1-5基础扩散模型
--control-typestrcanny控制类型 (canny/depth/openpose)
--promptstr"a beautiful landscape..."文本提示词
--num-inference-stepsint50去噪步数
--device-idint0NPU 设备 ID

4. ControlNet 架构说明

ControlNet 的核心思想是通过添加一个"锁定副本"分支来条件化扩散模型:

                    ┌──────────────────────────────────┐
                    │          Stable Diffusion         │
Text Prompt ──▶ Text Encoder │   UNet (冻结参数)  │──▶ Decoder ──▶ 图像
                    └──────────▲─────────────────▲────────┘
                               │                 │
                    ┌──────────┴─────────────────┴────────┐
                    │          ControlNet                  │
                    │  ┌─────────┐    ┌──────────────┐   │
Condition ─────────▶│  │ Encoder  │───▶│ Zero Convs   │──┘──▶ 条件信号注入
                    │  └─────────┘    └──────────────┘
                    └──────────────────────────────────────┘

5. 适配状态

5.1 适配结果

项目结果
模型权重可用性❌ 不可用(HuggingFace 已废弃)
模型配置可解析性❌ 无 config.json
vLLM-Ascend 兼容性❌ 不支持(扩散模型架构)
diffusers + torch_npu 兼容性✅ 理论兼容(需有效权重验证)
NPU 设备状态✅ 正常 (2x Ascend910)

5.2 失败原因

  1. 模型已废弃:qualcomm/ControlNet 在 HuggingFace 上标记为 deprecated
  2. 无模型权重:仓库中仅有 README.md 和 .gitattributes,无任何权重文件
  3. 架构不匹配:ControlNet 是扩散模型,vLLM-Ascend 不支持扩散模型推理
  4. 替代路径:README 指向 https://aihub.qualcomm.com 获取更新模型

5.3 建议

  1. 访问 Qualcomm AI Hub 查找最新的 ControlNet 模型
  2. 使用社区维护的 ControlNet 模型(如 lllyasviel/sd-controlnet-canny)
  3. 使用 diffusers + torch_npu 进行推理部署
  4. 如果需要在 Ascend NPU 上运行 SDXL,考虑使用 APT-CN(Ascend PyTorch Training & Inference)

6. Agent 适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. NPU 配置说明

测试设备: 2x Ascend910 NPU

$ npu-smi info
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.5                   Version: 25.5.5                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip  Phy-ID              | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 3     Ascend910           | OK            | 184.2       45                0    / 0             |
| 0     6                   | 0000:0B:00.0  | 0           0    / 0          3269 / 65536         |
+---------------------------+---------------+----------------------------------------------------+
| 3     Ascend910           | OK            | -           44                0    / 0          2870 / 65536         |
| 1     7                   | 0000:0A:00.0  | 0           0    / 0          2870 / 65536         |
+===========================+===============+====================================================+

CANN 版本: 8.5.1

验证命令:

python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"
# 输出: 2 Ascend910

8. 已知问题

  1. 模型已废弃:HuggingFace 上的 qualcomm/ControlNet 已标记为 deprecated,无法下载权重
  2. 无 config.json:无法通过配置解析模型架构
  3. vLLM 不适用:ControlNet 是扩散模型,vLLM-Ascend 仅支持 LLM/VLM/Whisper
  4. 建议使用替代模型:见第 5.3 节建议