AMD GPU#

本文档介绍了如何在 AMD GPU 上运行 SGLang。如果您遇到问题或有任何疑问,请提交 issue

系统配置#

使用 AMD GPU(如 MI300X)时,特定的系统级优化有助于确保性能稳定。这里我们以 MI300X 为例。AMD 提供了关于 MI300X 优化和系统调优的官方文档:

注意:我们强烈建议完整阅读这些文档和指南,以充分利用您的系统。

以下是针对 SGLang 需要确认或启用的几个关键设置:

更新 GRUB 设置#

/etc/default/grub 中,将以下内容追加到 GRUB_CMDLINE_LINUX

pci=realloc=off iommu=pt

之后,运行 sudo update-grub(或您发行版中的对应命令)并重启。

禁用 NUMA 自动平衡#

sudo sh -c 'echo 0 > /proc/sys/kernel/numa_balancing'

您可以使用这个实用的脚本来自动执行或验证此更改。

再次强调,请通读完整文档以确认您的系统正在使用推荐的配置。

安装 SGLang#

您可以使用以下方法之一安装 SGLang。

从源码安装#

# Use the last release branch
git clone -b v0.5.6.post2 https://github.com/sgl-project/sglang.git
cd sglang

# Compile sgl-kernel
pip install --upgrade pip
cd sgl-kernel
python setup_rocm.py install

# Install sglang python package
cd ..
rm -rf python/pyproject.toml && mv python/pyproject_other.toml python/pyproject.toml
pip install -e "python[all_hip]"

示例#

运行 DeepSeek-V3#

运行 DeepSeek-V3 的唯一区别在于启动服务器的方式。以下是一个示例命令:

drun -p 30000:30000 \
    -v ~/.cache/huggingface:/root/.cache/huggingface \
    --ipc=host \
    --env "HF_TOKEN=<secret>" \
    sglang_image \
    python3 -m sglang.launch_server \
    --model-path deepseek-ai/DeepSeek-V3 \ # <- here
    --tp 8 \
    --trust-remote-code \
    --host 0.0.0.0 \
    --port 30000

在单个 NDv5 MI300X 虚拟机上运行 DeepSeek-R1 也是一个很好的参考。

运行 Llama3.1#

运行 Llama3.1 与运行 DeepSeek-V3 几乎完全相同。唯一的区别是启动服务器时指定的模型,如下方示例命令所示:

drun -p 30000:30000 \
    -v ~/.cache/huggingface:/root/.cache/huggingface \
    --ipc=host \
    --env "HF_TOKEN=<secret>" \
    sglang_image \
    python3 -m sglang.launch_server \
    --model-path meta-llama/Meta-Llama-3.1-8B-Instruct \ # <- here
    --tp 8 \
    --trust-remote-code \
    --host 0.0.0.0 \
    --port 30000

预热步骤#

当服务器显示 The server is fired up and ready to roll! 时,表示启动成功。