Skip to content

Commit

Permalink
use padle.add
Browse files Browse the repository at this point in the history
  • Loading branch information
pangyoki committed Apr 4, 2022
1 parent 7002ad4 commit 878ea96
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 1 addition & 4 deletions python/paddle/fluid/dygraph/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ def __impl__(self, other_var):

# 4. calculation
axis = -1
if framework._in_eager_mode_ and op_type == 'elementwise_add':
math_op = getattr(_C_ops, 'final_state_add')
else:
math_op = getattr(_C_ops, op_type)
math_op = getattr(_C_ops, op_type)
return math_op(self, other_var, 'axis', axis)

comment = OpProtoHolder.instance().get_op_proto(op_type).comment
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/test_inplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def func_test_backward_success_2(self):

var_b[1:2] = 3 # var_b is modified inplace before using it

var_c = var_b + var_b # Here, the grad op of sum doesn't use the value of var_b
var_c = paddle.add(
var_b,
var_b) # Here, the grad op of sum doesn't use the value of var_b
loss = var_c.sum()

var_b[1:2] = 3 # var_b is modified inplace after using it
Expand Down

1 comment on commit 878ea96

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.