[Lint]Style: Convert root, benchmarks, tools and docs to ruff format (#5843)

### What this PR does / why we need it?
Description
This PR fixes linting issues in the root directory, benchmarks/, tools/
and docs/ to align with the project's Ruff configuration.

This is part of a gradual effort to enable full linting coverage across
the repository. The corresponding paths have been removed from the
exclude list in pyproject.toml.

### Does this PR introduce _any_ user-facing change?

### How was this patch tested?

- vLLM version: v0.13.0
- vLLM main:
2f4e6548ef

---------

Signed-off-by: root <root@LAPTOP-VQKDDVMG.localdomain>
Co-authored-by: root <root@LAPTOP-VQKDDVMG.localdomain>
This commit is contained in:
SILONG ZENG
2026-01-13 15:29:34 +08:00
committed by GitHub
parent 4b679984de
commit 523e83016b
14 changed files with 425 additions and 531 deletions

View File

@@ -29,60 +29,47 @@ import pandas as pd
from modelscope import snapshot_download # type: ignore
BENCHMARK_HOME = os.getenv("BENCHMARK_HOME", os.path.abspath("./benchmark"))
DATASET_CONF_DIR = os.path.join(BENCHMARK_HOME, "ais_bench", "benchmark",
"configs", "datasets")
REQUEST_CONF_DIR = os.path.join(BENCHMARK_HOME, "ais_bench", "benchmark",
"configs", "models", "vllm_api")
DATASET_CONF_DIR = os.path.join(BENCHMARK_HOME, "ais_bench", "benchmark", "configs", "datasets")
REQUEST_CONF_DIR = os.path.join(BENCHMARK_HOME, "ais_bench", "benchmark", "configs", "models", "vllm_api")
DATASET_DIR = os.path.join(BENCHMARK_HOME, "ais_bench", "datasets")
class AisbenchRunner:
RESULT_MSG = {
"performance": "Performance Result files locate in ",
"accuracy": "write csv to "
}
DATASET_RENAME = {
"aime2024": "aime",
"gsm8k-lite": "gsm8k",
"textvqa-lite": "textvqa"
}
RESULT_MSG = {"performance": "Performance Result files locate in ", "accuracy": "write csv to "}
DATASET_RENAME = {"aime2024": "aime", "gsm8k-lite": "gsm8k", "textvqa-lite": "textvqa"}
def _run_aisbench_task(self):
dataset_conf = self.dataset_conf.split('/')[-1]
dataset_conf = self.dataset_conf.split("/")[-1]
if self.task_type == "accuracy":
aisbench_cmd = [
'ais_bench', '--models', f'{self.request_conf}_custom',
'--datasets', f'{dataset_conf}'
]
aisbench_cmd = ["ais_bench", "--models", f"{self.request_conf}_custom", "--datasets", f"{dataset_conf}"]
if self.task_type == "performance":
aisbench_cmd = [
'ais_bench', '--models', f'{self.request_conf}_custom',
'--datasets', f'{dataset_conf}_custom', '--mode', 'perf'
"ais_bench",
"--models",
f"{self.request_conf}_custom",
"--datasets",
f"{dataset_conf}_custom",
"--mode",
"perf",
]
if self.num_prompts:
aisbench_cmd.extend(['--num-prompts', str(self.num_prompts)])
aisbench_cmd.extend(["--num-prompts", str(self.num_prompts)])
print(f"running aisbench cmd: {' '.join(aisbench_cmd)}")
self.proc: subprocess.Popen = subprocess.Popen(aisbench_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)
self.proc: subprocess.Popen = subprocess.Popen(
aisbench_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
def __init__(self,
model: str,
port: int,
aisbench_config: dict,
host_ip: str = "localhost",
verify=True):
def __init__(self, model: str, port: int, aisbench_config: dict, host_ip: str = "localhost", verify=True):
self.model = model
self.dataset_path = aisbench_config.get("dataset_path_local")
if not self.dataset_path:
self.dataset_path = maybe_download_from_modelscope(
aisbench_config["dataset_path"], repo_type="dataset")
self.dataset_path = maybe_download_from_modelscope(aisbench_config["dataset_path"], repo_type="dataset")
self.model_path = aisbench_config.get("model_path")
if not self.model_path:
self.model_path = maybe_download_from_modelscope(model)
assert self.dataset_path is not None and self.model_path is not None, \
assert self.dataset_path is not None and self.model_path is not None, (
f"Failed to download dataset or model: dataset={self.dataset_path}, model={self.model_path}"
)
self.port = port
self.host_ip = host_ip
self.task_type = aisbench_config["case_type"]
@@ -92,8 +79,7 @@ class AisbenchRunner:
self.max_out_len = aisbench_config["max_out_len"]
self.batch_size = aisbench_config["batch_size"]
self.request_rate = aisbench_config.get("request_rate", 0)
self.trust_remote_code = aisbench_config.get("trust_remote_code",
False)
self.trust_remote_code = aisbench_config.get("trust_remote_code", False)
self.temperature = aisbench_config.get("temperature")
self.top_k = aisbench_config.get("top_k")
self.top_p = aisbench_config.get("top_p")
@@ -122,52 +108,38 @@ class AisbenchRunner:
command = ["cp", "-r", self.dataset_path, dst_dir]
subprocess.call(command)
if self.task_type == "performance":
conf_path = os.path.join(DATASET_CONF_DIR,
f'{self.dataset_conf}.py')
conf_path = os.path.join(DATASET_CONF_DIR, f"{self.dataset_conf}.py")
if self.dataset_conf.startswith("textvqa"):
self.dataset_path = os.path.join(self.dataset_path,
"textvqa_val.jsonl")
with open(conf_path, 'r', encoding='utf-8') as f:
self.dataset_path = os.path.join(self.dataset_path, "textvqa_val.jsonl")
with open(conf_path, encoding="utf-8") as f:
content = f.read()
content = re.sub(r'path=.*', f'path="{self.dataset_path}",',
content)
conf_path_new = os.path.join(DATASET_CONF_DIR,
f'{self.dataset_conf}_custom.py')
with open(conf_path_new, 'w', encoding='utf-8') as f:
content = re.sub(r"path=.*", f'path="{self.dataset_path}",', content)
conf_path_new = os.path.join(DATASET_CONF_DIR, f"{self.dataset_conf}_custom.py")
with open(conf_path_new, "w", encoding="utf-8") as f:
f.write(content)
def _init_request_conf(self):
conf_path = os.path.join(REQUEST_CONF_DIR, f'{self.request_conf}.py')
with open(conf_path, 'r', encoding='utf-8') as f:
conf_path = os.path.join(REQUEST_CONF_DIR, f"{self.request_conf}.py")
with open(conf_path, encoding="utf-8") as f:
content = f.read()
content = re.sub(r'model=.*', f'model="{self.model}",', content)
content = re.sub(r'host_port.*', f'host_port = {self.port},', content)
content = re.sub(r'host_ip.*', f'host_ip = "{self.host_ip}",', content)
content = re.sub(r'max_out_len.*',
f'max_out_len = {self.max_out_len},', content)
content = re.sub(r'batch_size.*', f'batch_size = {self.batch_size},',
content)
content = re.sub(r'trust_remote_code=.*',
f'trust_remote_code={self.trust_remote_code},',
content)
content = re.sub(r"model=.*", f'model="{self.model}",', content)
content = re.sub(r"host_port.*", f"host_port = {self.port},", content)
content = re.sub(r"host_ip.*", f'host_ip = "{self.host_ip}",', content)
content = re.sub(r"max_out_len.*", f"max_out_len = {self.max_out_len},", content)
content = re.sub(r"batch_size.*", f"batch_size = {self.batch_size},", content)
content = re.sub(r"trust_remote_code=.*", f"trust_remote_code={self.trust_remote_code},", content)
content = content.replace("top_k", "#top_k")
content = content.replace("seed", "#seed")
content = content.replace("repetition_penalty", "#repetition_penalty")
if self.task_type == "performance":
content = re.sub(r'path=.*', f'path="{self.model_path}",', content)
content = re.sub(r'request_rate.*',
f'request_rate = {self.request_rate},', content)
content = re.sub(
r"temperature.*",
"temperature = 0,\n ignore_eos = True,", content)
content = re.sub(r"path=.*", f'path="{self.model_path}",', content)
content = re.sub(r"request_rate.*", f"request_rate = {self.request_rate},", content)
content = re.sub(r"temperature.*", "temperature = 0,\n ignore_eos = True,", content)
content = content.replace("top_p", "#top_p")
if self.task_type == "accuracy":
content = re.sub(
r"temperature.*",
"temperature = 0.6,\n ignore_eos = False,", content)
content = re.sub(r"temperature.*", "temperature = 0.6,\n ignore_eos = False,", content)
if self.temperature:
content = re.sub(r"temperature.*",
f"temperature = {self.temperature},", content)
content = re.sub(r"temperature.*", f"temperature = {self.temperature},", content)
if self.top_p:
content = re.sub(r"#?top_p.*", f"top_p = {self.top_p},", content)
if self.top_k:
@@ -175,12 +147,9 @@ class AisbenchRunner:
if self.seed:
content = re.sub(r"#seed.*", f"seed = {self.seed},", content)
if self.repetition_penalty:
content = re.sub(
r"#repetition_penalty.*",
f"repetition_penalty = {self.repetition_penalty},", content)
conf_path_new = os.path.join(REQUEST_CONF_DIR,
f'{self.request_conf}_custom.py')
with open(conf_path_new, 'w', encoding='utf-8') as f:
content = re.sub(r"#repetition_penalty.*", f"repetition_penalty = {self.repetition_penalty},", content)
conf_path_new = os.path.join(REQUEST_CONF_DIR, f"{self.request_conf}_custom.py")
with open(conf_path_new, "w", encoding="utf-8") as f:
f.write(content)
print(f"The request config is\n {content}")
@@ -200,8 +169,7 @@ class AisbenchRunner:
line = self.proc.stdout.readline().strip()
print(line)
if "Current exp folder: " in line:
self.exp_folder = re.search(r'Current exp folder: (.*)',
line).group(1)
self.exp_folder = re.search(r"Current exp folder: (.*)", line).group(1)
return
if "ERROR" in line:
error_msg = f"Some errors happened to Aisbench runtime, the first error is {line}"
@@ -221,53 +189,48 @@ class AisbenchRunner:
raise RuntimeError(error_msg) from None
def _get_result_performance(self):
result_dir = re.search(r'Performance Result files locate in (.*)',
self.result_line).group(1)[:-1]
dataset_type = self.dataset_conf.split('/')[0]
result_csv_file = os.path.join(result_dir,
f"{dataset_type}dataset.csv")
result_json_file = os.path.join(result_dir,
f"{dataset_type}dataset.json")
result_dir = re.search(r"Performance Result files locate in (.*)", self.result_line).group(1)[:-1]
dataset_type = self.dataset_conf.split("/")[0]
result_csv_file = os.path.join(result_dir, f"{dataset_type}dataset.csv")
result_json_file = os.path.join(result_dir, f"{dataset_type}dataset.json")
self.result_csv = pd.read_csv(result_csv_file, index_col=0)
print("Getting performance results from file: ", result_json_file)
with open(result_json_file, 'r', encoding='utf-8') as f:
with open(result_json_file, encoding="utf-8") as f:
self.result_json = json.load(f)
self.result = [self.result_csv, self.result_json]
def _get_result_accuracy(self):
acc_file = re.search(r'write csv to (.*)', self.result_line).group(1)
acc_file = re.search(r"write csv to (.*)", self.result_line).group(1)
df = pd.read_csv(acc_file)
self.result = float(df.loc[0][-1])
def _performance_verify(self):
self._get_result_performance()
output_throughput = self.result_json["Output Token Throughput"][
"total"].replace("token/s", "")
assert float(
output_throughput
) >= self.threshold * self.baseline, f"Performance verification failed. The current Output Token Throughput is {output_throughput} token/s, which is not greater than or equal to {self.threshold} * baseline {self.baseline}."
output_throughput = self.result_json["Output Token Throughput"]["total"].replace("token/s", "")
assert float(output_throughput) >= self.threshold * self.baseline, (
"Performance verification failed. "
f"The current Output Token Throughput is {output_throughput} token/s, "
f"which is not greater than or equal to {self.threshold} * baseline {self.baseline}."
)
def _accuracy_verify(self):
self._get_result_accuracy()
acc_value = self.result
assert self.baseline - self.threshold <= acc_value <= self.baseline + self.threshold, f"Accuracy verification failed. The accuracy of {self.dataset_path} is {acc_value}, which is not within {self.threshold} relative to baseline {self.baseline}."
assert self.baseline - self.threshold <= acc_value <= self.baseline + self.threshold, (
"Accuracy verification failed. "
f"The accuracy of {self.dataset_path} is {acc_value}, "
f"which is not within {self.threshold} relative to baseline {self.baseline}."
)
def run_aisbench_cases(model,
port,
aisbench_cases,
server_args="",
host_ip="localhost"):
def run_aisbench_cases(model, port, aisbench_cases, server_args="", host_ip="localhost"):
aisbench_results = []
aisbench_errors = []
for aisbench_case in aisbench_cases:
if not aisbench_case:
continue
try:
with AisbenchRunner(model=model,
port=port,
host_ip=host_ip,
aisbench_config=aisbench_case) as aisbench:
with AisbenchRunner(model=model, port=port, host_ip=host_ip, aisbench_config=aisbench_case) as aisbench:
aisbench_results.append(aisbench.result)
except Exception as e:
aisbench_results.append("")
@@ -299,8 +262,7 @@ def get_lock(model_name_or_path: str | Path, cache_dir: str | None = None):
# add hash to avoid conflict with old users' lock files
lock_file_name = hash_name + model_name + ".lock"
# mode 0o666 is required for the filelock to be shared across users
lock = filelock.FileLock(os.path.join(lock_dir, lock_file_name),
mode=0o666)
lock = filelock.FileLock(os.path.join(lock_dir, lock_file_name), mode=0o666)
return lock

View File

@@ -36,8 +36,8 @@ def check_init_file_in_package(directory):
return False
# If any .py file exists, we expect an __init__.py
if any(f.endswith('.py') for f in files):
init_file = os.path.join(directory, '__init__.py')
if any(f.endswith(".py") for f in files):
init_file = os.path.join(directory, "__init__.py")
if not os.path.isfile(init_file):
return False
return True
@@ -62,9 +62,7 @@ def main():
all_missing.update(missing)
if all_missing:
print(
"❌ Missing '__init__.py' files in the following Python package directories:"
)
print("❌ Missing '__init__.py' files in the following Python package directories:")
for pkg in sorted(all_missing):
print(f" - {pkg}")
sys.exit(1)

View File

@@ -24,39 +24,33 @@ from pathlib import Path
import regex as re
FORBIDDEN_PATTERNS = re.compile(
r'^\s*(?:import\s+re(?:$|\s|,)|from\s+re\s+import)')
FORBIDDEN_PATTERNS = re.compile(r"^\s*(?:import\s+re(?:$|\s|,)|from\s+re\s+import)")
ALLOWED_PATTERNS = [
re.compile(r'^\s*import\s+regex\s+as\s+re\s*$'),
re.compile(r'^\s*import\s+regex\s*$'),
re.compile(r"^\s*import\s+regex\s+as\s+re\s*$"),
re.compile(r"^\s*import\s+regex\s*$"),
]
def get_staged_python_files() -> list[str]:
try:
result = subprocess.run(
['git', 'diff', '--cached', '--name-only', '--diff-filter=AM'],
capture_output=True,
text=True,
check=True)
files = result.stdout.strip().split(
'\n') if result.stdout.strip() else []
return [f for f in files if f.endswith('.py')]
["git", "diff", "--cached", "--name-only", "--diff-filter=AM"], capture_output=True, text=True, check=True
)
files = result.stdout.strip().split("\n") if result.stdout.strip() else []
return [f for f in files if f.endswith(".py")]
except subprocess.CalledProcessError:
return []
def is_forbidden_import(line: str) -> bool:
line = line.strip()
return bool(
FORBIDDEN_PATTERNS.match(line)
and not any(pattern.match(line) for pattern in ALLOWED_PATTERNS))
return bool(FORBIDDEN_PATTERNS.match(line) and not any(pattern.match(line) for pattern in ALLOWED_PATTERNS))
def check_file(filepath: str) -> list[tuple[int, str]]:
violations = []
try:
with open(filepath, encoding='utf-8') as f:
with open(filepath, encoding="utf-8") as f:
for line_num, line in enumerate(f, 1):
if is_forbidden_import(line):
violations.append((line_num, line.strip()))
@@ -89,9 +83,7 @@ def main() -> int:
if total_violations > 0:
print(f"\n💡 Found {total_violations} violation(s).")
print("❌ Please replace 'import re' with 'import regex as re'")
print(
" Also replace 'from re import ...' with 'from regex import ...'"
) # noqa: E501
print(" Also replace 'from re import ...' with 'from regex import ...'") # noqa: E501
print("✅ Allowed imports:")
print(" - import regex as re")
print(" - import regex") # noqa: E501

View File

@@ -20,9 +20,7 @@ import re
import sys
from datetime import datetime
p = re.compile(
r'@(?P<user>[A-Za-z0-9-_]+)[^\`]*\`(?P<sha>[0-9a-fA-F]+)\`\s*[-–—]\s*(?P<date>.+)$'
)
p = re.compile(r"@(?P<user>[A-Za-z0-9-_]+)[^\`]*\`(?P<sha>[0-9a-fA-F]+)\`\s*[-–—]\s*(?P<date>.+)$")
def parse_lines(lines):
@@ -34,9 +32,9 @@ def parse_lines(lines):
m = p.search(ln)
if not m:
continue
user = m.group('user')
sha = m.group('sha')
datestr = m.group('date').strip()
user = m.group("user")
sha = m.group("sha")
datestr = m.group("date").strip()
try:
dt = datetime.fromisoformat(datestr)
except Exception:
@@ -51,27 +49,17 @@ def parse_lines(lines):
def main():
ap = argparse.ArgumentParser(
description=
"Format and sort contributor lines by date (newest first). Outputs markdown table by default."
description="Format and sort contributor lines by date (newest first). Outputs markdown table by default."
)
ap.add_argument(
'file',
nargs='?',
help=
'input file (default stdin), output from collect_user_first_contribution.sh'
"file", nargs="?", help="input file (default stdin), output from collect_user_first_contribution.sh"
)
ap.add_argument(
'--start',
type=int,
default=1,
help='minimum number for table (oldest row will have this number)')
ap.add_argument('--repo',
default='vllm-project/vllm-ascend',
help='repo used for commit links')
ap.add_argument("--start", type=int, default=1, help="minimum number for table (oldest row will have this number)")
ap.add_argument("--repo", default="vllm-project/vllm-ascend", help="repo used for commit links")
args = ap.parse_args()
if args.file:
with open(args.file, 'r', encoding='utf-8') as f:
with open(args.file, encoding="utf-8") as f:
lines = f.readlines()
else:
lines = sys.stdin.readlines()
@@ -88,9 +76,9 @@ def main():
for dt, user, sha, datestr in items:
short = sha[:7]
date_short = dt.strftime("%Y/%m/%d")
print(
f"| {n} | [@{user}](https://github.com/{user}) | {date_short} | [{short}](https://github.com/{args.repo}/commit/{sha}) |"
)
user_url = f"https://github.com/{user}"
commit_url = f"https://github.com/{args.repo}/commit/{sha}"
print(f"| {n} | [@{user}]({user_url}) | {date_short} | [{short}]({commit_url}) |")
n -= 1

View File

@@ -4,39 +4,30 @@ import os
import requests
from modelscope import snapshot_download # type: ignore
mm_dir = snapshot_download("vllm-ascend/mm_request", repo_type='dataset')
mm_dir = snapshot_download("vllm-ascend/mm_request", repo_type="dataset")
image_path = os.path.join(mm_dir, "test_mm2.jpg")
with open(image_path, 'rb') as image_file:
image_data = base64.b64encode(image_file.read()).decode('utf-8')
with open(image_path, "rb") as image_file:
image_data = base64.b64encode(image_file.read()).decode("utf-8")
data = {
"messages": [{
"role":
"user",
"content": [{
"type": "text",
"text": "What is the content of this image?"
}, {
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{image_data}"
}
}]
}],
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What is the content of this image?"},
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_data}"}},
],
}
],
"eos_token_id": [1, 106],
"pad_token_id":
0,
"top_k":
64,
"top_p":
0.95,
"max_tokens":
8192,
"stream":
False
"pad_token_id": 0,
"top_k": 64,
"top_p": 0.95,
"max_tokens": 8192,
"stream": False,
}
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
headers = {"Accept": "application/json", "Content-Type": "application/json"}
def send_image_request(model, server):

View File

@@ -20,10 +20,12 @@ def send_v1_completions(prompt, model, server, request_args=None):
def send_v1_chat_completions(prompt, model, server, request_args=None):
data: dict[str, Any] = {
"model": model,
"messages": [{
"role": "user",
"content": prompt,
}],
"messages": [
{
"role": "user",
"content": prompt,
}
],
}
if request_args:
data.update(request_args)

View File

@@ -24,42 +24,58 @@ from .aisbench import maybe_download_from_modelscope
class VllmbenchRunner:
def _run_vllm_bench_task(self):
vllm_bench_cmd = [
'vllm', 'bench', 'serve', '--backend', 'openai-chat',
'--trust-remote-code', '--served-model-name',
str(self.model_name), '--model', self.model_path, '--tokenizer',
self.model_path, '--metric-percentiles', '50,90,99', '--host',
self.host_ip, '--port',
str(self.port), '--save-result', '--result-filename',
self.result_filename, '--endpoint', '/v1/chat/completions',
'--ready-check-timeout-sec', '0'
"vllm",
"bench",
"serve",
"--backend",
"openai-chat",
"--trust-remote-code",
"--served-model-name",
str(self.model_name),
"--model",
self.model_path,
"--tokenizer",
self.model_path,
"--metric-percentiles",
"50,90,99",
"--host",
self.host_ip,
"--port",
str(self.port),
"--save-result",
"--result-filename",
self.result_filename,
"--endpoint",
"/v1/chat/completions",
"--ready-check-timeout-sec",
"0",
]
self._concat_config_args(vllm_bench_cmd)
print(f"running vllm_bench cmd: {' '.join(vllm_bench_cmd)}")
self.proc: subprocess.Popen = subprocess.Popen(vllm_bench_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)
self.proc: subprocess.Popen = subprocess.Popen(
vllm_bench_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
def __init__(self,
model_name: str,
port: int,
config: dict,
baseline: float,
threshold: float = 0.97,
model_path: str = "",
host_ip: str = "localhost"):
def __init__(
self,
model_name: str,
port: int,
config: dict,
baseline: float,
threshold: float = 0.97,
model_path: str = "",
host_ip: str = "localhost",
):
self.model_name = model_name
self.model_path = model_path
if not self.model_path:
self.model_path = maybe_download_from_modelscope(model_name)
assert self.model_path is not None, \
f"Failed to download model: model={self.model_path}"
assert self.model_path is not None, f"Failed to download model: model={self.model_path}"
self.port = port
self.host_ip = host_ip
curr_time = datetime.now().strftime('%Y%m%d%H%M%S')
curr_time = datetime.now().strftime("%Y%m%d%H%M%S")
self.result_filename = f"result_vllm_bench_{curr_time}.json"
self.config = config
self.baseline = baseline
@@ -96,19 +112,14 @@ class VllmbenchRunner:
stdout, stderr = self.proc.communicate()
if self.proc.returncode != 0:
logging.error(
f"vllm bench command failed, return code: {self.proc.returncode}"
)
logging.error(f"vllm bench command failed, return code: {self.proc.returncode}")
logging.error(f"Standard output: {stdout}")
logging.error(f"Standard error: {stderr}")
raise RuntimeError(
f"vllm bench command execution failed: {stderr}")
raise RuntimeError(f"vllm bench command execution failed: {stderr}")
logging.info(
f"vllm bench command completed, return code: {self.proc.returncode}"
)
logging.info(f"vllm bench command completed, return code: {self.proc.returncode}")
if stdout:
lines = stdout.split('\n')
lines = stdout.split("\n")
last_lines = lines[-100:] if len(lines) > 100 else lines
logging.info(f"Last {len(last_lines)} lines of standard output:")
for line in last_lines:
@@ -119,36 +130,28 @@ class VllmbenchRunner:
def _get_result(self):
result_file = os.path.join(os.getcwd(), self.result_filename)
print("Getting performance results from file: ", result_file)
with open(result_file, 'r', encoding='utf-8') as f:
with open(result_file, encoding="utf-8") as f:
self.result = json.load(f)
def _performance_verify(self):
self._get_result()
output_throughput = self.result["output_throughput"]
assert float(
output_throughput
) >= self.baseline * self.threshold, f"Performance verification failed. The current Output Token Throughput is {output_throughput} token/s, which is not greater than or equal to {self.threshold} * baseline {self.baseline}."
assert float(output_throughput) >= self.baseline * self.threshold, (
"Performance verification failed. "
f"The current Output Token Throughput is {output_throughput} token/s, "
f"which is not greater than or equal to {self.threshold} * baseline {self.baseline}."
)
def run_vllm_bench_case(model_name,
port,
config,
baseline,
threshold=0.97,
model_path="",
host_ip="localhost"):
def run_vllm_bench_case(model_name, port, config, baseline, threshold=0.97, model_path="", host_ip="localhost"):
try:
with VllmbenchRunner(model_name,
port,
config,
baseline,
threshold,
model_path=model_path,
host_ip=host_ip) as vllm_bench:
with VllmbenchRunner(
model_name, port, config, baseline, threshold, model_path=model_path, host_ip=host_ip
) as vllm_bench:
vllm_bench_result = vllm_bench.result
except Exception as e:
print(e)
error_msg = f"vllm_bench run failed, reason is {e}"
logging.error(error_msg)
assert False, f"vllm_bench run failed, reason is {e}"
raise RuntimeError(error_msg) from e
return vllm_bench_result