Skip to content

Bug: CPU loading fails when device=torch.device("cpu") #533

Description

@hmirheydari

Environment:

  • Windows 11
  • Python 3.11
  • CPU-only machine

Code:

from chatterbox.mtl_tts import ChatterboxMultilingualTTS
import torch

model = ChatterboxMultilingualTTS.from_pretrained(
device=torch.device("cpu")
)

Result:

RuntimeError:
Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False

Cause:

In D:\chatterbox\Lib\site-packages\chatterbox\mtl_tts.py
In from_local():

if device in ["cpu", "mps"]:
map_location = torch.device("cpu")
else:
map_location = None

When device is torch.device("cpu"), the condition evaluates to False.

Fix
Instead of
if device in ["cpu", "mps"]: map_location = torch.device("cpu") else: map_location = None

replace:

if str(device) in ["cpu", "mps"]: map_location = torch.device("cpu") else: map_location = None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions