CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
add acos_double_grad in dygraph composite #70409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
if (x_grad) { | ||
auto x_grad_tmp = (grad_out * (-x) * pow<T>(1 - x * x, -1.5) * grad_x_grad); | ||
set_output<T>(x_grad_tmp, x_grad); | ||
} | ||
|
||
if (grad_out_grad) { | ||
auto grad_out_grad_tmp = -pow<T>(1 - x * x, -0.5) * grad_x_grad; | ||
set_output<T>(grad_out_grad_tmp, grad_out_grad); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参考:
Paddle/paddle/fluid/prim/api/composite_backward/composite_double_backward_api.h
Lines 625 to 645 in b3afa7b
template <typename T> | |
void silu_double_grad(const Tensor& x, | |
const Tensor& out, | |
const Tensor& out_grad, | |
const Tensor& grad_x_grad, | |
Tensor* grad_x, | |
Tensor* grad_out_grad) { | |
auto s = sigmoid<T>(x); | |
auto tmp1 = scale<T>(s, -1.0, 1.0); | |
auto tmp2 = scale<T>(tmp1 * x, 1.0, 1.0); | |
auto grad_x_grad_mul_sigmoid = grad_x_grad * s; | |
if (grad_out_grad) { | |
auto ddout = grad_x_grad_mul_sigmoid * tmp2; | |
set_output<T>(ddout, grad_out_grad); | |
} | |
if (grad_x) { | |
auto dx = grad_x_grad_mul_sigmoid * out_grad * | |
(scale<T>(tmp2 - out, 1.0, 1.0)) * tmp1; | |
set_output<T>(dx, grad_x); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
另外PR描述里的验证代码,构造的张量形状太小,可以在百万级别的矩阵上验证一下。 |
// acos grad grad : ddout = -((1-x*x)^(-0.5)) * ddx, dx = dy * | ||
// (-x)*((1-x*x)^(-1.5)) * ddx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// acos grad grad : ddout = -((1-x*x)^(-0.5)) * ddx, dx = dy * | |
// (-x)*((1-x*x)^(-1.5)) * ddx | |
// ddout = -((1-x*x)^(-0.5)) * ddx | |
// dx = dy * (-x)*((1-x*x)^(-1.5)) * ddx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
paddle/phi/ops/yaml/backward.yaml
Outdated
output : Tensor(x_grad), Tensor(grad_out_grad) | ||
infer_meta : | ||
func : GeneralBinaryGradInferMeta | ||
param : [x, x] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第二个x最好写成grad_out,以防后面静态图使用出现一些奇怪的问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改,辛苦再看下
6fb252f
PR Category
Operator Mechanism
PR Types
New features
Description
Pcard-75624
添加acos的动态图二阶反向组合
精度对齐时,参考acos测试代码,使用[-0.95, 0.95]范围内数据作为输入。
与torch对齐验证代码: