Run local LLMs on low-RAM machines with automatic hardware detection and streaming inference
Project description
digvijay_llm
Run big open-source LLMs — including 70B-class models — on machines with as little as 16 GB of RAM, by streaming weights from disk instead of loading the full model into RAM.
This version is more production-oriented: it can detect your hardware automatically, choose sensible defaults for backend/device/threading/context, expose the detected configuration through llm.config, and support streaming plus basic benchmarking.
pip install digvijay_llm
⚠️ Read this first (important honesty note)
A CPU/GPU can only compute on data sitting in RAM/VRAM — it is physically impossible to run matrix multiplications directly on a disk. What this library actually does, and what makes low-RAM 70B inference possible, is disk-backed weight streaming: weights live on disk and are pulled into RAM only for the layer currently being computed, then released.
Peak RAM usage becomes roughly "one layer's worth of weights + activations" instead of "the entire model's weights." The tradeoff is speed — disk I/O is much slower than RAM, so expect lower tokens/sec than a fully-in-RAM setup, especially on HDDs. An NVMe SSD is strongly recommended.
How it works
digvijay_llm ships two backends:
| Backend | File format | Mechanism | Best for |
|---|---|---|---|
GGUFStreamingEngine |
.gguf (quantized) |
Wraps llama.cpp via llama-cpp-python, using mmap() so the OS pages weights in/out of RAM on demand |
Production use — fastest, most memory-efficient, supports 4-bit/5-bit quantization |
SafetensorsLayerStreamer |
raw HuggingFace .safetensors checkpoints |
Builds the model with empty weights, then uses accelerate's disk-offload hooks to load one transformer layer at a time from disk right before it's needed |
When you only have an unconverted HF checkpoint and don't want to quantize/convert to GGUF first |
Both are wrapped behind one simple class, LowRAMLLM, so your code doesn't need to care which backend is active.
Install
pip install digvijay_llm
# then install the backend you need:
pip install digvijay_llm[gguf] # GGUF backend only (recommended, lighter)
pip install digvijay_llm[hf] # safetensors / HuggingFace backend only
pip install digvijay_llm[all] # both backends
Step 1 — Automatic hardware detection
You no longer need to run a separate script first. digvijay_llm can detect your machine automatically when you create a model instance.
from digvijay_llm import LowRAMLLM
llm = LowRAMLLM.from_gguf("models/llama-70b.Q4_K_M.gguf")
print(llm.config)
print(llm.device_info)
The library will infer a sensible configuration for:
- backend selection
- GPU vs CPU placement
n_gpu_layersn_threadsn_ctxn_batchn_ram_gb
You can still override any of these manually when needed.
If you want the older CLI-style report, the standalone script is still available:
python detect_params.py
Step 2 — Get a model
Go to huggingface.co and search for llama 70b GGUF. Download the Q4_K_M version. Recommended repos:
bartowski/Meta-Llama-3.1-70B-Instruct-GGUFTheBloke/Llama-2-70B-GGUF
Place the .gguf file anywhere on your machine, e.g. models/llama-70b.Q4_K_M.gguf
Step 3 — Write your code
Option A — GGUF model (recommended, fastest)
from digvijay_llm import LowRAMLLM
llm = LowRAMLLM.from_gguf(
"models/llama-70b.Q4_K_M.gguf",
detect=True, # default: auto-detect and tune the config
n_ram_gb=16,
n_gpu_layers=0, # override if you want to force a different value
n_threads=8,
)
# Generate text
print(llm.generate("Explain quantum entanglement simply."))
# Stream token by token
for token in llm.stream("Write a short poem about the sea."):
print(token, end="", flush=True)
# Chat interface
reply = llm.chat([{"role": "user", "content": "Hello!"}])
print(reply)
# Basic benchmark summary
print(llm.benchmark("Summarize the benefits of local inference."))
Option B — Raw HuggingFace safetensors checkpoint (no conversion needed)
from digvijay_llm import LowRAMLLM
llm = LowRAMLLM.from_safetensors("models/llama-3-70b-hf/", detect=True, n_ram_gb=16)
print(llm.generate("Write a haiku about the ocean."))
Option C — Auto-detect format
from digvijay_llm import LowRAMLLM
llm = LowRAMLLM.auto("models/llama-3-70b.Q4_K_M.gguf", n_ram_gb=16)
# or
llm = LowRAMLLM.auto("models/llama-3-70b-hf/", n_ram_gb=16)
The same auto-detection logic applies here; the library will inspect the current machine and choose sensible runtime settings.
New in this version
- Built-in hardware detection for CPU, CUDA, ROCm, Metal, and Intel XPU-style backends
- Automatic tuning for
n_gpu_layers,n_threads,n_ctx,n_batch, andn_ram_gb llm.configandllm.device_infofor inspecting the detected settings- Streaming with callback support via
llm.stream(...) - Basic benchmark helpers via
llm.benchmark(...) - Clearer runtime error handling for missing optional dependencies
GPU support
digvijay_llm works on every machine — no GPU, small GPU, or big GPU. Just set n_gpu_layers accordingly (or let detect_params.py pick it for you):
| Your GPU VRAM | n_gpu_layers |
|---|---|
| No GPU | 0 |
| 4 GB | 10–15 |
| 6 GB | 20–25 |
| 8 GB | 30–35 |
| 12 GB | 45–50 |
| 16 GB | 60–65 |
| 24 GB+ | 80 (all layers, no disk streaming needed) |
Layers that fit in VRAM run at full GPU speed. Layers that don't fit are streamed from disk automatically. You always get the best of both.
# No GPU
llm = LowRAMLLM.from_gguf("model.gguf", n_ram_gb=16, n_gpu_layers=0)
# Small GPU (8GB VRAM)
llm = LowRAMLLM.from_gguf("model.gguf", n_ram_gb=16, n_gpu_layers=35)
# Big GPU (24GB+ VRAM) — everything fits, no disk streaming needed
llm = LowRAMLLM.from_gguf("model.gguf", n_ram_gb=16, n_gpu_layers=80)
Optional — Check your RAM budget
from digvijay_llm import plan_for_budget
plan = plan_for_budget(
model_path = "models/llama-3-70b-hf/",
total_params_billion = 70,
n_layers = 80,
bytes_per_param = 2.0, # fp16; use 0.6 for Q4 quantized
n_ram_gb = 16,
)
print(plan)
for w in plan.warnings:
print("WARNING:", w)
Warns you if your disk doesn't have enough free space or your RAM is too tight before you even try to load the model.
Minimum requirements
| Minimum | Recommended | |
|---|---|---|
| RAM | 16 GB | 32 GB |
| Disk | 45 GB free (for 70B Q4) | NVMe SSD |
| Python | 3.9+ | 3.11+ |
| OS | Windows / Mac / Linux | any |
| GPU | not required | any CUDA GPU helps |
Practical tips for 70B on 16GB
- Use Q4_K_M quantization — shrinks the model from ~140 GB (fp16) to ~38 GB on disk. Biggest single lever.
- Use an NVMe SSD, not a spinning HDD — random-access read speed directly sets your tokens/sec.
- Keep context length modest — the KV cache also eats RAM.
digvijay_llmauto-shrinks context on tight budgets. - Close other RAM-heavy apps while running — the OS needs free RAM as page cache for the mmap'd weights.
- Any GPU helps — even offloading a few layers to a small GPU (
n_gpu_layers=20) meaningfully improves speed.
Project layout
digvijay_llm/ ← repo root
├── digvijay_llm/ ← the package
│ ├── __init__.py
│ ├── api.py
│ ├── engine_gguf.py
│ ├── engine_safetensors.py
│ ├── hardware.py
│ └── ram_planner.py
├── examples/
│ ├── run_gguf_example.py
│ └── run_safetensors_example.py
├── tests/
│ ├── test_hardware_detection.py
│ └── test_ram_planner.py
├── .github/
│ └── workflows/
│ └── publish.yml
├── detect_params.py ← run this first!
├── .gitignore
├── LICENSE
├── pyproject.toml
├── requirements.txt
├── README.md
└── setup.py
License
MIT — see LICENSE
Author
Built by Digvijay Phutane
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 digvijay_llm-0.1.2.tar.gz.
File metadata
- Download URL: digvijay_llm-0.1.2.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5117de3609bce7c7377a3e71ebd226b82e286d27f4eafa989ef3abdb17690190
|
|
| MD5 |
00d44260080c0ed71d360c809645acff
|
|
| BLAKE2b-256 |
45caed73a7f71c1c82a9c09c092acffde386427983e31162438285ed37d2cd50
|
Provenance
The following attestation bundles were made for digvijay_llm-0.1.2.tar.gz:
Publisher:
publish.yml on DigvijayPhutane/digvijay_llm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
digvijay_llm-0.1.2.tar.gz -
Subject digest:
5117de3609bce7c7377a3e71ebd226b82e286d27f4eafa989ef3abdb17690190 - Sigstore transparency entry: 2182006958
- Sigstore integration time:
-
Permalink:
DigvijayPhutane/digvijay_llm@979b5d89bb4aeb780098f80727de040936703fe2 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/DigvijayPhutane
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@979b5d89bb4aeb780098f80727de040936703fe2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file digvijay_llm-0.1.2-py3-none-any.whl.
File metadata
- Download URL: digvijay_llm-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffffe68bfae442c37262c00a9d530de69ac4eba6523963a3e6edea70783d89b2
|
|
| MD5 |
68601785509ccbf039e3409db8290be6
|
|
| BLAKE2b-256 |
dba40f13d5f2ee388e93f4833b09bc2f3cba65eb342fd258bf0f87510e7b3678
|
Provenance
The following attestation bundles were made for digvijay_llm-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on DigvijayPhutane/digvijay_llm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
digvijay_llm-0.1.2-py3-none-any.whl -
Subject digest:
ffffe68bfae442c37262c00a9d530de69ac4eba6523963a3e6edea70783d89b2 - Sigstore transparency entry: 2182007120
- Sigstore integration time:
-
Permalink:
DigvijayPhutane/digvijay_llm@979b5d89bb4aeb780098f80727de040936703fe2 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/DigvijayPhutane
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@979b5d89bb4aeb780098f80727de040936703fe2 -
Trigger Event:
push
-
Statement type: