13586e689b216f660202b7701692b7a968db72fb
分析两个分支的内存布局差异,明确 Block-Based 设计对支持 任意长度推理的重要性。 核心发现: - tzj/vs_offload 的 max_seq_len 设计导致 GPU 内存随序列长度增长 - tzj/minference 的 block-based 设计使 GPU 内存固定(~1.6 GB) - 在 24GB RTX 3090 上可支持 4M+ tokens 推理 规划将 tzj/minference 的 chunked prefill 机制移植到 tzj/vs_offload 分支: - Block-based GPU cache (无 layer 维度) - Per-layer prefill buffer (完全并行 offload) - Cross-layer pipeline buffers (double-buffering) - Chunked prefill 流程和 LSE 在线合并 Sparse Policy 策略:保留架构,现阶段仅实现 FULL 策略 相关文件: - docs/chunked_prefill_integration_plan.md (新增)
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 |
Star History
Languages
Python
96.2%
Shell
2.4%
C++
1.1%
Cuda
0.3%
