Skip to main content

run-torch-model

Simple program to run a pytorch compatible model. Includes a tools function which has support for creating dataloader objects required for training/testing/validation.

Requirements

  • torch
  • torchmetrics
  • scikit-learn

Install

Install using pip:

pip install run-torch-model

Usage

Use create_dataloader to initiate datasets for training and testing:

from run_torch_model import create_dataloader

dataloader_train, dataloader_test = create_dataloader(features=features, 
                                                      targets=targets,
                                                      batch_size=batch_size,
                                                      train_size=train_size,
                                                      test_size=test_size)

To run a model we define the optimizer, its arguments and a criterion, feed into the class and perform a call for training.

import torch
from run_torch_model import RunTorchNN

optimizer = 'torch.optim.Adam'  # Must be string, if CUDA we initiate the optimizer after calling .cuda for speed-up
optimizer_args = {'lr': 0.001'} # Initialize some arguments for the optimizer
criterion = torch.nn.MSELoss()

run_model = RunTorchNN(model, # Some pytorch model
                          epochs=100, 
                          optimizer=optimizer,
                          optimizer_args=optimizer_args,
                          dataloaders=(dataloader_train, dataloader_test), 
                          criterion=criterion)
 
run_model() # Executes the training

To fetch metrics:

R2 = run_model.get_r2score()
loss = run_model.get_average_loss()

To evaluate the trained model on a different set of features:

predictions, loss = run_model.predict(new_features)

To evaluate the model on a validation set:

loss, r2 = run_model.evaluate(dataloader_validation)
predictions = run_model.get_predictions()  # To get predictions, if necessary 

Release files for run-torch-model 1.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 run-torch-model 1.0.2
File Size Uploaded
run_torch_model-1.0.2.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for run-torch-model 1.0.2
File Interpreter ABI Platform
run_torch_model-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / run_torch_model-1.0.2.tar.gz

Download URL run_torch_model-1.0.2.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
87a9c052970b00f940fcfa17c4acd5c86f447330678f8f457d1a070bb7130d11
BLAKE2b-256 checksum
How to use checksums
c70cc347c314dcc59d48e2dc60e1ade2d7a0d77f62afd6ec7710180c46ea6402
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.2.1 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8

Release files / run_torch_model-1.0.2-py3-none-any.whl

Download URL run_torch_model-1.0.2-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca15c26bfcaddb4cbf57a49b233d0c62b6aee3553f916ff1be334149f2545875
BLAKE2b-256 checksum
How to use checksums
5f1fac9987bafdbe16ff5b3321d826cf2b97b16eddc3f1af6b1a073213420b97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.2.1 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

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