Skip to main content

Trainer-Pytorch

Implementation of a boilerplate pytorch trainer, with wandb and Huggingface accelerate integration.

Installation

pip install trainer-pytorch

Usage

If you want to use accelerate and wandb:

# initialize wandb
wandb login

# initialize accelerate
accelerate launch

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

# 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])

Metadata

Release files for trainer-pytorch 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trainer-pytorch 0.0.2
File Size Uploaded Provenance Actions
trainer_pytorch-0.0.2.tar.gz 8.3 kB Without provenance Details for trainer_pytorch-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for trainer-pytorch 0.0.2
File Interpreter ABI Platform Actions
trainer_pytorch-0.0.2-py3-none-any.whl Python 3 none any Details for trainer_pytorch-0.0.2-py3-none-any.whl

Total release size: 15.3 kB

Release files / trainer_pytorch-0.0.2.tar.gz

Download URL trainer_pytorch-0.0.2.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6e5e41c5f3e466f99482c76f051c9101c5eb0b26f64cb58c5cd5a6c8500d8b3d
BLAKE2b-256 checksum
How to use checksums
d0ee3e98d816311a2b1762457e4ef2996962fe1ccde7c1e8496655e774162ddf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / trainer_pytorch-0.0.2-py3-none-any.whl

Download URL trainer_pytorch-0.0.2-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
745ee1b32975ab54cca455b633fef1619762d169cef940c2bba0dca8ed42e7ce
BLAKE2b-256 checksum
How to use checksums
0b3a237128c39ef0b2c5cfd3c5e75de7f1147e2a66ba0b9146a05908fdaeee55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Security for trainer-pytorch 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page