mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 13:44:15 +08:00
Add simple add op based framework overhead benchmark. (#23076)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23076 Tracing based and non tracing based added Reviewed By: mingzhe09088 Differential Revision: D16097280 fbshipit-source-id: 3a137092f7ccc3dd2d29d95e10178ec89d3ce892
This commit is contained in:
committed by
Facebook Github Bot
parent
4223e2f9e9
commit
0621068cdc
25
benchmarks/framework_overhead_benchmark/utils.py
Normal file
25
benchmarks/framework_overhead_benchmark/utils.py
Normal file
@ -0,0 +1,25 @@
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
import time
|
||||
from collections import namedtuple
|
||||
|
||||
NUM_PT_LOOP_ITERS = 1000
|
||||
BenchmarkConfig = namedtuple('BenchmarkConfig', 'num_warmup_iters num_iters')
|
||||
ModuleConfig = namedtuple('ModuleConfig', 'pt_fn num_params graph_mode')
|
||||
|
||||
def ms_to_us(time_ms):
|
||||
return (time_ms * 1e3)
|
||||
|
||||
def secs_to_us(time_s):
|
||||
return (time_s * 1e6)
|
||||
|
||||
def secs_to_ms(time_s):
|
||||
return (time_s * 1e3)
|
||||
|
||||
def benchmark_module(config, module):
|
||||
module.forward(config.num_warmup_iters)
|
||||
print("Running module for {} iterations".format(config.num_iters))
|
||||
start = time.time()
|
||||
module.forward(config.num_iters)
|
||||
end = time.time()
|
||||
time_elapsed_s = (end - start)
|
||||
return (secs_to_ms(time_elapsed_s) / config.num_iters / NUM_PT_LOOP_ITERS)
|
Reference in New Issue
Block a user