LMDeploy 推理与量化部署
LMDeploy 是上海 AI Lab 开源的大模型推理工具箱,提供 TurboMind 和 PyTorch 两种引擎,支持量化、OpenAI 兼容服务和多卡推理。对中文模型和国产 GPU 生态支持较好。
常用命令:lmdeploy convert、lmdeploy serve api_server、lmdeploy chat、lmdeploy lite。
安装:
pip install lmdeploy
启动 OpenAI 兼容服务:
lmdeploy serve api_server Qwen/Qwen2.5-7B-Instruct \
--server-port 23333 \
--tp 1
调用:
curl http://localhost:23333/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"Qwen/Qwen2.5-7B-Instruct","messages":[{"role":"user","content":"你好"}]}'
量化模型:
lmdeploy lite auto_awq Qwen/Qwen2.5-7B-Instruct \
--work-dir ./qwen-awq
多卡张量并行:
lmdeploy serve api_server Qwen/Qwen2.5-72B-Instruct --tp 4
命令行对话:
lmdeploy chat Qwen/Qwen2.5-7B-Instruct
--tp 与 GPU 数不匹配,启动失败。--cache-max-entry-count 或上下文长度。