"""Add quantization and dequantization operators to "program"
"""
for quantization training or testing.
add trainable quantization ops in program.
Args:
Args:
program(fluid.Program): training or testing ``program``.
program(fluid.Program): program
place(fluid.CPUPlace or fluid.CUDAPlace): This parameter represents
scope(fluid.Scope): the scope to store var, it's should be the value of program's scope, usually it's fluid.global_scope().
the executor run on which device.
place(fluid.CPUPlace or fluid.CUDAPlace): place
config(dict, optional): configs for quantization. if None, will use default config.
config(dict): configs for quantization, default values are in quant_config_default dict.
Default: None.
for_test: if program is test program, for_test should be set True, else False.
scope(fluid.Scope): Scope records the mapping between variable names and variables,
Return:
similar to brackets in programming languages. Usually users can use
fluid.Program: user can finetune this quantization program to enhance the accuracy.
`fluid.global_scope <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/executor_cn/global_scope_cn.html>`_. When ``None`` will use `fluid.global_scope() <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/executor_cn/global_scope_cn.html>`_ . Default: ``None``.
for_test(bool): If the 'program' parameter is a test program, this parameter should be set to ``True``.
Otherwise, set to ``False``.Default: False
Returns:
fluid.CompiledProgram | fluid.Program: Program with quantization and dequantization ``operators``
convert quantized and well-trained ``program`` to final quantized ``program`` that can be used to save ``inference model``.
add quantization ops in program. the program returned is not trainable.
Args:
Args:
program(fluid.Program): quantized and well-trained ``test program``.
program(fluid.Program): program
place(fluid.CPUPlace or fluid.CUDAPlace): This parameter represents the executor run on which device.
scope(fluid.Scope): the scope to store var, when is None will use fluid.global_scope()
config(dict, optional): configs for convert. if set None, will use default config.
place(fluid.CPUPlace or fluid.CUDAPlace): place
It must be same with config that used in 'quant_aware'. Default: None.
config(dict): configs for quantization, default values are in quant_config_default dict.
scope(fluid.Scope, optional): Scope records the mapping between variable names and variables,
save_int8: is export int8 freezed program.
similar to brackets in programming languages. Usually users can use
Return:
`fluid.global_scope <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/executor_cn/global_scope_cn.html>`_. When ``None`` will use `fluid.global_scope() <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/executor_cn/global_scope_cn.html>`_ . Default: ``None``.
fluid.Program: freezed program which can be used for inference.
save_int8: Whether to return ``program`` which model parameters' dtype is ``int8``.
parameters is float32 type, but it's value in int8 range.
This parameter can only be used to get model size. Default: ``False``.
fluid.Program: freezed int8 program which can be used for inference.
if save_int8 is False, this value is None.
Returns:
Tuple : freezed program which can be used for inference.
when ``save_int8`` is False, return ``freezed_program(fluid.Program)``.
when ``save_int8`` is True, return ``freezed_program(fluid.Program)`` and ``freezed_program_int8(fluid.Program)``