diff --git a/paddle/fluid/prim/api/composite_backward/composite_double_backward_api.h b/paddle/fluid/prim/api/composite_backward/composite_double_backward_api.h index 8e0827eeb0b7e..6e586a9ba8569 100644 --- a/paddle/fluid/prim/api/composite_backward/composite_double_backward_api.h +++ b/paddle/fluid/prim/api/composite_backward/composite_double_backward_api.h @@ -443,12 +443,13 @@ void silu_double_grad(const Tensor& x, auto sigmoid = 1 / (1 + exp(-x)); auto tmp1 = 1 - sigmoid; auto tmp2 = 1 + tmp1 * x; + auto grad_x_grad_mul_sigmoid = grad_x_grad * sigmoid; if (grad_out_grad) { - auto ddout = grad_x_grad * sigmoid * tmp2; + auto ddout = grad_x_grad_mul_sigmoid * tmp2; set_output(ddout, grad_out_grad); } if (grad_x) { - auto dx = sigmoid * grad_x_grad * out_grad * (1 + (tmp2 - out)) * tmp1; + auto dx = grad_x_grad_mul_sigmoid * out_grad * (1 + (tmp2 - out)) * tmp1; set_output(dx, grad_x); } }