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 bug of group norm and layer norm for npu #10609

Merged
merged 5 commits into from
Dec 26, 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
3 changes: 3 additions & 0 deletions oneflow/user/ops/group_norm_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ limitations under the License.

namespace oneflow {

DEFINE_ENV_BOOL(ONEFLOW_GROUP_NORM_USE_FP16_DIRECTLY, false);

namespace {

oneflow::DataType InferGnParamDataType(const DataType x_data_type) {
if (EnvBool<ONEFLOW_GROUP_NORM_USE_FP16_DIRECTLY>()) { return x_data_type; }
return (x_data_type == DataType::kFloat16 || x_data_type == DataType::kBFloat16)
? DataType::kFloat
: x_data_type;
Expand Down
7 changes: 7 additions & 0 deletions oneflow/user/ops/layer_norm_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ limitations under the License.

namespace oneflow {

DEFINE_ENV_BOOL(ONEFLOW_LAYER_NORM_PARAM_KEEP_DIM, false);

namespace {

int64_t ShiftNegativeAxisIfNeed(const Shape& shape, int64_t axis) {
Expand All @@ -31,6 +33,11 @@ Shape InferBnParamShape(const Shape& x_shape, const int64_t begin_norm_axis) {
DimVector bn_param_shape_dim_vec;
bn_param_shape_dim_vec.insert(bn_param_shape_dim_vec.end(), x_shape.dim_vec().cbegin(),
x_shape.dim_vec().cbegin() + begin_norm_axis);
if (EnvBool<ONEFLOW_LAYER_NORM_PARAM_KEEP_DIM>()) {
while (bn_param_shape_dim_vec.size() < x_shape.dim_vec().size()) {
bn_param_shape_dim_vec.push_back(1);
}
}
const Shape bn_param_shape(bn_param_shape_dim_vec);
return bn_param_shape;
}
Expand Down
Loading