diff --git a/paddle/fluid/operators/layer_norm_op.h b/paddle/fluid/operators/layer_norm_op.h index db794ed42116144f310b9d7dc529cff49ba2c405..9bea7018742663325b9a6653e639fa89f4b98c52 100644 --- a/paddle/fluid/operators/layer_norm_op.h +++ b/paddle/fluid/operators/layer_norm_op.h @@ -224,17 +224,35 @@ class LayerNormKernel : public framework::OpKernel { ctx, &out, bias, /*axis*/ 1, AddFunctor(), &out); } #else - PADDLE_ENFORCE_EQ(mean->numel(), left); - PADDLE_ENFORCE_EQ(var->numel(), left); - PADDLE_ENFORCE_EQ(scale->numel(), right); - PADDLE_ENFORCE_EQ(bias->numel(), right); + PADDLE_ENFORCE_EQ(mean->numel(), left, + platform::errors::InvalidArgument( + "mean's length (%d) is not equal with expected (%d).", + mean->numel(), left)); + PADDLE_ENFORCE_EQ(var->numel(), left, + platform::errors::InvalidArgument( + "var's length (%d) is not equal with expected (%d).", + var->numel(), left)); + if (scale) { + PADDLE_ENFORCE_EQ( + scale->numel(), right, + platform::errors::InvalidArgument( + "scale's length (%d) is not equal with expected (%d).", + scale->numel(), right)); + } + if (bias) { + PADDLE_ENFORCE_EQ( + bias->numel(), right, + platform::errors::InvalidArgument( + "bias's length (%d) is not equal with expected (%d).", + bias->numel(), right)); + } auto ker = jit::KernelFuncs, platform::CPUPlace>::Cache() .At(right); ker(x.data(), out.data(), mean->data(), var->data(), - scale->data(), bias->data(), static_cast(left), - static_cast(epsilon), right); + scale ? scale->data() : nullptr, bias ? bias->data() : nullptr, + static_cast(left), static_cast(epsilon), right); #endif } };