Skip to content

Commit

Permalink
fix device mismatch bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-hello committed Aug 31, 2024
1 parent 024f93e commit 1d5f1fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ChatTTS/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def _load(
self.config.embed.num_text_tokens,
self.config.embed.num_vq,
)
embed.from_pretrained(embed_path)
self.embed = embed
embed.from_pretrained(embed_path, device=self.device)
self.embed = embed.to(self.device)
self.logger.log(logging.INFO, "embed loaded.")

gpt = GPT(
Expand Down
3 changes: 2 additions & 1 deletion ChatTTS/model/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ def __init__(
)

@torch.inference_mode()
def from_pretrained(self, filename: str):
def from_pretrained(self, filename: str, device: torch.device):
state_dict_tensors = {}
with safe_open(filename, framework="pt") as f:
for k in f.keys():
state_dict_tensors[k] = f.get_tensor(k)
self.load_state_dict(state_dict_tensors)
self.to(device)

def __call__(
self, input_ids: torch.Tensor, text_mask: torch.Tensor
Expand Down

0 comments on commit 1d5f1fc

Please sign in to comment.