StreamLLM
Run bigger LLMs on smaller GPUs through intelligent, asynchronous layer streaming.
StreamLLM is a lightweight, memory-aware LLM inference runtime that breaks the physical VRAM barrier. By dynamically streaming transformer layers between host RAM and GPU VRAM using pre-allocated double-buffer scratchpads, StreamLLM allows running large quantized models on consumer GPUs (such as 4GB/6GB/8GB cards) with minimal transfer overhead.
Key Architectural Highlights
- Static GPU Scratchpad Pool (
GPUScratchpadPool): Pre-allocates two static VRAM buffers (Slot AandSlot B). EliminatescudaMallocandcudaFreeallocation churn during the token generation loop. - Dual CUDA Streams: Dedicated
compute_streamandtransfer_streamwith zero-CPU-blocking synchronization viatorch.cuda.Eventhardware queues. - Pinned Host Memory (
PinnedHostWeightRegistry): Uses page-locked RAM (torch.Tensor.pin_memory()) for true non-blocking PCIe DMA transfers. - KV-Cache Sizing Manager: Deterministic VRAM memory budgeting ensuring safe context lengths without Out-Of-Memory (OOM) crashes.
Installation
# Install locally in development mode:
pip install -e .
# Or install from GitHub / PyPI:
# pip install streamllm
Quickstart & Python Usage
from streamllm import AutoModel
MAX_LENGTH = 128
# 1. Initialize AutoModel (supports HuggingFace repo IDs or local paths)
model = AutoModel.from_pretrained("Qwen/Qwen2.5-7B-Instruct", prefetching=True)
# 2. Tokenize input prompt
input_text = ['What is the capital of the United States?']
input_tokens = model.tokenizer(
input_text,
return_tensors="pt",
return_attention_mask=False,
truncation=True,
max_length=MAX_LENGTH,
padding=False
)
# 3. Streamed layer generation
generation_output = model.generate(
input_tokens['input_ids'].cuda(),
max_new_tokens=20,
use_cache=True,
return_dict_in_generate=True
)
# 4. Decode output tokens
output = model.tokenizer.decode(generation_output.sequences[0])
print(output)
CLI & Diagnostic Commands
Once installed, the streamllm command is available directly in your terminal:
1. Check Hardware & PCIe Bandwidth
Measure GPU VRAM, system RAM, and live Host-to-Device (H2D) PCIe throughput:
streamllm hardware
2. Run Streaming vs. Prefetch Micro-Benchmark
Benchmark sequential layer execution against double-buffered prefetching:
streamllm bench --layers 16 --hidden-dim 2048 --seq-len 128
3. Run Test Suite
python -m unittest discover -s tests
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 streamllm-0.1.0.tar.gz.
File metadata
- Download URL: streamllm-0.1.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9eb9a42da7027c46a078ab1461209ab5fad5003452ca387eb7a1835ff923f501
|
|
| MD5 |
0265cff04b3cd21246cc3466abcdb2d2
|
|
| BLAKE2b-256 |
ab01d75bfd2167025a5b306588d09b312310ed5d9698bc622e76966c227742a3
|
File details
Details for the file streamllm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: streamllm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7a396fc8a3353e7dce3ead5da6fc7311d12487f71c74595dacf027328219460
|
|
| MD5 |
86b965c80d07ecea4c6e39ae9902d1ad
|
|
| BLAKE2b-256 |
36709b416e4c723f5c71d7b851b01f109a34dd44ad01a04610a525764e85533b
|