Skip to content

Commit 8438bde

Browse files
Cortex_M backend: Remove int8 requirement for zero_points (#16061)
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. cc @freddan80 @per @zingo @oscarandersson8218 @digantdesai Signed-off-by: Adrian Lundell <[email protected]>
1 parent 1d35df2 commit 8438bde

File tree

2 files changed

+1
-8
lines changed

2 files changed

+1
-8
lines changed

backends/cortex_m/ops/cortex_m_ops_common.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ inline void validate_single_quant_params(
8282
int64_t mult_val = multiplier.to<int64_t>();
8383
int64_t shift_val = shift.to<int64_t>();
8484

85-
ET_CHECK_MSG(
86-
zp_val >= std::numeric_limits<int8_t>::min() &&
87-
zp_val <= std::numeric_limits<int8_t>::max(),
88-
"%s zero point must be in int8 range [Value: %d]",
89-
param_name,
90-
zp_val);
91-
9285
ET_CHECK_MSG(
9386
mult_val >= std::numeric_limits<int32_t>::min() &&
9487
mult_val <= std::numeric_limits<int32_t>::max(),

backends/cortex_m/test/ops/test_activation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def forward(self, x):
485485
),
486486
"linear_hardswish": McuTestCase(
487487
model=CortexMLinearHardswish(in_features=12, out_features=6),
488-
example_inputs=(ramp_tensor(-12, 12, (1, 12)),),
488+
example_inputs=(ramp_tensor(-2, 0, (1, 12)),),
489489
),
490490
"conv2d_hardsigmoid_inplace": McuTestCase(
491491
model=CortexMConv2DHardsigmoid(),

0 commit comments

Comments
 (0)