{"id":10307,"library":"trainer","title":"Trainer (Coqui-AI)","description":"Trainer by Coqui-AI is a general-purpose model trainer for PyTorch, designed to be flexible for various deep learning tasks. It wraps common training patterns, including distributed training via Hugging Face Accelerate, making it suitable for quick experimentation and larger-scale projects. The library is in active development (v0.0.36) with frequent micro-releases addressing bugs and adding features.","status":"active","version":"0.0.36","language":"python","source_language":"en","source_url":"https://github.com/coqui-ai/Trainer","tags":["pytorch","deep-learning","training","coqui","accelerate","machine-learning"],"install":[{"cmd":"pip install trainer","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core deep learning framework.","package":"torch","optional":false},{"reason":"Enables distributed training and mixed precision.","package":"accelerate","optional":false},{"reason":"Scientific computing utilities, often used in data processing or metrics.","package":"scipy","optional":false}],"imports":[{"wrong":"from trainer import Trainer","symbol":"Trainer","correct":"from trainer import Trainer"}],"quickstart":{"code":"import torch\nfrom torch import nn, optim\nfrom torch.utils.data import DataLoader, Dataset\nfrom trainer import Trainer\nimport os\n\n# 1. Dummy Dataset\nclass DummyDataset(Dataset):\n    def __init__(self, num_samples=100, input_dim=10, output_dim=1):\n        self.X = torch.randn(num_samples, input_dim)\n        self.y = torch.randn(num_samples, output_dim)\n    def __len__(self):\n        return len(self.X)\n    def __getitem__(self, idx):\n        return self.X[idx], self.y[idx]\n\n# 2. Dummy Model\nclass DummyModel(nn.Module):\n    def __init__(self, input_dim=10, output_dim=1):\n        super().__init__()\n        self.linear = nn.Linear(input_dim, output_dim)\n    def forward(self, x):\n        return self.linear(x)\n\n# 3. Setup components\ninput_dim = 10\noutput_dim = 1\nmodel = DummyModel(input_dim, output_dim)\noptimizer = optim.Adam(model.parameters(), lr=0.001)\ncriterion = nn.MSELoss()\n\ntrain_dataset = DummyDataset(num_samples=100, input_dim=input_dim, output_dim=output_dim)\neval_dataset = DummyDataset(num_samples=20, input_dim=input_dim, output_dim=output_dim)\n\ndataloader_train = DataLoader(train_dataset, batch_size=4, shuffle=True)\ndataloader_eval = DataLoader(eval_dataset, batch_size=4, shuffle=False)\n\n# 4. Minimal Config (usually from argparse)\nconfig = {\n    \"output_path\": \"./trainer_quickstart_output\",\n    \"epochs\": 2,\n    \"start_by_epochs\": True, \n    \"print_step\": 1, \n    \"save_step\": 1, \n    \"eval_step\": 1\n}\n\n# Ensure output path exists for trainer to save checkpoints/logs\nos.makedirs(config[\"output_path\"], exist_ok=True)\n\n# 5. Initialize and run Trainer\ntrainer_instance = Trainer(\n    config=config,\n    model=model,\n    optimizer=optimizer,\n    criterion=criterion,\n    dataloader_train=dataloader_train,\n    dataloader_eval=dataloader_eval,\n)\n\nprint(f\"Starting training for {config['epochs']} epochs...\")\ntrainer_instance.train_loop()\nprint(\"Training finished.\")\n\n# Output files will be created in ./trainer_quickstart_output\n# In a real application, you might add cleanup or more complex logging.","lang":"python","description":"This quickstart demonstrates how to set up a minimal PyTorch model, optimizer, criterion, and data loaders, then initialize and run the `Trainer` class for a basic training loop. It uses dummy data and a simple linear model to illustrate the core workflow. The `config` dictionary is essential for guiding the trainer's behavior, including output paths and training epochs."},"warnings":[{"fix":"Always test checkpointing and resumption thoroughly after updating the library. Refer to the specific release notes for bug fixes related to `continue_path` and `save_best_model` in your target version.","message":"The `continue_path` (for resuming training from checkpoints) and `save_best_model` functionalities have undergone several reverts and fixes across versions v0.0.33, v0.0.34, and v0.0.35. This indicates potential instability and breaking changes in how checkpoints are handled or resumed.","severity":"breaking","affected_versions":">=0.0.33, <0.0.36"},{"fix":"Pin your `trainer` dependency to an exact version (`trainer==0.0.36`) in production environments and review GitHub releases/changelogs carefully before upgrading. Maintain robust integration tests for your training pipelines.","message":"As a pre-1.0 library (currently v0.0.36), the API may evolve rapidly. Methods, arguments, or configurations might change without extensive deprecation warnings, leading to unexpected errors with minor version updates.","severity":"gotcha","affected_versions":"<1.0.0"},{"fix":"Consult the `accelerate` documentation and `trainer`'s examples for distributed training. Ensure your environment is correctly configured for distributed processes, and verify that all ranks initialize correctly, especially when setting up for the first time.","message":"Distributed training setups, which leverage `accelerate`, can be complex. Issues like 'distribute rank initialization' have been fixed (v0.0.32), suggesting that multi-GPU or distributed configurations might require careful setup and debugging.","severity":"gotcha","affected_versions":"<0.0.33"}],"env_vars":null,"search_vec":"'acceler':39,74 'activ':55 'ad':66 'address':63 'ai':4,9 'bug':64 'common':30 'coqui':3,8,73 'coqui-ai':2,7 'deep':25,70 'deep-learn':69 'design':19 'develop':56 'distribut':34 'experiment':45 'face':38 'featur':67 'flexibl':22 'frequent':59 'general':13 'general-purpos':12 'hug':37 'includ':33 'larger':48 'larger-scal':47 'learn':26,71,77 'librari':52 'machin':76 'machine-learn':75 'make':40 'micro':61 'micro-releas':60 'model':15 'pattern':32 'project':50 'purpos':14 'pytorch':18,68 'quick':44 'releas':62 'scale':49 'suitabl':42 'task':27 'train':31,35,72 'trainer':1,5,16 'v0.0.36':57 'various':24 'via':36 'wrap':29","created_at":"2026-04-17T01:23:27.174301+00:00","updated_at":"2026-04-17T01:23:27.174301+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmpo4e1kz0e/venv/lib/python3.12/site-packages/trainer/__init__.py\", line 4, in <module>\n    from trainer.trainer import *\n  File \"/tmp/tmpo4e1kz0e/venv/lib/python3.12/site-packages/trainer/trainer.py\", line 23, in"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.0.36","cli_name":"trainer","cli_version":"","type":"library","homepage":null,"github":"https://github.com/coqui-ai/Trainer","docs":"https://github.com/coqui-ai/Trainer/","changelog":null,"pypi":"https://pypi.org/project/trainer/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","llm-agents"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}