From 94356aa276343b08eaad5046415bcac4dd1b16bf Mon Sep 17 00:00:00 2001 From: yeyunpeng2020 Date: Tue, 8 Mar 2022 15:27:36 +0800 Subject: [PATCH] handle case where encode_min_ == encode_max_ --- cmake/external_libs/openssl.cmake | 5 +++-- mindspore/lite/CMakeLists.txt | 5 +++-- .../tools/converter/quantizer/data_distribution.cc | 13 +++++-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmake/external_libs/openssl.cmake b/cmake/external_libs/openssl.cmake index 9524b743c97..767c96e80f9 100644 --- a/cmake/external_libs/openssl.cmake +++ b/cmake/external_libs/openssl.cmake @@ -14,6 +14,7 @@ endif() if(BUILD_LITE) if(PLATFORM_ARM64 AND ANDROID_NDK_TOOLCHAIN_INCLUDED) + set(openssl_USE_STATIC_LIBS OFF) set(ANDROID_NDK_ROOT $ENV{ANDROID_NDK}) set(PATH ${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin: @@ -39,7 +40,7 @@ if(BUILD_LITE) LIBS ssl crypto URL ${REQ_URL} MD5 ${MD5} - CONFIGURE_COMMAND ./Configure android-arm -D__ANDROID_API__=29 no-zlib + CONFIGURE_COMMAND ./Configure android-arm -D__ANDROID_API__=19 no-zlib PATCHES ${OPENSSL_PATCH_ROOT}/CVE-2021-3711.patch PATCHES ${OPENSSL_PATCH_ROOT}/CVE-2021-3712.patch ) @@ -49,7 +50,7 @@ if(BUILD_LITE) LIBS ssl crypto URL ${REQ_URL} MD5 ${MD5} - CONFIGURE_COMMAND ./config no-zlib no-shared + CONFIGURE_COMMAND ./config no-zlib PATCHES ${OPENSSL_PATCH_ROOT}/CVE-2021-3711.patch PATCHES ${OPENSSL_PATCH_ROOT}/CVE-2021-3712.patch ) diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index c900ebcfdc9..3dc59341a4b 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -34,7 +34,7 @@ option(MSLITE_ENABLE_V0 "support v0 schema" on) option(MSLITE_ENABLE_FP16 "Whether to compile Fp16 operator" off) option(MSLITE_ENABLE_INT8 "Whether to compile Int8 operator" on) option(MSLITE_ENABLE_ACL "enable ACL" off) -option(MSLITE_ENABLE_MODEL_ENCRYPTION "enable model encryption, only converter support" off) +option(MSLITE_ENABLE_MODEL_ENCRYPTION "enable model encryption" off) option(MSLITE_ENABLE_SPARSE_COMPUTE "enable sparse kernel" off) option(MSLITE_ENABLE_RUNTIME_CONVERT "enable runtime convert" off) option(MSLITE_ENABLE_RUNTIME_GLOG "enable runtime glog" off) @@ -127,7 +127,8 @@ if(DEFINED ENV{MSLITE_MINDDATA_IMPLEMENT}) set(MSLITE_MINDDATA_IMPLEMENT $ENV{MSLITE_MINDDATA_IMPLEMENT}) endif() if(DEFINED ENV{MSLITE_ENABLE_MODEL_ENCRYPTION}) - if((${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND PLATFORM_X86_64) OR (PLATFORM_ARM AND ANDROID_NDK_TOOLCHAIN_INCLUDED)) + if((${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND PLATFORM_X86_64) + OR((PLATFORM_ARM64 OR PLATFORM_ARM32) AND ANDROID_NDK_TOOLCHAIN_INCLUDED)) set(MSLITE_ENABLE_MODEL_ENCRYPTION $ENV{MSLITE_ENABLE_MODEL_ENCRYPTION}) else() set(MSLITE_ENABLE_MODEL_ENCRYPTION OFF) diff --git a/mindspore/lite/tools/converter/quantizer/data_distribution.cc b/mindspore/lite/tools/converter/quantizer/data_distribution.cc index b71459e8a84..41b81fe4b90 100644 --- a/mindspore/lite/tools/converter/quantizer/data_distribution.cc +++ b/mindspore/lite/tools/converter/quantizer/data_distribution.cc @@ -217,15 +217,12 @@ double DataDistribution::CalculateScaleAndZp(float min_value, float max_value) { } // Inputs are both negative and positive, real_min and real_max are slightly shifted to make the floating point zero // exactly representable. e.g. input range = [-5.1, 5.1] -> [-5.12, 5.08] - MS_ASSERT(quant_max_ - quant_min_ > 0); - auto range = encode_max_ - encode_min_; - if (max_value <= 0.0f) { - MS_LOG(INFO) << "The value is 0, so set to symmetry and the range to 0.01."; - const float zero_range = 0.01f; - range = zero_range; - symmetry_ = true; - } + // handle case where encode_min_ == encode_max_ + float epsilon = 1e-5; + encode_max_ = std::max(encode_max_, encode_min_ + epsilon); + auto range = encode_max_ - encode_min_; + MS_ASSERT(quant_max_ - quant_min_ > 0); return range / (quant_max_ - quant_min_); }