Skip to content

Commit f433913

Browse files
hl475facebook-github-bot
authored andcommitted
add more info back to BenchResult (pytorch#21502)
Summary: Pull Request resolved: pytorch#21502 In BenchResult, we keep name, avg_fwd, std_fwd, avg_bwd, and std_bwd. There is no information about the number of each iteration. In this diff, I am adding more info to BenchResult to include the number reported from each iteration. Reviewed By: wanchaol Differential Revision: D15706306 fbshipit-source-id: 3f14be4ba91f1f6da473995783bd7af1d067938d
1 parent d51bd21 commit f433913

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

benchmarks/fastrnns/bench.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
BenchResult = namedtuple('BenchResult', [
14-
'name', 'avg_fwd', 'std_fwd', 'avg_bwd', 'std_bwd',
14+
'name', 'avg_fwd', 'std_fwd', 'info_fwd', 'avg_bwd', 'std_bwd', 'info_bwd',
1515
])
1616

1717

@@ -97,12 +97,13 @@ def train_batch(modeldef):
9797

9898
fwd_times = torch.tensor(fwd_times)
9999
bwd_times = torch.tensor(bwd_times)
100-
101100
return BenchResult(name=name,
102101
avg_fwd=fwd_times.mean().item(),
103102
std_fwd=fwd_times.std().item(),
103+
info_fwd=fwd_times,
104104
avg_bwd=bwd_times.mean().item(),
105-
std_bwd=bwd_times.std().item())
105+
std_bwd=bwd_times.std().item(),
106+
info_bwd=bwd_times)
106107

107108

108109
def print_stderr(*args, **kwargs):
@@ -121,23 +122,22 @@ def print_json_oss_format(results):
121122
print(json.dumps(oss_results))
122123

123124

124-
def print_json_pep_format(num_iters, results):
125+
def print_json_pep_format(results):
125126
# print the AI-PEP format json string for each model
126127
for group_name, group_val in results.items():
127128
for model_name, run_time in group_val.items():
128129
# Output for AI-PEP
129-
print("Caffe2Observer " + json.dumps(
130-
{
131-
"type": "NET",
132-
"metric": group_name + "-" + model_name,
133-
"unit": "ms",
134-
"num_runs": num_iters,
135-
"summary": {
136-
"mean": run_time['avg'],
137-
"stdev": run_time['std']
130+
num_iters = len(run_time['info'])
131+
info = run_time['info'].tolist()
132+
for i in range(num_iters):
133+
print("Caffe2Observer " + json.dumps(
134+
{
135+
"type": "NET",
136+
"metric": group_name + "-" + model_name,
137+
"unit": "ms",
138+
"value": str(info[i])
138139
}
139-
}
140-
))
140+
))
141141

142142

143143
def bench(rnn_runners, group_name, print_json=False, sep=' ', **params):
@@ -147,15 +147,18 @@ def bench(rnn_runners, group_name, print_json=False, sep=' ', **params):
147147
with context():
148148
try:
149149
result = trainbench(name, creator, **params)
150-
print_stderr(pretty_print(result, sep=sep))
150+
# Replace the value of info_fwd and info_bwd to None
151+
result_with_no_info = result._replace(
152+
info_fwd='None', info_bwd='None')
153+
print_stderr(pretty_print(result_with_no_info, sep=sep))
151154
results[name] = result
152155
except Exception as e:
153156
if not print_json:
154157
raise
155158

156159
return {
157-
group_name: {k: {"avg": v.avg_fwd, "std": v.std_fwd} for k, v in results.items()},
158-
group_name + '-backward': {k: {"avg": v.avg_bwd, "std": v.std_bwd} for k, v in results.items()},
160+
group_name: {k: {"avg": v.avg_fwd, "std": v.std_fwd, "info": v.info_fwd} for k, v in results.items()},
161+
group_name + '-backward': {k: {"avg": v.avg_bwd, "std": v.std_bwd, "info": v.info_bwd} for k, v in results.items()},
159162
}
160163

161164

@@ -230,4 +233,4 @@ def bench_group(model_list, bench_name, bench_group, bench_args):
230233
if args.print_json == 'oss':
231234
print_json_oss_format(results)
232235
elif args.print_json == 'pep':
233-
print_json_pep_format(args.nloops, results)
236+
print_json_pep_format(results)

0 commit comments

Comments
 (0)