WanToDance: hardcoded `device='cuda'` in music encoder construction crashes model loading on Ascend NPU
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python, pytorch
调研方向
问题位于 diffsynth/models/wan_video_dit.py 第 462 行和 diffsynth/models/wantodance.py 第 156 行。从 WanToDanceMusicEncoderLayer 构造函数中移除硬编码的参数 device='cuda'。通过运行一个在非 CUDA 设备(如 CPU 或 NPU)上加载模型的测试来验证修复,确保不会发生断言错误。
由索引模型根据 Issue 内容生成。
描述
Summary
WanModel.__init__ builds the WanToDance music encoder with a hardcoded CUDA device (diffsynth/models/wan_video_dit.py:462):
self.music_encoder.append(
WanToDanceMusicEncoderLayer(
d_model=latent_dim,
nhead=nhead,
dim_feedforward=ff_size,
dropout=dropout,
activation=activation,
batch_first=True,
rotary=rotary,
device='cuda',
)
)
WanToDanceMusicEncoderLayer forwards device to nn.MultiheadAttention(..., device=device) (diffsynth/models/wantodance.py:156), so the attention parameters are allocated on CUDA at construction time.
Impact
On any build without CUDA (Ascend NPU, CPU-only, ...) the model cannot be constructed at all, before the surrounding pipeline ever gets a chance to move it to the target device:
AssertionError: Torch not compiled with CUDA enabled
This block is gated by wantodance_enable_global / wantodance_enable_dynamicfps / wantodance_enable_unimodel, i.e. loading a WanToDance model on Ascend fails outright. Every sibling layer in the same block (nn.Linear, nn.Sequential) leaves the device to the caller's .to(device), so the hardcoded argument is also inconsistent with the rest of the file — and with diffsynth.core.device.npu_compatible_device, which the project already ships for NPU support.
Reproduction
# Ascend 910B4, torch 2.15.0.dev + torch_npu 2.15.0.dev
from wantodance import WanToDanceMusicEncoderLayer
WanToDanceMusicEncoderLayer(d_model=256, nhead=4, dim_feedforward=1024,
dropout=0.1, batch_first=True, rotary=None,
device='cuda')
# AssertionError: Torch not compiled with CUDA enabled
Proposed fix
Drop the hardcoded device='cuda'; the module is moved to the real device by the pipeline afterwards, exactly like its sibling layers. Verified on real Ascend 910B4 hardware (construction + forward pass on NPU); I will open a PR referencing this issue.
- 主要语言
- Python
- 星标
- 13.1k
- 派生
- 1.3k
- 平均合并
- 12 小时 53 分钟
- 30 天内合并 PR
- 42
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelscope/DiffSynth-Studio 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 90/100
modelscope/DiffSynth-Studio#1702 ·
-
难度 1/5 1-3 小时 新手友好度 78/100
modelscope/DiffSynth-Studio#1668 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
modelscope/DiffSynth-Studio#1499 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 78/100
modelscope/DiffSynth-Studio#1373 · 5 条评论 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 30/100
modelscope/DiffSynth-Studio#1709 · 1 条评论 ·
查看 modelscope/DiffSynth-Studio 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
stephrobert/dsoxlab#238 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
sublimehq/package_control#1780 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 70/100
nwg-piotr/nwg-displays#145 ·