From d65fecc2f3a50f324152006284be2530c2443995 Mon Sep 17 00:00:00 2001 From: zengxianglong Date: Fri, 25 Dec 2020 16:00:52 +0800 Subject: [PATCH] fix some fp16 subgraph bugs --- mindspore/lite/src/ops/arithmetic_compare.cc | 10 +++------- mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc | 6 ++++-- .../lite/src/runtime/kernel/arm/fp32/shape_fp32.cc | 1 + mindspore/lite/src/sub_graph_kernel.cc | 3 +++ mindspore/lite/test/models_onnx.cfg | 1 + mindspore/lite/test/models_tflite_fp16.cfg | 6 +++++- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/mindspore/lite/src/ops/arithmetic_compare.cc b/mindspore/lite/src/ops/arithmetic_compare.cc index 661883b98a..57c3db7f74 100644 --- a/mindspore/lite/src/ops/arithmetic_compare.cc +++ b/mindspore/lite/src/ops/arithmetic_compare.cc @@ -21,13 +21,9 @@ namespace lite { int ArithmeticCompare::InferShape(std::vector inputs_, std::vector outputs_) { auto res = Arithmetic::InferShape(inputs_, outputs_); - if (res == RET_OK) { - auto output = outputs_.front(); - output->set_data_type(TypeId::kNumberTypeBool); - return RET_OK; - } else { - return res; - } + auto output = outputs_.front(); + output->set_data_type(TypeId::kNumberTypeBool); + return res; } } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc index f0ca63ff5e..6515c2a79e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc @@ -304,10 +304,12 @@ int PadCPUKernel::CheckPaddings(int *paddings, int length, int *input_shape, int for (auto i = 0; i < length; ++i) { int max_valid = input_shape[i] - offset; if (paddings[i * 2] > max_valid) { - MS_LOG(WARNING) << prefix << "paddings " << paddings[i * 2] << "should be less than " << max_valid + 1; + MS_LOG(ERROR) << prefix << "paddings " << paddings[i * 2] << "should be less than " << max_valid + 1; + return RET_ERROR; } if (paddings[i * 2 + 1] > max_valid) { - MS_LOG(WARNING) << prefix << "paddings " << paddings[i * 2 + 1] << "should be less than " << max_valid + 1; + MS_LOG(ERROR) << prefix << "paddings " << paddings[i * 2 + 1] << "should be less than " << max_valid + 1; + return RET_ERROR; } } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/shape_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/shape_fp32.cc index 452c590454..5cd4b8c438 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/shape_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/shape_fp32.cc @@ -77,5 +77,6 @@ kernel::LiteKernel *CpuShapeFp32KernelCreator(const std::vector } REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Shape, CpuShapeFp32KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Shape, CpuShapeFp32KernelCreator) REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Shape, CpuShapeFp32KernelCreator) } // namespace mindspore::kernel diff --git a/mindspore/lite/src/sub_graph_kernel.cc b/mindspore/lite/src/sub_graph_kernel.cc index 76c77c0429..b4cc23e3f2 100644 --- a/mindspore/lite/src/sub_graph_kernel.cc +++ b/mindspore/lite/src/sub_graph_kernel.cc @@ -238,6 +238,9 @@ int CpuFp16SubGraph::PreProcess() { } for (auto kernel : this->nodes_) { for (auto tensor : kernel->out_tensors()) { + if (kernel->Type() == schema::PrimitiveType_Cast) { + continue; + } if (tensor->data_type() == kNumberTypeFloat32) { tensor->set_data_type(kNumberTypeFloat16); } diff --git a/mindspore/lite/test/models_onnx.cfg b/mindspore/lite/test/models_onnx.cfg index 039bcf498c..ba8c614ccf 100644 --- a/mindspore/lite/test/models_onnx.cfg +++ b/mindspore/lite/test/models_onnx.cfg @@ -36,3 +36,4 @@ udnie-9.onnx adversarial_pruning.onnx residual_distill_res34_cifar10_bs_1_update.onnx residual_distill_res50_cifar10_bs_1_update.onnx +encoder.onnx;1,32,83 diff --git a/mindspore/lite/test/models_tflite_fp16.cfg b/mindspore/lite/test/models_tflite_fp16.cfg index c337f9041b..5309061db0 100644 --- a/mindspore/lite/test/models_tflite_fp16.cfg +++ b/mindspore/lite/test/models_tflite_fp16.cfg @@ -40,7 +40,11 @@ deeplabv3_257_mv_gpu.tflite 3 multi_person_mobilenet_v1_075_float.tflite 9 #hiai_vad.tflite 20 ide_label_base.tflite 22 -#ide_label_retrained.tflite 80 +# ide_label_retrained.tflite involves a softmax-like structure whose output channel is 12. +# The values in the first few channels are extremely small and casted into 0 in the fp16 subgraph. +# The next slice operator takes out data from the first 6 channels, which are all zero, causing the error of +# dividing 0 in the following operator. +#ide_label_retrained.tflite ml_ei_headpose.tflite 3 ml_ei_landmark.tflite 3 mnist.tflite 4