Repository navigation
fix: Preserve precision in NCHW quantized average pooling - #1320
vera-rubin wants to merge 1 commit into
Conversation
|
Could you share more about your use case for ACL?
As ACL approaches end of life, we want to help users identify suitable migration paths, including KleidiAI or LiteRT where appropriate. Understanding your requirements will help us assess which options could work for you. |
|
Same answer as on #1319: we don't ship ACL in a product, so there's nothing to migrate on our side. |
|
Same change here as on #1319: the SPDX-FileCopyrightText line is added to quantized.h and PoolingLayer.cpp, and Arm's line in quantized.h is back to 2021-2022, 2024. The copyright for these changes is held by Donmakino LLC dba ChipLab. |
7f59bf2 to
b5ae8c6
Compare
|
Squashed this one into a single commit too, same as #1319. |
morgolock
left a comment
There was a problem hiding this comment.
Please fix the saturation regression in the new scalar quantization at src/cpu/kernels/pool2d/neon/quantized.h:369.
Qasymm8QuantizationHelper<T>::quantize narrows the lround result to int before clamping to the output byte range. With a large input/output scale ratio, this can wrap and saturate at the wrong end of the range.
Reproduced on native AArch64 with GCC 11.5.0:
- NCHW QASYMM8, 2x2 input containing four values of 64.
- Input quantization
(0.25, 0), output quantization(2^-27, 0). - AVG, 2x2 window, stride 1, no padding.
The expected output is 255. The previous code returns 255, but this PR returns 0. The 3x3 kernel also fails. With signed data, positive values can produce -128 instead of 127, and negative values can produce the reverse. These configurations pass NEPoolingLayer::validate.
Please clamp the quantized floating-point result before integer narrowing, or use a saturating conversion, and add regression tests for large scale ratios and both signs.
The copyright changes address my earlier comment. All 24 added regression tests and 648 other targeted pooling validation tests passed; the saturation cases above are additional coverage.
|
Thanks for the reproducer. The scalar requantization now clamps |
NCHW quantized AVG pooling rounds the mean to an input byte before applying output quantization. A 2x2 QASYMM8 input containing 128, 127, 127, 128 with input quantization (0.25, 128) and output quantization (1/128, 128) returns 96 instead of the reference result 112. Keep the fractional mean until output quantization in the 2x2, 3x3 and generic NCHW kernels. In the scalar requantization of the 2x2/3x3 AVG, generic AVG and generic MAX NCHW paths, clamp value / scale to the output type's range in float before the integer conversion, so a large ratio between the input and output scales saturates instead of wrapping. Add deterministic regressions covering signed and unsigned inputs, strides 1 and 2, padding, partial vectors, and positive and negative saturation for AVG and MAX with pool sizes 2, 3 and 4. Signed-off-by: Nathan Chandrasekar <322284620+vera-rubin@users.noreply.github.com>
3b09a34 to
afd19fb
Compare
|
Squashed the saturation fix into the single commit for the squash check; the code is unchanged from the previous head. |
NCHW quantized AVG pooling rounds its mean to an input byte before applying output quantization. For a 2×2 QASYMM8 input
{128, 127, 127, 128}with input quantization(0.25, 128)and output quantization(1/128, 128), we get96instead of the quantized reference's112for the exact mean-0.125.We keep the fractional mean until output quantization in the 2×2, 3×3 and generic NCHW kernels.
We tested the reproducer, a deterministic regression and the existing NEON pooling validation tests.
— ChipLab