Skip to main content

Smart lazy loader for Transformers with memory-based unloading (CPU/GPU aware)

Project description

lazymodels

LazyModels is a lightweight utility for lazy-loading HuggingFace Transformers and managing memory automatically, both on CPU and GPU.

It keeps only the models you need in memory and unloads older ones when memory limits are exceeded. Works out of the box in one line of code:

from lazymodels import lazy_model_transformer

model = lazy_model_transformer("gpt2")

🔥 Features

  • ✅ Lazy loading of models by name
  • ✅ Smart task detection: causal-lm, seq2seq, token classification, etc.
  • ✅ Automatic unloading when RAM or VRAM usage exceeds the limit
  • ✅ One global manager to control all memory
  • ✅ Transformers support out of the box

📦 Example

from lazymodels import lazy_model_transformer

# Load a causal LM model
model = lazy_model_transformer("gpt2")

# Load a seq2seq model with tokenizer
model2, tokenizer = lazy_model_transformer("t5-small", tokenizer=True)

⚙️ Requirements

  • torch
  • transformers
  • psutil

Licensed under 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

lazymodels-0.1.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

lazymodels-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file lazymodels-0.1.1.tar.gz.

File metadata

  • Download URL: lazymodels-0.1.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for lazymodels-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f4b30b25d35acba9a5c600927cf6f6c12ec6f232f7b432db56d11e914ed889a
MD5 ce297c97464e7f0fb645bb829914614b
BLAKE2b-256 5a942195f0e70ebe2d89898e26b35394819509e99af1ca3f97dbde2d18005b28

See more details on using hashes here.

File details

Details for the file lazymodels-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lazymodels-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for lazymodels-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7501b07937025c00b248dc72b685c2628b05b9f644af3e5fa1d90ebbfff49d1
MD5 2e9c236e13cb67299b9e1c29adcea0d7
BLAKE2b-256 784d222419a8c8aad37a9487cc73e90d6a98f25e2383938f30a95f1a0cb05226

See more details on using hashes here.

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