diff --git a/paddle/operators/mul_op.h b/paddle/operators/mul_op.h index 9bbd0275261e68a86eb033398b50e73143c99e3b..8facc0281449785bf40726f23ca2fd5d166ff272 100644 --- a/paddle/operators/mul_op.h +++ b/paddle/operators/mul_op.h @@ -51,9 +51,11 @@ class MulGradKernel : public framework::OpKernel { auto* dX = ctx.Output(framework::GradVarName("X")); auto* dY = ctx.Output(framework::GradVarName("Y")); + dX->mutable_data(ctx.GetPlace()); + dY->mutable_data(ctx.GetPlace()); auto* device_context = const_cast(ctx.device_context_); - // dX = dOut' * Y. dX: M x K, dOut : M x N, Y : K x N + // dX = dOut * Y'. dX: M x K, dOut : M x N, Y : K x N math::matmul(*dOut, false, *Y, true, 1, dX, 0, device_context); // dY = X' * dOut. dY: K x N, dOut : M x N, X : M x K math::matmul(*X, true, *dOut, false, 1, dY, 0, device_context);