注意:
- 本教程需要访问 Oracle Cloud。要注册免费账户,请参阅开始使用 Oracle Cloud Infrastructure 免费套餐。
- 它对 Oracle Cloud Infrastructure 身份证明、租户和区间使用示例值。完成实验室后,请使用特定于云环境的那些值替换这些值。
在 Oracle Cloud Infrastructure Compute 上使用 vLLM 设置简单的 LLM 推断基准系统
简介
通过了解系统的性能特征,您可以对其组件以及期望的组件做出明智的选择。在本教程中,我们将为 AI 大语言模型 (LLM) 推断设置一个完整的基准测试系统。使用此功能,您可以运行各种实验,从评估特定 Oracle Cloud Infrastructure (OCI) 计算配置是否适合 LLM 和性能要求,到将各种 LLM 相互比较。
在本教程中,我们使用流行的开源推断服务器 vLLM ,该服务器支持许多先进的 LLM,并提供对高效服务这些模型至关重要的性能优化,并能够处理数千个并发请求。此外,我们使用 Ray LLMPerf 运行基准测试。
注:本教程假定您具有具有 GPU 限额的 OCI 租户。有关配额的更多信息,请参阅计算配额。
目标
-
预配 OCI Compute GPU 实例。
-
安装典型的 AI 堆栈先决条件。
-
设置 vLLM 和 LLMPerf。
-
运行 LLM 推断性能基准。
先决条件
-
访问 OCI 租户。
-
使用 NVIDIA GPU(例如 A10 GPU)访问配置。例如,
VM.GPU.A10.1
。有关提高限制的请求的详细信息,请参阅服务限制。 -
配置了访问令牌并有权下载 Llama-3.2-3B-Instruct 模型的 Hugging Face 帐户。
任务 1:配置网络
在此任务中,配置虚拟云网络 (Virtual Cloud Network,VCN) 以提供运行基准的功能和安全设置。在此示例中,我们需要一个具有一个公共子网和一个专用子网的 VCN。您可以使用 VCN 设置向导或手动设置所有组件,确保安全列表允许 SSH 访问,并将 NAT 网关分配给专用子网。
在预配 OCI 计算实例并继续进行基准设置之前,务必确保正确配置网络设置。默认情况下,预配的网络仅允许子网之间的重要通信。要允许基准测试所需的网络流量,您需要调整这些设置以允许公共子网和专用子网之间的 HTTP 流量。具体而言,请向专用子网的安全列表添加入站规则,以允许从 VCN CIDR 块到目标端口 8000 的流量传输。
任务 2:预配 OCI 计算实例
在此任务中,为基准设置预配两个 OCI 计算实例。一个是充当堡垒和基准客户机的唯一 CPU 虚拟机 (VM) 实例,另一个是测试中配备了 GPU 的实例。
-
预配具有八个 OCPU 和 Oracle Linux 8 的
VM.Flex.E5
实例。堡垒/基准测试客户端不需要 GPU,因为它只会向托管在单独机器上的模型发送请求,因此可以选择 CPU 配置。确保在网络参数中选择公共子网,不要忘记上载 SSH 公共密钥(如果需要,请下载提供的私有密钥)。 -
预配
VM.GPU.A10.1
实例。要简化设置,请使用包含 NVIDIA 驱动程序和 CUDA 框架的 Oracle Linux 8 映像预配实例。首先选择所需的配置,然后导航回映像选择菜单并选择具有内置 GPU 支持的 Oracle Linux 8 变体。应在专用子网中预配此实例,这意味着只能使用堡垒主机访问该实例。确保也设置 SSH 密钥。
任务 3:设置基准客户机
在本任务中,我们将为性能基准测试安装所有必需的组件并配置 GPU 主机。
-
使用 SSH 密钥登录到堡垒,并使用以下命令设置
LLMPerf
的所有要求。sudo dnf install epel-release -y sudo yum-config-manager --enable ol8_baseos_latest ol8_appstream ol8_addons ol8_developer_EPEL sudo dnf install git python3.11 python3.11-devel python3.11-pip -y
-
克隆 Ray LLMPerf 系统信息库,设置 Python
venv
并使用以下命令安装 LLMPerf。git clone https://github.com/ray-project/llmperf.git cd llmperf mkdir venv && python3.11 -mvenv venv && source venv/bin/activate
-
在安装 LLMPerf(及其 Python 相关项)之前,请编辑
pyproject.toml
文件并删除 Python 要求子句。该子句不必要地将 Python 版本限制为小于3.11
。diff --git a/pyproject.toml b/pyproject.toml index 7687fb2..521a2a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,6 @@ version = "0.1.0" description = "A framework for load testing LLM APIs" authors = [{name="Avnish Narayan", email="avnish@anyscale.com"}] license = {text= "Apache-2.0"} -requires-python = ">=3.8, <3.11" dependencies = ["pydantic<2.5", "ray", "pytest>=6.0",
-
运行
pip install -e
命令以完成设置。
任务 4:设置基准目标
在本任务中,我们将设置基准目标本身。由于我们已经为节点预配了必要的驱动程序和计算统一设备体系结构 (CUDA) 框架,因此我们只需安装 vLLM 及其 python 依赖项并部署我们希望基准测试的模型。
注:您预配的 GPU 计算实例位于专用子网中。因此,要访问它,必须首先登录堡垒主机并设置您为基准目标选择的私有 SSH 密钥。只有这样,您才能使用其专用 IP 地址登录到基准目标。
-
安装必要的软件包,如堡垒主机上的初始设置。此外,使用以下命令更新主机的防火墙以允许端口
8000
上的传入通信。sudo dnf install epel-release -y sudo yum-config-manager --enable ol8_baseos_latest ol8_appstream ol8_addons ol8_developer_EPEL sudo dnf install git python3.11 python3.11-devel python3.11-pip -y sudo firewall-cmd --permanent --zone=public --add-port=8000/tcp sudo firewall-cmd --reload
-
运行以下命令以安装 vLLM 及其要求。
mkdir venv python3.11 -mvenv venv && source venv/bin/activate pip install -U pip "bitsandbytes>=0.44.0" vllm gpustat mistral_common
-
我们已准备好使用要测试的模型启动 vLLM。
export HF_TOKEN=<your huggingface token> export MODEL="meta-llama/Llama-3.2-3B-Instruct" ulimit -Sn 65536 # increase limits to avoid running out of files that can be opened vllm serve $MODEL --tokenizer-mode auto --config-format hf --load-format auto \ --enforce-eager --max-model-len 65536
注:我们需要减小模型上下文长度以适应 A10 GPU 内存,将上下文长度从 128k 标记的默认大小减小到 64k 标记。加载后,模型 vLLM 应开始定期输出其推断统计信息。
INFO 12-09 15:46:36 metrics.py:449] Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.
-
我们让服务器在后台继续运行,同时切换到另一个终端,我们现在将测试和基准测试我们的设置。可以使用
curl
运行简单测试,如下所示。export HOST="<the ip address of the benchmark machine" export MODEL="meta-llama/Llama-3.2-3B-Instruct" curl --location "http://${HOST}:8000/v1/chat/completions" --header 'Content-Type: application/json' --header 'Authorization: Bearer token' --data '{ "model": "'"$MODEL"'", "messages": [ { "role": "user", "content": "What is the question to the answer to the ultimate question of life, the universe, and everything. You may give a humorous response." } ] }' -s | jq
输出将是:
{ "id": "chatcmpl-f11306f943604d41bad84be1dadd9da6", "object": "chat.completion", "created": 1733997638, "model": "meta-llama/Llama-3.2-3B-Instruct", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "You want to know the ultimate question to the answer of 42?\n\nWell, after years of intense research and contemplation, I've discovered that the answer is actually a giant, cosmic joke. The question is: \"What's for lunch?\"", "tool_calls": [] }, "logprobs": null, "finish_reason": "stop", "stop_reason": null } ], "usage": { "prompt_tokens": 62, "total_tokens": 112, "completion_tokens": 50, "prompt_tokens_details": null }, "prompt_logprobs": null }
任务 5:运行基准
现在,我们已准备好运行基准测试。给定一个特定应用程序场景,选择了一个大语言模型,我们希望在目标系统上了解运行并发推断请求的性能特征。
让我们对以下情况进行基准测试:
PARAMETER | 值 |
---|---|
模型 | Meta LLaMa 3.2 3B 说明 |
用例 | 聊天 |
输入标记 | N(200, 40) |
输出标记 | N(100, 10) |
并发请求数 | 1 - 32 |
-
在起始目录内的基准客户机(堡垒主机)上创建名为
llm_benchmark.sh
的以下脚本。#!/usr/bin/env bash set -xe # Use vLLM OpenAPI endpoint export OPENAI_API_BASE="http://<benchmark host>:8000/v1" # API key is not in use, but needs to be set for llmbench export OPENAI_API_KEY="none" model="meta-llama/Llama-3.2-3B-Instruct" modelname="${model##*/}" mkdir "$modelname" concurrent_requests=(1 2 4 8 16 32) pushd llmperf source venv/bin/activate for cr in "${concurrent_requests[@]}" do python3 token_benchmark_ray.py --model $model \ --mean-input-tokens 200 --stddev-input-tokens 40 \ --mean-output-tokens 100 --stddev-output-tokens 10 \ --max-num-completed-requests $((cr * 100)) --num-concurrent-requests $cr \ --metadata "use_case=chatbot" \ --timeout 1800 --results-dir "../$modelname/result_outputs_chat_creq_$cr" --llm-api openai done popd
此脚本允许您使用 llmperf 自动运行一系列基准测试,并发请求数量不断增加(从 1 开始,到 32 倍)。从传递给
token_benchmark_ray.py
脚本的参数中可以看出,我们将设置上表中定义的标记输入和输出。 -
使用以下命令运行基准测试脚本。
bash -x llm_benchmark.sh
完成后,您将在主目录中找到一个名为 Llama-3.2-3B-Instruct
的新目录,其中所有实验结果都将以 JSON 格式存储,您可以使用收藏的数据分析工具下载和后期处理。
注:将基准转换为绘图的一种简单方法是使用小 shell 脚本和
jq
将您最感兴趣的数字提取为.csv
格式,可以轻松地将其复制到 Excel 中。echo "concurrent_requests,token_throughput" for i in *; do cat $i/*_summary.json | jq -r '[.num_concurrent_requests, .results_request_output_throughput_token_per_s_mean] | join(",")' done;
确认
- 作者 — Omar Awile(Oracle EMEA GPU 专家团队,GPU 解决方案专家)
更多学习资源
浏览 docs.oracle.com/learn 上的其他实验室,或者访问 Oracle Learning YouTube 渠道上的更多免费学习内容。此外,请访问 education.oracle.com/learning-explorer 成为 Oracle Learning Explorer。
有关产品文档,请访问 Oracle 帮助中心。
Set up a Simple LLM Inference Benchmarking System with vLLM on Oracle Cloud Infrastructure Compute
G27544-01
February 2025
Copyright ©2025, Oracle and/or its affiliates.