{"id":9621,"library":"coqui-tts-trainer","title":"Coqui TTS Trainer","description":"Coqui TTS Trainer is a general-purpose model trainer for PyTorch, designed to be flexible and extensible. It's part of the wider Coqui AI ecosystem, providing core training utilities for various deep learning models, including those for Text-to-Speech. The current version is 0.4.0, with releases occurring on an irregular, feature-driven cadence.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/idiap/coqui-ai-Trainer","tags":["pytorch","deep-learning","training","tts","machine-learning"],"install":[{"cmd":"pip install coqui-tts-trainer","lang":"bash","label":"Basic Install"},{"cmd":"pip install coqui-tts-trainer[cpu]","lang":"bash","label":"Install with CPU dependencies"},{"cmd":"pip install coqui-tts-trainer[cuda]","lang":"bash","label":"Install with CUDA dependencies (for GPU)"},{"cmd":"pip install coqui-tts-trainer[wandb,tensorboard]","lang":"bash","label":"Install with experiment loggers"}],"dependencies":[{"reason":"Core deep learning framework dependency.","package":"torch","optional":false},{"reason":"Core deep learning framework dependency.","package":"torchvision","optional":false},{"reason":"Core deep learning framework dependency.","package":"torchaudio","optional":false},{"reason":"Configuration parsing and management.","package":"coqpit","optional":false},{"reason":"Tensor manipulation utility.","package":"einops","optional":false},{"reason":"Scientific computing utilities, often used in data processing.","package":"scipy","optional":false},{"reason":"Progress bar for iterations.","package":"tqdm","optional":false},{"reason":"Rich terminal output.","package":"rich","optional":false},{"reason":"HJSON configuration file parser.","package":"hjson","optional":false},{"reason":"Experiment tracking and visualization (optional extra).","package":"wandb","optional":true},{"reason":"Experiment tracking and visualization (optional extra).","package":"tensorboard","optional":true},{"reason":"Numerical computing (included with `[cpu]` and `[cuda]` extras).","package":"numpy","optional":true},{"reason":"Audio file handling (included with `[cpu]` and `[cuda]` extras).","package":"soundfile","optional":true}],"imports":[{"note":"The primary Trainer class is located within the 'trainer' submodule, not directly under the top-level package name.","wrong":"from coqui_tts_trainer import Trainer","symbol":"Trainer","correct":"from trainer.trainer import Trainer"},{"note":"Base configuration class for the trainer, useful for custom configurations.","symbol":"TrainerConfig","correct":"from trainer.generic_model_config import TrainerConfig"}],"quickstart":{"code":"import torch\nimport torch.nn as nn\nfrom torch.utils.data import DataLoader, Dataset\nfrom trainer.trainer import Trainer\nfrom trainer.generic_model_config import TrainerConfig\n\n# 1. Define a simple model\nclass SimpleModel(nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.linear = nn.Linear(10, 2)\n\n    def forward(self, x):\n        return self.linear(x)\n\n# 2. Define a dummy dataset\nclass DummyDataset(Dataset):\n    def __len__(self):\n        return 100\n\n    def __getitem__(self, idx):\n        return torch.randn(10), torch.randint(0, 2, ())\n\n# 3. Create a TrainerConfig\nconfig = TrainerConfig()\nconfig.num_epochs = 2\nconfig.output_path = \"./trainer_output\"\nconfig.batch_size = 4\n\n# 4. Instantiate model, optimizer, criterion, dataloaders\nmodel = SimpleModel()\noptimizer = torch.optim.Adam(model.parameters(), lr=0.001)\nscheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=1, gamma=0.1)\ncriterion = nn.CrossEntropyLoss()\n\ntrain_dataset = DummyDataset()\neval_dataset = DummyDataset()\ntrain_loader = DataLoader(train_dataset, batch_size=config.batch_size)\neval_loader = DataLoader(eval_dataset, batch_size=config.batch_size)\n\n# 5. Initialize and run the Trainer\ntrainer = Trainer(\n    config=config,\n    model=model,\n    optimizer=optimizer,\n    scheduler=scheduler,\n    criterion=criterion,\n    data_loader_train=train_loader,\n    data_loader_eval=eval_loader,\n    grad_scaler=None, # For mixed precision, can be torch.cuda.amp.GradScaler()\n    output_path=config.output_path\n)\n\ntrainer.train()","lang":"python","description":"This quickstart demonstrates how to set up a basic training loop using the `Trainer` class. It defines a simple PyTorch model and dataset, then configures the `Trainer` with a `TrainerConfig`, optimizer, scheduler, criterion, and data loaders. The `trainer.train()` method then executes the training process."},"warnings":[{"fix":"Review your code for direct calls to internal `coqui-tts-trainer` helper functions. Update to a compatible version of the main `coqui` library (v0.28.0 or newer if using the full Coqui stack) if experiencing integration issues.","message":"Version 0.4.0 introduced backwards-incompatible changes by removing various unused functions and arguments to streamline the code. While primarily affecting internal APIs, direct use of previously available utility functions may break.","severity":"breaking","affected_versions":"0.4.0 and later"},{"fix":"Upgrade your Python environment to version 3.10, 3.11, 3.12, 3.13, or 3.14. Using Python 3.15 or newer is not yet supported.","message":"Python 3.9 support was dropped starting from version 0.2.1. The library now requires Python >=3.10 and <3.15.","severity":"breaking","affected_versions":"0.2.1 and later"},{"fix":"Ensure your custom schedulers adhere to the standard `torch.optim.lr_scheduler` interface. Review any custom logic for loading optimizer/scheduler states from checkpoints to align with the updated restoration behavior.","message":"In version 0.3.0, the Coqui's custom LR schedulers adopted the standard PyTorch scheduler interface. This change, along with fixes to model/scheduler state restoration, might break custom scheduler implementations or existing checkpoint loading logic.","severity":"breaking","affected_versions":"0.3.0 and later"},{"fix":"Use a dedicated virtual environment to manage dependencies, preventing conflicts with other `coqpit` installations. The `coqui-tts-trainer` package will automatically install its required forked `coqpit` version.","message":"As of v0.2.0, `coqui-tts-trainer` switched to using a forked version of the `coqpit` library (from `idiap/coqui-ai-coqpit`). If you have other projects or an older `coqpit` installed, ensure compatibility or use a virtual environment.","severity":"gotcha","affected_versions":"0.2.0 and later"},{"fix":"Explicitly install `coqui-tts-trainer` with the `[cpu]` or `[cuda]` extras (e.g., `pip install coqui-tts-trainer[cpu]`) if your training pipeline requires `numpy` or `soundfile`.","message":"Starting from v0.3.3, `numpy` and `soundfile` were removed from the *core* dependencies. While still available via `[cpu]` and `[cuda]` extras, their absence from a minimal install might cause `ModuleNotFoundError` if you implicitly relied on them.","severity":"gotcha","affected_versions":"0.3.3 and later"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change your import statement to `from trainer.trainer import Trainer`.","cause":"The Trainer class is located in a submodule `trainer.trainer`, not directly under `coqui_tts_trainer`.","error":"ModuleNotFoundError: No module named 'trainer'"},{"fix":"Ensure you are passing all required arguments, such as `config`, `model`, `optimizer`, `criterion`, `data_loader_train`, and `data_loader_eval` to the `Trainer` constructor.","cause":"The `Trainer` class requires several mandatory arguments during initialization, including a `config` object.","error":"TypeError: __init__ missing 1 required positional argument: 'config'"},{"fix":"Move your model to the desired device (`model.to(device)`) and ensure all input tensors from your data loader are also moved to the same device (e.g., `data.to(device)`) before passing them to the model.","cause":"This is a common PyTorch error indicating that your model or data tensors are on different devices (CPU vs. GPU) without proper handling.","error":"RuntimeError: Expected all tensors to be on the same device, but found tensors on both cpu and cuda:0"}]}