大模型的 N 种高效部署方法:以 LLaMA2 为例
通过部署 LLaMA2 示例,比较不同 LLM 开源推理服务框架的优缺点。
本文未介绍深度学习模型推理服务的传统库,如 TorchServe、KServe 或 Triton Inference Server。
1. vLLM
它的吞吐量比 huggingface transformers(HF)高 14 倍到 24 倍,吞吐量比文本生成推理(TGI)高 2.2 倍。有连续批处理(Continuous batching)和 PagedAttention 功能,集成各种解码算法,包括并行采样、波束搜索等。但缺乏对适配器(LoRA、QLoRA 等)的支持。
后期功能迭代可以追踪官方库。
本地推理服务
# pip install vllm
from vllm import LLM, SamplingParams
prompts = [
"Funniest joke ever:",
"The capital of France is",
"The future of AI is",
]
sampling_params = SamplingParams(temperature=0.95, top_p=0.95, max_tokens=200)
llm = LLM(model="huggyllama/llama-13b")
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
API 服务
# Start the server:
python -m vllm.entrypoints.api_server --env MODEL_NAME=huggyllama/llama-13b
# Query the model in shell:
curl http://localhost:8000/generate \
-d '{
"prompt": "Funniest joke ever:",
"n": 1,
"temperature": 0.95,
"max_tokens": 200
}'
2. Text generation inference
用于文本生成推理的 Rust、Python 和 gRPC 服务框架。在 HuggingFace 的生产中使用,为 的 推理小部件提供支持。内置 ,可以监控服务器负载和性能,可以使用 和 。所有依赖项都安装在 中,支持 模型,有很多选项来管理模型推理,包括精度调整、量化、张量并行性、重复惩罚等。适合了解 Rust 编程的人。


