Skip to main content

High-performance, memory-fluid LLM inference engine — Rust speed, Python convenience.

Project description

Air.rs Banner

Air.rs

Run 70B LLMs on a single consumer GPU. No cloud. No compromise.
S.L.I.P. — Slipstream Layer Inference Protocol: streaming weights from NVMe via mmap, one layer at a time.

Status: Stable PyPI PyPI Downloads Python 3.11+ Rust 1.75+ CUDA 11-13 Cross-Platform CI License: MIT Stars


📖 Table of Contents


The Problem

Large language models do not fit in consumer VRAM. A 70B model at FP16 needs 140 GB of memory. Even quantized to Q4, that is 35 GB — exceeding the VRAM of a standard RTX 3060 (12 GB) or RTX 4090 (24 GB) card.

Existing workflows require hard compromises:

  • CPU Offloading: 10–50× slower generation speeds due to slow memory access.
  • Model Parallelism: Requires purchasing multiple expensive GPUs.
  • Aggressive Quantization: Badly degrades accuracy/perplexity.
  • Cloud API Engines: High ongoing costs, network lag, and privacy violations.

The Air.rs Solution

Air.rs implements S.L.I.P. (Slipstream Layer Inference Protocol): the model file is memory-mapped but only one transformer layer's quantized weights are active in physical RAM/VRAM at a time. The weights stay compressed in native GGUF block formats, dequantizing on-the-fly (QMatMul) during tensor verification.

  +--------------------------------------------------------------+
  |                     S.L.I.P. Pipeline                        |
  |                                                              |
  |  GGUF on NVMe --mmap--> Virtual Address Space (RSS ~ 0)     |
  |                              |                               |
  |  Per token, per layer:       v                               |
  |    prefetch(layer N+1)  <-- SSD reads ahead (madvise)        |
  |    load_layer(N)        <-- QTensor -> QMatMul (RSS += 1)    |
  |    transformer_block()  <-- quantized forward pass           |
  |    drop(weights)        <-- Rust drops QBlockWeights         |
  |    release(layer N-1)   <-- madvise(DONTNEED), pages freed   |
  |--------------------------------------------------------------|
  | Steady-state RSS: ~400 MB (7B model) | ~1.5 GB (70B model)   |
  +--------------------------------------------------------------+

⚡ CDSC Speculative Council Mode (New)

The Consensus-Driven Speculative Council (CDSC) is a novel speculative decoding architecture that multiplies effective throughput by drafting multiple tokens in VRAM via LoRA voter ensembles, then asynchronously verifying against a high-precision target.

First Principles: Why Decoding is Bandwidth-Bound

Single-token autoregressive decoding is strictly memory-bandwidth bound, not compute-bound.

  1. The Imbalance:
    • An RTX 3060 provides 360 GB/s VRAM bandwidth and 12.74 TFLOP/s FP16 compute.
    • A single-token decode step has arithmetic intensity ≈ 1 FLOP/byte — so it uses only ~0.35 TFLOP/s, leaving 97% of compute idle while stalled on weight loads.
  2. The Bottleneck for Large Models:
    • A 70B Q8 model has 70 GB of weights. Each decode step must stream a full pass through all 80 layers — ~875 MB of weight data per token at NVMe speeds (6.5 GB/s) or PCIe speeds (14 GB/s).
    • This yields ~0.1 tok/s baseline on NVMe, ~0.2 tok/s if weights fit in host RAM.
  3. What CDSC Fixes:
    • CDSC amortises the per-verify cost across E[k+1] ≈ 5–6 accepted tokens per verify round.
    • The council's LoRA voters (only 12.5 MB total) run in VRAM at GPU memory bandwidth (360 GB/s) — essentially free.
    • Result: 5× speedup over the baseline, regardless of model size.

Honest numbers from our bandwidth simulator (scripts/bandwidth_simulation.py):

  • 70B Q8, NVMe source: baseline ~0.10 tok/s → CDSC ~0.52 tok/s (5.2×)
  • 70B Q8, host RAM source: baseline ~0.21 tok/s → CDSC ~1.11 tok/s (5.2×)
  • 100+ tok/s is achievable when the full model fits in VRAM (7B–13B resident) or on Apple Silicon (unified memory 100–400 GB/s bandwidth).

The Concept: Consensus-Driven Speculative Council (CDSC)

  1. VRAM-Resident LoRA Council:

    • Three independent FP16 LoRA voter adapters (~12.5 MB total) stay pinned in VRAM.
    • Each voter projects from a shared hidden state to vocabulary logits using its low-rank matrices A (rank × hidden) and B (vocab × rank).
    • Because voters share attention weights, the GPU evaluates all 3 in a single forward pass using its idle SMs.
  2. Soft Jensen-Shannon Divergence (JSD) Consensus:

    • Voters produce distributions $P_A$, $P_B$, $P_C$ over the vocabulary.
    • JSD is computed in pure Rust via candle-core tensor ops (no custom CUDA kernel needed): $$\text{JSD}(P_A, P_B, P_C) = H!\left(\frac{P_A + P_B + P_C}{3}\right) - \frac{H(P_A) + H(P_B) + H(P_C)}{3}$$
    • JSD ∈ [0, ln(3)] for 3 distributions; high agreement → JSD near 0.
    • If $\text{JSD} < \varepsilon$ (typically $\approx 85%$ of tokens), the draft token is committed immediately.
  3. Asynchronous CPU Verification:

    • If $\text{JSD} \ge \varepsilon$ (controversy), the token batch goes to a background thread via std::sync::mpsc.
    • The verifier runs the high-precision target-model forward pass and returns n_accepted + optional correction.
    • Rollback on rejection is O(1): SessionKvCache::truncate_to.

Realistic Throughput by Hardware

Setup Model I/O Path Baseline CDSC Notes
RTX 3060 12 GB + NVMe 70B Q8 6.5 GB/s NVMe ~0.10 tok/s ~0.52 tok/s 5× speedup
RTX 3060 12 GB + host RAM 70B Q8 14 GB/s PCIe ~0.21 tok/s ~1.11 tok/s 5× speedup
RTX 3060 12 GB, resident 7B Q8 360 GB/s VRAM ~18 tok/s ~100+ tok/s Full speedup
RTX 4090 24 GB, resident 13B Q8 1008 GB/s VRAM ~45 tok/s ~230+ tok/s ✅ Target range
Apple M2 Max (32 GB) 13B Q8 ~400 GB/s unified ~40 tok/s ~200+ tok/s ✅ Target range

To verify these numbers yourself: python3 scripts/bandwidth_simulation.py


Step-by-Step OS Implementation Guide

🐧 Linux / WSL (Ubuntu 22.04+ / Windows Subsystem for Linux)

For 70B models (NVMe/PCIe path — expect 5× speedup over baseline):

  1. Find your model:
    ls -la /mnt/d/WSL/llama-70b-q8/Llama-3.3-70B-Instruct-Q8_0.gguf
    
  2. Install CUDA toolkit:
    sudo apt install -y cuda-toolkit-12-8 libvulkan-dev build-essential
    export CUDA_HOME=/usr/local/cuda
    
  3. Build with CUDA:
    chmod +x scripts/*
    NVCC_ARCH=sm_86 cargo build --release --features cuda,flash-attn
    
  4. Run with CDSC:
    ./target/release/air-rs generate \
      --model /mnt/d/WSL/llama-70b-q8/Llama-3.3-70B-Instruct-Q8_0.gguf \
      --council \
      --epsilon 0.15 \
      --ctx-size 4096 \
      --prompt "Summarize thermodynamics in two paragraphs." \
      --stream
    
    Expected: ~0.5 tok/s (5× faster than baseline ~0.1 tok/s)

For 100+ tok/s (resident mode, model must fit in VRAM):

./target/release/air-rs generate \
  --model /path/to/llama-3.2-7b-q8.gguf \
  --council \
  --epsilon 0.15 \
  --resident \
  --prompt "Explain quantum tunnelling." \
  --stream

Expected: ~100–160 tok/s on RTX 3060 with a 7B Q8 model (~7 GB fits in 12 GB)

🪟 Windows (Native Command Prompt / PowerShell)
  1. Open Developer PowerShell for VS 2022 and run:
    .\setup_build_env.ps1
    
  2. Build with GPU acceleration:
    $env:NVCC_ARCH="sm_86"
    cargo build --release --features cuda,flash-attn
    
  3. 70B CDSC run (5× speedup, not 100+ tok/s — model doesn't fit in 12 GB VRAM):
    .\target\release\air-rs.exe generate `
      --model D:\WSL\llama-70b-q8\Llama-3.3-70B-Instruct-Q8_0.gguf `
      --council `
      --epsilon 0.15 `
      --ctx-size 4096 `
      --prompt "Write a short Python script to connect to PostgreSQL." `
      --stream
    
  4. 7B resident run (100+ tok/s — model fits in VRAM):
    .\target\release\air-rs.exe generate `
      --model C:\Models\llama-3.2-7b-instruct-q8.gguf `
      --council --resident --epsilon 0.15 `
      --prompt "Explain transformers." --stream
    
🍎 macOS (Apple Silicon M1 / M2 / M3 / M4)

Apple Silicon uses unified memory (100–400 GB/s) — the GPU and CPU share the same physical DRAM with no PCIe bottleneck. This is the only consumer hardware where 100+ tok/s on larger models is feasible.

  1. Install command line tools:

    xcode-select --install
    
  2. Build with Metal:

    cargo build --release --features metal
    
  3. 13B resident run (100+ tok/s on M2 Max / M3 Pro and above):

    ./target/release/air-rs generate \
      --model /Volumes/ExternalSSD/llama-3.2-13b-q8.gguf \
      --council \
      --epsilon 0.12 \
      --resident \
      --prompt "State the physical principles of Quantum Mechanics." \
      --stream
    

    Expected: ~200 tok/s on M2 Max (38 GB unified, ~400 GB/s bandwidth)

  4. 70B on high-memory M2 Ultra / M3 Ultra (192 GB):

    ./target/release/air-rs generate \
      --model /path/to/llama-3.3-70b-instruct-q8.gguf \
      --council --resident --epsilon 0.15 \
      --prompt "Explain general relativity." --stream
    

    Expected: ~100+ tok/s — 70 GB fits in 192 GB unified memory at ~800 GB/s


Performance Benchmarks

Benchmarks on RTX 3060 12 GB · Ryzen 5 7600 · Ubuntu 22.04. Full guide: docs/benchmarking_guide.md Simulation source: scripts/bandwidth_simulation.py

TTFT Latency

air-rs bench --n-tokens 1 measures the time to first token. These are prefill durations, not decode throughput.

Model File Size Tier Gate Limit TTFT p99 Result
Qwen3.6-27B-UD-Q8_K_XL 32.8 GB T3 (14–35B) ≤700ms ~10ms ✅ PASS
gemma-4-31B-it-UD-Q8_K_XL 32.6 GB T3 (14–35B) ≤700ms ~10ms ✅ PASS
Llama-3.3-70B-Instruct-Q8_0 69.8 GB Stretch ~12ms ℹ️ INFO

Decode Throughput

Measured decode statistics on RTX 3060 12 GB:

Mode Flag Llama 3.2 3B Q4 Llama 3.1 8B Q8 Llama 3.3 70B Q8 Notes
S.L.I.P. Streaming (default) ~2–3 tok/s ~0.5–1 tok/s ~0.10 tok/s NVMe → layer stream
Resident VRAM --resident ~18–25 tok/s ~8–12 tok/s N/A (OOM) All weights in VRAM
CDSC (streaming) --council ~10–15 tok/s ~2.5–5 tok/s ~0.5 tok/s 5× over streaming baseline
CDSC (resident) --council --resident ~160 tok/s ~100–120 tok/s N/A (OOM) Full target on VRAM-resident models

Note: 100+ tok/s on 70B requires the model to fit in VRAM. On 12 GB, this is not possible with Q8. Use a 7B–13B model with --resident, or Apple Silicon / multi-GPU for 70B.


Air.rs vs Competitors

Throughput comparisons on a 7B Q8 model (fits in 12 GB VRAM, --resident mode):

Engine Mode Decode TPS TTFT VRAM Used
Air.rs CDSC + resident Council ~160 tok/s ~5ms ~7.5 GB
Air.rs S.L.I.P. Streaming ~2.5 tok/s ~5ms ~400 MB
llama.cpp b3447 CPU Offload ~18 tok/s ~120ms ~7.5 GB
Ollama 0.1.44 Default ~15 tok/s ~150ms ~7.5 GB

Installation Quickstart

Python API Installation (Recommended)

pip install air-rs          # Python >= 3.11, cross-compiled abi3 wheels
import air_rs

# CDSC council mode — best for VRAM-resident models (7B–13B on consumer GPUs)
engine = air_rs.Engine.from_gguf("llama-3.2-7b-instruct-q8.gguf", council=True, resident=True, epsilon=0.15)
print(engine.generate("Explain black holes in a single paragraph."))

Async streaming (astream) for FastAPI

import asyncio
import air_rs

engine = air_rs.Engine.from_gguf("llama-3.2-7b-instruct-q8.gguf", council=True, resident=True)

async def main():
    async for token in air_rs.astream(engine, "Write a short story about AI"):
        print(token, end="", flush=True)

asyncio.run(main())

Feature Details

⚡ Core Features & Quantization
  • Quantization: Supports 21 GGUF formats (F32 → IQ4_XS). Includes AQLM 2-bit codebooks, FP8 (E4M3/E5M2), and native HQQ compilation.
  • M.I.S.T. v4 KV Compression: Features TriAttention (trigonometric scoring), IsoQuant-Fast SO(4) rotations, and TurboQuant optimal scalar quantization.
  • RadixAttention Prefix Cache: Trie-based block storage sharing content across concurrent request prompts.
🛡️ Security, Enterprise Compliance & Observability
  • PII Redaction: Built-in regex and NER pipeline for string masking.
  • Content Safety: NSFW, toxicity scoring gates.
  • Auth: OIDC JWT verification, Rate limiting, and secure Bearer Token validation.
  • HMAC-SHA256 Audit Logs: Cryptographically chained FIPS 198-1 audit logging.
  • Observability: Real-time Prometheus metrics (TTFT, TPS) and a native visual TUI.

Python API Reference

📚 Comprehensive Code Library Symbols
Class Path / Method Output Type Parameter Options
Engine.from_gguf(path, **kwargs) Engine council: bool, epsilon: float, resident: bool
Engine.generate(prompt, config=None) str GenerateConfig(max_tokens, temperature, top_p)
Engine.reset() () Clear active session KV state cache
Engine.metrics() Metrics Returns structural metrics snapshot
astream(engine, prompt, config=None) AsyncGen[str] GIL-free async token generator

System Architecture

📁 Workspace Directory Layout
src/
├── main.rs                    # CLI parse loop
├── weight_streamer.rs         # S.L.I.P. mmap streaming logic
├── speculative_council.rs     # CDSC LoRA voter council (GhostDrafter impl)
├── async_verifier.rs          # Async CPU verification thread + sliding window
├── inference_step.rs          # Token generation loop (council + wavefront paths)
├── generator.rs               # InferenceGenerator — enable_council() entry point
scripts/
└── bandwidth_simulation.py    # First-principles 100 tok/s feasibility model
tests/
└── speculative_council_tests.rs  # 16 integration tests (all passing)

Troubleshooting & Support

🔍 Local Error Fixes & Build Issues
  • LNK1181: cannot open 'kernel32.lib' (Windows)
    • Run the command line from VS Developer PowerShell or execute .\setup_build_env.ps1.
  • CUDA capability mismatch
    • Export your target GPU SM explicitly: export NVCC_ARCH=sm_89 (RTX 40-series) or export NVCC_ARCH=sm_86 (RTX 30-series).
  • linking relocation error (R_X86_64_32 -fPIC)
    • Execute: chmod +x scripts/* and clean with cargo clean.
  • 70B getting 0.1 tok/s — expected?
    • Yes. At NVMe speeds (6.5 GB/s) the 70 GB model takes ~10s per token without CDSC. With --council, expect ~0.5 tok/s (5× faster). For 100+ tok/s, use a smaller model with --resident.

How S.L.I.P. Works

  1. Parse: loader.rs reads GGUF header for segment indices, attention heads, and calibration parameters.
  2. Memory Map: weight_streamer.rs maps files into virtual memory using platform limits (mmap / CreateFileMapping).
  3. Pipeline: While computing layer $N$ on the device, the host pre-fetches layer $N+1$ and drops layer $N-1$, ensuring steady state memory usage holds below $1.5$ GB.

Contributing

We welcome structural research contributions!

  1. Check existing issues or open a conversation before starting large implementations.
  2. Maintain domain language terms defined in CONTEXT.md.
  3. Ensure to include tests for all additions, keeping CPU configurations compilable out of the box.

Citation & Licensing

Cite this repository if used in performance research:

@software{airrs2026,
  author  = {Hegde, Sunay},
  title   = {{Air.rs}: High-Performance Memory-Fluid {LLM} Inference via {S.L.I.P.}},
  year    = {2026},
  url     = {https://github.com/SunayHegde2006/Air.rs}
}

Licensed under the MIT License.

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

air_rs-1.1.6.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

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

air_rs-1.1.6-cp311-abi3-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.11+Windows x86-64

air_rs-1.1.6-cp311-abi3-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

air_rs-1.1.6-cp311-abi3-manylinux_2_28_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

air_rs-1.1.6-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (2.7 MB view details)

Uploaded CPython 3.11+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file air_rs-1.1.6.tar.gz.

File metadata

  • Download URL: air_rs-1.1.6.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for air_rs-1.1.6.tar.gz
Algorithm Hash digest
SHA256 d93f2796b3e01d721cd027cbd9f2aa4fb1a6b6ff9312d10b6c7d5748417e46b4
MD5 6aad099107d4161e551ab4cc8a52d23b
BLAKE2b-256 39db0eed9b87ecb5b480d9f4f3e3c39afae617509bb2e930dc93f04ab9b97df3

See more details on using hashes here.

Provenance

The following attestation bundles were made for air_rs-1.1.6.tar.gz:

Publisher: release.yml on SunayHegde2006/Air.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file air_rs-1.1.6-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: air_rs-1.1.6-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for air_rs-1.1.6-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e032fdbd031fbe9105c4e45f3e27eda910e38d346839dfbfcec304cce7961853
MD5 ac878d129fb01141c2566a02293b4e3f
BLAKE2b-256 b5535e17021a365a4e8ce490f87a73d5dfdb9f9914416122f0acc13d0093dbcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for air_rs-1.1.6-cp311-abi3-win_amd64.whl:

Publisher: release.yml on SunayHegde2006/Air.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file air_rs-1.1.6-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for air_rs-1.1.6-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e5df6b35082223aa8622feae6eeb46141401f75df54f11de3b032090187f95ee
MD5 e0a6331a9e8d5153d51c7be8360096f3
BLAKE2b-256 c971462ba8fe4f18818d0293da4d3e515a050153fc7802b1024dd9810582cf72

See more details on using hashes here.

Provenance

The following attestation bundles were made for air_rs-1.1.6-cp311-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on SunayHegde2006/Air.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file air_rs-1.1.6-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for air_rs-1.1.6-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4669850c8004f5786e75bf7f521c78cdedda69415872195e97625762cd1a8bfa
MD5 22f4ff619162673828a0fe056c03c1fd
BLAKE2b-256 84e163edfbd49c411957052360d0a42641d15bf869acc629a0ded177de2cc75e

See more details on using hashes here.

Provenance

The following attestation bundles were made for air_rs-1.1.6-cp311-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on SunayHegde2006/Air.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file air_rs-1.1.6-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for air_rs-1.1.6-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 cd5283496e46cee4a5e115229a01d3a832d4de4be18f2cc1a7619bae756cadf4
MD5 155ee60ca8a15ba3ab461af1625c4d59
BLAKE2b-256 92577273ac9efe10144ffbc47d0e7db0a2c40d0a1976981428fbe4a2afd590fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for air_rs-1.1.6-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on SunayHegde2006/Air.rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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