-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Prim] support batch_norm vjp #51283
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
de465c6
to
5cda7b4
Compare
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.
some comments
paddle::Tensor saved_mean = this->GetSingleForwardOutput("SavedMean"); | ||
paddle::Tensor saved_variance = | ||
this->GetSingleForwardOutput("SavedVariance"); | ||
paddle::optional<paddle::Tensor> reserve_space = |
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.
Don't need this?
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.
done
auto use_global_stats = this->Attr<bool>("use_global_stats"); | ||
auto trainable_statistics = this->Attr<bool>("trainable_statistics"); | ||
|
||
VLOG(0) << "Runing batch_norm composite func"; |
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.
VLOG(3) is enough
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.
done
@@ -130,6 +130,7 @@ | |||
func : batch_norm_grad | |||
data_type : out_grad | |||
optional : mean_out, variance_out, reserve_space | |||
composite: batch_norm_grad(x, scale, bias, mean_out, variance_out, saved_mean, saved_variance, reserve_space, out_grad, momentum, epsilon, data_layout, is_test, use_global_stats, trainable_statistics) |
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.
add grad outputs in
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.
LGTM
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.
LGTM
PR types
Others
PR changes
Others
Describe
Pcard-66969
Prim batch_norm backward op.
Note
composite rule:
inv_var = 1 / sqrt(var + eps)
reduce_axis = [0, 2, 3] (NCHW) [0, 1, 2] (NHWC)
d_bias = np.sum(d_y, reduce_axis)
d_scale = np.sum((X - mean) / inv_var * dy, reduce_axis)
train mode
d_x = (1. / nhw) * scale * inv_var
*(nhw * d_y - np.sum(d_y, reduce_axis) - (X - mean) * inv_var * inv_var *
np.sum(d_y * (X - mean), reduce_axis))
test mode
d_x = d_y * scale * inv_var