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

[MXNET-1324] Add NaiveRunGraph to imperative utils #14192

Merged
merged 16 commits into from
Mar 6, 2019

Conversation

junrushao
Copy link
Member

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.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Add a NaiveForward pass.

Comments

  • Since it is only used in dynamic shape, this won't cause performance regression.

@junrushao
Copy link
Member Author

@szha @zheng-da Could you help review? Thanks a lot!

@roywei
Copy link
Member

roywei commented Feb 19, 2019

@mxnet-label-bot add[Backend, pr-awaiting-review]

@marcoabreu marcoabreu added Backend Issues related to the backend of MXNet pr-awaiting-review PR is waiting for code review labels Feb 19, 2019
@junrushao
Copy link
Member Author

@szha Hey I added a unit test for this PR :-)

@vandanavk
Copy link
Contributor

@zheng-da is this PR good to go?

@junrushao
Copy link
Member Author

Rebased to the master because of the dramatic change to TShape.

@junrushao
Copy link
Member Author

junrushao commented Mar 5, 2019

@szha @zheng-da Hey could you do another round of review? It has passed CI.

src/imperative/cached_op.cc Outdated Show resolved Hide resolved
@junrushao
Copy link
Member Author

@szha @zheng-da hey could you guys do another round of review?

@szha szha merged commit 83d2c2d into apache:master Mar 6, 2019
vdantu pushed a commit to vdantu/incubator-mxnet that referenced this pull request Mar 31, 2019
* 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
nswamy pushed a commit that referenced this pull request Apr 5, 2019
* 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,
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why inline?

Copy link
Contributor

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.

@junrushao
Copy link
Member Author

@larroy thanks for asking! So could you elaborate what’s the problem of inline?

@larroy
Copy link
Contributor

larroy commented Jun 13, 2019

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

@larroy
Copy link
Contributor

larroy commented Jun 13, 2019

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.
Copy link
Contributor

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.

Copy link
Member Author

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).

@junrushao
Copy link
Member Author

junrushao commented Jun 14, 2019

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.

I agree. This is part of this proposal by @zheng-da, but I believe it will be super helpful if

  1. the changes are reflected or elaborated in our docs so that the behavior is clearly understood.
  2. suppress the newly added naive run graph pass if other flags (like static_alloc) are on.

haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Backend Issues related to the backend of MXNet pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants