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

[DO NOT REVIEW] Subgraph API #12104

Merged
merged 14 commits into from
Aug 14, 2018
Merged

[DO NOT REVIEW] Subgraph API #12104

merged 14 commits into from
Aug 14, 2018

Conversation

reminisce
Copy link
Contributor

@reminisce reminisce commented Aug 9, 2018

Description

Incremental change to the dev branch. Not ready for review.

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

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

const std::string& prop_name,
const nnvm::ShapeVector& arg_shapes,
const nnvm::DTypeVector& arg_dtypes,
const StorageTypeVector arg_stypes,
Copy link
Contributor

Choose a reason for hiding this comment

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

use reference for arg_stypes.

@@ -398,17 +398,17 @@ void FindSubgraphs(Graph* g,
return indexed_graph.node_id(node1) < indexed_graph.node_id(node2);
};
size_t subgraph_id = 0;
auto subgraph_selector = subg_prop.CreateSubgraphSelector();
Copy link
Contributor

Choose a reason for hiding this comment

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

a selector should be created for each node. It's stateful.

g.outputs = ret.outputs;
g = InferForwardAttrs(g, arg_shapes, arg_dtypes, arg_stypes, default_ctx,
ctx_map, in_arg_ctxes, aux_state_ctxes);
subgraph_prop->SetAttr("graph", g);
Copy link
Contributor

Choose a reason for hiding this comment

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

This interface doesn't allow customizing g. I think it's better to provide an interface such as set_graph and allow the child class to override this virtual method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this can be done in CreateSubgraphSelector()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Subgraph selector is created by each node. I feel it's more intuitive to customize g somewhere subgraph property is created.

@ZhennanQin
Copy link
Contributor

Can this change cover hybridize gluon model? I don't see the change in cached_op.

@@ -1718,6 +1860,11 @@ Executor *Executor::SimpleBind(nnvm::Symbol symbol,
std::unordered_map<std::string, NDArray>* shared_buffer,
Executor* shared_exec) {
auto exec = new exec::GraphExecutor();
if (!exec->subgraph_property().empty()) {
symbol = exec::PartitionGraph(symbol, exec->subgraph_property(), arg_shape_map, arg_dtype_map,
Copy link
Contributor

Choose a reason for hiding this comment

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

Many subgraph pass can only be used on inference, eg. default_subgraph_op doesn't have FGradient attribute and can't support backward computation. Maybe default_subgraph_op will support backward in future, but some mkldnn fusion pass is designed to be used in inference only. Shall we allow subgraph_property to describe if it's inference only and apply it as it requires?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it necessary to indicate whether a subgraph property is for inference only or not?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's also my question. We indeed have some fusion passes only for inference, we need a way to disable it on training. If we can't describe this in subgraph property, then we need to find another way to indicate that.

@ZhennanQin
Copy link
Contributor

Another question: what's the sequence should we execute below 2 kinds of subgraph pass:

  1. the pass to cover all operators that backends support.(just like default_subgraph_op)
  2. Fusion pass to combine several ops into a new ops.

I'm asking this is because, if we want to apply 2 after 1, then we need to have the ability to traverse into subgraph node to do fusion. Do we support this?

@reminisce
Copy link
Contributor Author

@ZhennanQin CachedOp will be submitted through a another PR. We want to make this PR as small as possible.

I think what you described about fusion can be done in graph partitioning as well. In CreateSubgraphNode(), you can replace the subgraph symbol with a new subgraph symbol consisting of fused operators. Does this make sense?

@ZhennanQin
Copy link
Contributor

@reminisce Then we need to call PartitionGraph() inside CreateSubgraphNode() to traverse nodes, otherwise we have to implement a separate traverse method. If that meet your expectation, then I'm OK with this solution.

@reminisce
Copy link
Contributor Author

@ZhennanQin Yes, I fine with that.

@reminisce reminisce requested a review from szha as a code owner August 10, 2018 22:48
@szha szha removed their request for review August 11, 2018 18:46

#define MXNET_REGISTER_SUBGRAPH_PROPERTY(Name, SubgraphPropertyType) \
static DMLC_ATTRIBUTE_UNUSED auto __make_ ## SubgraphPropertyType ## _ ## Name ## __ = \
SubgraphPropertyRegistry::Get()->__REGISTER__(#Name, &SubgraphPropertyType::Create);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove ";" here.

}
};

MXNET_REGISTER_SUBGRAPH_PROPERTY(default, DefaultSubgraphProperty)
Copy link
Contributor

Choose a reason for hiding this comment

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

add a ";" at the end.

@reminisce reminisce merged commit 4c1933e into apache:subgraph Aug 14, 2018
reminisce added a commit to reminisce/mxnet that referenced this pull request Aug 14, 2018
Graph partitioner and subgraph op

Fix duplicate entry bugs (apache#11767)

Make subgraph var node name unique (apache#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (apache#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (apache#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky
reminisce added a commit to reminisce/mxnet that referenced this pull request Aug 21, 2018
Graph partitioner and subgraph op

Fix duplicate entry bugs (apache#11767)

Make subgraph var node name unique (apache#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (apache#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (apache#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky
reminisce added a commit to reminisce/mxnet that referenced this pull request Aug 23, 2018
Graph partitioner and subgraph op

Fix duplicate entry bugs (apache#11767)

Make subgraph var node name unique (apache#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (apache#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (apache#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky
reminisce added a commit to reminisce/mxnet that referenced this pull request Aug 24, 2018
Graph partitioner and subgraph op

Fix duplicate entry bugs (apache#11767)

Make subgraph var node name unique (apache#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (apache#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (apache#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky
reminisce added a commit to reminisce/mxnet that referenced this pull request Aug 28, 2018
Graph partitioner and subgraph op

Fix duplicate entry bugs (apache#11767)

Make subgraph var node name unique (apache#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (apache#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (apache#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky
reminisce added a commit to reminisce/mxnet that referenced this pull request Aug 29, 2018
Graph partitioner and subgraph op

Fix duplicate entry bugs (apache#11767)

Make subgraph var node name unique (apache#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (apache#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (apache#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky
eric-haibin-lin pushed a commit that referenced this pull request Aug 31, 2018
* Graph partitioner and subgraph op (#11251)

Graph partitioner and subgraph op

Fix duplicate entry bugs (#11767)

Make subgraph var node name unique (#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky

* Clean up

* Clean up

* Clean up

* Change version return type in NDArray

* Clean up

* Add register or get for subgraph prop registry

* Address cr

* Remove unnecessary code

* Handle var version issue in naive engine

* Delete example

* Remove registration of resource request for default subgraph op

* Add doc string

* Improve doc string
aaronmarkham pushed a commit to aaronmarkham/incubator-mxnet that referenced this pull request Sep 11, 2018
* Graph partitioner and subgraph op (apache#11251)

Graph partitioner and subgraph op

Fix duplicate entry bugs (apache#11767)

Make subgraph var node name unique (apache#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (apache#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (apache#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky

* Clean up

* Clean up

* Clean up

* Change version return type in NDArray

* Clean up

* Add register or get for subgraph prop registry

* Address cr

* Remove unnecessary code

* Handle var version issue in naive engine

* Delete example

* Remove registration of resource request for default subgraph op

* Add doc string

* Improve doc string
anirudh2290 pushed a commit to anirudh2290/mxnet that referenced this pull request Sep 19, 2018
* Graph partitioner and subgraph op (apache#11251)

Graph partitioner and subgraph op

Fix duplicate entry bugs (apache#11767)

Make subgraph var node name unique (apache#11876)

[DO NOT REVIEW] Fix bug of eliminating cycles (apache#11907)

* Fix cycle bug

* Fix decycle bug

* Fix comment

[DO NOT REVIEW] Subgraph API (apache#12104)

* Initial commit

* Add unit tests

* Fix lint

* Fix lint

* Clean up

* Add graph partitiong to Bind

* Add property name to graph partitioning c api

* Fix unit test gpu context

* Address cr

* Move subgraph to attrs.subgraphs and fix the example

* Fix lint

* Add var version unit test

* Address cr

* Enable unit test that was flaky

* Clean up

* Clean up

* Clean up

* Change version return type in NDArray

* Clean up

* Add register or get for subgraph prop registry

* Address cr

* Remove unnecessary code

* Handle var version issue in naive engine

* Delete example

* Remove registration of resource request for default subgraph op

* Add doc string

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

Successfully merging this pull request may close these issues.

3 participants