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, INT8 embeddings, VRAM compression down to 1.94 GB (3B) / 4.20 GB (7B), Companion Long-Term Memory, and a production-grade REST API server.

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, 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 2.09 GB 2.17 GB 15.89 t/s 3.7 s 100% (0% Loss) ๐Ÿ† VALIDATED (-67.3%)
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. 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.
  3. INT8 Quantized Embeddings & Outlier-Aware INT4 lm_head: Vocabulary lookup tables are compressed to INT8, while the massive lm_head classifier is compressed to Outlier-Aware INT4.
  4. 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.
  5. 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           # Layer-wise 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

๐Ÿ› ๏ธ Quickstart & Installation

Local Package Installation

To install otf-llm as an editable Python package in your environment:

pip install -e .

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-2.0.4.tar.gz (31.6 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-2.0.4-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for otf_llm-2.0.4.tar.gz
Algorithm Hash digest
SHA256 549f931d24c2f4eb69a687a02b5d129d6ca137213c084c8a27b6bc3f95e2cf74
MD5 5546cc6e6b82e2af593f26bb198dc5fb
BLAKE2b-256 bdaf7a4e2f590c23f330bf924d49b13be7408e80ff323e2923487e44f85e3ff0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: otf_llm-2.0.4-py3-none-any.whl
  • Upload date:
  • Size: 36.8 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-2.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 21e619550758fa12e3722d8670ed32c11abeefa9a37d6fb1e22b207e387b6491
MD5 ffad7f5b31f3983ea48f7c96f80b66bf
BLAKE2b-256 20426e09c3b6b0f2ec514942303c20161ac8b4abfe3febdc378960fcccda1508

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