Skip to main content

A lightweight training tool for pytorch projects.

Project description

TorchLiter

test License: MIT PyPI version

A freely customizable and truly lightweight training tool for any pytorch projects

Install

pip install torchliter

Example Usage:

import torchliter
import torch
import torch.nn as nn
import torch.nn.functional as F


cart = torchliter.Cart()
cart.model = nn.Linear(1, 3)
cart.train_loader = torch.utils.data.DataLoader(
    [i for i in range(100)], batch_size=5
)
cart.eval_loader = torch.utils.data.DataLoader(
    [i for i in range(100)], batch_size=5
)
cart.optimizer = torch.optim.AdamW(
    cart.model.parameters(), lr=1e-3, weight_decay=1e-5
)

def train_step(_, batch, **kwargs):
    image, target = batch
    logits = _.model(image)
    loss = F.cross_entropy(logits, target)
    _.optimizer.zero_grad()
    loss.backward()
    _.optimizer.step()

    yield "cross entropy loss", loss.item()

    acc = (logits.max(-1).indices == target).float().mean()

    yield "train acc", acc.item()

def eval_step(_, batch, **kwargs):
    image, target = batch
    with torch.no_grad():
        logits = _.model(image)
    acc = (logits.max(-1).indices == target).float().mean()
    yield "eval acc", acc.item()

def hello(_):
    print("hello")

train_buffers = torchliter.engine.AutoEngine.auto_buffers(
    train_step, torchliter.buffers.ExponentialMovingAverage
)
eval_buffers = torchliter.engine.AutoEngine.auto_buffers(
    eval_step, torchliter.buffers.ScalarSummaryStatistics
)
TestEngineClass = torchliter.engine.AutoEngine.build(
    "TestEngine", train_step, eval_step, print_hello=hello
)
test_engine = TestEngineClass(**{**cart.kwargs, **train_buffers, **eval_buffers})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchliter-0.3.1.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

torchliter-0.3.1-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file torchliter-0.3.1.tar.gz.

File metadata

  • Download URL: torchliter-0.3.1.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for torchliter-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e47cfb6a4e09e25dddb0688f9284caad2c305a1eb138fffcf8049165ff9a2584
MD5 3e2037348ab9c4e2d2f13ebe3161ab7f
BLAKE2b-256 6bce3de6f9ce85dca8bde2a2ce9c5c0d1c71d9c43d8624db7af7de59d1b81d2d

See more details on using hashes here.

File details

Details for the file torchliter-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: torchliter-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for torchliter-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce77025c196cb6ba00405072fed887a15545ff29b7a51e9340113654b585dd7d
MD5 578ffb91fdd07189b5540314697f3db8
BLAKE2b-256 f0fa53d428844885fa2af4724ab8b40fbc845bb771e2723326b400109ffce210

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page