基准测试和分析

基准测试和分析#

基准测试#

  • 通过运行以下命令而不启动服务器来对单个静态批次进行基准测试。参数与 launch_server.py 相同。请注意,这不是动态批处理服务器,因此它可能会在真实服务器可以处理的批次大小下耗尽内存。真实服务器将预填充截断为多个批次,而此单元测试不会。为了进行准确的大批次测试,请考虑使用 sglang.bench_serving

    python -m sglang.bench_latency --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch 32 --input-len 256 --output-len 32
    
  • 基准测试在线服务。首先启动服务器,然后运行以下命令。

    python3 -m sglang.bench_serving --backend sglang --num-prompt 10
    

使用 Nsight 进行分析#

  1. 先决条件

# install nsys
# https://docs.nvidia.com/nsight-systems/InstallationGuide/index.html
apt update
apt install -y --no-install-recommends gnupg
echo "deb http://developer.download.nvidia.com/devtools/repos/ubuntu$(source /etc/lsb-release; echo "$DISTRIB_RELEASE" | tr -d .)/$(dpkg --print-architecture) /" | tee /etc/apt/sources.list.d/nvidia-devtools.list
apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
apt update
apt install nsight-systems-cli
  1. 要分析单个批次,请使用 nsys profile --trace-fork-before-exec=true --cuda-graph-trace=node python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 64 --input-len 512

  2. 要分析服务器,例如

# server
# set the delay and duration times according to needs
nsys profile --trace-fork-before-exec=true --cuda-graph-trace=node -o sglang.out --delay 60 --duration 70 python3 -m sglang.launch_server --model-path meta-llama/Meta-Llama-3.1-8B-Instruct --disable-radix-cache

# client
python3 -m sglang.bench_serving --backend sglang --num-prompts 6000 --dataset-name random --random-input 4096 --random-output 2048
  1. 使用 NVTX,例如:

# install nvtx
pip install nvtx

# code snippets
import nvtx
with nvtx.annotate("description", color="color"):
    # some critical code