Skip to content

Commit 00c8ef1

Browse files
fangfangssjclaude
andcommitted
feat: add profiler_device speedup metric for CUDA benchmarks
Add PyTorch Profiler device time measurement and speedup calculation for CUDA benchmarks. This provides a more accurate kernel-level performance comparison between eager and compiled models. - Add --profiler-device-time CLI argument - Measure profiler_device via torch.profiler with CUDA activity - Print [Speedup][profiler_device] in benchmark results - Propagate flag through multi-model test runners Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8ce68eb commit 00c8ef1

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

graph_net_bench/test_compiler_util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def print_times_and_speedup(args, eager_stats, compiled_stats):
205205

206206
e2e_speedup = 0
207207
gpu_speedup = 0
208+
profiler_device_speedup = 0
208209

209210
eager_e2e_time_ms = eager_stats.get("e2e", {}).get("mean", 0)
210211
compiled_e2e_time_ms = compiled_stats.get("e2e", {}).get("mean", 0)
@@ -219,12 +220,29 @@ def print_times_and_speedup(args, eager_stats, compiled_stats):
219220
if eager_gpu_time_ms > 0 and compiled_gpu_time_ms > 0:
220221
gpu_speedup = eager_gpu_time_ms / compiled_gpu_time_ms
221222

223+
eager_profiler_device_ms = eager_stats.get("profiler_device", {}).get("mean", 0)
224+
compiled_profiler_device_ms = compiled_stats.get("profiler_device", {}).get(
225+
"mean", 0
226+
)
227+
228+
if eager_profiler_device_ms > 0 and compiled_profiler_device_ms > 0:
229+
profiler_device_speedup = (
230+
eager_profiler_device_ms / compiled_profiler_device_ms
231+
)
232+
222233
if e2e_speedup > 0:
223234
print_with_log_prompt("[Speedup][e2e]:", f"{e2e_speedup:.5f}", args.log_prompt)
224235

225236
if is_gpu_device(args.device) and gpu_speedup > 0:
226237
print_with_log_prompt("[Speedup][gpu]:", f"{gpu_speedup:.5f}", args.log_prompt)
227238

239+
if is_gpu_device(args.device) and profiler_device_speedup > 0:
240+
print_with_log_prompt(
241+
"[Speedup][profiler_device]:",
242+
f"{profiler_device_speedup:.5f}",
243+
args.log_prompt,
244+
)
245+
228246

229247
def check_type_match(eager_dtypes, compiled_dtypes):
230248
if len(eager_dtypes) != len(compiled_dtypes):

graph_net_bench/torch/test_compiler.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,28 @@ def measure_performance(model_call, args, compiler):
206206
e2e_times.append(duration_box.value)
207207
stats["e2e"] = test_compiler_util.get_timing_stats(e2e_times)
208208

209+
# Profiler device_time measurement (only when enabled and on CUDA)
210+
if args.profiler_device_time and "cuda" in args.device:
211+
profiler_device_times = []
212+
for i in range(args.trials):
213+
with torch.profiler.profile(
214+
activities=[torch.profiler.ProfilerActivity.CUDA],
215+
) as prof:
216+
model_call()
217+
compiler.synchronize()
218+
device_time_ms = (
219+
sum(evt.self_device_time_total for evt in prof.key_averages()) / 1000.0
220+
)
221+
profiler_device_times.append(device_time_ms)
222+
print(
223+
f"Trial {i + 1}: profiler_device={device_time_ms:.5f} ms",
224+
file=sys.stderr,
225+
flush=True,
226+
)
227+
stats["profiler_device"] = test_compiler_util.get_timing_stats(
228+
profiler_device_times
229+
)
230+
209231
return outs, stats
210232

211233

@@ -423,6 +445,7 @@ def test_multi_models(args):
423445
f"--trials {args.trials}",
424446
f"--log-prompt {args.log_prompt}",
425447
f"--config {args.config}",
448+
"--profiler-device-time" if args.profiler_device_time else "",
426449
]
427450
)
428451
try:
@@ -472,6 +495,7 @@ def test_multi_models_with_prefix(args):
472495
f"--trials {args.trials}",
473496
f"--log-prompt {args.log_prompt}",
474497
f"--config {args.config}",
498+
"--profiler-device-time" if args.profiler_device_time else "",
475499
]
476500
)
477501
try:
@@ -558,5 +582,11 @@ def main(args):
558582
default=None,
559583
help="base64 encode configuration json.",
560584
)
585+
parser.add_argument(
586+
"--profiler-device-time",
587+
action="store_true",
588+
default=False,
589+
help="Enable PyTorch Profiler device time measurement (CUDA only)",
590+
)
561591
args = parser.parse_args()
562592
main(args=args)

0 commit comments

Comments
 (0)