Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

Pass a graph symbol to an operator #430

Closed
wants to merge 8 commits into from
Closed

Conversation

zheng-da
Copy link

@zheng-da zheng-da commented Apr 7, 2018

This PR allows an operator to accept a graph symbol as input. The input graph will be stored inside the corresponding node.

@yzhliu
Copy link
Member

yzhliu commented Apr 7, 2018

what is the use-case?

@zheng-da
Copy link
Author

zheng-da commented Apr 7, 2018

This is for implementing a control flow operator in MXNet. Please see apache/mxnet#10451 as an example.

I think this functionality is useful in general. If we want to implement a high-order function like the ones in tensorflow, we also need to pass a subgraph to an operator.

@@ -80,6 +82,7 @@ struct NodeAttrs {
* For place holder variable, op == nullptr.
*/
const Op *op{nullptr};
std::shared_ptr<Graph> g;
Copy link
Member

Choose a reason for hiding this comment

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

put this to the end of the current NodeAttrs

Copy link
Member

Choose a reason for hiding this comment

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

add comments, the field name g is a bit too generic. Need to comment on what is the semantics here, is it just an attribute so that we can use to to compose a high order AST, or something else

@@ -176,6 +176,8 @@ using FSetInputVarAttrOnCompose = std::function<void(
NodePtr var,
const int index)>;

using FInputGraph = std::function<uint32_t(const NodeAttrs& attrs)>;
Copy link
Member

Choose a reason for hiding this comment

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

document what it is

// compositional logic
void Symbol::Compose(const array_view<const Symbol*>& args,
const std::unordered_map<std::string, const Symbol*>& kwargs,
const std::string& name) {
static auto& flist_inputs = Op::GetAttr<FListInputNames>("FListInputNames");
static auto& fset_attrs = Op::GetAttr<FSetInputVarAttrOnCompose>("FSetInputVarAttrOnCompose");
static auto& fgraph = Op::GetAttr<FInputGraph>("FInputGraph");

Node* n = outputs[0].node.get();
Copy link
Member

Choose a reason for hiding this comment

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

comment the behavior on what is expected when a node contains input graph.

@zheng-da
Copy link
Author

@tqchen Does the PR look OK? Should I add more tests? Do you have any suggestions on how to move forward? Thanks

@tqchen
Copy link
Member

tqchen commented Apr 15, 2018

cc @piiswrong can you also do a review?

* mini-batches. In this sense, the subgraphs are kind of similar to
* the parameters and show be kept as node attributes.
*/
std::vector<std::shared_ptr<Graph> > subgraphs;
Copy link
Member

Choose a reason for hiding this comment

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

why shared ptr?

for (size_t i = 0; i < gidx.num_nodes(); ++i) {
for (const auto& j : gidx[i].inputs) ++ref_count[gidx.entry_id(j)];
}
g->attrs["forward_ref_count"] = std::make_shared<dmlc::any>(std::move(ref_count));
Copy link
Member

Choose a reason for hiding this comment

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

dont do this here

@tqchen
Copy link
Member

tqchen commented May 16, 2018

@piiswrong any updates on this?

@zheng-da
Copy link
Author

@tqchen @piiswrong suggests that I should test it with everything in MXNet first before merging this PR. I'm almost finishing foreach. I'll run all the tests by the week and run some tests for this PR. After that, can we merge this PR?

@zheng-da
Copy link
Author

@piiswrong @tqchen I have run through all unit tests in mxnet (tests/python/unittest/*). They all work fine. Will this be good enough for merging this PR?

@tqchen
Copy link
Member

tqchen commented May 17, 2018

need to rebase master, and need @piiswrong 's approval

@zheng-da
Copy link
Author

for some reason, CI fails. I tried on my local machine, the tests work fine.
I'm trying to debug with CI directly.

@zheng-da zheng-da force-pushed the input_graph branch 2 times, most recently from 3cbda39 to 9636c9b Compare May 18, 2018 20:48
@zheng-da
Copy link
Author

zheng-da commented May 18, 2018

It seems the CI fails after I add the field of subgraphs in NodeAttrs. Does NNVM do anything special on NodeAttrs? @piiswrong @tqchen

@zheng-da
Copy link
Author

@tqchen after rebase, everything works fine now.

@tqchen
Copy link
Member

tqchen commented May 29, 2018

c.f. #518 we will redirect further changes to tvm repo, please open a new PR there. Please invite the original set of reviewers when the new PR is opened so they can review and approve the changes

@tqchen tqchen closed this May 29, 2018
abergeron pushed a commit to abergeron/nnvm that referenced this pull request May 31, 2018
Fix markdown syntax error (code shifts out of markdown-code box).
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.

4 participants