Skip to content
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
5 changes: 4 additions & 1 deletion reverb_tts/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def from_pretrained(
name_or_path: Union[str, Path] = REPOSITORY,
*,
variant: str = "int8",
revision: Optional[str] = REVISION,
revision: Optional[str] = None,
token: Optional[str] = None,
device: Optional[Union[str, torch.device]] = None,
dtype: Optional[torch.dtype] = None,
Expand All @@ -134,12 +134,15 @@ def from_pretrained(
model/safetensors/<variant>/) or one checkpoint (config.json and model.safetensors, with the tokenizer beside or
above it).

- revision: a branch, tag or commit of the repository; by default the released weights' tag for
software-mansion/Reverb-TTS, and the latest commit for any other repository.
- variant: fp32, fp16, int8 (the default) or int4. Every variant is converted to `dtype` on load, so the
smaller ones download faster but run at the same speed.
- device: cuda, mps or cpu; by default the first one available.
- dtype: by default bfloat16 on CUDA (float16 without bf16 support), float16 on MPS and float32 on the CPU.
"""

revision = revision or (REVISION if str(name_or_path).lower() == REPOSITORY.lower() else None)
weights, tokenizer = _resolve(name_or_path, variant, revision, token)
device = _pick_device(device)
network = Network.load(weights).to(device, dtype or _default_dtype(device))
Expand Down
21 changes: 21 additions & 0 deletions tests/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,24 @@ def test_resolve_finds_the_safetensors_layout(tmp_path: Path) -> None:
(weights / "config.json").write_text(json.dumps({}))
(tmp_path / "model" / "tokenizer.json").write_text("{}")
assert _resolve(tmp_path, "int4", None, None) == (weights, tmp_path / "model")


@pytest.mark.parametrize("name, revision, expected", [
("software-mansion/Reverb-TTS", None, "v1.0.0"),
("software-mansion/reverb-tts", None, "v1.0.0"),
("someone/reverb-tts-finetune", None, None),
("someone/reverb-tts-finetune", "v2", "v2"),
("software-mansion/Reverb-TTS", "main", "main"),
])
def test_only_the_released_repository_defaults_to_its_tag(monkeypatch: pytest.MonkeyPatch, name: str,
revision: Any, expected: Any) -> None:
asked: List[Any] = []

def resolve(name_or_path: Any, variant: str, revision: Any, token: Any) -> Any:
asked.append(revision)
raise StopIteration

monkeypatch.setattr(tts_module, "_resolve", resolve)
with pytest.raises(StopIteration):
TTS.from_pretrained(name, **({} if revision is None else {"revision": revision}))
assert asked == [expected]
Loading