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

Gluon Reshape does in-place for NDArray and out-of-place for Symbol #17471

Open
gautham-kollu opened this issue Jan 29, 2020 · 3 comments
Open

Comments

@gautham-kollu
Copy link

Description

Gluon Reshape() behaves differently for NDArray and Symbol.
NDArray -> Does the reshape IN-place
Symbol -> Does the reshape Out-of-place

Error Message

(Paste the complete error message. Please also include stack trace by setting environment variable DMLC_LOG_STACK_TRACE_DEPTH=10 before running your script.)

To Reproduce

import mxnet as mx
from mxnet.gluon import nn

class HybridNet(nn.HybridBlock):
def init(self, **kwargs):
super(HybridNet, self).init(**kwargs)

def hybrid_forward(self, F, x):
    y = x.reshape(-1)
    y = F.square(y, out = y)
    return x+y

model = HybridNet()
model.initialize()

x = mx.nd.array([1,2,3])
print(model(x))

model.hybridize()
x = mx.nd.array([1,2,3])
print(model(x))

Running the above on CPU

[ 2. 8. 18.]
<NDArray 3 @cpu(0)>

[ 2. 6. 12.]
<NDArray 3 @cpu(0)>

Steps to reproduce

(Paste the commands you ran that produced the error.)

What have you tried to solve it?

Environment

We recommend using our script for collecting the diagnositc information. Run the following command and paste the outputs below:

curl --retry 10 -s https://raw.githubusercontent.com/dmlc/gluon-nlp/master/tools/diagnose.py | python

# paste outputs here
@gautham-kollu gautham-kollu changed the title Gluon Reshape behaves differently for NDArray and Symbol Gluon Reshape does in-place for NDArray and out-of-place for Symbol Jan 29, 2020
@szha
Copy link
Member

szha commented Jan 30, 2020

In Gluon one should not specify where the output is stored using out= argument. In the future, Gluon should automatically detect and warn (or throw execption) on such case.

cc @leezu

@gautham-kollu
Copy link
Author

Would Gluon not support in-place ops ?

@leezu
Copy link
Contributor

leezu commented Jan 31, 2020

Not when hybridizing. Ideally the framework can optimize the computational plan in the background and decide when in-place can be used.

@leezu leezu added the Gluon label Jan 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants