From a12b0e0d2e9fe9fc6a7a672e921fd8dfdff4604f Mon Sep 17 00:00:00 2001 From: Adrian Lundell Date: Wed, 3 Dec 2025 09:28:34 +0100 Subject: [PATCH] Cortex_M backend: Remove int8 requirement for zero_points The zero point would sometimes get out of range in the hardswish decomposition (depending on the range of the quantized output) as it adjusts the zero point. Since the zero_point is applied in int32 accumulation there is no actual reason for the limitation, so we can just remove it. Additionally change the input to linear_hardswish to reliably trigger the behaviour causing the crash before the fix was introduced to catch future regressions. Signed-off-by: Adrian Lundell Change-Id: Ia300d57acd2f3e63f49bdf1bc8664da8a3f49bf9 --- backends/cortex_m/ops/cortex_m_ops_common.h | 7 ------- backends/cortex_m/test/ops/test_activation.py | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/backends/cortex_m/ops/cortex_m_ops_common.h b/backends/cortex_m/ops/cortex_m_ops_common.h index 5e95e1daae6..eea9792efcf 100644 --- a/backends/cortex_m/ops/cortex_m_ops_common.h +++ b/backends/cortex_m/ops/cortex_m_ops_common.h @@ -82,13 +82,6 @@ inline void validate_single_quant_params( int64_t mult_val = multiplier.to(); int64_t shift_val = shift.to(); - ET_CHECK_MSG( - zp_val >= std::numeric_limits::min() && - zp_val <= std::numeric_limits::max(), - "%s zero point must be in int8 range [Value: %d]", - param_name, - zp_val); - ET_CHECK_MSG( mult_val >= std::numeric_limits::min() && mult_val <= std::numeric_limits::max(), diff --git a/backends/cortex_m/test/ops/test_activation.py b/backends/cortex_m/test/ops/test_activation.py index bae8e5f98ea..407966521f3 100644 --- a/backends/cortex_m/test/ops/test_activation.py +++ b/backends/cortex_m/test/ops/test_activation.py @@ -485,7 +485,7 @@ def forward(self, x): ), "linear_hardswish": McuTestCase( model=CortexMLinearHardswish(in_features=12, out_features=6), - example_inputs=(ramp_tensor(-12, 12, (1, 12)),), + example_inputs=(ramp_tensor(-2, 0, (1, 12)),), ), "conv2d_hardsigmoid_inplace": McuTestCase( model=CortexMConv2DHardsigmoid(),