Commit 00f8165c by Eric Junyuan Xie Committed by Tianqi Chen

add additional field into node for autograd (#145)

* add additional field into node for autograd

* check inputs reachable

* fix
parent ae70a6eb
......@@ -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 */
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment