需自行用 huggingface-cli 下载模型权重并传入本地路径;示例中需设置 enforce_eager=True 关闭 CUDA graph;API 与 vLLM 有细微差异,generate 返回字典需取 text 字段

pip install git+https://github.com/GeeeekExplorer/nano-vllm.git 硬件要求按 README 说明
README 的基准测试在 RTX 4070 Laptop(8GB 显存)上运行 Qwen3-0.6B,未说明 CPU 运行或其他 GPU 厂商支持情况
需要 CUDA多卡 / 张量并行
从零实现的轻量 vLLM,用约 1200 行 Python 提供接近 vLLM 的离线推理速度
用 PyTorch 从零实现的轻量级 vLLM,代码精简易读,适合学习大模型推理引擎的调度、KV Cache 和 PagedAttention 等核心机制。
核心能力
- 约 1200 行 Python 的清晰实现,便于阅读源码
- 离线批量推理吞吐接近 vLLM
- 支持前缀缓存复用已算 KV
- 支持张量并行与 CUDA graph
- 集成 Torch 编译优化推理
容易踩的坑
内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选共 0 条
还没有人点评。第一个说出真实体验的人最有价值。
Nano-vLLM
A lightweight vLLM implementation built from scratch.
Key Features
- 🚀 Fast offline inference - Comparable inference speeds to vLLM
- 📖 Readable codebase - Clean implementation in ~ 1,200 lines of Python code
- ⚡ Optimization Suite - Prefix caching, Tensor Parallelism, Torch compilation, CUDA graph, etc.
Installation
pip install git+https://github.com/GeeeekExplorer/nano-vllm.git
Model Download
To download the model weights manually, use the following command:
huggingface-cli download --resume-download Qwen/Qwen3-0.6B \
--local-dir ~/huggingface/Qwen3-0.6B/ \
--local-dir-use-symlinks False
Quick Start
See example.py for usage. The API mirrors vLLM's interface with minor differences in the LLM.generate method:
from nanovllm import LLM, SamplingParams
llm = LLM("/YOUR/MODEL/PATH", enforce_eager=True, tensor_parallel_size=1)
sampling_params = SamplingParams(temperature=0.6, max_tokens=256)
prompts = ["Hello, Nano-vLLM."]
outputs = llm.generate(prompts, sampling_params)
outputs[0]["text"]
Benchmark
See bench.py for benchmark.
Test Configuration:
- Hardware: RTX 4070 Laptop (8GB)
- Model: Qwen3-0.6B
- Total Requests: 256 sequences
- Input Length: Randomly sampled between 100–1024 tokens
- Output Length: Randomly sampled between 100–1024 tokens
Performance Results:
| Inference Engine | Output Tokens | Time (s) | Throughput (tokens/s) |
|---|---|---|---|
| vLLM | 133,966 | 98.37 | 1361.84 |
| Nano-vLLM | 133,966 | 93.41 | 1434.13 |