A lightweight training tool for pytorch projects.
Project description
TorchLiter
A freely customizable and truly lightweight training tool for any pytorch projects
Install
pip install torchliter
Example Usage:
import torchliter as lux
import torch
import torch.nn as nn
import torch.nn.functional as F
cart = lux.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 = lux.engine.AutoEngine.auto_buffers(
train_step, lux.buffers.ExponentialMovingAverage
)
eval_buffers = lux.engine.AutoEngine.auto_buffers(
eval_step, lux.buffers.ScalarSummaryStatistics
)
TestEngineClass = lux.engine.AutoEngine.build(
"TestEngine", train_step, eval_step, print_hello=hello
)
test_engine = TestEngineClass(**{**cart.kwargs, **train_buffers, **eval_buffers})
Project details
Release history Release notifications | RSS feed
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.2.tar.gz
(16.4 kB
view details)
Built Distribution
File details
Details for the file torchliter-0.3.2.tar.gz
.
File metadata
- Download URL: torchliter-0.3.2.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a03f6949e8cab0a827f05c0bf3cabbabc7d6eb3eb9a586d9ff1e5835d2edcda |
|
MD5 | 340afa76e0761aa1a4bf71f73f091e9c |
|
BLAKE2b-256 | 7e01aa9e4be3d6ad3aa6c54d97a438139d57c55945bccd34ea52137ada25a56e |
File details
Details for the file torchliter-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: torchliter-0.3.2-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa1834ad37b8a2907271b360a1a2f5b3f2e165bbddbed4c847bcb24ab05dcf99 |
|
MD5 | e7089876d2a5e7d6dcea84587d7e14f0 |
|
BLAKE2b-256 | 79ea60af8f90962e5dcfdfc911413f7dd85c94a11094d9eb8157b716e86d1095 |