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
17 changes: 10 additions & 7 deletions paddle/fluid/imperative/basic_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,16 @@ void BasicEngine::PrepareGradAccumulators(
void BasicEngine::PrepareDeps() {
PADDLE_ENFORCE_EQ(
node_deps_.empty(), true,
platform::errors::AlreadyExists("Op deps must be initialized."));
PADDLE_ENFORCE_EQ(
accumulators_.empty(), true,
platform::errors::AlreadyExists("Accumulators must be initialized."));
PADDLE_ENFORCE_EQ(
accumulators_with_grad_node_.empty(), true,
platform::errors::AlreadyExists("Accumulators must be initialized."));
platform::errors::AlreadyExists("Op deps are not empty before preparing "
"it for backward network execution."));
PADDLE_ENFORCE_EQ(accumulators_.empty(), true,
platform::errors::AlreadyExists(
"Accumulators are not empty before preparing it for "
"backward network execution."));
PADDLE_ENFORCE_EQ(accumulators_with_grad_node_.empty(), true,
platform::errors::AlreadyExists(
"Accumulators with grad_node as the key are not empty "
"before preparing it for backward network execution."));

std::queue<GradOpNode*> q;
std::unordered_set<GradOpNode*> visited;
Expand Down
12 changes: 7 additions & 5 deletions paddle/fluid/imperative/variable_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ class VariableWrapper {

auto shared_node = grad_node_.lock();
if (shared_node != grad_node) {
PADDLE_ENFORCE_EQ(
!shared_node || !grad_node->InplaceGradNameMap().empty(), true,
platform::errors::PermissionDenied(
"Cannot set gradient op twice unless using Inplace Strategy."));
if (shared_node) {
if (grad_node->InplaceGradNameMap().empty()) {
// grad_node doesn't have Inplace message
PADDLE_ENFORCE_EQ(
shared_node, nullptr,
platform::errors::PermissionDenied(
"Cannot set gradient op twice unless using Inplace Strategy."));
} else if (shared_node) {
VLOG(3) << "The gradient op of Var (" << Name()
<< ") has been set twice. Because Inplace Strategy is used.";
}
Expand Down