๐ On-The-Fly Weight Synthesizer (OTF-LLM Engine)
High-performance hybrid LLM inference engine featuring custom Fused Triton INT4 GEMM kernels, Outlier-Aware weight quantization, global activation permutation, Zero-RAM Streaming mmap Quantization, INT8 embeddings, VRAM compression down to 1.89 GB (3B) / 4.20 GB (7B), Companion Long-Term Memory, and a production-grade REST API server.
๐ฌ Engineering & Research: GT Labs AI
This project is developed and maintained by GT Labs AI.
- ๐ GT Labs AI Mission: Ultra-fast MVP engineering, custom AI integration, and deep neural network optimization research.
- ๐จโ๐ป Author & Lead AI Engineer: Gleb Tikhiy (@GlebTikhiy)
- ๐ง Contact & Inquiries: team.gtlabs@gmail.com
- ๐ Organization: GT Labs AI on GitHub
๐ฏ Project Goal
Overcoming memory-bound bottlenecks and hardware VRAM constraints when executing Large Language Models (LLMs) on consumer GPUs.
Instead of transferring heavy FP16 weights from VRAM, OTF-LLM Engine performs hardware-accelerated dequantization of Outlier-Aware INT4 weights directly inside GPU registers (SRAM) via custom OpenAI Triton GEMM Kernels, streams weights without RAM allocation via safetensors.safe_open (mmap), compresses vocabulary embeddings (embed_tokens) into INT8, compresses the classifier (lm_head), integrates long-term user memory (companion_memory.py), and employs predictive Query-Guided Sparse Offloading.
๐ Performance Benchmark (RTX 5060 Ti 16GB)
Benchmarking conducted on an NVIDIA GeForce RTX 5060 Ti GPU:
| Model / Architecture | Format | Static VRAM | Peak VRAM | Speed | Load Time | Intelligence Parity | Status |
|---|---|---|---|---|---|---|---|
| Qwen2.5-3B (Base) | FP16 | 5.75 GB | 5.81 GB | 25.6 t/s | ~15.0 s | 100% (Baseline) | Baseline |
| Qwen2.5-3B (OTF Champion) | INT4/8 | 1.94 GB | 1.99 - 2.06 GB | 16.15 t/s | 4.2 s | 100% (0% Loss) | ๐ CHAMPION (-66.1%) |
| Llama-3.2-3B (Base) | FP16 | 6.40 GB | 6.48 GB | 22.1 t/s | ~16.0 s | 100% (Baseline) | Baseline |
| Llama-3.2-3B (OTF Champion) | INT4/8 | 1.89 GB | 1.99 - 2.17 GB | 15.89 t/s | 3.7 s | 100% (0% Loss) | ๐ RECORD (-70.5%) |
| Qwen2.5-7B (Base) | FP16 | 15.27 GB | 15.80 GB | 14.2 t/s | ~28.0 s | 100% (Baseline) | Baseline |
| Qwen2.5-7B (OTF Champion) | INT4/8 | 4.20 GB | 4.25 GB | 8.60 t/s | 15.5 s | 100% (0% Loss) | ๐ CHAMPION (-72.5%) |
๐๏ธ Architecture & Key Innovations
[Input Vector X] โโโบ [Global Static Permutation (global_perm_idx)]
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ โผ
[Outlier Channels (1% FP16)] [Background Block (99% INT4)]
โ โ
โโโโบ Pure FP16 โโโโบ Range [-7 ... +7]
โโโโบ Input X_outliers โโโโบ 2:1 Packing (uint8)
โโโโบ Zero-Point = 0 BYTES!
โ
โผ
[Custom Fused Triton GEMM Kernel]
(Dequantization in GPU SRAM Registers)
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
[Continuous GEMM Addition: Outliers + Triton Background = Exact FP16 Output]
- Custom Outlier-Aware Fused Triton GEMM Kernel (
otf_triton_kernel.py): Packeduint8weights are streamed from VRAM and dequantized directly inside GPU chip registers (SRAM) during matrix multiplication, eliminating temporary FP16 tensor allocations in VRAM. - Zero-RAM Streaming Safetensors Quantizer (
convert_global_universal.py): Usessafetensors.safe_openmemory-mapping (mmap) to stream weights directly from disk layer-by-layer during quantization, dropping peak CPU RAM consumption down to < 500 MB (enabling 70B+ model quantization on low-RAM machines). - Global Static Permutation (
global_perm_idx) & Outlier Preservation: A unified channel permutation table across the entire model (requiring only 1.6 MB VRAM). Isolating the Top-1% critical outlier channels ($|W| \times |X_{\text{profile}}|$) in FP16 completely suppresses quantization noise and guarantees 100% accuracy retention across Qwen and Llama architectures. - INT8 Quantized Embeddings & Outlier-Aware INT4
lm_head: Vocabulary lookup tables are compressed to INT8, whilelm_headsupports Tied Word Embeddings for zero-overhead output projection. - Companion Long-Term Memory Manager (
companion_memory.py): Zero-VRAM, lightweight CPU RAM module that automatically extracts and retrieves user facts in < 2 ms via TF-IDF cosine similarity, injecting relevant facts into system prompts. - FastAPI REST API Server (
server_fastapi.py): An asynchronous production server featuring OpenAI API specification compatibility (/v1/chat/completions), SSE (Server-Sent Events) token streaming, and an async request queue manager to protect VRAM from overflow.
๐ Repository Structure
otf-llm-engine/
โโโ setup.py # Setuptools configuration
โโโ pyproject.toml # PEP 517/518 build system
โโโ MANIFEST.in # Package assets configuration
โโโ pipeline_run.py # Automated 1-click end-to-end pipeline
โโโ validate_llama3_2_3b.py # Validation runner for Llama-3.2-3B
โโโ test_client.py # Streaming client for SSE validation
โโโ otf_llm/ # Main python package namespace
โ โโโ __init__.py # Module entry point
โ โโโ make_profile_universal.py # Activation profile calibrator
โ โโโ convert_global_universal.py # Zero-RAM mmap safetensors quantizer
โ โโโ run_triton_universal.py # Triton GEMM inference runner
โ โโโ otf_triton_kernel.py # Custom Fused Triton INT4 GEMM kernel
โ โโโ companion_memory.py # Zero-VRAM long-term user memory store
โ โโโ query_guided_sparse_kv.py # Context retrieval (CPU RAM -> GPU)
โ โโโ otf_context_compressor.py # SnapKV / KIVI cache compressor
โ โโโ benchmark_profiler.py # Byte-level weights and VRAM profiler
โ โโโ server_fastapi.py # REST API server (OpenAI API + SSE)
โโโ README.md # Project documentation
โโโ LICENSE # MIT License
๐ ๏ธ Installation & Usage
Official PyPI Installation
pip install otf-llm
Usage Example
from otf_llm import run_inference, CompanionMemoryManager
# 1. Initialize Long-Term Memory
memory = CompanionMemoryManager()
memory.add_explicit_fact("User is an AI Engineer using RTX 5060 Ti.")
# 2. Run Triton Engine Inference
run_inference("unsloth/Llama-3.2-3B-Instruct", prompt="Write a binary search in Python.")
๐ License
Distributed under the MIT License. See LICENSE for 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 otf_llm-3.1.1.tar.gz.
File metadata
- Download URL: otf_llm-3.1.1.tar.gz
- Upload date:
- Size: 35.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b8b03072521bac5d52a1b325146d120dc9db35690120455bbd3ad01ed851526
|
|
| MD5 |
a260fdbc743b08762215968b48ab0ad5
|
|
| BLAKE2b-256 |
d81cac3b9e946a67a55758e05d5c5ce3819d50c8c31e7449423525bad21e7ab5
|
File details
Details for the file otf_llm-3.1.1-py3-none-any.whl.
File metadata
- Download URL: otf_llm-3.1.1-py3-none-any.whl
- Upload date:
- Size: 40.9 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 |
802dcce7875ac64c1d9e199ce4638e8faf6356d92184977a0a052dab4a9dbe5e
|
|
| MD5 |
c25d047d3591e040fcc0debfc0b8cde4
|
|
| BLAKE2b-256 |
e3c9460ff458381b910536450f2bf3848eac0b3f33afc9f153aaa4bf1bc4570d
|