Skip to content
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

Fix GELU formula and Turn OFF FASTMATH #7103

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions oneflow/core/autograd/gradient_funcs/layer_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,21 @@ Maybe<void> LayerNorm::Apply(const LayerNormCaptureState* ctx, const TensorTuple
if (begin_norm_axis < 0) { begin_norm_axis += dy->shape()->NumAxes(); }

std::shared_ptr<Tensor> gamma = saved_tensors.at(ctx->gamma_index);
if (!ctx->has_affine) {
// Use LayerNormParamGrad(Tensor dy, Tensor gamma, Int64 begin_params_axis, Double epsilon).
dy = JUST(functional::LayerNormParamGrad(dy, begin_params_axis, ctx->epsilon));
} else {
// Use LayerNormAffineParamGrad(Tensor dy, Tensor gamma, Tensor normalized, Int64
// begin_params_axis, Double epsilon).
std::shared_ptr<Tensor> normalized = saved_tensors.at(ctx->normalized_index);
const auto& results = JUST(functional::LayerNormAffineParamGrad(
dy, gamma, normalized, begin_params_axis, ctx->epsilon));
in_grads->at(1) = results->at(0); // For gamma.
in_grads->at(2) = results->at(1); // For beta.
dy = results->at(2);
}

// TODO
// if (!ctx->has_affine) {
// // Use LayerNormParamGrad(Tensor dy, Tensor gamma, Int64 begin_params_axis, Double epsilon).
// dy = JUST(functional::LayerNormParamGrad(dy, begin_params_axis, ctx->epsilon));
// } else {
// // Use LayerNormAffineParamGrad(Tensor dy, Tensor gamma, Tensor normalized, Int64
// // begin_params_axis, Double epsilon).
// std::shared_ptr<Tensor> normalized = saved_tensors.at(ctx->normalized_index);
// const auto& results = JUST(functional::LayerNormAffineParamGrad(
// dy, gamma, normalized, begin_params_axis, ctx->epsilon));
// in_grads->at(1) = results->at(0); // For gamma.
// in_grads->at(2) = results->at(1); // For beta.
// dy = results->at(2);
// }

if (ctx->x_requires_grad) {
const auto& x = saved_tensors.at(ctx->x_index);
Expand Down
Loading