Skip to content

Commit febe334

Browse files
authored
Enable sleeping between trials (#363) (#363)
Summary: Pull Request resolved: #363 Adds command line support for a `--sleep` argument that can be used to inject a sleep in between trials. This is potentially useful on Blackwell where due to the floating clock measurements sometimes favor a earlier running kernel. While most of this should be covered by just specifying running for at least 2 seconds, this can help ensure a more consistent run. Reviewed By: xuzhao9, FindHao Differential Revision: D81152631
1 parent 07088a7 commit febe334

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _run(args: argparse.Namespace, extra_args: List[str]) -> BenchmarkOperatorRe
4444
extra_args=extra_args,
4545
)
4646
try:
47-
opbench.run(args.warmup, args.iter)
47+
opbench.run(args.warmup, args.rep, sleep=args.sleep)
4848
finally:
4949
metrics = opbench.output
5050
if not args.skip_print:

tritonbench/utils/parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def get_parser(args=None):
6060
default=DEFAULT_REP,
6161
help="The rep time for each benchmark run.",
6262
)
63+
parser.add_argument(
64+
"--sleep",
65+
type=float,
66+
default=0.0,
67+
help="The amount of time (in seconds) to sleep between benchmark runs.",
68+
)
6369
parser.add_argument(
6470
"--csv",
6571
action="store_true",

tritonbench/utils/triton_op.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class BenchmarkOperatorBackend:
8181
DEFAULT_WARMUP = 25
8282
DEFAULT_REP = 100
8383
DEFAULT_QUANTILES = [0.5, 0.1, 0.9]
84+
DEFAULT_SLEEP = 0.0
8485
REGISTERED_BENCHMARKS: Dict[str, OrderedDict[str, BenchmarkOperatorBackend]] = {}
8586
REGISTERED_METRICS: defaultdict[str, List[str]] = defaultdict(list)
8687
OVERRIDDEN_METRICS: defaultdict[str, List[str]] = defaultdict(list)
@@ -808,7 +809,11 @@ def fwd_no_grad_fn():
808809
return fwd_no_grad_fn
809810

810811
def run(
811-
self, warmup=DEFAULT_WARMUP, rep=DEFAULT_REP, quantiles=DEFAULT_QUANTILES
812+
self,
813+
warmup=DEFAULT_WARMUP,
814+
rep=DEFAULT_REP,
815+
quantiles=DEFAULT_QUANTILES,
816+
sleep=DEFAULT_SLEEP,
812817
) -> None:
813818
"""Benchmarking the operator and returning its metrics."""
814819
metrics = []
@@ -910,6 +915,9 @@ def _reduce_benchmarks(acc, bm_name: str):
910915
)
911916
if baseline:
912917
self.baseline_metrics = acc[bm_name]
918+
if sleep:
919+
logging.debug(f"Sleeping for {sleep} seconds before next run")
920+
time.sleep(sleep)
913921
return acc
914922

915923
y_vals: Dict[str, BenchmarkOperatorMetrics] = functools.reduce(

0 commit comments

Comments
 (0)