A TTS that fits in your CPU (and pocket)
Python
docs: correct GPU speedup claim + add CUDA usage notes (#213)
moduvoice1857d2ea2ff3
diff --git a/AGENTS.md b/AGENTS.mdindex 9dc0f88..a03c3f8 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -105,7 +105,17 @@ This is a pure Python package with Rust extensions in `training/rust_exts/audio_- **Thread Safety**: The code is NOT thread-safe. Server mode does not support concurrent requests.- **Batching**: Batch size is always 1. No batching support currently.-- **Device**: Defaults to CPU. GPU does not provide speedup for this small model.+- **Device**: Defaults to CPU. Whether GPU helps is hardware-dependent: on hardware with strong+ single-thread CPU performance (e.g. Apple Silicon) we did not observe a speedup, but on a cloud+ x86 VM with a Tesla T4, `.to("cuda")` measured ~2.6x speedup over CPU (RTF ~2.3-2.5x CPU vs.+ ~6.28x GPU). There is no `device` argument on `TTSModel.load_model()` (the `generate` CLI has a+ documented `--device`, though its own doc page's "no speedup" note predates this finding; `serve`+ and Docker have none and are CPU-only). `generate_audio()` returns a tensor on the model's device,+ so code moved to GPU must call `.detach().cpu().numpy()` instead of `.numpy()`. `quantize=True` is+ CPU-only and raises `NotImplementedError` on CUDA; the optional `torchao` backend declares+ `torch>=2.11`, which a fresh install satisfies, but installing it on top of an older pinned+ `torch` (e.g. for GPU driver compatibility) can break `quantize=True` even on CPU. See README's+ "Running on GPU" section for details.- **Torch Threads**: `torch.set_num_threads(1)` in `tts_model.py` for optimal CPU performance- **dtype**: Models use float32 by default (configurable in YAML)- **Beartype**: Runtime type checking is enabled via beartype claw in `__init__.py`diff --git a/README.md b/README.mdindex 83be1f4..de1209b 100644--- a/README.md+++ b/README.md@@ -157,14 +157,58 @@ audio = model.generate_audio(model_state_copy, "Hello world!")You can check out the [Python API documentation](https://kyutai-labs.github.io/pocket-tts/API%20Reference/python-api/) for more details and examples.+## Running on GPU++Pocket TTS is designed to run on CPU, and on hardware with strong single-thread CPU performance+(e.g. Apple Silicon) we did not observe a GPU speedup, notably because we use a batch size of 1+and a very small model. However, this turns out to be hardware-dependent: measured on a cloud x86+VM (4 vCPUs) with a Tesla T4, moving the model to GPU gave a consistent ~2.6x speedup over CPU+(RTF ~2.3-2.5x on CPU vs. ~6.28x on GPU, for both short and long input text). If your CPU is+thread-limited or otherwise weaker than a modern laptop chip, it's worth trying the GPU.++This is not officially supported (there is no `device` argument on `TTSModel.load_model()`), but+since `TTSModel` is a regular `nn.Module` you can move it yourself:++```python+tts_model = TTSModel.load_model()+tts_model.to("cuda")+...+audio = tts_model.generate_audio(voice_state, "Hello world, this is a test.")+# generate_audio() returns a tensor on the same device as the model, so on GPU you need+# to move it back to CPU before calling .numpy():+scipy.io.wavfile.write("output.wav", tts_model.sample_rate, audio.detach().cpu().numpy())+```++A few things to be aware of if you want to use the GPU:+- The `generate` CLI command has a `--device` option (defaults to `cpu`, documented in the+ [CLI reference](docs/CLI%20Commands/generate.md) — note that page's own description ("you may not+ get a speedup by using a gpu since it's a small model") is what this section is correcting, based+ on the T4 measurements above); the `serve` command and the Docker image do not expose any device+ option and will always run on CPU.+- `pip install pocket-tts` / `uv add pocket-tts` install whatever `torch` build is current on+ PyPI, which may require a newer CUDA version than your driver supports. In that case+ `torch.cuda.is_available()` silently returns `False` (you'll only see a `UserWarning` about an+ outdated driver, not an error). If this happens, install a `torch` build matching your driver's+ CUDA version explicitly, e.g. `pip install torch --index-url https://download.pytorch.org/whl/cu121`.+- `quantize=True` (int8 dynamic quantization) only works on CPU; calling it on a model moved to+ CUDA raises `NotImplementedError: Could not run 'quantized::linear_dynamic' ... 'CUDA' backend`.+ Separately, the optional `torchao` backend (`pip install pocket-tts[quantize]`) declares+ `torch>=2.11` — fine with a fresh install (torch 2.11+ is on PyPI as of this writing), but if+ you've pinned an older `torch` (e.g. to match an older GPU driver's CUDA build, per the point+ above), adding this extra can pull in a `torchao` that's incompatible with your pinned `torch`+ and break `quantize=True` even on CPU. Match `torchao`'s `torch` requirement to whatever `torch`+ you actually have installed.+## Unsupported featuresAt the moment, we do not support (but would love pull requests adding):- [Adding silence in the text input to generate pauses.](https://github.com/kyutai-labs/pocket-tts/issues/6)-We tried running this TTS model on the GPU but did not observe a speedup compared to CPU execution,-notably because we use a batch size of 1 and a very small model.+We tried running this TTS model on the GPU but did not observe a speedup compared to CPU execution+on hardware with very strong single-thread CPU performance, notably because we use a batch size of+1 and a very small model. See the ["Running on GPU"](#running-on-gpu) section above for measurements+on other hardware and caveats if you want to try it yourself.## Development and local setupdiff --git a/docs/CLI Commands/generate.md b/docs/CLI Commands/generate.mdindex 7cf3509..4974880 100644--- a/docs/CLI Commands/generate.md+++ b/docs/CLI Commands/generate.md@@ -32,7 +32,7 @@ This will generate a WAV file `./tts_output.wav` with the default text and voice### Performance Options-- `--device DEVICE`: Device to use (default: "cpu", you may not get a speedup by using a gpu since it's a small model)+- `--device DEVICE`: Device to use (default: "cpu"). Whether GPU helps is hardware-dependent — see the main [README's "Running on GPU" section](../../README.md#running-on-gpu) for measured numbers (no speedup observed on some CPUs with strong single-thread performance like Apple Silicon, but a measured ~2.6x speedup on a cloud x86 VM with a Tesla T4).- `--quantize`: Use int8 quantization for the model (default: False). This can reduce memory usage and increase speed, with minimal impact on audio quality.- `--quiet`, `-q`: Disable logging output