-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1324] Add NaiveRunGraph to imperative utils #14192
Conversation
@mxnet-label-bot add[Backend, pr-awaiting-review] |
edd748f
to
697d772
Compare
@szha Hey I added a unit test for this PR :-) |
@zheng-da is this PR good to go? |
db50798
to
82e4c37
Compare
Rebased to the master because of the dramatic change to TShape. |
* Add NaiveRunGraph to imperative utils * update * update * Update * Update * Add unittest * Rebase to master * Add something to be consistent with master branch * Retrigger CI * Address comments from Da * Address comments from Sheng * Address * Refactor * Fix lint * Retrigger CI * Retrigger CI
* Add NaiveRunGraph to imperative utils * update * update * Update * Update * Add unittest * Rebase to master * Add something to be consistent with master branch * Retrigger CI * Address comments from Da * Address comments from Sheng * Address * Refactor * Fix lint * Retrigger CI * Retrigger CI
return ndinputs; | ||
} | ||
|
||
inline std::vector<NDArray*> NodeOutputs(const nnvm::IndexedGraph& idx, |
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 inline?
return req; | ||
} | ||
|
||
inline void InvokeOperator(const nnvm::IndexedGraph& idx, |
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 inline?
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.
Also this function should be static or in the anonymous namespace as it's not used outside this unit.
@larroy thanks for asking! So could you elaborate what’s the problem of inline? |
You are inlining a big function, this will cause code bloat at no benefit. Let the compiler do the inline for you in the majority of the cases. I removed the inline anyway so it's no longer in master. See also: #15182 |
Since this commit might cause a regression, I would kindly request if you can elaborate a bit about the differences between running operators one at a time vs the previous behaviour. |
} | ||
// We leverage the shape inference pass to detect whether dynamic shape exists. | ||
// If so, the pass will fail with `contain_dynamic_shape = true`, | ||
// This method is only called once, so the overhead is negligible. |
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.
Were you able to verify this? I'm afraid this could cause slowdown.
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.
If infer shape fails, it means there is probably an op of dynamic shape (np.unique, boolean mask).
MXNet didn't support this kind of op before, because of the limitation of our system. Because of these lines, we now can support it in Gluon blocks.
I would suggest to clearly mention the behavior in our docs that if infer shape fails, the code will go to the slow path (naive run graph, etc).
I agree. This is part of this proposal by @zheng-da, but I believe it will be super helpful if
|
* Add NaiveRunGraph to imperative utils * update * update * Update * Update * Add unittest * Rebase to master * Add something to be consistent with master branch * Retrigger CI * Address comments from Da * Address comments from Sheng * Address * Refactor * Fix lint * Retrigger CI * Retrigger CI
Description
This PR introduces another way of executing a graph,
NaiveRunGraph
, which runs the operators one by another. This is part of effort of enabling dynamic shapes inside a CahcedOp. Since the output shape of operators coundn't be determined ahead of time, we have to run these operators one at a time.Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
NaiveForward
pass.Comments