This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Fix reshape to add in-place back#14903
Merged
Merged
Conversation
…to fix-reshape
…to fix-reshape
…to fix-reshape
…to fix-reshape
Contributor
|
@TaoLv please share the performance data too |
Member
Author
|
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. |
Contributor
|
@mxnet-label-bot add [pr-awaiting-review, MKLDNN] @mseth10 for review |
| prims_.push_back(mkldnn::reorder(*data_, *temp_)); | ||
| prims_.push_back(mkldnn::reorder(*temp_, *out_)); | ||
| needInvalidateInput = true; | ||
| } |
Contributor
There was a problem hiding this comment.
what's the situation of else?
pengzhao-intel
approved these changes
May 9, 2019
Contributor
pengzhao-intel
left a comment
There was a problem hiding this comment.
Thanks for the explanations. Will merge the PR after CI pass.
Contributor
|
The PR is verified internally with performance and accuracy. |
haohuanw
pushed a commit
to haohuanw/incubator-mxnet
that referenced
this pull request
Jun 23, 2019
* fix reshape * save * fix reshape * clean code * fix memory allocation & lint * add unit test * req type * add comments to describe the logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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