Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit c50bfe2

Browse files
ChaiBapchyaroywei
authored andcommitted
[OpPerf] Handle positional arguments (#15761)
* handle args * intermediate, error with getting 2 values for data param for other ops * handle args * None type issue * try * indent fix * lint fix * Trigger notification * Trigger notification bcoz validation/edge passed but shows pending
1 parent 64a0502 commit c50bfe2

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

benchmark/opperf/rules/default_params.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
"""Default Input Tensor shapes to use for benchmarking"""
2727

28+
# For operators like concat, ElementWiseSum, squeeze, stack
29+
# argument data is passed as variable arg (*args)
30+
DEFAULT_ARGS = [(1024, 1024)]
31+
2832
# For Unary operators like abs, arccos, arcsin etc..
2933
DEFAULT_DATA = [(1024, 1024), (10000, 1), (10000, 100)]
3034

@@ -146,7 +150,8 @@
146150
"data_4d": DEFAULT_DATA_4d,
147151
"dim1": DEFAULT_DIM_1,
148152
"dim2": DEFAULT_DIM_2,
149-
"block_size": DEFAULT_BLOCK_SIZE}
153+
"block_size": DEFAULT_BLOCK_SIZE,
154+
"args": DEFAULT_ARGS}
150155

151156

152157
# These are names of MXNet operator parameters that is of type NDArray.
@@ -157,4 +162,5 @@
157162
PARAMS_OF_TYPE_NDARRAY = ["lhs", "rhs", "data", "base", "exp", "sample",
158163
"mu", "sigma", "lam", "alpha", "beta", "gamma", "k", "p",
159164
"low", "high", "weight", "bias", "moving_mean", "moving_var",
160-
"weight", "weight32", "grad", "mean", "var", "mom", "n", "d", "v", "z", "g", "delta"]
165+
"weight", "weight32", "grad", "mean", "var", "mom", "n", "d",
166+
"v", "z", "g", "delta", "args"]

benchmark/opperf/utils/benchmark_utils.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,25 @@
2929

3030
def _prepare_op_inputs(inputs, run_backward, dtype, ctx):
3131
kwargs_list = []
32+
args_list = []
3233

3334
for inp in inputs:
3435
kwargs = {}
3536
for key, value in inp.items():
36-
if key in PARAMS_OF_TYPE_NDARRAY:
37+
if key in PARAMS_OF_TYPE_NDARRAY and key=='args':
38+
args_list.append(get_mx_ndarray(ctx=ctx, in_tensor=value,
39+
dtype=dtype,
40+
initializer=nd.normal,
41+
attach_grad=run_backward))
42+
elif key in PARAMS_OF_TYPE_NDARRAY:
3743
kwargs[key] = get_mx_ndarray(ctx=ctx, in_tensor=value,
3844
dtype=dtype,
3945
initializer=nd.normal,
4046
attach_grad=run_backward)
4147
else:
4248
kwargs[key] = value
4349
kwargs_list.append(kwargs)
44-
45-
return kwargs_list
50+
return args_list, kwargs_list
4651

4752

4853
def _run_nd_operator_performance_test(op, inputs, run_backward, warmup, runs, kwargs_list, profiler):
@@ -60,17 +65,28 @@ def _run_nd_operator_performance_test(op, inputs, run_backward, warmup, runs, kw
6065
raise ValueError("Incorrect input for profiler. Valid input - 'python' or 'native'")
6166

6267
# Warm up, ignore the profiler output
63-
_, _ = benchmark_helper_func(op, warmup, **kwargs_list[0])
68+
if not args_list:
69+
_, _ = benchmark_helper_func(op, warmup, [], **kwargs_list[0])
70+
else:
71+
_, _ = benchmark_helper_func(op, warmup, args_list[0], **kwargs_list[0])
6472

6573
# Run Benchmarks
6674
op_benchmark_result = {op.__name__: []}
6775
logging.info("Begin Benchmark - {name}".format(name=op.__name__))
68-
for idx, kwargs in enumerate(kwargs_list):
69-
_, profiler_output = benchmark_helper_func(op, runs, **kwargs)
76+
if not args_list:
77+
for idx, kwargs in enumerate(kwargs_list):
78+
_, profiler_output = benchmark_helper_func(op, runs, [], **kwargs)
79+
80+
# Add inputs used for profiling this operator into result
81+
profiler_output["inputs"] = inputs[idx]
82+
op_benchmark_result[op.__name__].append(profiler_output)
83+
else:
84+
for idx, (args,kwargs) in enumerate(zip(args_list,kwargs_list)):
85+
_, profiler_output = benchmark_helper_func(op, runs, args, **kwargs)
7086

71-
# Add inputs used for profiling this operator into result
72-
profiler_output["inputs"] = inputs[idx]
73-
op_benchmark_result[op.__name__].append(profiler_output)
87+
# Add inputs used for profiling this operator into result
88+
profiler_output["inputs"] = inputs[idx]
89+
op_benchmark_result[op.__name__].append(profiler_output)
7490
logging.info("Complete Benchmark - {name}".format(name=op.__name__))
7591
return op_benchmark_result
7692

@@ -110,15 +126,15 @@ def run_performance_test(ops, inputs, run_backward=True,
110126
List of dictionary of benchmark results. key -> name of the operator, Value is benchmark results.
111127
112128
"""
113-
kwargs_list = _prepare_op_inputs(inputs, run_backward, dtype, ctx)
129+
args_list, kwargs_list = _prepare_op_inputs(inputs, run_backward, dtype, ctx)
114130

115131
if not isinstance(ops, list):
116132
ops = [ops]
117133

118134
op_benchmark_result = []
119135
for op in ops:
120136
if hasattr(mx.nd, op.__name__):
121-
benchmark_result = _run_nd_operator_performance_test(op, inputs, run_backward, warmup, runs, kwargs_list, profiler)
137+
benchmark_result = _run_nd_operator_performance_test(op, inputs, run_backward, warmup, runs, args_list, kwargs_list, profiler)
122138
else:
123139
raise ValueError("Unknown NDArray operator provided to benchmark. - ", op.__name__)
124140
op_benchmark_result.append(benchmark_result)

benchmark/opperf/utils/ndarray_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def nd_forward_backward_and_profile(op, runs, *args, **kwargs):
4444
"""
4545
for _ in range(runs):
4646
with mx.autograd.record():
47-
res = op(*args, **kwargs)
47+
if not isinstance(args[0],nd.NDArray):
48+
res = op(**kwargs)
49+
else:
50+
res = op(*args, **kwargs)
4851
res.backward()
4952
nd.waitall()
5053
return res
@@ -72,7 +75,10 @@ def nd_forward_and_profile(op, runs, *args, **kwargs):
7275
any results from NDArray operation execution
7376
"""
7477
for _ in range(runs):
75-
res = op(*args, **kwargs)
78+
if not isinstance(args[0],nd.NDArray):
79+
res = op(**kwargs)
80+
else:
81+
res = op(*args, **kwargs)
7682
nd.waitall()
7783
return res
7884

0 commit comments

Comments
 (0)