Skip to content

Commit

Permalink
add TensorCopy in reduce_sum_grad
Browse files Browse the repository at this point in the history
  • Loading branch information
pangyoki committed Mar 16, 2021
1 parent 70b715b commit 1269cfe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions paddle/fluid/operators/reduce_ops/reduce_sum_op_npu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class ReduceSumGradNPUKernel : public framework::OpKernel<T> {
Tensor out_grad_tmp(out_grad->type());
out_grad_tmp.Resize(out_dims);
out_grad_tmp.mutable_data<T>(ctx.GetPlace());
framework::TensorCopy(
*out_grad, ctx.GetPlace(),
ctx.template device_context<platform::DeviceContext>(),
&out_grad_tmp);
out_grad_tmp.Resize(out_dims);

auto runner = NpuOpRunner("BroadcastToD", {out_grad_tmp}, {*x_grad},
{{"shape", framework::vectorize(x->dims())}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def _test(self, run_npu=True):
label = paddle.static.data(
name="label", shape=[2, 1], dtype='int64')

z = paddle.add(a, b)
a_1 = fluid.layers.fc(input=a, size=4, num_flatten_dims=2, act=None)
b_1 = fluid.layers.fc(input=b, size=4, num_flatten_dims=2, act=None)
z = paddle.add(a_1, b_1)
z_1 = self.set_reduce_sum_function(z)

prediction = fluid.layers.fc(input=z_1, size=2, act='softmax')
Expand Down

1 comment on commit 1269cfe

@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.

🕵️ CI failures summary

🔍PR: #31666 Commit ID: 1269cfe contains failed CI.

Please sign in to comment.