服务器参数#
要启用多GPU张量并行,添加
--tp 2。如果报告错误“这两个设备之间不支持对等访问”,则在服务器启动命令中添加--enable-p2p-check。
python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3-8B-Instruct --tp 2
要启用多GPU数据并行,添加
--dp 2。如果有足够的内存,数据并行对于吞吐量更好。它也可以与张量并行一起使用。以下命令总共使用4个GPU。
python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3-8B-Instruct --dp 2 --tp 2
如果在服务过程中看到内存不足的错误,尝试通过设置较小的
--mem-fraction-static值来减少KV缓存池的内存使用。默认值为0.9。
python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3-8B-Instruct --mem-fraction-static 0.7
请参阅超参数调优以了解如何调整超参数以获得更好的性能。
如果在长提示的预填充过程中看到内存不足错误,请尝试设置较小的分块预填充大小。
python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3-8B-Instruct --chunked-prefill-size 4096
要启用torch.compile加速,请添加
--enable-torch-compile。它可以在小批量大小上加速小型模型。目前这不适用于FP8。要启用torchao量化,请添加
--torchao-config int4wo-128。它还支持其他量化策略(INT8/FP8)。要启用fp8权重量化,请在fp16检查点上添加
--quantization fp8,或者直接加载fp8检查点而不指定任何参数。要启用fp8 kv缓存量化,请添加
--kv-cache-dtype fp8_e5m2。如果模型在Hugging Face分词器中没有聊天模板,您可以指定一个自定义聊天模板。
要在多个节点上运行张量并行,添加
--nnodes 2。如果你有两个节点,每个节点上有两个GPU,并且想要运行TP=4,让sgl-dev-0作为第一个节点的主机名,50000作为可用端口,你可以使用以下命令。如果遇到死锁,请尝试添加--disable-cuda-graph
# Node 0
python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3-8B-Instruct --tp 4 --nccl-init sgl-dev-0:50000 --nnodes 2 --node-rank 0
# Node 1
python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3-8B-Instruct --tp 4 --nccl-init sgl-dev-0:50000 --nnodes 2 --node-rank 1
使用来自ModelScope的模型#
More
要使用来自ModelScope的模型,请设置环境变量SGLANG_USE_MODELSCOPE。
export SGLANG_USE_MODELSCOPE=true
启动 Qwen2-7B-Instruct 服务器
SGLANG_USE_MODELSCOPE=true python -m sglang.launch_server --model-path qwen/Qwen2-7B-Instruct --port 30000
或者通过docker启动它。
docker run --gpus all \
-p 30000:30000 \
-v ~/.cache/modelscope:/root/.cache/modelscope \
--env "SGLANG_USE_MODELSCOPE=true" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server --model-path Qwen/Qwen2.5-7B-Instruct --host 0.0.0.0 --port 30000
示例:运行 Llama 3.1 405B#
More
# Run 405B (fp8) on a single node
python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3.1-405B-Instruct-FP8 --tp 8
# Run 405B (fp16) on two nodes
## on the first node, replace the `172.16.4.52:20000` with your own first node ip address and port
python3 -m sglang.launch_server --model-path meta-llama/Meta-Llama-3.1-405B-Instruct --tp 16 --nccl-init-addr 172.16.4.52:20000 --nnodes 2 --node-rank 0
## on the first node, replace the `172.16.4.52:20000` with your own first node ip address and port
python3 -m sglang.launch_server --model-path meta-llama/Meta-Llama-3.1-405B-Instruct --tp 16 --nccl-init-addr 172.16.4.52:20000 --nnodes 2 --node-rank 1