SGLang 高吞吐推理框架
SGLang 通过 RadixAttention 复用前缀缓存,适合多轮对话、结构化输出和高并发推理。提供 OpenAI 兼容 API,可与 vLLM 对比选型。
安装:
pip install "sglang[all]"
启动服务:
python -m sglang.launch_server \
--model-path Qwen/Qwen2.5-7B-Instruct \
--host 0.0.0.0 --port 30000
调用 OpenAI 兼容接口:
curl http://localhost:30000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"Qwen/Qwen2.5-7B-Instruct","messages":[{"role":"user","content":"你好"}]}'
多卡张量并行:
python -m sglang.launch_server \
--model-path Qwen/Qwen2.5-72B-Instruct \
--tp 4 --port 30000
启用结构化输出:
curl http://localhost:30000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"Qwen/Qwen2.5-7B-Instruct","messages":[{"role":"user","content":"返回 JSON"}],"response_format":{"type":"json_object"}}'
--tp 与 GPU 数量不匹配,启动失败。--mem-fraction-static,显存预留不合理。