Metadata-Version: 2.4
Name: trainer-pytorch
Version: 0.0.2
Summary: Generic Pytorch Trainer
Home-page: https://github.com/pacocp/trainer_pytorch
Author: Francisco Carrillo Pérez
Author-email: Francisco Carrillo Pérez <carrilloperezfrancisco@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Francisco Carrillo Pérez
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://pypi.org/project/trainer-pytorch/
Project-URL: Repository, https://github.com/pacocp/trainer-pytorch
Keywords: artificial intelligence,deep learning,transformers,flow matching,autonomous driving
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.2
Requires-Dist: wandb>=0.20.1
Requires-Dist: accelerate>=0.10.0
Requires-Dist: pytest>=8.4.1
Provides-Extra: examples
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: author
Dynamic: home-page
Dynamic: license-file

# Trainer-Pytorch

Implementation of a boilerplate pytorch trainer, with [wandb](https://wandb.ai/) and Huggingface [accelerate](https://huggingface.co/docs/accelerate/index) integration. 

## Installation

```bash
pip install trainer-pytorch
```
## Usage

If you want to use accelerate and wandb:

```bash

# initialize wandb
wandb login

# initialize accelerate
accelerate launch
```

Then, you can initialize the trainer with your model, optimizer, loss function, and scheduler:

```python
# Initialize the TrainerPytorch with a simple model, optimizer, and loss function
model = nn.Linear(10, 1)
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
loss_fn = nn.MSELoss()
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=1, gamma=0.1)
trainer = TrainerPytorch(model, optimizer, loss_fn, scheduler=scheduler, device=device, 
                         use_wandb=True, use_accelerate=True, save_dir='my_experiment')

# generate dummy data
inputs = torch.randn(100, 10)
targets = torch.randn(100, 1)
dataset = TensorDataset(inputs, targets)
train_loader = DataLoader(dataset, batch_size=10, shuffle=True)
eval_loader = DataLoader(dataset, batch_size=10, shuffle=False)

# Train the model
trainer.train(train_loader, eval_loader=eval_loader, epochs=5, patience=2)

# Evaluate the model
outputs = trainer.predict_samples(inputs[:5])
```
