-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1215] Allow dynamic shape exists in imperative mode #13283
Conversation
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.
Test should be added as well. Overall good approach!
* \param dtype data type of this ndarray | ||
*/ | ||
explicit NDArray(Context ctx, int dtype = mshadow::default_type_flag) { | ||
ptr_ = std::make_shared<Chunk>(TShape(mshadow::Shape1(0)), ctx, true, dtype); |
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.
Why not lazily create Chunk when NDArray::Init() is called? Then we don't need to add Chunk::Init() function.
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.
@zheng-da Do you have any specific consideration about this? I am not sure
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.
Because TShape(mshadow::Shape1(0)) doesn't mean no shape. It may confuse other developer, and also cause Chunk shape mismatch with NDArray, which may have potential risk.
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.
The main reason we want to create a chunk here is to create the var in the chunk. Originally, I wanted to allow async execution. Now we only allow sync execution in the imperative mode. We probably don't need to create a chunk here.
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.
Why this PR is merged without approve? I guess this comment isn't addressed. @junrushao1994 @zheng-da @szha
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.
@ZhennanQin Sorry I was too hurry. Personally, I think it is okay just to leave it 0-d for now. In the long term, we could support 0-d tensors in a more systematic approach.
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.
@ZhennanQin we discussed it and think it's ok to use 0-dim tensor for now. Actually, we are using 0-dim shape when the shape is unknown in other places, so it should be fine.
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.
it's true that we should have commented it here as well.
@mxnet-label-bot add [pr-awaiting-review] |
Have updated according to @zheng-da's comments |
I think we are ready to merge this PR. @zheng-da |
We merge this PR per our discussion both online and offline, and are aware of the 0-d tensor introduced in this PR. We sincerely thank @ZhennanQin for the very helpful and exemplary comments! |
The explanation is OK for me. But it's better to post your offline discussion result in this page before merge, then external reviewer can get involved. Thanks. |
@ZhennanQin I agree with every word of your comment. It is completely my fault pushing this PR too hard, mainly because I don't want to block upcoming work. I will definitely behave next time. |
Description
It is the PR I took over from @zheng-da at #12400. All credits go to Da Zheng.
This PR relaxes the constraint on NDArrays that shape used to be pre-determined. For unittesting, this PR introduces an operator called
BooleanMask
in contrib, which is a practical use case that actually produces dynamic shape. Note that the support for boolean mask is very experimental, which only allows 2-d inputs, and 1-d mask, because it serves only the functionality of testing. We could improve its better in future PRs.This is an initial step for the roadmap #12732.
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments
No comments.
TODO