neural_compressor.common.base_tuning
The auto-tune module.
Classes
Evaluation function wrapper. |
|
Evaluator is a collection of evaluation functions. |
|
A class representing a set of configurations. |
|
Base class for samplers. |
|
Samples elements sequentially, always in the same order. |
|
ConfigLoader is a generator that yields configs from a config set. |
|
Config for auto tuning pipeline. |
|
The tuning monitor class for auto-tuning. |
Functions
|
Initializes the tuning process. |
Module Contents
- class neural_compressor.common.base_tuning.EvaluationFuncWrapper(eval_fn: Callable, eval_args=None)[source]
Evaluation function wrapper.
- class neural_compressor.common.base_tuning.Evaluator[source]
Evaluator is a collection of evaluation functions.
Note: will deprecate this class in the future.
Examples
- def eval_acc(model):
…
- def eval_perf(molde):
…
# Usage user_eval_fns1 = eval_acc user_eval_fns2 = {“eval_fn”: eval_acc} user_eval_fns3 = {“eval_fn”: eval_acc, “weight”: 1.0, “name”: “accuracy”} user_eval_fns4 = [
{“eval_fn”: eval_acc, “weight”: 0.5}, {“eval_fn”: eval_perf, “weight”: 0.5, “name”: “accuracy”}, ]
- class neural_compressor.common.base_tuning.ConfigSet(config_list: List[neural_compressor.common.base_config.BaseConfig])[source]
A class representing a set of configurations.
- Parameters:
config_list (List[BaseConfig]) – A list of BaseConfig objects.
- config_list[source]
The list of BaseConfig objects.
- Type:
List[BaseConfig]
- class neural_compressor.common.base_tuning.Sampler(config_source: ConfigSet | None)[source]
Base class for samplers.
- class neural_compressor.common.base_tuning.SequentialSampler(config_source: Sized)[source]
Samples elements sequentially, always in the same order.
- Parameters:
config_source (_ConfigSet) – config set to sample from
- class neural_compressor.common.base_tuning.ConfigLoader(config_set: ConfigSet, sampler: Sampler = default_sampler, skip_verified_config: bool = True)[source]
ConfigLoader is a generator that yields configs from a config set.
- class neural_compressor.common.base_tuning.TuningConfig(config_set: neural_compressor.common.base_config.BaseConfig | List[neural_compressor.common.base_config.BaseConfig] = None, sampler: Sampler = default_sampler, tolerable_loss=0.01, max_trials=100)[source]
Config for auto tuning pipeline.
Examples
from neural_compressor.torch.quantization import TuningConfig tune_config = TuningConfig(
config_set=[config1, config2, …], max_trials=3, tolerable_loss=0.01)
- The tuning process stops when either of the following conditions is met:
The number of trials reaches the maximum trials.
The metric loss is within the tolerable loss.
- For condition 2), we calculate the metric loss as follows:
relative_loss = (fp32_baseline - eval_result_of_q_model) / fp32_baseline If relative_loss <= tolerable_loss, we stop the tuning process. For example:
tolerable_loss = 0.01 fp32_baseline = 100 eval_result_of_q_model = 99 relative_loss = (100 - 99) / 100 = 0.01 The metric loss is within the tolerable loss, so the tuning process is stopped.
- class neural_compressor.common.base_tuning.TuningMonitor(tuning_config: TuningConfig)[source]
The tuning monitor class for auto-tuning.
- neural_compressor.common.base_tuning.init_tuning(tuning_config: TuningConfig) Tuple[ConfigLoader, neural_compressor.common.utils.TuningLogger, TuningMonitor] [source]
Initializes the tuning process.
- Parameters:
tuning_config (TuningConfig) – The configuration for the tuning process.