Skip to content

Commit

Permalink
Stop the tuning process early when enabling smooth quant (#1542)
Browse files Browse the repository at this point in the history
Signed-off-by: yiliu30 <yi4.liu@intel.com>
  • Loading branch information
yiliu30 committed Jan 18, 2024
1 parent ab63541 commit 844a032
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions neural_compressor/strategy/strategy.py
Expand Up @@ -186,6 +186,9 @@ def __init__(
# track tuning cfg with the current best accuracy
self.cur_best_tuning_cfg = {}
self.re_quant = False
# two cases to stop sq process early
# 1) alpha is a scalar, e.g., alpha = 0.5, early stop after the 1st trial
# 2) alpha is a list containing more than 1 element, early stop after trying all alpha
self.early_stop_sq_tuning_process = False

self._trials_count = 0
Expand Down Expand Up @@ -591,6 +594,8 @@ def _initialize_recipe(self):
logger.info(f"Adaptor has {len(adaptor_recipes)} recipes.")
logger.debug(adaptor_recipes)
usr_recipes_cfg = self.config.recipes if self.config.recipes else {}
# if smooth quant is `True`, early stop
self.early_stop_sq_tuning_process = usr_recipes_cfg.get("smooth_quant", False)
for recipe_name, recipe_val in usr_recipes_cfg.items():
# for not tuning recipes, use the value specified by user.
if recipe_name in adaptor_recipes and recipe_val != adaptor_recipes[recipe_name][0]:
Expand Down
2 changes: 1 addition & 1 deletion test/algorithm/test_smooth_quant.py
Expand Up @@ -1198,7 +1198,7 @@ def fake_eval(model, eval_result_lst):
(
[1, 0.8, 1.1, 0.7, 1.1],
0.5,
"Expect tuning ends at 2nd trial with alpha is 0.5 and not tune sq's alpha.",
"Expect tuning ends at 1st trial with alpha is 0.5 and not tune sq's alpha.",
),
(
[1, 0.8, 0.9, 0.7, 1.1],
Expand Down

0 comments on commit 844a032

Please sign in to comment.