Skip to main content

๐Ÿš€ On-The-Fly Weight Synthesizer (OTF-LLM Engine)

High-performance hybrid LLM inference engine featuring custom Fused OpenAI Triton INT4 GEMM kernels, Outlier-Aware weight quantization, Zero-RAM Incremental Quantizer (<150MB RAM), 98.16% Scientific Logit Parity, 3-Tier Hierarchical MoE Offloader [EXPERIMENTAL], Companion Long-Term Memory, and an Interactive Gradio Web UI.

PyPI PyTorch CUDA Triton Gradio FastAPI License


๐Ÿ”ฌ Engineering & Research: GT Labs AI

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 & Key Breakthroughs

Overcoming memory-bound bottlenecks and hardware VRAM constraints when executing Large Language Models (LLMs) on consumer GPUs (RTX 3060 / 4060 / 5060 Ti).

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 incrementally without RAM allocation (< 150 MB RAM peak), and integrates long-term user memory (companion_memory.py).


๐Ÿ”ฌ Formal Scientific Logit Parity Benchmark (20 Prompts)

Evaluated via tests/test_formal_parity.py comparing Base FP16 vs OTF INT4 Champion Engine across 20 multi-domain prompts:

  • ๐Ÿ“ Average Logit Cosine Similarity: 98.1556%
  • ๐ŸŽฏ Top-1 Exact Token Match Rate: 70.0% (14/20 exact token identity)
  • ๐Ÿ“‰ Average KL-Divergence: 0.2154

๐Ÿ“Š Performance Benchmark (NVIDIA RTX 5060 Ti 16GB)

Benchmarking conducted on an NVIDIA GeForce RTX 5060 Ti 16GB 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 GB 16.15 t/s 4.2 s 98.3% Logit Parity ๐Ÿ† 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 GB 15.89 t/s 3.7 s 98.2% Logit Parity ๐Ÿ† 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 10.13 t/s 5.1 s 98.3% Logit Parity ๐Ÿ† CHAMPION (-72.5%)
Qwen1.5-MoE-A2.7B (14.3B Total) 3-Tier 3.09 GB 3.40 GB 4.14 t/s 6.0 s R&D Alpha ๐Ÿงช [EXPERIMENTAL]

๐Ÿ›๏ธ 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. Incremental Sharded Quantizer with Resume Support (convert_global_universal.py): Memory-mapped (mmap) sharded quantizer with < 150 MB CPU RAM footprint. Saves intermediate disk chunks to enable crash-resilient resuming.
  3. Global Static Permutation (global_perm_idx) & Outlier Preservation: A unified channel permutation table across the model (1.6 MB VRAM). Isolating the Top-1% critical outlier channels ($|W| \times |X_{\text{profile}}|$) in FP16 completely suppresses quantization noise and guarantees 98.16% logit similarity.
  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. 3-Tier Hierarchical MoE Offloader [EXPERIMENTAL] (otf_moe_offloader.py): R&D module for executing Mixture-of-Experts models via a 3-tier memory hierarchy (Disk โž” CPU RAM โž” GPU VRAM).
  6. Gradio Web Demo (otf-demo) & FastAPI REST API (otf-server): Includes a built-in interactive browser Web UI with real-time VRAM allocation counters and OpenAI API spec compatibility (/v1/chat/completions).

๐Ÿ“ Repository Structure

otf-llm-engine/
โ”œโ”€โ”€ setup.py                                  # Setuptools package configuration
โ”œโ”€โ”€ pyproject.toml                            # PEP 517/518 build system
โ”œโ”€โ”€ MANIFEST.in                               # Package assets configuration
โ”œโ”€โ”€ pipeline_run.py                           # Automated 1-click end-to-end pipeline
โ”œโ”€โ”€ otf_llm/                                  # Main python package namespace
โ”‚   โ”œโ”€โ”€ __init__.py                           # Module entry point (v3.2.0)
โ”‚   โ”œโ”€โ”€ make_profile_universal.py             # Activation profile calibrator
โ”‚   โ”œโ”€โ”€ convert_global_universal.py           # Incremental 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
โ”‚   โ”œโ”€โ”€ web_demo.py                           # Interactive Gradio Web UI
โ”‚   โ”œโ”€โ”€ otf_moe_offloader.py                  # [EXPERIMENTAL] 3-Tier MoE Offloader
โ”‚   โ”œโ”€โ”€ direct_quantized_importer.py          # [EXPERIMENTAL] AWQ/GPTQ importer
โ”‚   โ”œโ”€โ”€ query_guided_sparse_kv.py             # Context retrieval (CPU RAM -> GPU)
โ”‚   โ”œโ”€โ”€ otf_context_compressor.py             # SnapKV / KIVI cache compressor
โ”‚   โ””โ”€โ”€ server_fastapi.py                     # REST API server (OpenAI API + SSE)
โ”œโ”€โ”€ tests/                                    # Benchmark & validation test suites
โ”‚   โ”œโ”€โ”€ test_formal_parity.py                 # Scientific logit parity benchmark (20 prompts)
โ”‚   โ”œโ”€โ”€ validate_llama3_2_3b.py               # Llama-3.2-3B validation runner
โ”‚   โ”œโ”€โ”€ test_intelligence_suite.py            # Intelligence and logic reasoning suite
โ”‚   โ”œโ”€โ”€ test_base_model_suite.py              # Baseline FP16 model suite
โ”‚   โ””โ”€โ”€ test_client.py                        # SSE streaming test client
โ”œโ”€โ”€ README.md                                 # Project documentation
โ””โ”€โ”€ LICENSE                                   # MIT License

๐Ÿ› ๏ธ Quickstart & Installation

Official PyPI Installation

pip install otf-llm

Launch Interactive Web Demo

otf-demo

Run Formal Scientific Parity Test

python tests/test_formal_parity.py

๐Ÿ“œ 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.2.0.tar.gz (45.4 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.2.0-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: otf_llm-3.2.0.tar.gz
  • Upload date:
  • Size: 45.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 ed0234fe48a8b7a820c0cd4edf3463fab092f2eb1bb01bb506e8ded5f6ef2027
MD5 177ac1884f76b29eee91e4813c989c76
BLAKE2b-256 ca4453301cd6c1136553935f598c67c390205ae1090cdcb18362d9b64e62d9ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: otf_llm-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 48.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b796bf237acf2adb3ae1067df514d9285189f8c85435351c21fea5da34f82ec1
MD5 e7b62f5bb19ffcdba3087c1e5439fa71
BLAKE2b-256 6b3dfc44eb025ec0c5a21ce49bcacfc2a8b691b7083f337afae4cf653d5836dc

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