推理引擎¶
llama.cpp / vLLM / TensorRT / ONNX Runtime / TGI / SGLang
引擎对比¶
| 引擎 | 语言 | 特点 | 链接 |
|---|---|---|---|
| llama.cpp | C++ | GGUF 量化,CPU/GPU 混合,轻量 | https://github.com/ggerganov/llama.cpp |
| vLLM | Python | PagedAttention,连续批处理,高吞吐 | https://github.com/vllm-project/vllm |
| Ollama | Go | 本地模型管理,极简 API | https://github.com/ollama/ollama |
| TGI | Rust+Python | HuggingFace 生产级推理 | https://github.com/huggingface/text-generation-inference |
| TensorRT-LLM | C++ | NVIDIA GPU 极致优化 | https://github.com/NVIDIA/TensorRT-LLM |
| ONNX Runtime | C++ | 跨平台,多后端 | https://github.com/microsoft/onnxruntime |
| SGLang | Python | 结构化生成,RadixAttention | https://github.com/sgl-project/sglang |
| MLCEngine | Python | TVM 编译优化 | https://github.com/mlc-ai/mlc-llm |
关键技术¶
- PagedAttention — vLLM 核心,分页管理 KV Cache
- Continuous Batching — 动态批处理,提高 GPU 利用率
- Speculative Decoding — 小模型草拟 + 大模型验证,加速推理
- Flash Attention — IO-aware,减少 HBM 访问
练习¶
- 用 llama.cpp 部署 Qwen2.5-7B-Q4,benchmark 推理速度
- 用 vLLM 部署同一模型,对比吞吐量
- 阅读 vLLM PagedAttention 源码
资源¶
| 资源 | 链接 |
|---|---|
| FlashAttention 论文 | https://arxiv.org/abs/2205.14135 |
| PagedAttention 论文 | https://arxiv.org/abs/2309.06680 |
| vLLM 文档 | https://docs.vllm.ai/ |