From 4f1771ab4d321afba9f5a52411855b5dc33bf247 Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Fri, 29 Mar 2024 16:00:24 +0000 Subject: MLCE-1248 Removing limitations on zero scale value in quantization. Currently Arm NN will fail to load models containing quantization scale value of zero. Signed-off-by: Colm Donelan Change-Id: Ifefcee1279b8667da63d1aa7d42e5d44875f9fbe --- shim/sl/canonical/ModelToINetworkTransformer.cpp | 5 +++-- src/armnn/Network.cpp | 11 +---------- src/armnn/Tensor.cpp | 9 ++++++++- src/armnn/TypesUtils.cpp | 10 +--------- src/armnn/test/RuntimeTests.cpp | 18 +++++------------- 5 files changed, 18 insertions(+), 35 deletions(-) diff --git a/shim/sl/canonical/ModelToINetworkTransformer.cpp b/shim/sl/canonical/ModelToINetworkTransformer.cpp index 8efacaf3bf..4cf2160c8a 100644 --- a/shim/sl/canonical/ModelToINetworkTransformer.cpp +++ b/shim/sl/canonical/ModelToINetworkTransformer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022, 2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -31,7 +31,8 @@ ModelToINetworkTransformer::ModelToINetworkTransformer( catch (std::exception& e) { m_ConversionResult = ConversionResult::UnsupportedFeature; - VLOG(DRIVER) << "ModelToINetworkTransformer: Unexpected exception: " << e.what(); + VLOG(DRIVER) << "ModelToINetworkTransformer: Unexpected exception: " << e.what() << " Model was: " + << GetModelSummary(model); assert(false); } } diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp index 6f33fb6a15..810abaa5b9 100644 --- a/src/armnn/Network.cpp +++ b/src/armnn/Network.cpp @@ -818,16 +818,6 @@ bool CheckScaleSetOnQuantizedType(Layer* layer, OptionalGetType()) - << " (" << layer->GetNameStr() << ") is of type" - << " Quantized value but the scale parameter has not been set"; - ReportError(ss.str(), errMessages); - } // Softmax under QuantisedAsymm8 must always be scale (1.0f/256.0f) and offset 0 if (!info.HasPerAxisQuantization() && quantizationDataType == DataType::QAsymmU8 && (info.GetQuantizationScale() != (1.0f / 256.0f) || @@ -841,6 +831,7 @@ bool CheckScaleSetOnQuantizedType(Layer* layer, Optional @@ -32,10 +32,6 @@ QuantizedType armnn::Quantize(float value, float scale, int32_t offset) static_assert(IsQuantizedType(), "Not an integer type."); constexpr QuantizedType max = std::numeric_limits::max(); constexpr QuantizedType min = std::numeric_limits::lowest(); - if (scale == 0.f) - { - throw armnn::InvalidArgumentException("Quantize: Scale cannot be 0.f"); - } if (std::isnan(value)) { throw armnn::InvalidArgumentException("Quantize: Value is NaN"); @@ -52,10 +48,6 @@ template float armnn::Dequantize(QuantizedType value, float scale, int32_t offset) { static_assert(IsQuantizedType(), "Not an integer type."); - if (scale == 0.f) - { - throw armnn::InvalidArgumentException("Dequantize: Scale cannot be 0.f"); - } if (std::isnan(value)) { throw armnn::InvalidArgumentException("Dequantize: Value is NaN"); diff --git a/src/armnn/test/RuntimeTests.cpp b/src/armnn/test/RuntimeTests.cpp index 7079f0e4e8..6d5e2ae2b5 100644 --- a/src/armnn/test/RuntimeTests.cpp +++ b/src/armnn/test/RuntimeTests.cpp @@ -540,20 +540,12 @@ TEST_CASE("IVGCVSW_1929_QuantizedSoftmaxIssue") std::vector backends = { armnn::Compute::CpuRef }; std::vector errMessages; - try - { - armnn::IOptimizedNetworkPtr optNet = Optimize(*net, - backends, - runtime->GetDeviceSpec(), - OptimizerOptionsOpaque(), - errMessages); - FAIL("An exception should have been thrown"); - } - catch (const armnn::InvalidArgumentException&) - { - // Different exceptions are thrown on different backends - } + // We expect optimize to work but the errMessages should contain something. + CHECK_NOTHROW(armnn::IOptimizedNetworkPtr optNet = + Optimize(*net, backends, runtime->GetDeviceSpec(), OptimizerOptionsOpaque(), errMessages)); CHECK(errMessages.size() > 0); + // Should contain "updated to Scale" + CHECK(errMessages[0].find("updated to Scale") != std::string::npos); } TEST_CASE("RuntimeBackendOptions") -- cgit v1.2.1