Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions paddle/fluid/imperative/basic_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,13 @@ void BasicEngine::Execute() {
"Cannot find gradient of variable %s", var->Name()));
}

// leaf_accumulators_ : hooks and accumulate-grad for leaf tensor
// leaf_accumulators_ : hooks and accumulate-grad for leaf tensor,
// it should be orderly and not reapeated.
if (var->IsLeafGrad()) {
leaf_accumulators_.insert(iter->second.get());
if (std::find(leaf_accumulators_.begin(), leaf_accumulators_.end(),
iter->second.get()) == leaf_accumulators_.end()) {
leaf_accumulators_.push_back(iter->second.get());
}

if (iter->second->HasInnerVar()) {
var = iter->second->InnerVar();
Expand Down
4 changes: 3 additions & 1 deletion paddle/fluid/imperative/basic_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class BasicEngine : public Engine {
std::vector<std::pair<GradientAccumulator*, std::shared_ptr<VariableWrapper>>>
need_accu_var_list_;
// leaf_accumulators_ is only for leaf tensor(hooks/accumulate grad)
std::unordered_set<GradientAccumulator*> leaf_accumulators_;
// It should be orderly and not repeated, because multiple cards must ensure
// that the order of vars is the same.
std::vector<GradientAccumulator*> leaf_accumulators_;

bool retain_graph_;
};
Expand Down