Skip to content

Commit

Permalink
[TVMC] Runner.py Updates (apache#7779)
Browse files Browse the repository at this point in the history
* change runner to ms instead of s, consider reformatting

* adjust formatting and test in test_runner.py to be more realistic

* change device in run_module runner.py to be mandatory

* make hostname optional in run_module, in runner.py

* update order and doc string

* remove print statement

* black files

* device error lint

* argument order was incorrect

* arguments funkiness attempt fix 2

* Fix merge with main.

Co-authored-by: Jocelyn <[email protected]>
Co-authored-by: Josh Fromm <[email protected]>
Co-authored-by: Josh Fromm <[email protected]>
  • Loading branch information
4 people authored and Trevor Morris committed May 6, 2021
1 parent ebca010 commit bba762f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
35 changes: 18 additions & 17 deletions python/tvm/driver/tvmc/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def drive_run(args):

outputs, times = run_module(
args.FILE,
rpc_hostname,
rpc_port,
args.rpc_key,
args.device,
hostname=rpc_hostname,
port=rpc_port,
rpc_key=args.rpc_key,
inputs=inputs,
device=args.device,
fill_mode=args.fill_mode,
repeat=args.repeat,
profile=args.profile,
Expand Down Expand Up @@ -290,10 +290,10 @@ def make_inputs_dict(shape_dict, dtype_dict, inputs=None, fill_mode="random"):

def run_module(
module_file,
hostname,
device,
hostname=None,
port=9090,
rpc_key=None,
device=None,
inputs=None,
fill_mode="random",
repeat=1,
Expand All @@ -309,16 +309,16 @@ def run_module(
----------
module_file : str
The path to the module file (a .tar file).
hostname : str
device: str,
the device (e.g. "cpu" or "gpu") to be targeted by the RPC
session, local or remote).
hostname : str, optional
The hostname of the target device on which to run.
port : int, optional
The port of the target device on which to run.
rpc_key : str, optional
The tracker key of the target device. If this is set, it
will be assumed that remote points to a tracker.
device: str, optional
the device (e.g. "cpu" or "gpu") to be targeted by the RPC
session, local or remote).
inputs : dict, optional
A dictionary that maps input names to numpy values.
fill_mode : str, optional
Expand Down Expand Up @@ -443,7 +443,7 @@ def format_times(times):
This has the effect of producing a small table that looks like:
Execution time summary:
mean (s) max (s) min (s) std (s)
mean (ms) max (ms) min (ms) std (ms)
0.14310 0.16161 0.12933 0.01004
Parameters
Expand All @@ -458,13 +458,14 @@ def format_times(times):
"""

# timestamps
mean_ts = np.mean(times)
std_ts = np.std(times)
max_ts = np.max(times)
min_ts = np.min(times)
mean_ts = np.mean(times) * 1000
std_ts = np.std(times) * 1000
max_ts = np.max(times) * 1000
min_ts = np.min(times) * 1000

header = "Execution time summary:\n{0:^10} {1:^10} {2:^10} {3:^10}".format(
"mean (s)", "max (s)", "min (s)", "std (s)"
"mean (ms)", "max (ms)", "min (ms)", "std (ms)"
)
stats = "{0:^10.5f} {1:^10.5f} {2:^10.5f} {3:^10.5f}".format(mean_ts, max_ts, min_ts, std_ts)
stats = "{0:^10.2f} {1:^10.2f} {2:^10.2f} {3:^10.2f}".format(mean_ts, max_ts, min_ts, std_ts)

return "%s\n%s\n" % (header, stats)
4 changes: 2 additions & 2 deletions tests/python/driver/tvmc/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def test_generate_tensor_data__type_unknown():


def test_format_times__contains_header():
sut = tvmc.runner.format_times([60, 120, 12, 42])
assert "std (s)" in sut
sut = tvmc.runner.format_times([0.6, 1.2, 0.12, 0.42])
assert "std (ms)" in sut


def test_get_top_results_keep_results():
Expand Down

0 comments on commit bba762f

Please sign in to comment.