Skip to content

Commit b0fa0a2

Browse files
committed
Silence profiler warnings in benchmark utils
1 parent d8ca182 commit b0fa0a2

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

benchmarks/fav4.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import csv
88
import itertools
9-
import warnings
109
from dataclasses import dataclass, asdict
1110
from typing import Literal
1211

@@ -21,10 +20,6 @@
2120

2221
from transformer_nuggets.utils.benchmark import benchmark_cuda_function_in_microseconds
2322

24-
warnings.filterwarnings("ignore", message=".*SyncActivityProfilerHandler.*")
25-
warnings.filterwarnings("ignore", message=".*profiler_start.*")
26-
warnings.filterwarnings("ignore", message=".*profiler_stop.*")
27-
2823
try:
2924
from flash_attn.cute import flash_attn_func
3025

transformer_nuggets/utils/benchmark.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import random
77
import statistics
8+
import warnings
89
from contextlib import contextmanager, nullcontext
910
from dataclasses import dataclass, field
1011
from pathlib import Path
@@ -19,6 +20,10 @@
1920
from torch.cuda._memory_viz import profile_plot # type: ignore
2021
from torch.profiler import profile, ProfilerActivity, record_function, schedule
2122

23+
warnings.filterwarnings("ignore", message=".*SyncActivityProfilerHandler.*")
24+
warnings.filterwarnings("ignore", message=".*profiler_start.*")
25+
warnings.filterwarnings("ignore", message=".*profiler_stop.*")
26+
2227
logger = logging.getLogger(__name__)
2328
logger.addHandler(logging.NullHandler())
2429

@@ -265,7 +270,6 @@ def _call_do_bench_using_profiling(
265270
return do_bench_using_profiling(fn, **call_kwargs)
266271

267272

268-
269273
def _benchmark_cuda_graph_replay_samples_us(
270274
func: Callable,
271275
*args,
@@ -310,7 +314,6 @@ def _benchmark_cuda_graph_replay_samples_us(
310314
return samples_us
311315

312316

313-
314317
def benchmark_cuda_function_stats(func: Callable, *args, **kwargs) -> CudaBenchmarkStats:
315318
"""Benchmark a CUDA callable and return median-centered summary stats.
316319
@@ -353,9 +356,7 @@ def benchmark_cuda_function_stats(func: Callable, *args, **kwargs) -> CudaBenchm
353356
func,
354357
*args,
355358
NUM_ITERS=num_iters,
356-
CUDAGRAPH_WARMUP_ITERS=kwargs.pop(
357-
"CUDAGRAPH_WARMUP_ITERS", memory_warmup_iters
358-
),
359+
CUDAGRAPH_WARMUP_ITERS=kwargs.pop("CUDAGRAPH_WARMUP_ITERS", memory_warmup_iters),
359360
LOCK_CLOCKS=kwargs.pop("LOCK_CLOCKS", False),
360361
**kwargs,
361362
)
@@ -424,7 +425,9 @@ def benchmark_cuda_function_in_microseconds(func: Callable, *args, **kwargs) ->
424425
*args,
425426
NUM_ITERS=num_iters,
426427
LOCK_CLOCKS=kwargs.pop("LOCK_CLOCKS", False),
427-
CUDAGRAPH_WARMUP_ITERS=kwargs.pop("CUDAGRAPH_WARMUP_ITERS", max(10, min(25, num_iters))),
428+
CUDAGRAPH_WARMUP_ITERS=kwargs.pop(
429+
"CUDAGRAPH_WARMUP_ITERS", max(10, min(25, num_iters))
430+
),
428431
**kwargs,
429432
)
430433
return statistics.median(samples_us)

0 commit comments

Comments
 (0)