Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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) == REPOSITORY else None)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By sillicon friend:

The name match is case-sensitive. The new line is str(name_or_path) == REPOSITORY. 
Hugging Face repo names are case-insensitive, so TTS.from_pretrained("software-mansion/reverb-tts") loads the official weights but from the latest commit instead of v1.0.0. 
Today that gives the same weights, because the commits after the tag only touch the README and add a root config.json. It would quietly stop being pinned once main gets new weights. 
A one-word fix is to compare str(name_or_path).lower() == REPOSITORY.lower().

Is this the intended effect, that we want to load from main and not v1.0.0?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, not intended. Only fine-tunes should load main. Any spelling of software-mansion/Reverb-TTS should stay on v1.0.0. The Hub does resolve software-mansion/reverb-tts to our repo (checked), so I've made the comparison case-insensitive and added that case to the test.

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
20 changes: 20 additions & 0 deletions tests/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,23 @@ 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"),
("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