From 2d8ea6a56a037df10bd4dfa08e97989f54ae5091 Mon Sep 17 00:00:00 2001 From: yintong-lu <108845308+yintong-lu@users.noreply.github.com> Date: Mon, 18 Dec 2023 09:32:54 +0800 Subject: [PATCH] [Bug] fix alpha-space generation (#1465) Signed-off-by: Lu, Yintong (cherry picked from commit 33ece90016bce790ad00729b885b15b1b496f4d7) --- .../adaptor/torch_utils/smooth_quant.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/neural_compressor/adaptor/torch_utils/smooth_quant.py b/neural_compressor/adaptor/torch_utils/smooth_quant.py index 0cf32183084..e0fd3d7d23f 100644 --- a/neural_compressor/adaptor/torch_utils/smooth_quant.py +++ b/neural_compressor/adaptor/torch_utils/smooth_quant.py @@ -32,6 +32,7 @@ logger = logging.getLogger() from collections import UserDict, defaultdict +import numpy from tqdm import tqdm @@ -976,15 +977,10 @@ def _auto_tune_alpha( :return: """ logger.info("start sq auto tuning") - alpha_scale = 100 - alpha_space = list( - range( - round(alpha_min * alpha_scale), - round((alpha_max + alpha_step) * alpha_scale), - round(alpha_step * alpha_scale), - ) + round_num = max( + len(str(alpha_min).split(".")[1]), len(str(alpha_max).split(".")[1]), len(str(alpha_step).split(".")[1]) ) - alpha_space = [alpha / alpha_scale for alpha in alpha_space] + alpha_space = numpy.round(numpy.arange(alpha_min, alpha_max + alpha_step, alpha_step), round_num).tolist() ##wrapper new module self._qdq_model_wrapper_for_auto(save_q_input=True) ##set alpha to 0.5 as default @@ -1189,7 +1185,6 @@ def transform( self.insert_mul, self.allow_absorb = True, False if isinstance(alpha, float) and (alpha < 0 or alpha > 1): logger.warning("reset alpha to in range [0.0, 1.0]") - import numpy alpha = numpy.clip(alpha, 0.0, 1.0)