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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ that runs it.
- **0.96% word error rate** on the Open TTS Leaderboard's MiniMax test set, lower than every model on the leaderboard.
- **297M parameters**, plus a 22M-parameter codec decoder.
- **232.3× real time** on an NVIDIA H200 and **164.9×** on an RTX 5090 at batch 32, **over 20×** on an Apple M4 Pro and an iPhone 17 at batch 1.
- **Weights:** fp32, fp16, int8, int8a8, and int4 safetensors, and ExecuTorch programs for MLX, Vulkan, and QNN.
- **Weights:** fp32, fp16, int8, and int4 safetensors, and ExecuTorch programs for MLX, Vulkan, and QNN.

## Install

Expand Down
5 changes: 2 additions & 3 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

### safetensors

PyTorch weights for the `reverb-tts` package, in five variants (`TTS.from_pretrained(variant=...)`):
PyTorch weights for the `reverb-tts` package, in four variants (`TTS.from_pretrained(variant=...)`):

| Variant | Weights | Activations | Download |
|---|---|---|---|
| `fp32` | fp32 | full precision | 1.19 GB |
| `fp16` | fp16 | full precision | 594 MB |
| `int8` (default) | int8, one scale per output channel | full precision | 307 MB |
| `int8a8` | int8, one scale per output channel | int8, one scale per token | 307 MB |
| `int4` | int4, one scale per group of 32 inputs | full precision | 191 MB |

In the quantized variants the decoder's linear layers hold the quantized weights, with fp16 scales. On an internal test
Expand Down Expand Up @@ -55,7 +54,7 @@ The weights on Hugging Face, [software-mansion/Reverb-TTS](https://huggingface.c
```
model/
tokenizer.json, tokenizer_config.json, chat_template.jinja
safetensors/<variant>/ config.json, model.safetensors: fp32, fp16, int8, int8a8, int4
safetensors/<variant>/ config.json, model.safetensors: fp32, fp16, int8, int4
executorch/mlx/<precision>/ reverb_mlx_<precision>.pte: fp16, int8, int4
executorch/vulkan/int4/ reverb_vulkan_int4.pte
executorch/qnn/int4/ reverb_qnn_int4_<hexagon>.pte: v69, v73, v75, v79, v81
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ for text that is already written out, in `generate` or in `voice`.
```python
import torch

tts = TTS.from_pretrained(variant="int4") # fp32, fp16, int8 (default), int8a8 or int4
tts = TTS.from_pretrained(variant="int4") # fp32, fp16, int8 (default) or int4
tts = TTS.from_pretrained(device="cpu", dtype=torch.float32)
tts = TTS.from_pretrained("path/to/weights") # a local folder
```
Expand Down
19 changes: 3 additions & 16 deletions reverb_tts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import json
from pathlib import Path
from typing import Dict, Optional, Tuple
from typing import Dict, Optional

import torch
from safetensors.torch import load_file
Expand Down Expand Up @@ -63,12 +63,6 @@ def load(cls, folder: Path) -> "Network":
heads = weights["audio_heads.weight"].view(CODEBOOKS, CODES, -1)
weights["audio_heads.weight"] = (heads - heads.mean(1, keepdim=True)).flatten(0, 1)
network.load_state_dict(weights)

# An int8a8 checkpoint was made to run with each token's projection inputs rounded to int8.
if quantization and quantization.get("activations"):
for module in network.llm.layers.modules():
if isinstance(module, torch.nn.Linear):
module.register_forward_pre_hook(round_per_token)
return network.eval()


Expand All @@ -80,6 +74,8 @@ def dequantize(weights: Dict[str, torch.Tensor], quantization: Dict) -> Dict[str

if quantization.get("rotation"):
raise NotImplementedError("checkpoints with rotated projections are not supported")
if quantization.get("activations"):
raise NotImplementedError("checkpoints with quantized activations, such as int8a8, are not supported")
bits, group = quantization["bits"], quantization.get("group_size")
for key in [key for key in weights if key.endswith(SCALE)]:
name, scale = key[: -len(SCALE)], weights.pop(key).float()
Expand All @@ -95,12 +91,3 @@ def dequantize(weights: Dict[str, torch.Tensor], quantization: Dict) -> Dict[str
weights[name] = codes * scale
return weights


def round_per_token(module: torch.nn.Module, args: Tuple[torch.Tensor, ...]) -> Tuple[torch.Tensor, ...]:
"""
Rounds each token's input to symmetric int8, with a scale of its own.
"""

x = args[0]
scale = x.abs().amax(-1, keepdim=True).clamp(min=1e-12) / 127
return ((x / scale).round().clamp(-127, 127) * scale,) + args[1:]
4 changes: 2 additions & 2 deletions reverb_tts/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
REPOSITORY, REVISION = "software-mansion/Reverb-TTS", "v1.0.0" # the released weights
PRESETS = REPOSITORY # preset voices, as voices/<name>.json
CODEC, CODEC_REVISION = "eustlb/higgs-audio-v2-tokenizer", "0e3a9177c2991016b8e5e17d23aa474ee665bef2"
VARIANTS = ("fp32", "fp16", "int8", "int8a8", "int4")
VARIANTS = ("fp32", "fp16", "int8", "int4")
FRAME_RATE = 25 # codec frames per second
LONGEST, PIECE = 30.0, 15.0 # seconds: a text estimated longer than LONGEST is spoken in pieces of about PIECE
END_CUT = 0.2 # seconds cut from every take's end, where the codec can leave a short burst of noise
Expand Down Expand Up @@ -134,7 +134,7 @@ def from_pretrained(
model/safetensors/<variant>/) or one checkpoint (config.json and model.safetensors, with the tokenizer beside or
above it).

- variant: fp32, fp16, int8 (the default), int8a8 or int4. Every variant is converted to `dtype` on load, so the
- 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.
Expand Down
7 changes: 3 additions & 4 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ def test_quantized_checkpoints_are_expanded_on_load(network: Network, tmp_path:
assert (table - loaded.state_dict()["llm.embed_tokens.table.weight"]).abs().max() <= table.abs().amax() / 254 + 1e-3


def test_int8a8_checkpoint_rounds_projection_inputs(network: Network, tmp_path: Path) -> None:
def test_checkpoints_with_quantized_activations_are_rejected(network: Network, tmp_path: Path) -> None:
quantization = {"bits": 8, "group_size": None, "activations": "per_token", "rotation": None}
loaded = Network.load(write_checkpoint(tmp_path, network, quantization))
hooked = [m for m in loaded.llm.layers.modules() if isinstance(m, torch.nn.Linear) and m._forward_pre_hooks]
assert len(hooked) == 7 * 2 # q, k, v, o, gate, up, down in each of 2 layers
with pytest.raises(NotImplementedError, match="int8a8"):
Network.load(write_checkpoint(tmp_path, network, quantization))


def test_rotated_checkpoints_are_rejected(network: Network, tmp_path: Path) -> None:
Expand Down
Loading