XPU#

本文档介绍了如何设置 SGLang 环境并在 Intel GPU 上运行 LLM 推理,查看更多关于 PyTorch 生态系统中 Intel GPU 支持的背景信息

具体而言,SGLang 针对 Intel® Arc™ Pro B 系列显卡 Intel® Arc™ B 系列显卡 进行了优化。

优化模型列表#

一系列大语言模型(LLM)已在 Intel GPU 上完成优化,更多模型正在适配中

模型名称

BF16

Llama-3.2-3B

meta-llama/Llama-3.2-3B-Instruct

Llama-3.1-8B

meta-llama/Llama-3.1-8B-Instruct

Qwen2.5-1.5B

Qwen/Qwen2.5-1.5B

注意:上表中列出的模型标识符已在 Intel® Arc™ B580 显卡 上经过验证。

安装#

从源码安装#

目前 SGLang XPU 仅支持从源码安装。请参考 “Intel GPU 入门指南” 来安装 XPU 依赖项。

# Create and activate a conda environment
conda create -n sgl-xpu python=3.12 -y
conda activate sgl-xpu

# Set PyTorch XPU as primary pip install channel to avoid installing the larger CUDA-enabled version and prevent potential runtime issues.
pip3 install torch==2.9.0+xpu torchao torchvision torchaudio pytorch-triton-xpu==3.5.0 --index-url https://download.pytorch.org/whl/xpu
pip3 install xgrammar --no-deps # xgrammar will introduce CUDA-enabled triton which might conflict with XPU

# Clone the SGLang code
git clone https://github.com/sgl-project/sglang.git
cd sglang
git checkout <YOUR-DESIRED-VERSION>

# Use dedicated toml file
cd python
cp pyproject_xpu.toml pyproject.toml
# Install SGLang dependent libs, and build SGLang main package
pip install --upgrade pip setuptools
pip install -v .

使用 Docker 安装#

适用于 XPU 的 Docker 镜像正在积极开发中。敬请期待。

启动推理引擎服务#

启动 SGLang 服务示例命令

python -m sglang.launch_server       \
    --model <MODEL_ID_OR_PATH>       \
    --trust-remote-code              \
    --disable-overlap-schedule       \
    --device xpu                     \
    --host 0.0.0.0                   \
    --tp 2                           \   # using multi GPUs
    --attention-backend intel_xpu    \   # using intel optimized XPU attention backend
    --page-size                      \   # intel_xpu attention backend supports [32, 64, 128]

使用请求进行基准测试#

您可以通过 bench_serving 脚本进行性能基准测试。请在另一个终端中运行该命令。

python -m sglang.bench_serving   \
    --dataset-name random        \
    --random-input-len 1024      \
    --random-output-len 1024     \
    --num-prompts 1              \
    --request-rate inf           \
    --random-range-ratio 1.0

参数的详细说明可以通过该命令进行查询

python -m sglang.bench_serving -h

此外,请求可以采用 OpenAI Completions API 格式,并通过命令行(例如使用 curl)或您自己的脚本发送。