Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nano_batch: High-Performance LLM Inference Engine

License: MIT Python 3.8+ Rust 1.70+

nano_batch is a minimalist, high-performance inference engine for Large Language Models, built from scratch. It combines a Rust-based scheduler backend with a PagedAttention kernel in PyTorch to achieve vastly improved throughput and latency relative to standard implementations such as HuggingFace Transformers .generate().

Key Features

  • Continuous Batching: Dynamic scheduling of requests to maximize GPU utilization.
  • PagedAttention: Memory-efficient KV cache management inspired by vLLM.
  • Rust Core: High-performance scheduler and block allocator written in Rust.

Performance

I benchmarked nano_batch against a standard HuggingFace baseline using a Mistral 7B model (dummy weights but same architecture). The results demonstrate significant improvements in both throughput and latency.

1. Throughput Comparison (4.4x Speedup)

The engine achieves 300+ tokens/s compared to the baseline's ~70 tokens/s.

Throughput Comparison

2. Throughput Scaling

The real power of nano_batch lies in its ability to scale with concurrency. While the baseline plateaus, the engine's throughput increases with the number of concurrent requests, leveraging continuous batching.

Throughput Scaling

3. Latency Reduction

I achieve a 92% reduction in First Token Latency (TTFT) and 77% lower Average Latency per token, meaning a significantly snappier user experience even under load in theory.

Latency Comparison

TODO:

  • More benchmarks
  • Trition paged attention kernel (could properly use the slot mappings)
  • Run on full weight mistral 7B model

Acknowledgments

This project was greatly inspired and helped by:

  • Mistral 7B Paper - For the excellent model architecture and implementation details
  • Paged Attention Paper - For the innovative approach to memory-efficient attention
  • vLLM Project - For pioneering continuous batching and production serving patterns (with a very well engineered codebase)

Usage

# Install dependencies
pip install -r requirements.txt
maturin develop --release

# Run benchmarks
python nano_batch_models/benchmarks/dummy_nano_batch_benchmark.py

About

High-performance LLM inference engine, inspired by vLLM, written in Rust.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages