Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fairseq): handle change of model file name #264

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions TTS/tts/models/vits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import os
from dataclasses import dataclass, field, replace
from itertools import chain
from typing import Dict, List, Tuple, Union
from pathlib import Path
from typing import Any, Dict, List, Tuple, Union

import numpy as np
import torch
Expand Down Expand Up @@ -1581,13 +1582,16 @@ def load_fairseq_checkpoint(

self.disc = None
# set paths
config_file = os.path.join(checkpoint_dir, "config.json")
checkpoint_file = os.path.join(checkpoint_dir, "G_100000.pth")
vocab_file = os.path.join(checkpoint_dir, "vocab.txt")
checkpoint_dir = Path(checkpoint_dir)
config_file = checkpoint_dir / "config.json"
checkpoint_file = checkpoint_dir / "model.pth"
if not checkpoint_file.is_file():
checkpoint_file = checkpoint_dir / "G_100000.pth"
vocab_file = checkpoint_dir / "vocab.txt"
# set config params
with open(config_file, "r", encoding="utf-8") as file:
with open(config_file, "r", encoding="utf-8") as f:
# Load the JSON data as a dictionary
config_org = json.load(file)
config_org = json.load(f)
self.config.audio.sample_rate = config_org["data"]["sampling_rate"]
# self.config.add_blank = config['add_blank']
# set tokenizer
Expand Down Expand Up @@ -1821,7 +1825,7 @@ def to_config(self) -> "CharactersConfig":


class FairseqVocab(BaseVocabulary):
def __init__(self, vocab: str):
def __init__(self, vocab: Union[str, os.PathLike[Any]]):
super(FairseqVocab).__init__()
self.vocab = vocab

Expand All @@ -1831,7 +1835,7 @@ def vocab(self):
return self._vocab

@vocab.setter
def vocab(self, vocab_file):
def vocab(self, vocab_file: Union[str, os.PathLike[Any]]):
with open(vocab_file, encoding="utf-8") as f:
self._vocab = [x.replace("\n", "") for x in f.readlines()]
self.blank = self._vocab[0]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build-backend = "hatchling.build"

[project]
name = "coqui-tts"
version = "0.25.2"
version = "0.25.3"
description = "Deep learning for Text to Speech."
readme = "README.md"
requires-python = ">=3.9, <3.13"
Expand Down
1 change: 1 addition & 0 deletions tests/zoo_tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def manager(tmp_path):
num_partitions = int(os.getenv("NUM_PARTITIONS", "1"))
partition = int(os.getenv("TEST_PARTITION", "0"))
model_names = [name for name in TTS.list_models() if name not in MODELS_WITH_SEP_TESTS]
model_names.extend(["tts_models/deu/fairseq/vits", "tts_models/sqi/fairseq/vits"])
model_names = [name for i, name in enumerate(model_names) if i % num_partitions == partition]


Expand Down
Loading