Skip to main content

๐Ÿš€ 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.

PyPI PyTorch CUDA Triton FastAPI Transformers License


๐Ÿ”ฌ 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]
  1. Custom Outlier-Aware Fused Triton GEMM Kernel (otf_triton_kernel.py): Packed uint8 weights are streamed from VRAM and dequantized directly inside GPU chip registers (SRAM) during matrix multiplication, eliminating temporary FP16 tensor allocations in VRAM.
  2. Zero-RAM Streaming Safetensors Quantizer (convert_global_universal.py): Uses safetensors.safe_open memory-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).
  3. 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.
  4. INT8 Quantized Embeddings & Outlier-Aware INT4 lm_head: Vocabulary lookup tables are compressed to INT8, while lm_head supports Tied Word Embeddings for zero-overhead output projection.
  5. 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.
  6. 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

otf_llm-3.0.1.tar.gz (34.7 kB view details)

Uploaded Source

Built Distribution

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

otf_llm-3.0.1-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file otf_llm-3.0.1.tar.gz.

File metadata

  • Download URL: otf_llm-3.0.1.tar.gz
  • Upload date:
  • Size: 34.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for otf_llm-3.0.1.tar.gz
Algorithm Hash digest
SHA256 659e292df2b7e0255aa1b6f6378d483c6d202d186f9e98e3ecf845785de27700
MD5 b3de426af7cd3c7d30d3361a1a724787
BLAKE2b-256 d362c16a6f9ab904c38cb159a46eb019a34726532f277fd1f348bcc90a75fdbf

See more details on using hashes here.

File details

Details for the file otf_llm-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: otf_llm-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for otf_llm-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 437a0a11509e2cf897bc91e635b3538bfbf4ab3b306ae35f590e71b1bda06ad4
MD5 35f71f130905b0e118600c1c2106961b
BLAKE2b-256 5021300fa993a2c6c03082cf4e9fbc196edaf7df08e30e6e7a3da8065358f6e5

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 Sentry Error logging StatusPage Status page