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

Bug with arange inside a foreach #14983

Open
matteosal opened this issue May 17, 2019 · 6 comments
Open

Bug with arange inside a foreach #14983

matteosal opened this issue May 17, 2019 · 6 comments
Labels

Comments

@matteosal
Copy link
Contributor

symbol.zip

Download+extract the attached json and run this script:

import mxnet as mx

sym = mx.symbol.load('/path/to/symbol.json')
args = {
	".Inputs.Input": mx.nd.zeros([1, 1, 2]),
	".States.Element": mx.nd.zeros([1]),
	"zeroarray0": mx.nd.zeros([1]),
	".Inputs.Position": mx.nd.zeros([1, 1]),
	"fixedarray:.Parameters.Net.Nodes.2:Limit": mx.nd.zeros([1]),
}
ex = sym.bind(mx.cpu(), args=args)
outputs = ex.forward()
print(outputs)

It fails with the following error:

mxnet.base.MXNetError: [15:37:57] src/imperative/./imperative_utils.h:145: Operator _arange inferring shapes failed.
input shapes:
output shapes:
None
operator attributes:
start : 0
dtype : float32
infer_range : true

This example stopped working at this commit: 83d2c2d

Before that, it was producing the expected result:

[
[[0.]]
<NDArray 1x1 @cpu(0)>, 
[0.]
<NDArray 1 @cpu(0)>]

@sbodenstein

@mxnet-label-bot
Copy link
Contributor

Hey, this is the MXNet Label Bot.
Thank you for submitting the issue! I will try and suggest some labels so that the appropriate MXNet community members can help resolve it.
Here are my recommended labels: Bug

@szha szha added the Bug label May 17, 2019
@junrushao
Copy link
Member

Thanks for raising this! I am not super familiar with the arange operator, but through the error message, I saw its attributes like "start = 0, infer_range = true". I got a little bit confused so would love to confirm with you...Is it indicating that it is trying to generate [0, 0)?

Thank you so much!

@matteosal
Copy link
Contributor Author

matteosal commented May 18, 2019

Thanks for raising this! I am not super familiar with the arange operator, but through the error message, I saw its attributes like "start = 0, infer_range = true". I got a little bit confused so would love to confirm with you...Is it indicating that it is trying to generate [0, 0)?

Thank you so much!

Thanks for answering.
No, it means it is inferring the end of the interval from its output size, that is the input size of the node it's attached to: operator elemwise_add named .Parameters.Net.Nodes.2$8. So arange should generate [0, n), where n is the input length of .Parameters.Net.Nodes.2$8.
That should, in turn, infer its input shape from the output of the broadcast_like op named .Parameters.Net.Nodes.2$7, but apparently something is going wrong in the process.

@junrushao
Copy link
Member

I see. A known limitation for dynamic shape operators is that it does not support reverse shape inference, and control flow operators are now assumed to be dynamic shape operators.

@matteosal
Copy link
Contributor Author

Ok, so is this to be considered a bug or a feature no more supported? In case it's something intended to work, can you give a time estimate for the fix to happen? Thanks

@aaronmarkham aaronmarkham assigned reminisce and unassigned reminisce May 24, 2019
@leezu
Copy link
Contributor

leezu commented Aug 23, 2019

You may be able to use the following workaround to work around the lack of reverse shape inference

            zeros = F.zeros_like(inputs)
            arange = F.arange(start=0, repeat=1, step=1, infer_range=True, dtype='int32')
            arange = F.elemwise_add(arange, zeros)

https://github.com/dmlc/gluon-nlp/blob/a9eb2fd38180b5affbd30ec78f33f6ef16ef9c20/src/gluonnlp/model/bert.py#L497-L499

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants