错误: 当 device=torch.device("cpu") 时, CPU 加载失败

作者: hmirheydari创建于 2026年6月25日更新于 2026年8月27日

环境: - Windows 11 - Python 3.11 - 仅支持 CPU 的机器 代码: from chatterbox.mtl_tts import ChatterboxMultilingualTTS import torch model = ChatterboxMultilingualTTS.from_pretrained(device=torch.device("cpu")) 结果: RuntimeError: 尝试在 CUDA 设备上反序列化对象,但 torch.cuda.is_available() 为 False 原因: 在 D:\chatterbox\Lib\site-packages\chatterbox\mtl_tts.py 中,在 from_local() 中: if device in ["cpu", "mps"]: map_location = torch.device("cpu") else: map_location = None 当 device 为 torch.device("cpu") 时,该条件的值为 False。 ** 修复 ** 将 `if device in ["cpu", "mps"]: map_location = torch.device("cpu") else: map_location = None` 替换为: `if str(device) in ["cpu", "mps"]: map_location = torch.device("cpu") else: map_location = None`

内容来源: resemble-ai/chatterbox