From 50221b6d2c515c4c7a4156cf4a2f02c50fc50973 Mon Sep 17 00:00:00 2001 From: Shweta Salaria Date: Tue, 17 Nov 2020 02:16:57 +0900 Subject: [PATCH 1/4] parse conv2d params --- benchmarker/__main__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/benchmarker/__main__.py b/benchmarker/__main__.py index 519bf496..aa2e1141 100644 --- a/benchmarker/__main__.py +++ b/benchmarker/__main__.py @@ -4,6 +4,7 @@ import json import os import sys +import re from benchmarker import fapp from benchmarker.nvprof import get_nvprof_counters @@ -37,6 +38,25 @@ def run_cmd_and_get_output(command): result = filter_json_from_output(process_out) return result +def parse_dict(profile_dict): + for key,value in profile_dict.items(): + if isinstance(value, dict): + parse_dict(value) + else: + if key == "param": + # Split strings with multiple delimiters + sep_list = re.split(',|\(|\)|\=|\ ', value) + if "Conv2d" in sep_list: + params = {} + params["name"] = sep_list[0] + params["in_channels"] = sep_list[1] + params["out_channels"] = sep_list[3] + for param_name in ["kernel_size", "stride", "padding"]: + if param_name in sep_list: + index = sep_list.index("kernel_size") + params[param_name] = sep_list[index+2] + profile_dict[key] = params + def main(): parser = argparse.ArgumentParser(description="Benchmark me up, Scotty!") parser.add_argument("--flops", action="store_true") @@ -73,6 +93,7 @@ def main(): result["profile_pytorch"] = True result["profile_data"] = profile_result["profile_data"] result["path_out"] = "./logs/profile" + parse_dict(result["profile_data"]) cute_device = get_cute_device_str(result["device"]).replace(" ", "_") result["path_out"] = os.path.join(result["path_out"], result["problem"]["name"]) From bda7cc57f5ce42fa793f1a080cfeae0754e4878d Mon Sep 17 00:00:00 2001 From: Shweta Salaria Date: Tue, 1 Dec 2020 14:35:14 +0900 Subject: [PATCH 2/4] set record_shapes=True and pass it to profiler --- benchmarker/modules/torchprof.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmarker/modules/torchprof.py b/benchmarker/modules/torchprof.py index 15c83af9..783488cb 100644 --- a/benchmarker/modules/torchprof.py +++ b/benchmarker/modules/torchprof.py @@ -6,8 +6,7 @@ from collections import namedtuple, defaultdict, OrderedDict Trace = namedtuple("Trace", ["path", "leaf", "module"]) -Measure = namedtuple("Measure", ["self_cpu_total", "cpu_total", "cuda_total", "occurrences", "param"]) -#Measure = namedtuple("Measure", ["self_cpu_total", "cpu_total", "cuda_total", "occurrences"]) +Measure = namedtuple("Measure", ["self_cpu_total", "cpu_total", "cuda_total", "occurrences", "param", "input_shape"]) def walk_modules(module, name="", path=()): """Generator. Walks through a PyTorch Module and outputs Trace tuples""" @@ -73,7 +72,7 @@ def _hook_trace(self, trace): @functools.wraps(_forward) def wrap_forward(*args, **kwargs): - with tprofiler.profile(use_cuda=self.use_cuda) as prof: + with tprofiler.profile(use_cuda=self.use_cuda,record_shapes=True) as prof: res = _forward(*args, **kwargs) event_list = prof.function_events event_list.populate_cpu_children() @@ -124,7 +123,6 @@ def traces_to_display(traces, trace_events, show_events=False, paths=None): current_tree = tree # unwrap all of the events, in case model is called multiple times events = [te for tevents in trace_events[path] for te in tevents] - #print(path) for depth, name in enumerate(path, 1): if name not in current_tree: current_tree[name] = OrderedDict() @@ -140,7 +138,8 @@ def traces_to_display(traces, trace_events, show_events=False, paths=None): sum([e.cpu_time_total for e in events if e.name == event.name]), sum([e.cuda_time_total for e in events if e.name == event.name]), len([e for e in events if e.name == event.name]), - str(module) + str(module), + event.input_shapes )._asdict() } else: @@ -149,7 +148,8 @@ def traces_to_display(traces, trace_events, show_events=False, paths=None): sum([e.cpu_time_total for e in events]), sum([e.cuda_time_total for e in events]), len(trace_events[path]), - str(module) + str(module), + [e.input_shapes for e in events][0] )._asdict() current_tree = current_tree[name] return tree From ceeec51f20caaac6f93e309018ee154b60a105c6 Mon Sep 17 00:00:00 2001 From: Shweta Salaria Date: Tue, 8 Dec 2020 10:05:12 +0900 Subject: [PATCH 3/4] cleanup --- benchmarker/__main__.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/benchmarker/__main__.py b/benchmarker/__main__.py index aa2e1141..d3231839 100644 --- a/benchmarker/__main__.py +++ b/benchmarker/__main__.py @@ -42,20 +42,18 @@ def parse_dict(profile_dict): for key,value in profile_dict.items(): if isinstance(value, dict): parse_dict(value) - else: - if key == "param": - # Split strings with multiple delimiters - sep_list = re.split(',|\(|\)|\=|\ ', value) - if "Conv2d" in sep_list: - params = {} - params["name"] = sep_list[0] - params["in_channels"] = sep_list[1] - params["out_channels"] = sep_list[3] - for param_name in ["kernel_size", "stride", "padding"]: - if param_name in sep_list: - index = sep_list.index("kernel_size") - params[param_name] = sep_list[index+2] - profile_dict[key] = params + elif key == "param": + params = {} + if "Linear" in value: + params["name"] = "fc" + else: + params["name"] = value.split('(')[0].lower() + params["args"] = value + profile_dict[key] = params + + for key,value in profile_dict.items(): + if key == "null" and isinstance(value["param"],dict): + profile_dict[value["param"]["name"]] = profile_dict.pop(key) def main(): parser = argparse.ArgumentParser(description="Benchmark me up, Scotty!") From 2c366f78503dab11d2f7ed7eddad0571dc92cda4 Mon Sep 17 00:00:00 2001 From: Shweta Salaria Date: Tue, 8 Dec 2020 10:09:12 +0900 Subject: [PATCH 4/4] remove unused import package --- benchmarker/__main__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/benchmarker/__main__.py b/benchmarker/__main__.py index d3231839..cb5b77ce 100644 --- a/benchmarker/__main__.py +++ b/benchmarker/__main__.py @@ -4,7 +4,6 @@ import json import os import sys -import re from benchmarker import fapp from benchmarker.nvprof import get_nvprof_counters