Skip to content

Commit

Permalink
add additional field into node for autograd (dmlc#145)
Browse files Browse the repository at this point in the history
* add additional field into node for autograd

* check inputs reachable

* fix
  • Loading branch information
piiswrong authored Sep 2, 2017
1 parent bbfcfb6 commit 3890c77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/nnvm/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class Node {
* Gives operation must be performed before this operation.
*/
std::vector<NodePtr> control_deps;
/*! \brief additional fields for this node */
any info;
/*! \brief destructor of node */
~Node();
/*! \return operator in this node */
Expand Down
7 changes: 7 additions & 0 deletions src/pass/gradient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ Graph Gradient(Graph src) {
output_grads[ys[i].node.get()][ys[i].index].grads = { ograd };
}

// Check that all xs are reachable from ys
for (size_t i = 0; i < xs.size(); ++i) {
CHECK(output_grads.find(xs[i].node.get()) != output_grads.end())
<< "Cannot differentiate with respect to the " << i+1 << "-th variable "
<< "because it is unreachable from the outputs.";
}

// construct mirror reduece memory strategy if needed
std::unordered_map<Node*, NodePtr> mirror_map;
if (mirror_fun != nullptr) {
Expand Down

0 comments on commit 3890c77

Please sign in to comment.