Skip to content

Commit e720f59

Browse files
alec-flowersclaude
andcommitted
feat: add aiperf_package config for controlling aiperf version
Add benchmark.aiperf_package field to specify the pip install spec for aiperf (e.g., "aiperf>=0.7.0"). Passed as AIPERF_PACKAGE env var to bench.sh which does pip install --upgrade. Defaults to "aiperf" if not set. Always installs tiktoken alongside. Needed because container-bundled aiperf may predate fixes like trust-remote-code propagation to pool workers (aiperf PR #744). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a641da8 commit e720f59

6 files changed

Lines changed: 42 additions & 16 deletions

File tree

src/srtctl/benchmarks/base.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,20 @@ def build_command(
6161

6262

6363
class AIPerfBenchmarkRunner(BenchmarkRunner):
64-
"""Marker base class for AIPerf-driven benchmarks."""
64+
"""Base class for AIPerf-driven benchmarks.
65+
66+
Provides shared aiperf_args handling for subclasses.
67+
"""
68+
69+
def append_aiperf_args(self, cmd: list[str], config: SrtConfig) -> list[str]:
70+
"""Append aiperf_args from config as CLI flags."""
71+
for key, value in config.benchmark.aiperf_args.items():
72+
if isinstance(value, bool):
73+
if value:
74+
cmd.append(f"--{key}")
75+
else:
76+
cmd.extend([f"--{key}", str(value)])
77+
return cmd
6578

6679

6780
# Registry of benchmark runners

src/srtctl/benchmarks/mooncake_router.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def build_command(
101101
# For HF models, use the model ID directly so transformers downloads it
102102
tokenizer_path = str(runtime.model_path) if runtime.is_hf_model else "/model"
103103

104-
return [
104+
cmd = [
105105
"bash",
106106
self.script_path,
107107
endpoint,
@@ -111,3 +111,7 @@ def build_command(
111111
str(itl_threshold),
112112
tokenizer_path,
113113
]
114+
115+
self.append_aiperf_args(cmd, config)
116+
117+
return cmd

src/srtctl/benchmarks/scripts/trace-replay/bench.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,24 @@ if [ ! -f "${TRACE_FILE}" ]; then
6767
exit 1
6868
fi
6969

70-
# Install aiperf if not present
71-
if ! command -v aiperf &> /dev/null; then
72-
echo "Installing aiperf..."
73-
pip install aiperf
70+
# Create isolated aiperf environment (avoids polluting container packages)
71+
# AIPERF_PACKAGE env var controls the version (e.g., "aiperf>=0.7.0")
72+
AIPERF_SPEC="${AIPERF_PACKAGE:-aiperf}"
73+
AIPERF_VENV="/tmp/aiperf-${SLURM_JOB_ID:-$$}"
74+
75+
echo "Setting up aiperf environment: ${AIPERF_SPEC}"
76+
77+
# Install uv if not in container
78+
if ! command -v uv &> /dev/null; then
79+
echo "Installing uv..."
80+
curl -LsSf https://astral.sh/uv/install.sh | sh
81+
export PATH="$HOME/.local/bin:$PATH"
7482
fi
7583

76-
# Install tiktoken if not present (needed for custom tokenizers like Kimi)
77-
python3 -c "import tiktoken" 2>/dev/null || pip install tiktoken
84+
uv venv "${AIPERF_VENV}"
85+
uv pip install -p "${AIPERF_VENV}" "${AIPERF_SPEC}" tiktoken
86+
export PATH="${AIPERF_VENV}/bin:${PATH}"
87+
echo "aiperf $(aiperf --version 2>/dev/null || echo 'installed') in ${AIPERF_VENV}"
7888

7989
# Run small benchmark for warmup
8090
echo "Running warmup..."

src/srtctl/benchmarks/trace_replay.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ def build_command(
9494
tokenizer_path,
9595
]
9696

97-
# Pass through extra aiperf CLI flags from config
98-
for key, value in b.aiperf_args.items():
99-
if isinstance(value, bool):
100-
if value:
101-
cmd.append(f"--{key}")
102-
else:
103-
cmd.extend([f"--{key}", str(value)])
97+
self.append_aiperf_args(cmd, config)
10498

10599
return cmd

src/srtctl/cli/mixins/benchmark_stage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ def _get_benchmark_env(self, runner: "BenchmarkRunner") -> dict[str, str]:
285285
env = self._get_benchmark_profiling_env(runner)
286286
env["SRTCTL_FRONTEND_TYPE"] = self.config.frontend.type
287287

288-
# Add AIPerf metrics URLs for AIPerf-driven benchmarks
288+
# Add AIPerf-specific env vars for AIPerf-driven benchmarks only
289289
if isinstance(runner, AIPerfBenchmarkRunner):
290290
env.update(self._get_aiperf_server_metrics_env())
291+
if self.config.benchmark.aiperf_package:
292+
env["AIPERF_PACKAGE"] = self.config.benchmark.aiperf_package
291293

292294
return env

src/srtctl/core/schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@ class BenchmarkConfig:
546546
trace_file: str | None = None # Path to trace JSONL file (container path, e.g., /traces/dataset.jsonl)
547547
custom_tokenizer: str | None = None # Custom tokenizer class (e.g., "module.path.ClassName")
548548
use_chat_template: bool = True # Pass --use-chat-template to benchmark (default: true)
549+
# aiperf pip install spec (e.g., "aiperf>=0.7.0", "aiperf @ git+https://...@commit")
550+
# If set, runs pip install <spec> before benchmarking. Upgrades if already installed.
551+
aiperf_package: str | None = None
549552
# Extra aiperf CLI flags passed through to bench.sh (e.g., benchmark-duration: 600, workers-max: 200)
550553
aiperf_args: dict[str, Any] = field(default_factory=dict)
551554

0 commit comments

Comments
 (0)