Skip to content

Commit c9fc7ba

Browse files
committed
Do not sum output if that output is not a gradient
* increament is default inplace
1 parent 6d41bfb commit c9fc7ba

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

paddle/framework/backward.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ std::vector<std::unique_ptr<OpDescBind>> MakeBlockBackward(
408408

409409
for (const auto& desc : op_grads) {
410410
for (const std::string& out_name : desc->OutputArgumentNames()) {
411+
if (out_name.find("@GRAD") == std::string::npos) {
412+
// Not all outputs of a backward operator is a gradient. Only gradient
413+
// need to be sum. Skip variables are not gradient.
414+
continue;
415+
}
411416
dup_out_ops[out_name].emplace_back(grad_desc_idx);
412417
}
413418
++grad_desc_idx;

python/paddle/v2/framework/layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def zeros(shape, dtype, main_program=None):
823823
return fill_constant(value=0.0, **locals())
824824

825825

826-
def increment(x, value=1.0, in_place=False, main_program=None):
826+
def increment(x, value=1.0, in_place=True, main_program=None):
827827
helper = LayerHelper("increment", **locals())
828828
if in_place:
829829
tmp = x

0 commit comments

Comments
 (0)