mindspore_gs.ptq.RoundToNearest

View Source On Gitee
class mindspore_gs.ptq.RoundToNearest(config=None)[source]

Native implementation for post training quantization based on min/max statistic values.

Parameters

config (mindspore_gs.ptq.PTQConfig) – config for RoundToNearst, default is None.

Raises

TypeError – If config type is not PTQConfig when it’s not None.

Examples

>>> import mindspore_gs
>>> from mindspore_gs import ptq
>>> from mindspore_gs.ptq import RoundToNearest as rtn
>>> from mindspore_gs.ptq import PTQConfig
>>> # Define the network structure of LeNet5. Refer to
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/lenet.py
>>> ptq = rtn()
>>> network = LeNet5()
>>> fake_quant_net = ptq.apply(net_work)
>>> quant_net = ptq.convert(fake_quant_net)
apply(network: Cell)[source]

Define how to add fake quantizer to network.

Parameters

network (Cell) – Network to be fake quantized.

Returns

fake quantized network.

convert(net_opt: Cell, ckpt_path='')[source]

Define how to convert a compressed network to a standard network before exporting.

Parameters
  • net_opt (Cell) – Network to be converted which is transformed by RoundToNearest.apply.

  • ckpt_path (str) – Path to checkpoint file for net_opt. Default is "", which means not loading checkpoint file to net_opt.

Returns

An instance of Cell represents converted network.

Raises