伪量化算子
class horizon_plugin_pytorch.quantization.FakeQuantize (observer: type = <class 'horizon_plugin_pytorch.quantization.observer.MovingAverageMinMaxObserver'>, saturate: bool | None = None, in_place: bool = False, compat_mask: bool = True, channel_len: int = 1, fast_training=True, **observer_kwargs)
Simulate the quantize and dequantize operations in training time.
The output of this module is given by
fake_quant_x = clamp(round(x / scale), quant_min, quant_max) * scale
-
scaledefines the scale factor used for quantization. -
zero_pointspecifies the quantized value to which 0 in floating point maps to -
quant_minspecifies the minimum allowable quantized value. -
quant_maxspecifies the maximum allowable quantized value. -
fake_quant_enabledcontrols the application of fake quantization on tensors, note that statistics can still be updated. -
observer_enabledcontrols statistics collection on tensors -
dtypespecifies the quantized dtype that is being emulated with fake-quantization, the allowable values is qint8 and qint16. The values of quant_min and quant_max should be chosen to be consistent with the dtype -
Parameters:
- observer (
type) – Module for observing statistics on input tensors and calculating scale and zero-point. - saturate (
Optional[bool]) – Whether zero out the grad for value out of quanti range. - in_place (
bool) – Whether use in place fake quantize. - compat_mask (
bool) – Whether pack the bool mask into bitfield when saturate = True. - channel_len (
int) – Size of data at channel dim. - fast_training – Whether use fast training mode. If True, computing scale and fake quantization will be done in one step.
- observer_kwargs – Arguments for the observer module
- observer (
observer
User provided module that collects statistics on the input tensor and provides a method to calculate scale and zero-point.
set_qparams (scale: Tensor | Sequence | float, zero_point: Tensor | Sequence | int | None = None)
Set qparams, default symmetric.
- Parameters:
- scale ( Tensor | Sequence | float)
- zero_point ( Tensor | Sequence | int | None)
classmethod with_args (**kwargs)
Wrapper that allows creation of class factories.
This can be useful when there is a need to create classes with the same constructor arguments, but different instances. Can be used in conjunction with _callable_args
Example:
