参考自: git@github.com:GeeeekExplorer/nano-vllm.git
- 🚀 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, CUDA graph etc.
- 当前支持:
Qwen3、MiniCPM、Llama - 已验证:
- Qwen3-0.6B / 1.7B / 4B / 8B / 14B / 30B(含 FP8 KV cache)
- MiniCPM4.1-0.5B / 8B
- Llama
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完整示例见 example.py。当前 LLM.generate() 返回的是一个 dict:
outputs: 生成结果列表(每项含text和token_ids)ttft/ttft_token: batch 首 token 时间(秒)per_request_ttft: 各请求 TTFT(秒)per_request_completion_time: 各请求完成时间(秒)ttfd_decode_step: 首次 decode 调度时间(秒)total_time: 整个 batch 耗时(秒)
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."]
result = llm.generate(prompts, sampling_params)
text = result["outputs"][0]["text"]可选开启 KV cache quant:
llm = LLM("/YOUR/MODEL/PATH", kv_cache_quant="int8")
llm = LLM("/YOUR/MODEL/PATH", kv_cache_quant="fp8_e4m3fn")
llm = LLM("/YOUR/MODEL/PATH", kv_cache_quant="fp8_e5m2")bench.py:基础离线吞吐bench_cache_aware.py:cache-aware 调度策略效果bench_contextpilot.py:测试 ContextPilot + cache-aware schedulingbench_kv_quant.py:测试 KV cache quant(baseline / int8 / fp8)
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
在 bench_contextpilot.py 的长上下文合成场景中,当前集成结果大致为:
- baseline:prefill TTFT ~ 1.4s,decode 总耗时 ~ 66s
- contextpilot+cache-aware:prefill TTFT ~ 0.42s,decode 总耗时 ~ 40s
在 bench_kv_quant.py 中,Qwen3-0.6B(A5000)典型结果:
baseline: 约 13.6k tok/sint8: 约 13.6k tok/s(显存明显下降)fp8_e4m3fn: 约 13.9k tok/s
详细测试与原理说明见 docs/kv_cache_quant_interview.md。
docs/contextpilot_scheduler_interview.md:ContextPilot + cache-aware 调度设计与效果docs/cache_aware_scheduler_refactor.md:调度器重构说明docs/kv_cache_quant_interview.md:KV cache quant 设计与 benchmark 解读docs/nanovllm_minicpm41_interview.md:MiniCPM 支持说明docs/llama_main_qwen3_minicpm41_adaptation.md:Qwen3 / Llama / MiniCPM4.1 模型支持演进分析