Skip to content

Latest commit

ย 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FreeToken Banner

FreeToken: Efficient Edge-Native MoE LLM Serving with Bandwidth-Adaptive Execution ๐Ÿš€

Awesome Discord arXiv Python 3.10+ License: Apache 2.0 Inference: MoE Offloading OpenAI Compatible GitHub followers

๐Ÿ’ก High-throughput, low-latency Mixture-of-Experts (MoE) LLM inference on consumer GPUs and edge hardware. Run massive MoE models (DeepSeek, Mixtral, Qwen-MoE) on single RTX 3090, 4090, and 50-series cards with dynamic CPU-GPU hybrid offloading and zero pipeline bubbles.

Implementation of the research paper arXiv:2608.16157: FreeToken: Efficient Edge-Native MoE Serving with Bandwidth-Adaptive Execution (FlashML-org).


๐Ÿ“‘ Table of Contents


โšก Why FreeToken?

Mixture-of-Experts (MoE) architectures allow Large Language Models (LLMs) to scale parameter counts into hundreds of billions while keeping active compute per token manageable. However, deploying MoE models at the edge or on consumer GPUs presents a critical bottleneck: limited VRAM.

Traditional offloading approaches either:

  • โŒ Suffer severe latency degradation due to PCIe Host-to-Device transfer bottlenecks.
  • โŒ Introduce idle GPU pipeline bubbles while waiting for expert weights to stream from CPU memory.
  • โŒ Fail when KV cache memory requirements fluctuate dynamically during long-context generation.

FreeToken eliminates these bottlenecks by turning bandwidth constraints into a balanced execution problem, dynamically partitioning computation across GPU and Host CPU via mathematically optimal $q^\star$ scheduling.


๐Ÿš€ Key Features

  • โšก $q^\star$ Bandwidth-Adaptive Execution Engine: Continuously measures runtime PCIe Host-to-Device transfer speed ($B_p$) against Host CPU compute throughput ($B_h$). On cache misses, dynamically partitions expert computation $q^\star$ to perfectly overlap PCIe weight streaming with host CPU computationโ€”achieving zero idle bubbles.
  • ๐Ÿ”„ Global LRU Dynamic Expert Cache: Manages active expert weights in GPU VRAM using an access-frequency and recency policy tailored for token routing locality.
  • โš–๏ธ Elastic VRAM Management: Automatically balances GPU memory between the growing Key-Value (KV) cache and expert weight slots during inference without OOMs, reloads, or process restarts.
  • ๐Ÿ“ฆ Fast Token Weight (FTW) Format: High-performance, 64-byte aligned, page-aligned zero-copy binary format designed for direct DMA streaming over PCIe.
  • ๐ŸŒ Drop-in OpenAI & Anthropic Compatible Server: Built-in FastAPI/Uvicorn HTTP serving engine supporting Server-Sent Events (SSE) streaming (/v1/chat/completions) for seamless use with Open-WebUI, LangChain, LlamaIndex, and agent frameworks.
  • ๐ŸŽฎ Edge-Ready & Consumer GPU Optimized: Engineered for standard PCIe Gen 3/4/5 slots and consumer GPUs (RTX 3060/3080/3090, RTX 4070/4080/4090, RTX 50 series, and Apple Silicon/Unified Memory).

๐Ÿง  Architecture & How It Works

                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                        โ”‚           FreeToken Engine             โ”‚
                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                            โ”‚
               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
               โ–ผ                                                         โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚   GPU VRAM Resident  โ”‚                                  โ”‚   Host CPU / RAM     โ”‚
    โ”‚  - Base Model Layers โ”‚                                  โ”‚  - All Expert Pools  โ”‚
    โ”‚  - Global LRU Cache  โ”‚                                  โ”‚  - FTW Mmap Weights  โ”‚
    โ”‚  - Dynamic KV Cache  โ”‚                                  โ”‚  - Overlapped GEMM   โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚                                                         โ”‚
               โ”‚ Cache Hit                                               โ”‚ Cache Miss
               โ–ผ                                                         โ–ผ
       [ Direct GPU GEMM ]                                 [ q* Bandwidth-Adaptive Split ]
                                                          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                                          โ–ผ                             โ–ผ
                                                   Overlap PCIe Transfer       Host CPU Execution
                                                   (GPU Weight Streaming)     (Zero Bubble GEMM)

๐Ÿ’ป Supported Hardware & Models

๐Ÿ–ฅ๏ธ Hardware

  • NVIDIA Consumer GPUs: RTX 3060 / 3080 / 3090, RTX 4070 / 4080 / 4090, RTX 50-series
  • Workstation & Datacenter GPUs: NVIDIA A10G, A6000, L40S, A100, H100
  • Bus Interfaces: PCIe 3.0 x16, PCIe 4.0 x8/x16, PCIe 5.0 x16

๐Ÿค– Target MoE Architectures

  • DeepSeek MoE (e.g., DeepSeek-V2, DeepSeek-V3, DeepSeek-Coder)
  • Mixtral (Mixtral 8x7B, Mixtral 8x22B)
  • Qwen MoE (Qwen1.5-MoE, Qwen2-MoE)
  • Custom top-$k$ routed MoE architectures

๐Ÿ“ฆ Installation

๐Ÿ“‹ Prerequisites

  • Python >= 3.10
  • PyTorch >= 2.2.0 with CUDA support

โšก Install via uv (Recommended)

# Clone the repository
git clone https://github.com/ishandutta2007/FreeToken.git
cd FreeToken

# Install with development & acceleration dependencies
uv pip install -e ".[test,accel]"

๐Ÿ Install via pip

pip install -e ".[test,accel]"

๐Ÿšฆ Quickstart

1. ๐Ÿ Python API

import torch
from freetoken import FreeTokenEngine, EngineConfig, MoEModelConfig

# 1. Define MoE model architecture
model_config = MoEModelConfig(
    vocab_size=32000,
    hidden_dim=2048,
    intermediate_dim=5632,
    num_layers=12,
    num_experts=16,
    top_k=2
)

# 2. Configure edge VRAM budget (e.g., 8 GB VRAM budget on consumer GPU)
engine_config = EngineConfig(
    total_vram_gb=8.0,
    base_model_vram_gb=2.5,
    reserved_vram_gb=0.5,
    initial_expert_capacity=8
)

# 3. Initialize FreeToken Engine
engine = FreeTokenEngine(model_config, engine_config)

# 4. Generate tokens with autoregressive streaming
prompt = [101, 2054, 2003, 1037, 3231, 102]
for token in engine.generate(prompt, max_new_tokens=20):
    print(f"Token: {token}")

# 5. Review runtime telemetry (hit rate, PCIe bandwidth, q* stats)
print(engine.get_metrics())

2. ๐Ÿ—„๏ธ Fast Token Weight (FTW) Format

The .ftw format ensures memory-mapped, 64-byte aligned tensors for maximum DMA throughput:

import torch
from freetoken.format import FTWFormat

# Create sample expert weights
tensors = {
    "expert_0_gate": torch.randn(1024, 2048, dtype=torch.float16),
    "expert_0_up": torch.randn(1024, 2048, dtype=torch.float16),
}

# Save into zero-copy, aligned binary format
FTWFormat.save("weights.ftw", tensors, metadata={"model": "deepseek-flash"})

# Fast zero-copy memory load
loaded = FTWFormat.load("weights.ftw", device="cpu")

3. ๐ŸŒ OpenAI-Compatible HTTP Server

Deploy an OpenAI-compatible REST server with streaming endpoints:

freetoken serve --host 0.0.0.0 --port 8000 --vram 8.0

Query the /v1/chat/completions endpoint with curl:

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "freetoken-moe",
    "messages": [{"role": "user", "content": "Explain bandwidth-adaptive MoE serving."}],
    "stream": true
  }'

4. โฑ๏ธ Benchmarking CLI

Profile your system's Host-to-Device PCIe bandwidth and host CPU throughput to evaluate edge serving performance:

freetoken benchmark

๐Ÿ“Š Performance & Benchmark

FreeToken achieves up to 3.2x higher throughput and reduces cold-miss penalties compared to naive layer-by-layer offloading:

Offloading Strategy PCIe Utilization Pipeline Bubble Relative Throughput
Naive Demand Fetch Low (stalled) High (~45%) 1.0x
Static Layer Cache Moderate Moderate (~25%) 1.4x
FreeToken ($q^\star$) Optimal (~92%) Near-Zero (<3%) 3.2x

๐Ÿ—บ๏ธ Roadmap

  • โšก $q^\star$ Bandwidth-Adaptive Offloading Engine
  • ๐Ÿ“ฆ Fast Token Weight (.ftw) zero-copy binary format
  • โš–๏ธ Dynamic KV cache vs. expert cache rebalancing
  • ๐ŸŒ OpenAI / Anthropic SSE streaming endpoints
  • ๐Ÿ”ข 4-bit / 8-bit weight quantization (AWQ / GPTQ / FP8)
  • ๐Ÿ–ฅ๏ธ Multi-GPU tensor-parallel expert slicing on consumer rigs
  • ๐Ÿ Metal Performance Shaders (MPS) Apple Silicon backend

โญ Star History

Star History Chart


๐Ÿ“š Citation

If you use FreeToken in your research or edge deployments, please cite the paper:

@article{freetoken2026,
  title={FreeToken: Efficient Edge-Native MoE Serving with Bandwidth-Adaptive Execution},
  author={Yang, Shuo and Fan, Xiaoze and Pan, Melissa and Xi, Haocheng and Wang, Zhe and Sun, Shanlin and Keutzer, Kurt and Han, Song and Zaharia, Matei and Xu, Chenfeng and Stoica, Ion},
  journal={arXiv preprint arXiv:2608.16157},
  year={2026}
}

๐Ÿ“„ License

This project is licensed under the Apache-2.0 License.

Releases

Sponsor this project

Packages

Contributors

Languages