Skip to main content

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.

PyPI version License: MIT

๐ŸŒŸ 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:

  1. Load layer N weights from disk
  2. Compute forward pass
  3. Immediately free layer N memory
  4. 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 HuggingFace
  • generate: Run inference
  • shard_model: Pre-shard models for efficiency
  • get_model_info: Query model metadata
  • unload_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

๐Ÿ“ฌ Contact

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

ommi_llm-0.2.0.tar.gz (35.5 kB view details)

Uploaded Source

Built Distribution

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

ommi_llm-0.2.0-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

File details

Details for the file ommi_llm-0.2.0.tar.gz.

File metadata

  • Download URL: ommi_llm-0.2.0.tar.gz
  • Upload date:
  • Size: 35.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for ommi_llm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 680c527dc75fb7e6cfbc416d27d79b12a87f5bb4978e25adb0b0f18a2dfdde21
MD5 86ea3e5aef048c302adfb431028085ab
BLAKE2b-256 a3811f7ffda3f334f189389c94b37d415b975bced1353e5a24c264516cbaf6ab

See more details on using hashes here.

File details

Details for the file ommi_llm-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ommi_llm-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 46.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for ommi_llm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aec34888c3c772bc53b02ccf1d83476e06acd559cb159b6bb1a40519c9a71f50
MD5 5380a6fbbfe3ed2dd3e7c962595b5646
BLAKE2b-256 941f5a5cfe6cf1527bb86dbff3243de6c2dd78c25098499cd3fb84aa0ee4460e

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