问题描述 / Bug description
swift/template/templates/deepseek.py 的 Janus 图像生成分支 (DeepSeekTemplate.generate(), generate_mode=True) 里有两处硬编码的 .cuda():
tokens = torch.zeros((bsz, parallel_size * 2, max_input_token_num),
dtype=torch.int).cuda()
...
generated_tokens = torch.zeros((bsz, parallel_size, self.image_token_num_per_image),
dtype=torch.int).cuda()
在未编译 CUDA 的设备(华为昇腾 NPU / 其他非 CUDA 后端)上,.cuda() 直接抛
AssertionError: Torch not compiled with CUDA enabled,Janus 图像生成在 NPU 上完全不可用。
input_ids 已经是位于目标设备上的张量,这两处只需跟随它的设备即可。
复现 / Reproduction
昇腾 910B4 + torch 2.15.0 / torch_npu(真机实测):
BEFORE: hardcoded .cuda() FAILED on NPU -> AssertionError: Torch not compiled with CUDA enabled
AFTER : device=input_ids.device OK -> npu:0 dtype torch.int32
最小复现即 torch.zeros((1, 2, 8), dtype=torch.int).cuda()(NPU 上必崩)。
提议修法 / Proposed fix
把 dtype=torch.int).cuda() 改成 dtype=torch.int, device=input_ids.device)(两处),
行为在 CUDA 上完全不变,同时让 NPU 等非 CUDA 后端可用。
PR 已附上,见下方关联链接。这是为昇腾/非 CUDA 用户做的设备无关修复。
问题描述 / Bug description
swift/template/templates/deepseek.py的 Janus 图像生成分支 (DeepSeekTemplate.generate(),generate_mode=True) 里有两处硬编码的.cuda():在未编译 CUDA 的设备(华为昇腾 NPU / 其他非 CUDA 后端)上,
.cuda()直接抛AssertionError: Torch not compiled with CUDA enabled,Janus 图像生成在 NPU 上完全不可用。input_ids已经是位于目标设备上的张量,这两处只需跟随它的设备即可。复现 / Reproduction
昇腾 910B4 + torch 2.15.0 / torch_npu(真机实测):
最小复现即
torch.zeros((1, 2, 8), dtype=torch.int).cuda()(NPU 上必崩)。提议修法 / Proposed fix
把
dtype=torch.int).cuda()改成dtype=torch.int, device=input_ids.device)(两处),行为在 CUDA 上完全不变,同时让 NPU 等非 CUDA 后端可用。
PR 已附上,见下方关联链接。这是为昇腾/非 CUDA 用户做的设备无关修复。