From bf716e667c43d5091af5bd2418eb7bdbcb9d4c23 Mon Sep 17 00:00:00 2001 From: Ye Wang <52801275+wangyems@users.noreply.github.com> Date: Mon, 29 Nov 2021 12:43:17 -0800 Subject: [PATCH] layernorm throw error if input has no data (#9837) --- onnxruntime/contrib_ops/cuda/bert/skip_layer_norm.cc | 8 ++++++++ onnxruntime/contrib_ops/cuda/layer_norm.cc | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/onnxruntime/contrib_ops/cuda/bert/skip_layer_norm.cc b/onnxruntime/contrib_ops/cuda/bert/skip_layer_norm.cc index dd975ca90f..d6cac35261 100644 --- a/onnxruntime/contrib_ops/cuda/bert/skip_layer_norm.cc +++ b/onnxruntime/contrib_ops/cuda/bert/skip_layer_norm.cc @@ -41,6 +41,14 @@ Status SkipLayerNorm::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, diff --git a/onnxruntime/contrib_ops/cuda/layer_norm.cc b/onnxruntime/contrib_ops/cuda/layer_norm.cc index 50cb1c735f..3095ebf437 100644 --- a/onnxruntime/contrib_ops/cuda/layer_norm.cc +++ b/onnxruntime/contrib_ops/cuda/layer_norm.cc @@ -61,6 +61,12 @@ Status LayerNorm::ComputeInternal(OpKernelContext* ctx) const auto bias_data = (simplified || (nullptr == bias)) ? nullptr : reinterpret_cast(bias->template Data()); 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(x_shape.SizeToDimension(axis));