Skip to content

Commit bf716e6

Browse files
authored
layernorm throw error if input has no data (#9837)
1 parent 9e75ebf commit bf716e6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

onnxruntime/contrib_ops/cuda/bert/skip_layer_norm.cc

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ Status SkipLayerNorm<T>::ComputeInternal(OpKernelContext* ctx) const {
4141

4242
Tensor* output = ctx->Output(0, input->Shape());
4343

44+
if (input->SizeInBytes() == 0) {
45+
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Inputs 'input' has no data from upstream nodes");
46+
}
47+
48+
if (skip->SizeInBytes() == 0) {
49+
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Inputs 'skip' has no data from upstream nodes");
50+
}
51+
4452
const auto& input_dims = input->Shape().GetDims();
4553
if (input_dims.size() != 3) {
4654
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,

onnxruntime/contrib_ops/cuda/layer_norm.cc

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Status LayerNorm<T, U, simplified>::ComputeInternal(OpKernelContext* ctx) const
6161
auto bias_data = (simplified || (nullptr == bias)) ? nullptr : reinterpret_cast<const CudaT*>(bias->template Data<T>());
6262

6363
const TensorShape& x_shape = X->Shape();
64+
// Sometimes due to conversion issue, the input 'X' has no data which is a case that cuda kernel cannot handle.
65+
// Provide more error infomation here instead of CUDA errors.
66+
if (X->SizeInBytes() == 0) {
67+
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Inputs 'X' has no data from upstream nodes");
68+
}
69+
6470
const int64_t axis = HandleNegativeAxis(axis_, x_shape.NumDimensions());
6571

6672
int n1 = gsl::narrow<int>(x_shape.SizeToDimension(axis));

0 commit comments

Comments
 (0)