layernorm throw error if input has no data (#9837)

This commit is contained in:
Ye Wang 2021-11-29 12:43:17 -08:00 committed by GitHub
parent 9e75ebf0dc
commit bf716e667c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -41,6 +41,14 @@ Status SkipLayerNorm<T>::ComputeInternal(OpKernelContext* ctx) const {
Tensor* output = ctx->Output(0, input->Shape());
if (input->SizeInBytes() == 0) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Inputs 'input' has no data from upstream nodes");
}
if (skip->SizeInBytes() == 0) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Inputs 'skip' has no data from upstream nodes");
}
const auto& input_dims = input->Shape().GetDims();
if (input_dims.size() != 3) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,

View file

@ -61,6 +61,12 @@ Status LayerNorm<T, U, simplified>::ComputeInternal(OpKernelContext* ctx) const
auto bias_data = (simplified || (nullptr == bias)) ? nullptr : reinterpret_cast<const CudaT*>(bias->template Data<T>());
const TensorShape& x_shape = X->Shape();
// Sometimes due to conversion issue, the input 'X' has no data which is a case that cuda kernel cannot handle.
// Provide more error infomation here instead of CUDA errors.
if (X->SizeInBytes() == 0) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Inputs 'X' has no data from upstream nodes");
}
const int64_t axis = HandleNegativeAxis(axis_, x_shape.NumDimensions());
int n1 = gsl::narrow<int>(x_shape.SizeToDimension(axis));