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

Add fast_ln spmd rules #68148

Merged
merged 2 commits into from
Sep 12, 2024
Merged
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
27 changes: 27 additions & 0 deletions paddle/phi/infermeta/spmd_rules/layer_norm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -445,5 +445,32 @@ SpmdInfo LayerNormGradInferSpmd(const DistMetaTensor& x,
{x_grad_dist_attr, scale_grad_dist_attr, bias_grad_dist_attr});
}

SpmdInfo FastLnInferSpmd(const DistMetaTensor& x,
const DistMetaTensor& scale,
const DistMetaTensor& bias,
float epsilon) {
int begin_norm_axis = x.dims().size() - 1;
VLOG(4) << "FastLnInferSpmd call LayerNormInferSpmd with begin_norm_axis="
<< begin_norm_axis;
return LayerNormInferSpmd(x, scale, bias, epsilon, begin_norm_axis);
}

SpmdInfo FastLnGradInferSpmd(const DistMetaTensor& x,
const DistMetaTensor& scale,
const DistMetaTensor& mean,
const DistMetaTensor& invvar,
const DistMetaTensor& y_grad,
float epsilon) {
int begin_norm_axis = x.dims().size() - 1;
const DistMetaTensor& bias(scale); // bias is not used in FastLnGrad
VLOG(4)
<< "FastLnGradInferSpmd call LayerNormGradInferSpmd with begin_norm_axis="
<< begin_norm_axis << ", the input 'bias' will be ignored.";
SpmdInfo spmd_info = LayerNormGradInferSpmd(
x, scale, bias, mean, invvar, y_grad, epsilon, begin_norm_axis);
spmd_info.first.erase(spmd_info.first.begin() + 2); // remove bias_dist_attr
return spmd_info;
}

} // namespace distributed
} // namespace phi
12 changes: 12 additions & 0 deletions paddle/phi/infermeta/spmd_rules/layer_norm.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,17 @@ SpmdInfo LayerNormInferSpmdReverse(const DistMetaTensor& x,
float epsilon,
int begin_norm_axis);

SpmdInfo FastLnInferSpmd(const DistMetaTensor& x,
const DistMetaTensor& scale,
const DistMetaTensor& bias,
float epsilon);

SpmdInfo FastLnGradInferSpmd(const DistMetaTensor& x,
const DistMetaTensor& scale,
const DistMetaTensor& mean,
const DistMetaTensor& invvar,
const DistMetaTensor& y_grad,
float epsilon);

} // namespace distributed
} // namespace phi