Skip to content

Commit

Permalink
[EXEC/NNVM] Enforce sum order for addto optimization (apache#4093)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored and piiswrong committed Dec 29, 2016
1 parent 22f3ce9 commit e7a2735
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/executor/graph_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ nnvm::NodeEntry AggregateGradient(std::vector<nnvm::NodeEntry>&& v) {
// use a stream line of plus instead
nnvm::NodeEntry ret = v[0];
for (size_t i = 1; i < v.size(); ++i) {
// Add control flow dependency from to previous node
// This enforces the gradient sum order will be in the inverse
// order of forward traversal
// NOTE: adding control dependency can be dangerous and cause cycle in the dep.
// The curent usage is correct, because of the following invariant:
// assert: v[i-1] do not depend on v[i]
// To put in plain text: v is gradient vector that get pushed in the order
// that can generate them, which means if v[i] is not yet pushed,
// all previous gradient cannot depend on it.
v[i].node->control_deps.push_back(ret.node);

std::ostringstream os;
os << "sum_grad_" << i;
nnvm::NodePtr x = nnvm::Node::Create();
Expand Down

0 comments on commit e7a2735

Please sign in to comment.