nano-vllm is a minimal reimplementation of vLLM’s core inference engine, targeting Qwen3 model family, and is a pure offline inference library.
High Level Architecture
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| ┌─────────────────────────────────────────────────────────┐ │ User API: LLM.generate(prompts, sampling_params) │ └────────────────────────┬────────────────────────────────┘ ▼ ┌─────────────────────────────────────────────────────────┐ │ LLMEngine (engine/llm_engine.py) │ │ Central orchestrator. Loops step() until all finished. │ └──────┬──────────────────────────────────────┬───────────┘ ▼ ▼ ┌──────────────┐ ┌────────────────────┐ │ Scheduler │ │ ModelRunner │ │ + BlockMgr │◄────────────────────│ (MP for TP>1) │ │ + Sequence │ batch & results │ engine/ │ │ engine/ │ │ model_runner.py │ │ scheduler.py │ └────────┬───────────┘ └──────────────┘ ▼ │ ┌────────────────────┐ │ │ Qwen3ForCausalLM │ │ │ (models/qwen3.py) │ │ │ + layers/ │ │ │ attention.py │ │ │ linear.py │ │ │ sampler.py │ │ │ ... │ │ └────────────────────┘ │ ┌────┴────────────┐ │ BlockManager │ Paged KV cache + prefix caching via xxhash │ Sequence │ Per-request state machine └─────────────────┘
|