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
torchtransformerspsutil
Licensed under MIT.
Release files for lazymodels 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lazymodels-0.1.6.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lazymodels-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / lazymodels-0.1.6.tar.gz
| Download URL | lazymodels-0.1.6.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d68ff1710d3be7d29bdba50eb44293d1d7b54dde0e17ecdabfcd77eb2bc55f41
|
|
BLAKE2b-256 checksum How to use checksums |
6cc5bf809543557892360d19da1dea4cb2bc042bd7a2a5ae23356eb1ab86f88e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.11
|
Release files / lazymodels-0.1.6-py3-none-any.whl
| Download URL | lazymodels-0.1.6-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea74e60069410d04639c1d9685b2a102d49b3302d6bcc86d6b1653336f180f7f
|
|
BLAKE2b-256 checksum How to use checksums |
1d4f2c5ed35f633971a5ebfdc33b7a4ab3f806412b1ae4369909cd53dc5647f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.11
|