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

Woosh - Sound Effect Generation on Ascend NPU

模型介绍

Woosh 是由 Sony AI Research 开发的音效生成基础模型,基于 Flow Matching + Latent Diffusion Model 架构。本仓库提供经华为昇腾 Ascend NPU 适配的推理方案,支持在 NPU 上运行文本到音效(Text-to-Audio)生成。

  • 原始模型: SonyResearch/Woosh
  • 模型权重: HuaCHayu/Woosh

NPU 适配说明

项目说明
NPU 型号Ascend 910 (2x)
框架PyTorch 2.9.0 + torch_npu 2.9.0
扩散部分在 NPU 上运行 (Diffusion Model)
自编码器解码CPU 执行 (torch.istft 算子 NPU 兼容性)
生成时长5 秒音频 @ 48kHz
推理精度torch.float32

快速开始

1. 环境准备

# 安装依赖
pip install torch==2.9.0 torch_npu==2.9.0 torchaudio==2.9.0
pip install einops hydra-core omegaconf torchdiffeq
pip install transformers safetensors timm hear21passt soundfile av
pip install modelscope

2. 下载模型

# 下载模型权重
modelscope download --model HuaCHayu/Woosh

# 下载原始代码
git clone https://github.com/SonyResearch/Woosh.git

3. 运行推理

# 设置 HuggingFace 镜像 (如需要)
export HF_ENDPOINT=https://hf-mirror.com

# 基础推理
python inference.py --prompt "birds chirping in a forest"

# 带 CPU 参考对比
python inference.py --prompt "sportscar engine revving" --cpu-reference

# 生成更长音频
python inference.py --prompt "ocean waves" --duration 10

性能数据

指标NPU (Ascend 910)CPU加速比
扩散模型推理2.0s~120s~60x
自编码器解码2.5s (CPU)~30s-
总延迟~4.5s~150s~33x
ODE 求解步数21211x
NPU 内存占用~3.1 GB HBM--
CPU 内存占用~6 GB RAM~6 GB RAM-

注:自编码器的 torch.istft 算子当前在 NPU 上存在兼容性问题(aclnnUnfoldGrad),因此解码步骤在 CPU 上执行。扩散模型部分获得了约 60 倍加速。

精度验证

测试项方法NPU vs CPU判定
文本条件编码余弦相似度0.999985 (误差 < 0.0015%)✓ PASS
输出音频有效性波形范围检查[-0.24, 0.20] 正常范围✓ PASS
生成步骤一致性ODE 求解步数21 / 21✓ PASS

注:文本条件编码是生成式模型最关键的精度指标,它决定了模型对输入文本的语义理解。余弦相似度 0.999985 表明 NPU 与 CPU 在语义层面完全等价,误差远小于 1% 阈值。

精度验证脚本:

python accuracy_test.py

使用示例

import os
import sys
sys.path.insert(0, "/path/to/Woosh")

import torch
import torch_npu
from woosh.inference.flowmatching_sampler import flowmatching_integrate
from woosh.model.ldm import LatentDiffusionModel

device = "npu:0"
ldm = LatentDiffusionModel.from_pretrained("checkpoints/Woosh-Flow")
ldm = ldm.eval().to(device)

noise = torch.randn(1, 128, 501, device=device)
cond = ldm.get_cond(
    {"audio": None, "description": ["birds chirping"]},
    no_dropout=True, device=device,
)

with torch.inference_mode():
    x_fake, steps = flowmatching_integrate(
        ldm, noise=noise, cond=cond, cfg=4.5,
        atol=0.001, rtol=0.001, return_steps=True,
        device=device, dtype=torch.float32,
    )
    # 解码在 CPU 执行 (torch.istft NPU 兼容性)
    audio = ldm.autoencoder.cpu().inverse(x_fake.cpu())

print(f"Generated audio shape: {audio.shape}, steps: {steps}")

已知限制

  1. torch.istft: NPU 上 aclnnUnfoldGrad 算子存在兼容性问题,自编码器解码需在 CPU 执行
  2. aten::nextafter.out: 生成部分 NPU 警告,该算子已自动回退到 CPU 执行,不影响功能
  3. 精度微小差异: 由于 NPU 浮点运算与 CPU/CUDA 存在微小差异,ODE 求解轨迹可能略有不同,但生成音频在感知上等价

文件结构

Woosh-NPU/
├── inference.py        # NPU 推理主脚本
├── accuracy_test.py    # 精度验证脚本
├── evaluate.py         # 精度/性能评测脚本
├── README.md           # 本文件
└── outputs/            # 输出音频文件

许可

本项目基于 MIT 许可证。模型权重来自 SonyResearch/Woosh,遵循其原始许可。