Skip to content

Commit

Permalink
correct computation equation
Browse files Browse the repository at this point in the history
  • Loading branch information
HydrogenSulfate committed Feb 28, 2024
1 parent 3df912d commit 62d9e51
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,15 @@ void silu_double_grad(const Tensor& x,
Tensor* grad_x,
Tensor* grad_out_grad) {
auto sigmoid = 1 / (1 + exp<T>(-x));
auto ddx_mul_tt = grad_x_grad * (x - out + 1);
auto tmp = 1 + x - out;
auto ddx_mul_sigmoid = grad_x_grad * sigmoid;
if (grad_out_grad) {
set_output<T>(ddx_mul_tt * sigmoid, grad_out_grad);
set_output<T>(ddx_mul_sigmoid * tmp, grad_out_grad);
}
if (grad_x) {
auto sigmoid_g = sigmoid * (1 - sigmoid);
set_output<T>(ddx_mul_tt * sigmoid_g, grad_x);
set_output<T>(ddx_mul_sigmoid * out_grad * (1 - sigmoid) * (tmp - out + 1),
grad_x);
}
}

Expand Down

0 comments on commit 62d9e51

Please sign in to comment.