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

[OpPerf] Fixes the issue when you pass NDArray to run_perf_test #17508

Merged
merged 2 commits into from
Feb 4, 2020

Conversation

ChaiBapchya
Copy link
Contributor

@ChaiBapchya ChaiBapchya commented Feb 2, 2020

Description

Upon running run_performance_test, user can input shape (as tuple) or NDArray directly in parameters that need NDArray.

Internally, opperf creates an NDArray if user has given shape as input. (default initializer is random_normal)

Now, when I pass an NDArray to run_perf_test follow issues occur

  1. Fix typeError in isinstance check for NDArray
    It errors out
run_performance_test(nd.gather_nd, inputs=[{"data": (2, 22), "indices":nd.random_uniform(low=0,high=1,shape=(1,2))}], run_backward=T
rue, warmup=1, runs=1)
TypeError: isinstance() arg 2 must be a type or tuple of types

The issue is at this line
elif isinstance(in_tensor, mx.ndarray):

It should check for nd.NDArray and not mx.ndarray

  1. subsequently, as_in_context doesn't take keyword argument. Fixed that by removing 'ctx='

Test

run_performance_test(nd.gather_nd, inputs=[{"data": (2, 22), "indices":nd.random_uniform(low=0,high=1,shape=(1,2))}], run_backward=True, warmup=1, runs=1)
INFO:root:Begin Benchmark - gather_nd
INFO:root:Complete Benchmark - gather_nd
[{'gather_nd': [{'avg_time_forward_gather_nd': 0.099, 'avg_time_backward_gather_nd': 0.048, 'max_storage_mem_alloc_cpu/0': 0.09, 'inputs': {'data': (2, 22), 'indices':
[[0.5488135 0.5928446]]
<NDArray 1x2 @cpu(0)>}}]}]

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Code is well-documented:
  • To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Fixes the issue when you pass NDArray to the opperf. It errors out 
```
run_performance_test(nd.gather_nd, inputs=[{"data": (2, 22), "indices":nd.random_uniform(low=0,high=1,shape=(1,2))}], run_backward=T
rue, warmup=1, runs=1)
TypeError: isinstance() arg 2 must be a type or tuple of types
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/incubator-mxnet/benchmark/opperf/utils/benchmark_utils.py", line 133, in run_performance_test
    args_list, kwargs_list = _prepare_op_inputs(inputs, run_backward, dtype, ctx)
  File "/home/ubuntu/incubator-mxnet/benchmark/opperf/utils/benchmark_utils.py", line 50, in _prepare_op_inputs
    attach_grad=run_backward)
  File "/home/ubuntu/incubator-mxnet/benchmark/opperf/utils/ndarray_utils.py", line 120, in get_mx_ndarray
    tensor = in_tensor.as_in_context(ctx=ctx).astype(dtype=dtype)
TypeError: as_in_context() got an unexpected keyword argument 'ctx'
Copy link
Contributor

@connorgoggins connorgoggins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice fix :)

@ChaiBapchya
Copy link
Contributor Author

@mxnet-label-bot add [pr-awaiting-review]

@lanking520 lanking520 added the pr-awaiting-review PR is waiting for code review label Feb 4, 2020
@apeforest apeforest merged commit c95631c into apache:master Feb 4, 2020
@ChaiBapchya ChaiBapchya deleted the patch-1 branch February 14, 2020 23:25
zheyuye pushed a commit to zheyuye/incubator-mxnet that referenced this pull request Feb 19, 2020
…he#17508)

* Fix typeError

Fixes the issue when you pass NDArray to the opperf. It errors out 
```
run_performance_test(nd.gather_nd, inputs=[{"data": (2, 22), "indices":nd.random_uniform(low=0,high=1,shape=(1,2))}], run_backward=T
rue, warmup=1, runs=1)
TypeError: isinstance() arg 2 must be a type or tuple of types
```

* Fix unexpected keyword argument 'ctx' error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/incubator-mxnet/benchmark/opperf/utils/benchmark_utils.py", line 133, in run_performance_test
    args_list, kwargs_list = _prepare_op_inputs(inputs, run_backward, dtype, ctx)
  File "/home/ubuntu/incubator-mxnet/benchmark/opperf/utils/benchmark_utils.py", line 50, in _prepare_op_inputs
    attach_grad=run_backward)
  File "/home/ubuntu/incubator-mxnet/benchmark/opperf/utils/ndarray_utils.py", line 120, in get_mx_ndarray
    tensor = in_tensor.as_in_context(ctx=ctx).astype(dtype=dtype)
TypeError: as_in_context() got an unexpected keyword argument 'ctx'
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants