Skip to main content

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.

CI PyPI Python License: MIT


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

pip install torchloop

# With TFLite export support
pip install torchloop[export]

Usage

Training

from torchloop import Trainer

trainer = Trainer(
    model,
    optimizer=torch.optim.Adam(model.parameters()),
    criterion=torch.nn.CrossEntropyLoss(),
    device="cuda",
    patience=5,           # early stopping
)

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)

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.3.0 — W&B / MLflow logging hooks

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

torchloop-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchloop-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file torchloop-0.1.0.tar.gz.

File metadata

  • Download URL: torchloop-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torchloop-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7ec733544fcacc21db17a63d627be3b8700cd4a964a9f08783bc7de05c5f60d6
MD5 b5f992e85454737b184daf8faa9326ed
BLAKE2b-256 3bb3985aac0bd8a1488f06828fc8162521ce85c5ef2cbc25f4527937f7699a25

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchloop-0.1.0.tar.gz:

Publisher: publish.yml on Tharun007-TK/torchlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchloop-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: torchloop-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torchloop-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c1e66a058de8a07e5a0f433945837f05a56435bad3c02b7f98ef257b6c469c9
MD5 924b1820b16cec908b08d7908d40b299
BLAKE2b-256 986c6172a6254efcd5c600097b396300fccb0d2e429a97f2896168d49b168f90

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchloop-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Tharun007-TK/torchlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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