From f8b3b6a7357407ad56ea11ca47f3d1867db17d20 Mon Sep 17 00:00:00 2001 From: myousaf64 Date: Tue, 18 Aug 2026 19:28:38 +0200 Subject: [PATCH 1/8] chore: ignore Python cache and test artifacts --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 9f11b75..dd26b83 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ .idea/ +__pycache__/ +*.pyc +.pytest_cache/ +.venv/ +venv/ +Dockerfile.ci From bf8292cf8e987b56a82d4117137d4457b7309a4d Mon Sep 17 00:00:00 2001 From: myousaf64 Date: Tue, 18 Aug 2026 19:28:38 +0200 Subject: [PATCH 2/8] build: trim requirements.txt to the imported packages --- requirements-dev.txt | 14 +++++++++++++ requirements.txt | 50 ++++++++++++++------------------------------ 2 files changed, 30 insertions(+), 34 deletions(-) create mode 100644 requirements-dev.txt diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..e608ad5 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,14 @@ +# Development dependencies. Not needed to run the benchmark. +-r requirements.txt + +# formatting and linting +ruff==0.1.5 + +# type checking +mypy==0.991 +types-requests +types-setuptools + +# testing +pytest +pytest-asyncio diff --git a/requirements.txt b/requirements.txt index 1a9d7f7..53453ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,39 +1,21 @@ -# formatting -yapf==0.32.0 -toml==0.10.2 -ruff==0.1.5 +# Runtime dependencies for benchmark_serving.py. +# This tool is an HTTP client. It does not run a model, so it does not need +# torch, xformers, ray, or a server framework. +# Dev tools are in requirements-dev.txt. +# The dataset tool has its own file: datasets/requirements.txt. +# The analysis tool needs only matplotlib: see analysis/README.md. -# type checking -mypy==0.991 -types-PyYAML -types-requests -types-setuptools - -# testing -pytest -pytest-forked -pytest-asyncio -httpx -einops # required for MPT -openai +aiohttp +numpy requests +transformers >= 4.42.0 # Required for Qwen2. Used for AutoTokenizer only. -# run -ninja # For faster builds. -psutil -ray >= 2.9 -sentencepiece # Required for LLaMA tokenizer. -numpy < 2.0 -torch -transformers >= 4.42.0 # Required for Qwen2 -xformers -fastapi -uvicorn[standard] -pydantic >= 2.0 # Required for OpenAI server. -aioprometheus[starlette] -pynvml == 11.5.0 -accelerate -aiohttp +# Metrics export +prometheus_client >= 0.21.0 + +# Google Cloud output upload and auth google-auth google-cloud-storage >= 2.18.2 -prometheus_client >= 0.21.0 +protobuf + +# Add sentencepiece if your model uses a slow SentencePiece tokenizer. From e59d822363fe7ff1b5380c375ed915485ca9087c Mon Sep 17 00:00:00 2001 From: myousaf64 Date: Tue, 18 Aug 2026 19:28:38 +0200 Subject: [PATCH 3/8] fix: save TPOT statistics to the benchmark results --- benchmark_serving.py | 1 + test_benchmark_serving.py | 79 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 test_benchmark_serving.py diff --git a/benchmark_serving.py b/benchmark_serving.py index 7919c89..7fe1137 100644 --- a/benchmark_serving.py +++ b/benchmark_serving.py @@ -873,6 +873,7 @@ async def print_and_save_result(args: argparse.Namespace, benchmark_duration_sec ])), **ttft_stats, **itls_stats, + **tpot_stats, # NOTE: The latency below includes requests awaiting time on server side. # It's not comparable with the model inference latency for batch size 1. **(get_stats_for_set("latency_ms", "milliseconds/request (includes waiting time on server)" ,[latency for _, _, latency in request_latencies])), diff --git a/test_benchmark_serving.py b/test_benchmark_serving.py new file mode 100644 index 0000000..4dbfb50 --- /dev/null +++ b/test_benchmark_serving.py @@ -0,0 +1,79 @@ +"""Regression checks for the result assembly in benchmark_serving.py. + +Run with: pytest test_benchmark_serving.py +""" + +import argparse +import asyncio + +import benchmark_serving as bs + + +def _make_args(): + return argparse.Namespace( + stream_request=True, + machine_cost=None, + scrape_server_metrics=False, + save_json_results=True, + num_prompts=3, + backend="vllm", + pm_namespace="", + pm_job="", + ) + + +def _capture_result(monkeypatch): + """Runs print_and_save_result once and returns the assembled result dict.""" + captured = {} + + def fake_save(args, benchmark_result, server_metrics, model, errors): + captured.update(benchmark_result) + + monkeypatch.setattr(bs, "save_json_results", fake_save) + + async def run(): + # print_and_save_result reads the QPS counter, which needs _end_time set. + bs.AsyncRequestCounter._instance = None + counter = await bs.AsyncRequestCounter(target_requests=3) + for _ in range(3): + await counter.increment() + + # (prompt_len, output_len, latency_ms) per request. + request_latencies = [(10, 5, 100.0), (20, 10, 200.0), (30, 15, 300.0)] + await bs.print_and_save_result( + args=_make_args(), + benchmark_duration_sec=10.0, + total_requests=3, + model="test-model", + request_latencies=request_latencies, + ttfts=[10.0, 20.0, 30.0], + itls=[1.0, 2.0, 3.0], + tpots=[5.0, 10.0, 15.0], + errors=bs.init_errors_map(), + ) + + asyncio.run(run()) + return captured + + +def test_tpot_stats_reach_the_saved_result(monkeypatch): + """TPOT was printed but dropped before the JSON save. Guard against that.""" + result = _capture_result(monkeypatch) + assert result["avg_TPOT_ms"] == 10.0 + assert result["median_TPOT_ms"] == 10.0 + assert result["min_TPOT_ms"] == 5.0 + assert result["max_TPOT_ms"] == 15.0 + + +def test_streaming_latency_metrics_are_all_present(monkeypatch): + result = _capture_result(monkeypatch) + for name in ("TTFT_ms", "ITL_ms", "TPOT_ms"): + for stat in ("avg", "median", "sd", "min", "max", "p90", "p99"): + assert f"{stat}_{name}" in result, f"missing {stat}_{name}" + + +def test_throughput_totals(monkeypatch): + result = _capture_result(monkeypatch) + assert result["total_input_tokens"] == 60 + assert result["total_output_token"] == 30 + assert result["throughput"] == 3.0 # 30 output tokens over 10 seconds From f36f1077e1d8fb4d52aa9037376ba1e2a36ad429 Mon Sep 17 00:00:00 2001 From: myousaf64 Date: Tue, 18 Aug 2026 19:28:38 +0200 Subject: [PATCH 4/8] fix: remove the Docker COPY that matches no files --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c658cfc..61e67c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,9 @@ RUN wget https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfilter COPY benchmark_serving.py benchmark_serving.py COPY latency_throughput_curve.sh latency_throughput_curve.sh -COPY datasets/*.json /workspace/ + +# Custom datasets are not in this repository. Generate them with +# datasets/import_dataset.py, then mount or copy the JSON into /workspace. RUN chmod +x latency_throughput_curve.sh RUN chmod +x benchmark_serving.py From d950ababa03e1b0ab4cc102fe9efe8b84b356609 Mon Sep 17 00:00:00 2001 From: myousaf64 Date: Tue, 18 Aug 2026 19:28:38 +0200 Subject: [PATCH 5/8] chore: use the Python 3.11 base image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 61e67c2..bedd17f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9.20-slim-bookworm as dev +FROM python:3.11-slim-bookworm AS dev RUN apt-get update -y \ && apt-get install -y python3-pip git vim curl wget From 309c984ceeb86e7e943c6ec3863d8ef03c889cfa Mon Sep 17 00:00:00 2001 From: myousaf64 Date: Tue, 18 Aug 2026 19:28:38 +0200 Subject: [PATCH 6/8] style: fix the ruff findings --- analysis/analyze.py | 6 ++++-- benchmark_serving.py | 2 +- datasets/import_dataset.py | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/analysis/analyze.py b/analysis/analyze.py index 57bfdee..12b202e 100644 --- a/analysis/analyze.py +++ b/analysis/analyze.py @@ -114,8 +114,10 @@ def parse_and_plot(folder_path, instance_price_per_hour=None): print(f" - Note: 'avg_normalized_time_per_output_token_ms' not found in {filename}.") else: missing_core = [] - if throughput is None: missing_core.append("'throughput'") - if request_rate is None: missing_core.append("'request_rate'") + if throughput is None: + missing_core.append("'throughput'") + if request_rate is None: + missing_core.append("'request_rate'") print(f"Warning: Missing core metric(s) ({', '.join(missing_core)}) in {filename}. Skipping this file for plots.") except (json.JSONDecodeError, FileNotFoundError) as e: diff --git a/benchmark_serving.py b/benchmark_serving.py index 7fe1137..943199d 100644 --- a/benchmark_serving.py +++ b/benchmark_serving.py @@ -27,7 +27,7 @@ import random import requests import time -from typing import AsyncGenerator, List, Optional, Tuple, Dict +from typing import AsyncGenerator, List, Tuple, Dict from prometheus_client import start_http_server, Histogram, Gauge, Counter import logging diff --git a/datasets/import_dataset.py b/datasets/import_dataset.py index 4c3da2f..e444f38 100644 --- a/datasets/import_dataset.py +++ b/datasets/import_dataset.py @@ -6,7 +6,6 @@ import pandas as pd from tqdm import tqdm import matplotlib.pyplot as plt -import os import subprocess import csv @@ -72,7 +71,7 @@ def calculate_token_stats(dataset, filename, tokenizer_name, max_samples=None, i output_token_counts = [] prompts = [] responses = [] - results, histogram_data, js = None, None, None + results, histogram_data = None, None # Process each example for example in tqdm(dataset, desc="sampling examples", unit="example"): From 808ab9aab6ea571aedf3c38ceb6c7ded916ebdd3 Mon Sep 17 00:00:00 2001 From: myousaf64 Date: Tue, 18 Aug 2026 19:28:38 +0200 Subject: [PATCH 7/8] ci: add lint, test, and Docker build workflow --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d0c7e0e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: pip + + - name: Install dependencies + run: pip install -r requirements-dev.txt + + # Fails if requirements.txt is missing a package that the script imports. + - name: Import check + run: python benchmark_serving.py --help + + - name: Lint + run: ruff check . + + - name: Test + run: pytest -q + + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # Builds the dependency layers only. The full image downloads the + # ShareGPT dataset, which is too large for every CI run. + - name: Build dependency layers + run: | + sed '/^RUN wget /,$d' Dockerfile > Dockerfile.ci + docker build -f Dockerfile.ci -t inference-benchmark:ci . From 9f9d080800f751f9bb8d486f79d2cb4ed65e32b6 Mon Sep 17 00:00:00 2001 From: myousaf64 Date: Tue, 18 Aug 2026 19:28:38 +0200 Subject: [PATCH 8/8] docs: add the fork status and change list to the README --- README.md | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b6808b4..9d1cdef 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,24 @@ -> [!NOTE] -> This repository is no longer under active development. For inference benchmarking, use https://github.com/kubernetes-sigs/inference-perf instead. -> +## Archive Status + +This repository is maintained by AI Software Commons. + +Original project: +https://github.com/AI-Hypercomputer/inference-benchmark + +Upstream status: Archived +Fork status: MAINTAINED FORK + +This repository is not affiliated with or endorsed by Google or AI-Hypercomputer. + +> [!IMPORTANT] +> **For new benchmarking work, use https://github.com/kubernetes-sigs/inference-perf.** +> It is the actively developed successor and the upstream project points to it. +> +> This fork exists for one reason: to keep the original harness installable and +> runnable, so benchmark numbers produced with it stay reproducible. Scope is +> limited to dependency health, packaging, and correctness fixes. No new features. + +--- # Inference Benchmark @@ -8,6 +26,17 @@ A model server agnostic inference benchmarking tool that can be used to benchmark LLMs running on different infrastructure like GPUs and TPUs. It can also be run on a GKE cluster as a container. +## Changes in this fork + +- Fixed: TPOT statistics were printed but never written to the saved JSON results. +- Fixed: `docker build` failed because `COPY datasets/*.json` matched no files. +- `requirements.txt` now lists only what `benchmark_serving.py` imports. It no + longer installs `torch`, `xformers`, `ray`, `fastapi`, or `uvicorn`. This is a + benchmark client, not a model server. +- Development tools moved to `requirements-dev.txt`. +- Docker base image moved from Python 3.9 (end of life) to Python 3.11. +- Added CI and regression tests. + ## Run the benchmark 1. Create a python virtualenv.