Skip to main content

torchgs

Pytorch wrapper for grid search of hyperparameters [https://github.com/danny-1k/torch-gs]

Install

$ pip install torchgs

Example

Finding the best set of hyper-parameters and models for a classification problem

from sklearn.datasets import make_classification

import torch
import torch.nn as nn

from torch.utils.data import TensorDataset

from torchgs import GridSearch

from torchgs.metrics import Loss

X,Y = make_classification(n_samples=200, n_features=20, n_informative=10,n_classes=2,shuffle=True, random_state=42)

X = torch.Tensor(X).float()
Y = torch.Tensor(Y).long()

traindata = TensorDataset(X,Y)

net1 = nn.Sequential(
    nn.Linear(20,10),
    nn.ReLU(),
    nn.Linear(10,2)
)

net2 = nn.Sequential(
    nn.Linear(20,10),
    nn.Tanh(),
    nn.Linear(10,2)
)

net3 = nn.Sequential(
    nn.Linear(20,20),
    nn.ReLU(),
    nn.Linear(20,10),
    nn.ReLU(),
    nn.Linear(10,2)
)

net4 = nn.Sequential(
    nn.Linear(20,20),
    nn.Tanh(),
    nn.Linear(20,10),
    nn.Tanh(),
    nn.Linear(10,2)
)


search_space = {
    'trainer':
        {
            'net': [net1,net2,net3,net4],
            'optimizer': [torch.optim.Adam],
            'lossfn': [torch.nn.CrossEntropyLoss()],
            'epochs': list(range(11)),
            'metric': [Loss(torch.nn.CrossEntropyLoss())],
        },
    'train_loader': {
        'batch_size': [32,64],
    },

    'optimizer':
        {
            'lr': [1e-1,1e-2,1e-3,1e-4],
    },
}

searcher = GridSearch(search_space)
results = searcher.fit(traindata)
best = searcher.best(results,using='mean',topk=10,should_print=True)

Output

output

torchgs

  • Trainer
  • GridSearch
  • metrics
  • optimizers

torchgs.metrics

  • Metric
  • Loss
  • Accuracy
  • Recall
  • Precision
  • F1

torchgs.optimizers

  • Optimizer
  • LRscheduler

Todo

  • Parallel Training on multiple GPUS
  • Tensorboard Integration

Pull requests are welcome, let's collab 🤲.

Release files for torchgs 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 torchgs 0.0.2
File Size Uploaded
torchgs-0.0.2.tar.gz 8.2 kB Details

Built distribution (wheel)

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

Total release size: 16.1 kB

Release files / torchgs-0.0.2.tar.gz

Download URL torchgs-0.0.2.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
34301572366a53b9cdad5365cafc011ce70ad1546cc7d2edc00a622509e61802
BLAKE2b-256 checksum
How to use checksums
deb9735fb1cf89c7260d4622408bec72d4fa12555aaa4eb6ad4f5f467faae7d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

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

Download URL torchgs-0.0.2-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79554f298aed1c383b85c2f0f69a143eec6e8ed3b2d48de7469266acb6267dad
BLAKE2b-256 checksum
How to use checksums
e0fbe9020dbfff020c91937adfcb3d6d741566987999ae5b69fd1fc4c1b9d65e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.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