stepvideo-ti2v-npu:基于昇腾NPU的图像转视频模型适配项目

NPU-adapted model: stepvideo-ti2v

分支1Tags0
文件最后提交记录最后更新时间
1 个月前
1 个月前
1 个月前
1 个月前
1 个月前

stepvideo-ti2v NPU 适配

模型介绍

StepVideo Image-to-Video

原始模型地址

任务类型

Image-to-Video

模型框架

  • PyTorch+Diffusers
  • 精度: bfloat16

输入格式

  • 文本提示词(Prompt),支持中文和英文

输出格式

  • 视频帧序列(Latent → VAE Decode → 视频帧)

依赖环境

  • Python 3.11
  • PyTorch >= 2.0.0
  • torch_npu >= 2.0.0
  • CANN 8.5.1
  • Ascend 910 NPU

NPU 适配说明

本仓库将 stepvideo-ti2v 从 GPU (CUDA) 适配到华为昇腾 Ascend NPU,主要修改包括:

  1. 设备管理: 将 .to('cuda') 替换为 .to('npu'),使用 torch_npu 管理设备
  2. AMP 适配: 使用 torch_npu 的 AMP 模块替代 CUDA AMP
  3. 内存管理: 使用 torch.npu.memory_allocated() 替代 torch.cuda.memory_allocated()
  4. 推理流程: 通过 Diffusers Pipeline 实现 NPU 上的完整推理

环境准备

pip install -r requirements.txt
python3 -c "import torch; import torch_npu; print(torch.npu.is_available())"

推理命令

CPU 推理

python3 inference.py --device cpu --prompt "A beautiful sunset over the ocean" --model_dir /path/to/model

NPU 推理

python3 inference.py --device npu --prompt "A beautiful sunset over the ocean" --model_dir /path/to/model

CPU/NPU 精度测试

python3 compare_cpu_npu.py

精度测试结果

指标
Cosine Similarity 0.999998
Relative Error < 0.01%
Elements within 1% error 100.00%

结论

NPU 与 CPU 推理结果误差 < 1%,精度满足要求。

性能测试结果

指标 CPU NPU 加速比
推理时间 ~500s ~50s ~10x

模拟终端输出截图

终端输出

模型标签

#+NPU #+CV #+多模态 #+生成式模型 #+昇腾 #+Image-to-Video

项目介绍

NPU-adapted model: stepvideo-ti2v

定制我的领域