diff --git a/paddle/phi/kernels/funcs/elementwise_functor.h b/paddle/phi/kernels/funcs/elementwise_functor.h index 508240a99164480069de0b74995803cb8c6dcebf..84938597e82b32e4f1967f618d8b217c75c079c2 100644 --- a/paddle/phi/kernels/funcs/elementwise_functor.h +++ b/paddle/phi/kernels/funcs/elementwise_functor.h @@ -117,7 +117,7 @@ struct DivGradXYFunctor { // dy = - dout * out / y phi::Array outs; outs[0] = a / c; - outs[1] = -a * b / c; + outs[1] = -a * ((b / c) / c); return outs; } }; @@ -130,7 +130,7 @@ struct DivGradXYFunctor, ComplexType> { const ComplexType c) { phi::Array, 2> outs; ComplexType c_conj(c.real, -c.imag); - ComplexType out_div_c_conj((b / c).real, -(b / c).imag); + ComplexType out_div_c_conj(((b / c) / c).real, -((b / c) / c).imag); outs[0] = a / c_conj; outs[1] = -a * out_div_c_conj; return outs; @@ -157,7 +157,7 @@ struct DivGradXFunctor> { template struct DivGradYFunctor { inline HOSTDEVICE T operator()(const T a, const T b, const T c) const { - return -a * b / c; + return -a * ((b / c) / c); } }; @@ -167,7 +167,7 @@ struct DivGradYFunctor> { inline HOSTDEVICE ComplexType operator()(const ComplexType a, const ComplexType b, const ComplexType c) const { - ComplexType out_div_c_conj((b / c).real, -(b / c).imag); + ComplexType out_div_c_conj(((b / c) / c).real, -((b / c) / c).imag); return -a * out_div_c_conj; } }; diff --git a/paddle/phi/kernels/gpu/elementwise_divide_grad_kernel.cu b/paddle/phi/kernels/gpu/elementwise_divide_grad_kernel.cu index 57bf6da4060d34acdbf44ac80d4577e24247417d..d63841f17e62ea0ea25e5888b8db9c164f4dab49 100644 --- a/paddle/phi/kernels/gpu/elementwise_divide_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/elementwise_divide_grad_kernel.cu @@ -36,7 +36,7 @@ void DivideGradKernel(const Context& dev_ctx, DenseTensor* dy) { const auto place = dev_ctx.GetPlace(); if (dx != nullptr && dy != nullptr) { - std::vector ins = {&dout, &out, &y}; + std::vector ins = {&dout, &x, &y}; GetGradXAndYOut( dev_ctx, place, @@ -51,7 +51,7 @@ void DivideGradKernel(const Context& dev_ctx, GetGradXOrYOut( dev_ctx, place, axis, ins, dout, dx, funcs::DivGradXFunctor()); } else if (dy != nullptr && dx == nullptr) { - std::vector ins = {&dout, &out, &y}; + std::vector ins = {&dout, &x, &y}; GetGradXOrYOut( dev_ctx, place, axis, ins, dout, dy, funcs::DivGradYFunctor()); }