torchliter 0.3.4
pip install torchliter
Latest version
Released:
A lightweight training tool for pytorch projects.
Navigation
Unverified details
These details have not been verified by PyPIMeta
- License: MIT
- Author: Chenchao Zhao
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
Unverified details
These details have not been verified by PyPIMeta
- License: MIT
- Author: Chenchao Zhao
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
Built Distribution
File details
Details for the file torchliter-0.3.4.tar.gz
.
File metadata
- Download URL: torchliter-0.3.4.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b41546bba8038d86772111381d6b00b7bbf02cadd947a8706797a17d439fa2e9 |
|
MD5 | 4fb86d69ce4ad1001fad90f3d97842a1 |
|
BLAKE2b-256 | 91d6511209e6f97416c67a0b817a87b9212046c6982a9c2a7de25d555f454321 |
File details
Details for the file torchliter-0.3.4-py3-none-any.whl
.
File metadata
- Download URL: torchliter-0.3.4-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bf87c1665d05a6645b877307be9a031f89ccedf060223a24e40127f97c67d61 |
|
MD5 | fab80deef95cebab0a1c381274ac0fbd |
|
BLAKE2b-256 | 97b9e8b28c0e7397a0c02a08d1164b30db0d0fe56906a1f5fe6959202a855b76 |