Skip to content

Commit d5ed959

Browse files
committed
Created a workflow for vllm profiling
1 parent 644dd73 commit d5ed959

2 files changed

Lines changed: 318 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
# Script to run vLLM profiling with configurable parameters via environment variables
6+
7+
echo 'Running vLLM profiling with the following configuration:'
8+
echo " Model: ${MODEL_NAME:-facebook/opt-125m}"
9+
echo " Served Model: ${SERVED_MODEL_NAME:-${MODEL_NAME:-facebook/opt-125m}}"
10+
echo " Dataset: ${DATASET_NAME:-random}"
11+
echo " Input Length: ${RANDOM_INPUT_LEN:-750}"
12+
echo " Output Length: ${RANDOM_OUTPUT_LEN:-75}"
13+
echo " Endpoint: ${ENDPOINT:-/v1/completions}"
14+
echo " Host: ${HOST:-localhost}"
15+
echo " Port: ${PORT:-8000}"
16+
echo " Num Prompts: ${NUM_PROMPTS:-100}"
17+
echo " VLLM_USE_V1: ${VLLM_USE_V1:-1}"
18+
19+
# Ensure we're in the right directory (mounted workspace)
20+
cd /tmp/workspace/vllm
21+
22+
# Create profiling results directory
23+
mkdir -p profiling-results
24+
25+
# Set default values for any missing environment variables
26+
export VLLM_USE_V1=${VLLM_USE_V1:-1}
27+
MODEL_NAME=${MODEL_NAME:-facebook/opt-125m}
28+
SERVED_MODEL_NAME=${SERVED_MODEL_NAME:-${MODEL_NAME}}
29+
DATASET_NAME=${DATASET_NAME:-random}
30+
RANDOM_INPUT_LEN=${RANDOM_INPUT_LEN:-750}
31+
RANDOM_OUTPUT_LEN=${RANDOM_OUTPUT_LEN:-75}
32+
ENDPOINT=${ENDPOINT:-/v1/completions}
33+
HOST=${HOST:-localhost}
34+
PORT=${PORT:-8000}
35+
NUM_PROMPTS=${NUM_PROMPTS:-100}
36+
37+
# Run the vLLM profiling command
38+
echo "Starting vLLM bench serve profiling..."
39+
40+
vllm bench serve \
41+
--dataset-name "${DATASET_NAME}" \
42+
--model "${MODEL_NAME}" \
43+
--served-model-name "${SERVED_MODEL_NAME}" \
44+
--random-input-len "${RANDOM_INPUT_LEN}" \
45+
--random-output-len "${RANDOM_OUTPUT_LEN}" \
46+
--endpoint "${ENDPOINT}" \
47+
--ignore-eos \
48+
--host "${HOST}" \
49+
--port "${PORT}" \
50+
--num-prompts "${NUM_PROMPTS}" \
51+
--profile
52+
53+
echo "vLLM profiling completed successfully!"
54+
55+
# Copy any generated profiling results to the profiling-results directory
56+
if [ -d "${VLLM_TORCH_PROFILER_DIR:-}" ]; then
57+
echo "Copying profiling results from ${VLLM_TORCH_PROFILER_DIR} to profiling-results/"
58+
cp -r "${VLLM_TORCH_PROFILER_DIR}"/* profiling-results/ 2>/dev/null || echo "No profiling results found in ${VLLM_TORCH_PROFILER_DIR}"
59+
fi
60+
61+
# Look for any .json or .trace files that might have been generated
62+
find . -name "*.json" -o -name "*.trace" -o -name "*.chrome_trace" | while read -r file; do
63+
echo "Moving profiling artifact: ${file}"
64+
cp "${file}" profiling-results/ 2>/dev/null || echo "Failed to copy ${file}"
65+
done
66+
67+
echo "Profiling artifacts copied to profiling-results/"
68+
ls -la profiling-results/
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
name: vLLM Profiling
2+
3+
on:
4+
schedule:
5+
# Run every week on Sunday at midnight
6+
- cron: '0 0 * * 0'
7+
workflow_dispatch:
8+
inputs:
9+
vllm_branch:
10+
description: vLLM branch (main, releases/vERSION for release validation, or refs/pull/PR_NUMBER/head for pre-merge check on pull request)
11+
required: true
12+
type: string
13+
default: main
14+
vllm_commit:
15+
description: vLLM commit (optional, default to the latest commit in the branch that has not yet been benchmarked)
16+
required: false
17+
type: string
18+
models:
19+
description: |
20+
A comma-separated list of models (optional, default to run everything)
21+
required: false
22+
type: string
23+
default: 'facebook/opt-125m'
24+
pull_request:
25+
paths:
26+
- .github/workflows/vllm-profiling.yml
27+
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
30+
cancel-in-progress: true
31+
32+
jobs:
33+
set-parameters:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
39+
- uses: actions/setup-python@v5
40+
with:
41+
python-version: '3.12'
42+
profiling:
43+
name: Run vLLM profiling
44+
needs: set-parameters
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
include:
49+
# TODO: Figure out later if we need to scale this up to multiple runners
50+
- runs-on: linux.aws.h100.4
51+
device-name: cuda
52+
runs-on: ${{ matrix.runs-on }}
53+
environment: pytorch-x-vllm
54+
permissions:
55+
id-token: write
56+
contents: read
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
60+
61+
- name: Checkout vLLM repository
62+
uses: actions/checkout@v4
63+
with:
64+
repository: vllm-project/vllm
65+
path: vllm
66+
ref: ${{ inputs.vllm_branch || 'main' }}
67+
fetch-depth: 0
68+
69+
- uses: actions/setup-python@v5
70+
# Amazon Linux fails on this step
71+
continue-on-error: true
72+
with:
73+
python-version: '3.12'
74+
cache: 'pip'
75+
76+
- name: Check if the device is supported
77+
shell: bash
78+
run: |
79+
set -eux
80+
81+
if command -v nvidia-smi; then
82+
DEVICE_NAME=cuda
83+
nvidia-smi
84+
elif command -v rocm-smi; then
85+
DEVICE_NAME=rocm
86+
rocm-smi
87+
else
88+
DEVICE_NAME=cpu
89+
lscpu
90+
fi
91+
echo "DEVICE_NAME=$DEVICE_NAME" >> $GITHUB_ENV
92+
93+
- name: Set GPU name and type
94+
shell: bash
95+
run: |
96+
set -eux
97+
98+
if [[ "${DEVICE_NAME}" == "cuda" ]]; then
99+
DEVICE_TYPE=$(nvidia-smi -i 0 --query-gpu=name --format=csv,noheader | awk '{print $2}')
100+
elif [[ "${DEVICE_NAME}" == "rocm" ]]; then
101+
DEVICE_TYPE=$(rocminfo | grep "Marketing Name" | tail -n1 | awk -F':' '{print $2}' | xargs)
102+
elif [[ "${DEVICE_NAME}" == "cpu" ]]; then
103+
DEVICE_TYPE=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | cut -f 2 -d " ")
104+
fi
105+
echo "DEVICE_TYPE=$DEVICE_TYPE" >> $GITHUB_ENV
106+
107+
- name: Install dependencies
108+
shell: bash
109+
run: |
110+
set -eux
111+
112+
if [[ "${DEVICE_NAME}" == "rocm" ]]; then
113+
pip install -r .github/scripts/requirements.txt \
114+
--extra-index-url https://download.pytorch.org/whl/rocm6.3
115+
else
116+
pip install -r .github/scripts/requirements.txt \
117+
--extra-index-url https://download.pytorch.org/whl/cu128
118+
fi
119+
120+
- name: Set Docker registry
121+
shell: bash
122+
env:
123+
HEAD_BRANCH: ${{ inputs.vllm_branch || 'main' }}
124+
run: |
125+
set -eux
126+
127+
# Mimic the logic from vllm ci-infra test template
128+
if [[ "${HEAD_BRANCH}" == "main" ]]; then
129+
DOCKER_IMAGE_PREFIX=public.ecr.aws/q9t5s3a7/vllm-ci-postmerge-repo
130+
else
131+
DOCKER_IMAGE_PREFIX=public.ecr.aws/q9t5s3a7/vllm-ci-test-repo
132+
fi
133+
134+
DOCKER_IMAGE_SUFFIX=""
135+
if [[ "${DEVICE_NAME}" == "rocm" ]]; then
136+
DOCKER_IMAGE_PREFIX=docker.io/rocm/vllm-ci
137+
elif [[ "${DEVICE_NAME}" == "cpu" ]]; then
138+
DOCKER_IMAGE_SUFFIX=-cpu
139+
fi
140+
echo "DOCKER_IMAGE_PREFIX=$DOCKER_IMAGE_PREFIX" >> $GITHUB_ENV
141+
echo "DOCKER_IMAGE_SUFFIX=$DOCKER_IMAGE_SUFFIX" >> $GITHUB_ENV
142+
143+
- name: Check for last commit
144+
env:
145+
HEAD_BRANCH: ${{ inputs.vllm_branch || 'main' }}
146+
HEAD_SHA: ${{ inputs.vllm_commit || '' }}
147+
run: |
148+
set -eux
149+
150+
if [[ -z "${HEAD_SHA}" ]]; then
151+
pushd vllm
152+
# Looking back the latest 100 commits is enough
153+
for i in {0..99}
154+
do
155+
# Check if the image is there, if it doesn't then check an older one
156+
# because the commit is too recent
157+
HEAD_SHA=$(git rev-parse --verify HEAD~${i})
158+
DOCKER_IMAGE="${DOCKER_IMAGE_PREFIX}:${HEAD_SHA}${DOCKER_IMAGE_SUFFIX}"
159+
160+
# No Docker image available yet because the commit is too recent
161+
if ! docker manifest inspect "${DOCKER_IMAGE}"; then
162+
continue
163+
fi
164+
done
165+
popd
166+
fi
167+
168+
echo "HEAD_SHA=$HEAD_SHA" >> $GITHUB_ENV
169+
170+
# Print the profiling commit for rereference
171+
echo "### Run profiling on [${HEAD_SHA}](https://github.com/vllm-project/vllm/commit/${HEAD_SHA})" >> "${GITHUB_STEP_SUMMARY}"
172+
173+
- name: Setup CUDA GPU_FLAG for docker run
174+
if: env.DEVICE_NAME == 'cuda'
175+
run: |
176+
echo "GPU_FLAG=--gpus all -e NVIDIA_DRIVER_CAPABILITIES=all" >> "${GITHUB_ENV}"
177+
178+
- name: Setup ROCm
179+
if: env.DEVICE_NAME == 'rocm'
180+
uses: pytorch/pytorch/./.github/actions/setup-rocm@main
181+
182+
- name: Setup SCCACHE_SERVER_PORT environment for docker run when on container
183+
run: |
184+
echo "SCCACHE_SERVER_PORT_DOCKER_FLAG=-e SCCACHE_SERVER_PORT=$((RUNNER_UID + 4226))" >> "${GITHUB_ENV}"
185+
186+
- name: Run vLLM profiling
187+
env:
188+
SCCACHE_BUCKET: ossci-compiler-cache-circleci-v2
189+
SCCACHE_REGION: us-east-1
190+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
191+
DOCKER_IMAGE: ${{ env.DOCKER_IMAGE_PREFIX }}:${{ env.HEAD_SHA }}${{ env.DOCKER_IMAGE_SUFFIX }}
192+
# vLLM-related environment variables
193+
VLLM_USE_MODELSCOPE: false
194+
VLLM_TORCH_PROFILER_DIR: ~/tmp/workspace/vllm_profile
195+
CUDA_VISIBLE_DEVICES: 0
196+
VLLM_USE_V1: 1
197+
# Profiling parameters
198+
MODEL_NAME: ${{ inputs.models || 'facebook/opt-125m' }}
199+
SERVED_MODEL_NAME: ${{ inputs.models || 'facebook/opt-125m' }}
200+
RANDOM_INPUT_LEN: 750
201+
RANDOM_OUTPUT_LEN: 75
202+
PORT: 8000
203+
NUM_PROMPTS: 100
204+
DATASET_NAME: random
205+
206+
run: |
207+
set -eux
208+
209+
if [[ "${DEVICE_NAME}" == "cpu" ]]; then
210+
ON_CPU=1
211+
else
212+
ON_CPU=0
213+
fi
214+
215+
container_name=$(docker run \
216+
${GPU_FLAG:-} \
217+
${SCCACHE_SERVER_PORT_DOCKER_FLAG:-} \
218+
-e SCCACHE_BUCKET \
219+
-e SCCACHE_REGION \
220+
-e DEVICE_NAME \
221+
-e DEVICE_TYPE \
222+
-e HF_TOKEN \
223+
-e VLLM_USE_MODELSCOPE \
224+
-e VLLM_TORCH_PROFILER_DIR \
225+
-e CUDA_VISIBLE_DEVICES \
226+
-e VLLM_USE_V1 \
227+
-e MODEL_NAME \
228+
-e SERVED_MODEL_NAME \
229+
-e RANDOM_INPUT_LEN \
230+
-e RANDOM_OUTPUT_LEN \
231+
-e PORT \
232+
-e NUM_PROMPTS \
233+
-e DATASET_NAME \
234+
-e ON_CPU="${ON_CPU}" \
235+
--ipc=host \
236+
--tty \
237+
--detach \
238+
--security-opt seccomp=unconfined \
239+
--shm-size=4g \
240+
-v "${GITHUB_WORKSPACE}:/tmp/workspace" \
241+
-w /tmp/workspace \
242+
"${DOCKER_IMAGE}"
243+
)
244+
docker exec -t "${container_name}" bash -c "bash .github/scripts/run_vllm_profiling.sh"
245+
246+
# Keep a copy of the profiling results on GitHub for reference
247+
- uses: actions/upload-artifact@v4
248+
with:
249+
name: profiling-results--${{ env.DEVICE_TYPE }}
250+
path: vllm/profiling-results

0 commit comments

Comments
 (0)