Lightweight PyTorch utility library for training, evaluation, and TFLite export — without the framework lock-in.
Project description
torchloop
Lightweight PyTorch utility library for training, evaluation, and TFLite export — without the framework lock-in.
The Problem
You write the same PyTorch training loop in every project. Same checkpoint logic. Same metric assembly. Same TFLite export steps. It's tedious and inconsistent.
torchloop abstracts exactly that — nothing more.
Install
# Base installation
pip install torchloop
# With TFLite export support
pip install torchloop[export]
# With edge deployment support
pip install torchloop[edge]
# Development setup
pip install torchloop[dev]
Usage
Training
from torchloop import EarlyStopping, ModelCheckpoint, Trainer
trainer = Trainer(
model,
optimizer=torch.optim.Adam(model.parameters()),
criterion=torch.nn.CrossEntropyLoss(),
device="cuda",
use_amp=True,
accumulate_steps=4,
patience=5,
)
trainer.add_callback(EarlyStopping(patience=5))
trainer.add_callback(ModelCheckpoint(filepath="best.pt"))
history = trainer.fit(train_loader, val_loader, epochs=30)
trainer.save("best.pt")
Evaluation
from torchloop import Evaluator
ev = Evaluator(model, device="cuda")
results = ev.report(val_loader, class_names=["No Damage", "Minor", "Major", "Destroyed"])
# prints sklearn classification report
fig = ev.confusion_matrix(val_loader)
fig.savefig("cm.png")
per_class = ev.f1_per_class(val_loader)
# {'No Damage': 0.91, 'Minor': 0.78, ...}
Export
from torchloop.exporter import Exporter
exp = Exporter(model, input_shape=(1, 3, 224, 224))
exp.to_onnx("model.onnx")
exp.to_tflite("model.tflite", quantize=True)
Edge Deployment
from torchloop.edge import deploy_to_edge, estimate_model
stats = estimate_model(model, (1, 3, 224, 224), target_device="esp32")
print(f"RAM: {stats['estimated_ram_mb']} MB")
print(f"Latency: {stats['estimated_latency_ms']} ms")
deploy_to_edge(
model,
target="esp32",
input_shape=(1, 3, 224, 224),
output_path="model.tflite",
quantize=True,
quantize_type="int8",
)
Design Principles
- No lock-in: Works with any nn.Module. No subclassing required.
- Minimal surface area: Three modules. That's it.
- You own the model: torchloop wraps your loop, doesn't replace your architecture.
Roadmap
-
v0.1.0— Trainer, Evaluator, Exporter -
v0.2.0— LR scheduler support, mixed precision (AMP) -
v0.2.1— Gradient accumulation + callbacks -
v0.2.2— Edge submodule -
v0.3.0— W&B / MLflow hooks + CoreML export -
v0.3.1— Model pruning utilities
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchloop-0.3.0.tar.gz.
File metadata
- Download URL: torchloop-0.3.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49ccfdfae7942b259a07a8eb1a395e4256a58af7f5cf53f7262e29e588c5c509
|
|
| MD5 |
8fab35f88214343c0b719ed975385c87
|
|
| BLAKE2b-256 |
0b6b98941fe280062eaba323eefe253b3332a6541f9a04fe175b2bf257748948
|
Provenance
The following attestation bundles were made for torchloop-0.3.0.tar.gz:
Publisher:
publish.yml on Tharun007-TK/torchloop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchloop-0.3.0.tar.gz -
Subject digest:
49ccfdfae7942b259a07a8eb1a395e4256a58af7f5cf53f7262e29e588c5c509 - Sigstore transparency entry: 1188117024
- Sigstore integration time:
-
Permalink:
Tharun007-TK/torchloop@dacfbcecc9e2f12ed34994483ee26dd946e58f5a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Tharun007-TK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dacfbcecc9e2f12ed34994483ee26dd946e58f5a -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchloop-0.3.0-py3-none-any.whl.
File metadata
- Download URL: torchloop-0.3.0-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22dbe0adbeff9765f740dc9754a62d6f2e4c3443506ef49fb67de5e13a2e1e98
|
|
| MD5 |
af6e8dc9bdf193d7369f65d93ca37022
|
|
| BLAKE2b-256 |
d9d297918f46b91f67d603eca651c1586a37de444b89902cb2395b163bab7733
|
Provenance
The following attestation bundles were made for torchloop-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on Tharun007-TK/torchloop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchloop-0.3.0-py3-none-any.whl -
Subject digest:
22dbe0adbeff9765f740dc9754a62d6f2e4c3443506ef49fb67de5e13a2e1e98 - Sigstore transparency entry: 1188117049
- Sigstore integration time:
-
Permalink:
Tharun007-TK/torchloop@dacfbcecc9e2f12ed34994483ee26dd946e58f5a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Tharun007-TK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dacfbcecc9e2f12ed34994483ee26dd946e58f5a -
Trigger Event:
push
-
Statement type: