From e0ced99dbe762bc5f5ed0db107a041acca82b4ed Mon Sep 17 00:00:00 2001 From: Jongsoo Park Date: Sun, 26 Feb 2023 09:53:41 -0800 Subject: [PATCH] check min<=max in ChooseQuantizationParams (#95529) Summary: X-link: https://github.com/pytorch/pytorch/pull/95529 Pull Request resolved: https://github.com/pytorch/FBGEMM/pull/1612 https://github.com/pytorch/FBGEMM/issues/1590 Reviewed By: summerdengfb Differential Revision: D43383474 fbshipit-source-id: 7b61eda2e80e5ca9c34cfe6b26f85adfd20ddc6e --- src/QuantUtils.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/QuantUtils.cc b/src/QuantUtils.cc index 5fd58c13ce..ed97bc9ae3 100644 --- a/src/QuantUtils.cc +++ b/src/QuantUtils.cc @@ -36,6 +36,11 @@ TensorQuantizationParams ChooseQuantizationParams( int32_t qmax, bool preserve_sparsity, bool force_scale_power_of_two) { + if (min > max) { + throw std::runtime_error( + "In ChooseQuantizationParams, min should be less than or equal to max"); + } + if (min < 0 && max > 0 && preserve_sparsity) { int symmetric_qmin = -((qmax - qmin) / 2 + 1); int symmetric_qmax = (qmax - qmin) / 2;