-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Conversation
@TaoLv please share the performance data too |
I use the code snippet below for benchmarking. Transpose is added before and after reshape operator in order to make it in-placed. import time
import mxnet as mx
from mxnet import Context
data = mx.symbol.Variable('data')
res = mx.symbol.transpose(data=data, axes=(1, 0, 2, 3))
res = mx.symbol.reshape(data=res, shape=(-1, 16, 16, 16))
res = mx.symbol.transpose(data=res, axes=(1, 0, 2, 3))
shape = (64, 4, 16, 16)
exe = res.simple_bind(Context.default_ctx, data=shape, grad_req='null')
tic = 0
for i in range(205):
if i == 5:
mx.profiler.set_config(profile_symbolic=True, profile_imperative=True, profile_api=False, profile_memory=False, aggregate_stats=True, filename='profile_output.json')
mx.profiler.set_state('run')
tic = time.time()
q = exe.forward(is_train=False)
q[0].wait_to_read()
toc = time.time()
print("total time: %f ms " % ((toc - tic) * 1000))
mx.profiler.set_state('stop')
print(mx.profiler.dumps()) With mxnet-mkl==1.5.0b20190506, profile as following:
With this PR, reshape time is reduce from 7.50 ms to 1.73 ms.
|
@mxnet-label-bot add [pr-awaiting-review, MKLDNN] @mseth10 for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments.
prims_.push_back(mkldnn::reorder(*data_, *temp_)); | ||
prims_.push_back(mkldnn::reorder(*temp_, *out_)); | ||
needInvalidateInput = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the situation of else
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanations. Will merge the PR after CI pass.
The PR is verified internally with performance and accuracy. |
* fix reshape * save * fix reshape * clean code * fix memory allocation & lint * add unit test * req type * add comments to describe the logic
Description
Previously in-place option was removed when build with MKL-DNN. It makes reshape operator taking much time in mxnet-mkl package. This PR adds the in-pace option back and uses a temporal buffer for reordering when the input is a MKL-DNN layout.
Besides, this PR also adds a unit test from #14766
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments