Skip to content

Commit 844a032

Browse files
authored
Stop the tuning process early when enabling smooth quant (#1542)
Signed-off-by: yiliu30 <yi4.liu@intel.com>
1 parent ab63541 commit 844a032

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

neural_compressor/strategy/strategy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ def __init__(
186186
# track tuning cfg with the current best accuracy
187187
self.cur_best_tuning_cfg = {}
188188
self.re_quant = False
189+
# two cases to stop sq process early
190+
# 1) alpha is a scalar, e.g., alpha = 0.5, early stop after the 1st trial
191+
# 2) alpha is a list containing more than 1 element, early stop after trying all alpha
189192
self.early_stop_sq_tuning_process = False
190193

191194
self._trials_count = 0
@@ -591,6 +594,8 @@ def _initialize_recipe(self):
591594
logger.info(f"Adaptor has {len(adaptor_recipes)} recipes.")
592595
logger.debug(adaptor_recipes)
593596
usr_recipes_cfg = self.config.recipes if self.config.recipes else {}
597+
# if smooth quant is `True`, early stop
598+
self.early_stop_sq_tuning_process = usr_recipes_cfg.get("smooth_quant", False)
594599
for recipe_name, recipe_val in usr_recipes_cfg.items():
595600
# for not tuning recipes, use the value specified by user.
596601
if recipe_name in adaptor_recipes and recipe_val != adaptor_recipes[recipe_name][0]:

test/algorithm/test_smooth_quant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ def fake_eval(model, eval_result_lst):
11981198
(
11991199
[1, 0.8, 1.1, 0.7, 1.1],
12001200
0.5,
1201-
"Expect tuning ends at 2nd trial with alpha is 0.5 and not tune sq's alpha.",
1201+
"Expect tuning ends at 1st trial with alpha is 0.5 and not tune sq's alpha.",
12021202
),
12031203
(
12041204
[1, 0.8, 0.9, 0.7, 1.1],

0 commit comments

Comments
 (0)