Skip to content

Commit 0b186d1

Browse files
Add Containerized Benchmarking Support for GuideLLM (#123)
# Add Containerized Benchmarking Support for GuideLLM ## Description This PR adds containerization support for GuideLLM benchmarking, making it easier to run benchmarks in containerized environments. The changes include: 1. A new `Dockerfile` that: - Uses Python 3.11 slim as the base image - Installs necessary dependencies, including git and curl - Sets up a non-root user for security - Includes healthcheck functionality - Properly configures the benchmark script 2. A new `run_benchmark.sh` script that: - Provides a flexible way to run benchmarks with configurable parameters - Supports environment variable overrides for customization - Handles different output formats (json, yaml) - Includes proper error handling and logging ## Testing The container can be built and tested using: ```bash docker build -t <container-image-repo>/guidellm-benchmark:latest . docker run -e TARGET="http://localhost:8000" -e MODEL="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16" <container-image-repo>/guidellm-benchmark:latest ``` ## Configuration Options The container supports the following environment variables: - `TARGET`: The target endpoint for benchmarking (default: http://localhost:8000) - `MODEL`: The model to benchmark (default: neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16) - `RATE_TYPE`: The rate type for benchmarking (default: sweep) - `DATA`: The data configuration (default: prompt_tokens=256,output_tokens=128) - `MAX_REQUESTS`: Maximum number of requests (default: 100) - `MAX_SECONDS`: Maximum duration in seconds - `OUTPUT_PATH`: Path for output files (default: /results/guidellm_benchmark_results) - `OUTPUT_FORMAT`: Output format (json, yaml, or yml) ## Security Considerations - Uses a non-root user for running the benchmark - Includes proper file permissions - Implements healthcheck for container monitoring - Follows container security best practices ## Related Issues - Closes #119 - Closes #111 ## Checklist - [x] Added Dockerfile with proper security configurations - [x] Added run_benchmark.sh script with environment variable support - [x] Added documentation for configuration options - [x] Tested container build and run - [x] Followed security best practices --------- Co-authored-by: Samuel Monson <smonson@redhat.com>
1 parent d401ebd commit 0b186d1

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

deploy/Containerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ARG PYTHON=3.13
2+
3+
# Use a multi-stage build to create a lightweight production image
4+
FROM docker.io/python:${PYTHON}-slim as builder
5+
6+
# Copy repository files
7+
COPY / /src
8+
9+
# Create a venv and install guidellm
10+
RUN python3 -m venv /opt/guidellm \
11+
&& /opt/guidellm/bin/pip install --no-cache-dir /src
12+
13+
# Copy entrypoint script into the venv bin directory
14+
RUN install -m0755 /src/deploy/entrypoint.sh /opt/guidellm/bin/entrypoint.sh
15+
16+
# Prod image
17+
FROM docker.io/python:${PYTHON}-slim
18+
19+
# Copy the virtual environment from the builder stage
20+
COPY --from=builder /opt/guidellm /opt/guidellm
21+
22+
# Add guidellm bin to PATH
23+
ENV PATH="/opt/guidellm/bin:$PATH"
24+
25+
# Create a non-root user
26+
RUN useradd -md /results guidellm
27+
28+
# Switch to non-root user
29+
USER guidellm
30+
31+
# Set working directory
32+
WORKDIR /results
33+
34+
# Metadata
35+
LABEL org.opencontainers.image.source="https://github.com/neuralmagic/guidellm" \
36+
org.opencontainers.image.description="GuideLLM Performance Benchmarking Container"
37+
38+
# Set the environment variable for the benchmark script
39+
# TODO: Replace with scenario environment variables
40+
ENV GUIDELLM_TARGET="http://localhost:8000" \
41+
GUIDELLM_MODEL="neuralmagic/Meta-Llama-3.1-8B-Instruct-quantized.w4a16" \
42+
GUIDELLM_RATE_TYPE="sweep" \
43+
GUIDELLM_DATA="prompt_tokens=256,output_tokens=128" \
44+
GUIDELLM_MAX_REQUESTS="100" \
45+
GUIDELLM_MAX_SECONDS="" \
46+
GUIDELLM_OUTPUT_PATH="/results/results.json"
47+
48+
ENTRYPOINT [ "/opt/guidellm/bin/entrypoint.sh" ]

deploy/entrypoint.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Path to the guidellm binary
5+
guidellm_bin="/opt/guidellm/bin/guidellm"
6+
7+
# If we receive any arguments switch to guidellm command
8+
if [ $# -gt 0 ]; then
9+
echo "Running command: guidellm $*"
10+
exec $guidellm_bin "$@"
11+
fi
12+
13+
# Get a list of environment variables that start with GUIDELLM_
14+
args="$(printenv | cut -d= -f1 | grep -E '^GUIDELLM_')"
15+
16+
# NOTE: Bash array + exec prevent shell escape issues
17+
CMD=("${guidellm_bin}" "benchmark")
18+
19+
# Parse environment variables for the benchmark command
20+
for var in $args; do
21+
# Remove GUIDELLM_ prefix
22+
arg_name="${var#GUIDELLM_}"
23+
24+
# If there is an extra underscore at the
25+
# start than this is a config variable
26+
if [ "${arg_name:0:1}" == "_" ]; then
27+
continue
28+
fi
29+
30+
# Convert to lowercase
31+
arg_name="${arg_name,,}"
32+
# Replace underscores with dashes
33+
arg_name="${arg_name//_/-}"
34+
35+
# Add the argument to the command array if set
36+
if [ -n "${!var}" ]; then
37+
CMD+=("--${arg_name}" "${!var}")
38+
fi
39+
done
40+
41+
# Execute the command
42+
echo "Running command: ${CMD[*]}"
43+
exec "${CMD[@]}"

0 commit comments

Comments
 (0)