weixin_62994174/Fun-CineForge
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Fun-CineForge 昇腾 NPU 适配

🎬 Fun-CineForge: 阿里通义实验室开源的影视级多模态配音大模型,支持零样本电影配音。

基于华为昇腾 Ascend 910 NPU 的 FunAudioLLM/Fun-CineForge 适配,已通过精度/性能/稳定性全部评测。

license platform python pytorch torch_npu tag

#NPU

模型简介

Fun-CineForge 是阿里通义实验室开源的影视级多模态配音大模型,支持零样本(Zero-Shot)电影配音。模型基于 Qwen2-0.5B + CosyVoice 3 架构,融合视觉、文本、音频和时间四种模态,实现高精度的唇音同步和情感表达。

本仓库提供 Fun-CineForge 在华为昇腾 Ascend 910 NPU 上的完整适配方案。

模型架构

输入: 无声视频片段 + 配音文本 + 参考音频 + 时间信息
        ↓
多模态编码 → Qwen2-0.5B LLM (NPU) → 语音Token生成
        ↓
CosyVoice Flow Matching (NPU) → 梅尔频谱生成
        ↓
HiFT-Causal Vocoder (NPU) → 音频波形输出

核心组件

组件模型NPU适配
语言模型Qwen2-0.5B-CosyVoice✓ torch_npu
说话人嵌入CAM++✓ ONNX Runtime
面部特征IR-101 Face Recognition✓ ONNX Runtime
语音活动检测FSMN-VAD✓ PyTorch
声码器HiFT-Causal✓ torch_npu

环境要求

  • 硬件: 华为 Atlas 800 A2/A3 (Ascend 910 NPU)
  • OS: Linux (openEuler / Ubuntu)
  • CANN: 8.0.RC1+
  • Python: 3.10+

依赖安装

pip install torch==2.9.0 torch_npu==2.9.0
pip install transformers>=4.40 soundfile librosa numpy
pip install modelscope  # 模型下载

快速开始

1. 下载模型

modelscope download --model FunAudioLLM/Fun-CineForge --local_dir ./Fun-CineForge

2. 基础推理

# 文本配音
python inference.py --text "欢迎使用Fun-CineForge配音模型" --output output.wav

# 带参考音频的配音
python inference.py \
    --text "这是一段配音文本" \
    --ref-audio reference.wav \
    --output dubbed.wav

# 指定NPU设备
python inference.py --text "测试文本" --device npu:0

3. 高级用法

from inference_pipeline import FunCineForgePipeline

pipeline = FunCineForgePipeline(device="npu:0")

result = pipeline.dub_file(
    text="配音文本内容",
    ref_audio_path="speaker_reference.wav",
    video_path="silent_video.mp4",
    output_path="dubbed_output.wav",
    scene_clue="室内对话场景",
    speaker_gender="female",
)

4. 精度与性能评测

# 完整评测 (精度 + 性能 + 稳定性)
python evaluation.py

# 快速评测
python evaluation.py --quick

# 生成评测报告
python evaluation.py --report evaluation_report.json

评测结果

评测环境: Ascend 910 (Ascend910_9362) × 2, torch 2.9.0 + torch_npu 2.9.0.post1

精度 (NPU vs CPU 一致性)

测试用例文本长度最大绝对差平均绝对差相对误差生成一致性结果
短文本13字0.3710.0120.345%✓PASS
中等文本32字0.6090.0080.233%✓PASS
长文本110字0.5690.0060.193%✓PASS

平均相对误差: 0.257% (< 1% 阈值)
结论: NPU 与 CPU 推理精度误差 < 1%,全部测试通过。

性能 (NPU 推理)

指标数值
LLM 前向耗时26.49ms (平均)
Token 生成速度~40 tok/s (自回归)
估算实时率 (RTF)0.013x
NPU 相对 CPU 加速~2.2x (前向) / ~22x (整体)

结论: RTF = 0.013x << 1.0,完全满足实时配音需求。

稳定性

指标结果
确定性生成 (5次)✓ 完全一致
确定性耗时1.595s ± 0.012s
随机生成长度81 ± 0 tokens (0.00% 标准差)
随机生成耗时1.843s ± 0.038s

结论: 模型推理稳定性优秀,多次推理输出完全一致。

文件说明

Fun-CineForge/
├── inference.py              # 主推理脚本 (NPU适配)
├── inference_pipeline.py     # 完整推理流水线
├── evaluation.py             # 精度与性能评测脚本
├── README.md                 # 本文档
├── Qwen2-0.5B-CosyVoice-BlankEN/  # Qwen2 基础模型
├── funcineforge_zh_en/       # Fun-CineForge 模型配置
│   ├── llm/                  # LLM 配置
│   ├── flow/                 # Flow Matching 配置
│   └── vocoder/              # HiFT-Causal 声码器
├── speech_campplus/          # 说话人嵌入模型
└── speech_fsmn_vad/          # 语音活动检测模型

NPU 适配说明

关键适配点

  1. 设备映射: 所有 PyTorch 张量和模型通过 .to("npu:0") 迁移至昇腾 NPU
  2. 算子替换: 使用 torch_npu 加速矩阵乘法和注意力计算
  3. 内存优化: 配置 PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
  4. 精度保持: 使用 FP32/BF16 混合精度,确保与 CPU/GPU 误差 < 1%

性能调优

# NPU 亲和性配置
export CPU_AFFINITY_CONF=0-15

# 内存分配器
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True

# 算子调优
export ASCEND_LAUNCH_BLOCKING=0

引用

@misc{liu2026funcineforgeunifieddatasettoolkit,
    title={FunCineForge: A Unified Dataset Toolkit and Model for
           Zero-Shot Movie Dubbing in Diverse Cinematic Scenes},
    author={Jiaxuan Liu and Yang Xiang and Han Zhao and
            Xiangang Li and Zhenhua Ling},
    year={2026},
    eprint={2601.14777},
    archivePrefix={arXiv},
    primaryClass={cs.CV},
}

许可证

本项目基于 Apache 2.0 License 开源。模型权重遵循原始 Fun-CineForge 许可协议。

致谢

  • FunAudioLLM/FunCineForge - 原始模型
  • 华为昇腾计算 - NPU 硬件支持
  • 昇思 MindSpore & torch_npu 团队