-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_benchmark.py
More file actions
136 lines (114 loc) · 4.09 KB
/
Copy pathrun_benchmark.py
File metadata and controls
136 lines (114 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""Submit a NCCL networking benchmark to SLURM.
Usage:
benchmark-networking vllm-lens-0.17.0_0.4.0.sif
benchmark-networking vllm-lens-0.17.0_0.4.0.sif --backend tcp
benchmark-networking vllm-lens-0.17.0_0.4.0.sif --nodes 4
benchmark-networking vllm-lens-0.17.0_0.4.0.sif --reservation interactive
"""
from __future__ import annotations
import logging
import re
import subprocess
from enum import Enum
from pathlib import Path
from typing import Annotated
import typer
from sifter import api
logger = logging.getLogger(__name__)
_PKG_DIR = Path(__file__).resolve().parent.parent
BENCHMARK_SCRIPT = Path(__file__).resolve().parent / "benchmark_allreduce.py"
TEMPLATES = {
"slingshot": _PKG_DIR / "templates" / "benchmarks" / "benchmark_slingshot.slurm",
"tcp": _PKG_DIR / "templates" / "benchmarks" / "benchmark_tcp.slurm",
}
app = typer.Typer(help="Submit a NCCL networking benchmark to SLURM.")
class Backend(str, Enum):
slingshot = "slingshot"
tcp = "tcp"
@app.command()
def main(
container: Annotated[
str,
typer.Argument(help="Container name or path (e.g. vllm-lens-0.17.0_0.4.0.sif)"),
],
backend: Annotated[
Backend,
typer.Option(
help="Networking backend: slingshot (native CXI) or tcp (baseline)"
),
] = Backend.slingshot,
nodes: Annotated[int, typer.Option(help="Number of nodes")] = 2,
time: Annotated[str, typer.Option(help="SLURM time limit (HH:MM:SS)")] = "00:10:00",
partition: Annotated[str, typer.Option(help="SLURM partition")] = "workq",
reservation: Annotated[
str | None,
typer.Option(help="SLURM reservation name (e.g. 'interactive')"),
] = None,
interactive: Annotated[
bool,
typer.Option(
help="Shorthand for --partition=interactive --reservation=interactive",
),
] = False,
) -> None:
"""Benchmark NCCL all-reduce bandwidth across nodes."""
if interactive:
partition = "interactive"
reservation = "interactive"
# Accept a .sif path as-is, or resolve a sifter ref ("<name>" / "<name>:<tag>").
if container.endswith(".sif"):
container_path = container
else:
ref_name, _, ref_tag = container.partition(":")
if ref_tag:
container_path = next(
(
str(img.sif_path)
for img in api.list_local_sifs()
if img.name == ref_name and img.tag == ref_tag
),
container,
)
else:
try:
container_path = str(api.latest(ref_name))
except FileNotFoundError:
container_path = container
if not Path(container_path).exists():
logger.error("Container not found: %s", container_path)
raise typer.Exit(1)
template = TEMPLATES[backend.value]
logs_dir = Path.cwd() / "logs"
logs_dir.mkdir(exist_ok=True)
env_vars = {
"CONTAINER": container_path,
"BENCHMARK_SCRIPT": str(BENCHMARK_SCRIPT),
}
export_pairs = ",".join(f"{k}={v}" for k, v in env_vars.items())
cmd = [
"sbatch",
f"--nodes={nodes}",
f"--time={time}",
f"--partition={partition}",
f"--output={logs_dir}/%x_%j.out",
f"--export=ALL,{export_pairs}",
]
if reservation is not None:
cmd.append(f"--reservation={reservation}")
cmd.append(str(template))
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
if result.returncode != 0:
logger.error("sbatch failed (exit %d): %s", result.returncode, result.stderr)
raise typer.Exit(result.returncode)
output = result.stdout.strip()
match = re.search(r"Submitted batch job (\d+)", output)
if match:
job_id = match.group(1)
typer.echo(f"Submitted {backend.value} benchmark: job {job_id}")
typer.echo(f" Container: {container_path}")
typer.echo(f" Nodes: {nodes}")
typer.echo(f" Logs: {logs_dir}/bench_{backend.value}_{job_id}.out")
else:
typer.echo(output)
if __name__ == "__main__":
app()