Run 70B+ LLMs on consumer GPUs with layer-wise inference
Project description
Ommi LLM
Run 70B+ LLMs on consumer GPUs with layer-wise inference
Ommi LLM is a memory-efficient inference engine that enables running large language models with 70B+ parameters on consumer GPUs with limited VRAM (4-8GB) through innovative layer-wise processing.
๐ Features
- ๐ Layer-wise Inference: Process one transformer layer at a time, using only ~4GB VRAM for 70B models
- ๐ง Meta Device Pattern: Virtual model skeleton with zero memory footprint
- ๐พ SafeTensor Sharding: Pre-shard models for efficient layer-by-layer disk loading
- โก Async Prefetching: Overlap I/O with computation using ThreadPoolExecutor
- ๐ง Quantization Support: 4-bit and 8-bit compression for 3x speedup
- ๐ฏ Multi-Architecture: Supports Llama, Mistral, Qwen, Mixtral, Baichuan, ChatGLM, InternLM
- ๐ MCP Server: Model management via Model Context Protocol
- ๐จ Skill System: Pluggable optimizations for different use cases
๐ Performance
| Model | VRAM Required | Speed (tok/s) |
|---|---|---|
| Llama 3.1 405B | 8 GB | 2.1 |
| Llama 2/3 70B | 4 GB | 4.3 |
| Mixtral 8x7B | 6 GB | 3.8 |
| Qwen-72B | 4 GB | 4.1 |
| Platypus2-70B | 4 GB | 4.5 |
๐ Quick Start
Installation
pip install ommi-llm
Basic Usage
from ommi_llm import AutoModel
# Load a 70B model on a 4GB GPU
model = AutoModel.from_pretrained("meta-llama/Llama-2-70b-chat")
# Generate
output = model.generate(
"What is the capital of France?",
max_new_tokens=100,
temperature=0.7
)
print(output)
CLI Usage
# Show memory stats
ommi memory
# Generate text
ommi generate "meta-llama/Llama-2-70b-chat" "What is quantum computing?"
# Shard a model for faster loading
ommi shard "meta-llama/Llama-2-70b-chat" ./sharded-model
# List supported architectures
ommi list-architectures
๐๏ธ Architecture
Core Concepts
Layer-wise Inference: Instead of loading the entire model into GPU memory, ommi llm processes one transformer layer at a time:
- Load layer N weights from disk
- Compute forward pass
- Immediately free layer N memory
- Repeat for layer N+1
Memory Strategy:
- Single layer: ~1.6 GB
- Hidden states: ~0.4 GB
- KV cache: ~30 MB
- Total peak: ~4 GB for 70B models
Project Structure
ommi-llm/
โโโ src/ommi_llm/
โ โโโ core/ # Inference engine
โ โ โโโ engine.py # Layer-wise forward pass
โ โ โโโ auto_model.py # Architecture detection
โ โโโ adapters/ # Model-specific implementations
โ โ โโโ llama.py
โ โ โโโ mistral.py
โ โ โโโ ...
โ โโโ persistence/ # Model sharding & loading
โ โ โโโ loader.py
โ โ โโโ sharder.py
โ โโโ server/ # MCP server
โ โ โโโ mcp_server.py
โ โโโ skills/ # Pluggable optimizations
โ โ โโโ registry.py
โ โโโ utils/ # Utilities
โ โโโ memory.py
โ โโโ constants.py
โโโ examples/ # Usage examples
โโโ docs/ # Documentation
โโโ tests/ # Test suite
๐ง Advanced Usage
Quantization
# 4-bit quantization for 3x speedup
model = AutoModel.from_pretrained(
"meta-llama/Llama-2-70b-chat",
compression="4bit"
)
Custom Configuration
from ommi_llm import AutoModel
from ommi_llm.skills.registry import get_skill_registry
# Load model with skills
model = AutoModel.from_pretrained(
"mistralai/Mistral-7B",
device="cuda",
dtype="bfloat16",
prefetching=True
)
# Apply skills
registry = get_skill_registry()
registry.apply_skill("flash_attention", model)
registry.apply_skill("kv_cache", model, {"max_cache_size": 2048})
MCP Server
# Start MCP server
python -m ommi_llm.server.mcp_server
Tools available:
load_model: Load models from HuggingFacegenerate: Run inferenceshard_model: Pre-shard models for efficiencyget_model_info: Query model metadataunload_model: Free memory
Model Sharding
from ommi_llm.persistence.sharder import ModelSharder
# Pre-shard model for faster inference
sharder = ModelSharder(
"meta-llama/Llama-2-70b-chat",
output_path="./sharded-model",
compression="4bit"
)
sharder.shard_model(delete_original=False)
๐ฏ Supported Models
- Llama: 7B, 13B, 30B, 65B, 70B, 405B
- Llama 2: 7B, 13B, 70B
- Llama 3/3.1: 8B, 70B, 405B
- Mistral: 7B
- Mixtral: 8x7B, 8x22B
- Qwen/Qwen2: 7B, 14B, 72B
- Baichuan: 7B, 13B
- ChatGLM: 6B
- InternLM: 7B, 20B
๐ก How It Works
The Problem
Running a 70B parameter model in FP16 normally requires:
- Model weights: 140 GB VRAM
- Activations: Additional memory
- Total: 150+ GB VRAM (impossible on consumer GPUs)
The Solution
Layer-wise inference treats transformers as a divide-and-conquer problem:
# Instead of loading all 80 layers:
model = load_entire_model() # 140GB - IMPOSSIBLE
# Process one layer at a time:
for layer in layers:
weights = load_layer_weights(layer) # 1.6GB
output = compute_layer(weights, input) # Fast!
unload_layer(layer) # Free memory
input = output
Trade-offs
| Aspect | Impact |
|---|---|
| Memory | โ 4GB VRAM for 70B models |
| Speed | โ ๏ธ 35-100+ seconds per token |
| Disk | โ ๏ธ 2x model size for sharding |
| Accuracy | โ Full precision maintained |
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
๐ License
MIT License - see LICENSE for details.
๐ Acknowledgments
- Inspired by AirLLM
- Built on HuggingFace Transformers
- Uses Accelerate for meta device support
- SafeTensor sharding via safetensors
๐ฌ Contact
- GitHub: https://github.com/ommi-ai/ommi-llm
- Issues: https://github.com/ommi-ai/ommi-llm/issues
- Discussions: https://github.com/ommi-ai/ommi-llm/discussions
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 ommi_llm-0.2.3.tar.gz.
File metadata
- Download URL: ommi_llm-0.2.3.tar.gz
- Upload date:
- Size: 37.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18b60bb9c6a03c9225fd1b0c7fa01c0096e61c02b6c5aa0d92b5ff43a7cad518
|
|
| MD5 |
2e65b486190cb48cd63493bcd3885b69
|
|
| BLAKE2b-256 |
e92d8a97a39ebf6262d4ab4d4619afea8a68890c9057e2f09bceaff57ec4efda
|
File details
Details for the file ommi_llm-0.2.3-py3-none-any.whl.
File metadata
- Download URL: ommi_llm-0.2.3-py3-none-any.whl
- Upload date:
- Size: 48.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4130bd6aa9cbbd1b08a530395f8aeeafbb89135fda964ffe0fed4d91e55c8676
|
|
| MD5 |
e4ef93630ad6d7c4ae8a46156dc62a05
|
|
| BLAKE2b-256 |
8e9aad0cc4298a575381ec9ec52f636ef3c6aeb686cedf9c92e9ab1f8cf819b7
|