diff --git a/paddle/fluid/operators/layer_norm_op.h b/paddle/fluid/operators/layer_norm_op.h index ff2935b0b450f5e42c77e5bd06396b4ab21fb8ca..5907d1d727835f2a19c025f2db3ba12f5fd87ea7 100644 --- a/paddle/fluid/operators/layer_norm_op.h +++ b/paddle/fluid/operators/layer_norm_op.h @@ -210,17 +210,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 } };