Skip to content

Commit 123a001

Browse files
committed
update ilit tuner.tune() API interface description.
1 parent 5b3f106 commit 123a001

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

ilit/tuner.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,32 @@ def __init__(self, conf_fname):
3434
def tune(self, model, q_dataloader=None, q_func=None, eval_dataloader=None, eval_func=None, resume_file=None):
3535
"""The main entry point of automatic quantization tuning.
3636
37-
This interface works on all the DL frameworks that ilit supports and provides two usages:
38-
a) Calibration and tuning with pre-defined evaluation metrics: User specifies fp32 "model",
39-
calibration dataset "q_dataloader" and evaluation dataset "eval_dataloader". The calibrated
40-
and quantized model is evaluated with "eval_dataloader" with evaluation metrics specified
37+
This interface works on all the DL frameworks that ilit supports and provides three usages:
38+
a) Fully yaml configuration: User specifies all the info through yaml, including dataloaders used in calibration and evaluation
39+
phases and quantization tuning settings.
40+
41+
For this usage, only model parameter is mandotory.
42+
43+
b) Partial yaml configuration: User specifies dataloaders used in calibration and evaluation phase by code.
44+
The tool provides built-in dataloaders and evaluators, user just need provide a dataset implemented __iter__ or
45+
__getitem__ methods and invoke dataloader() with dataset as input parameter before calling tune().
46+
47+
After that, User specifies fp32 "model", calibration dataset "q_dataloader" and evaluation dataset "eval_dataloader".
48+
The calibrated and quantized model is evaluated with "eval_dataloader" with evaluation metrics specified
4149
in the configuration file. The evaluation tells the tuner whether the quantized model meets
4250
the accuracy criteria. If not, the tuner starts a new calibration and tuning flow.
4351
44-
b) Calibration and tuning with custom evaluation: User specifies fp32 "model", calibration dataset
45-
"q_dataloader" and a custom "eval_func" which encapsulates the evaluation dataset by itself.
52+
For this usage, model, q_dataloader and eval_dataloader parameters are mandotory.
53+
54+
c) Partial yaml configuration: User specifies dataloaders used in calibration phase by code.
55+
This usage is quite similar with b), just user specifies a custom "eval_func" which encapsulates
56+
the evaluation dataset by itself.
4657
The calibrated and quantized model is evaluated with "eval_func". The "eval_func" tells the
4758
tuner whether the quantized model meets the accuracy criteria. If not, the Tuner starts a new
4859
calibration and tuning flow.
4960
61+
For this usage, model, q_dataloader and eval_func parameters are mandotory.
62+
5063
Args:
5164
model (object): For Tensorflow model, it could be a path to frozen pb,loaded graph_def
5265
object or a path to ckpt/savedmodel folder.
@@ -57,7 +70,12 @@ def tune(self, model, q_dataloader=None, q_func=None, eval_dataloader=None, eval
5770
dataset containing label, or yield (input, _) for label-free calibration
5871
dataset. The input could be a object, list, tuple or dict, depending on
5972
user implementation, as well as it can be taken as model input.
60-
q_func (function, optional): Reserved for future use.
73+
q_func (function, optional): Training function for Quantization-Aware Training. It is optional and only
74+
takes effect when user choose "quantization_aware_training" approach in yaml.
75+
This function takes "model" as input parameter and executes entire training
76+
process with self contained training hyper-parameters. If this parameter
77+
specified, eval_dataloader parameter plus metric defined in yaml, or eval_func
78+
parameter should also be specified at same time.
6179
eval_dataloader (generator, optional): Data loader for evaluation. It is iterable and should yield a tuple
6280
of (input, label). The input could be a object, list, tuple or dict,
6381
depending on user implementation, as well as it can be taken as model

0 commit comments

Comments
 (0)