mindspore.nn.MulQuant

class mindspore.nn.MulQuant(ema_decay=0.999, quant_config=quant_config_default, quant_dtype=QuantDtype.INT8)[source]

Adds fake quantized operation after Mul operation.

This part is a more detailed overview of Mul operation. For more details about Quantization, please refer to the implementation of class of FakeQuantWithMinMaxObserver, mindspore.nn.FakeQuantWithMinMaxObserver.

Parameters
  • ema_decay (float) – Exponential Moving Average algorithm parameter. Default: 0.999.

  • quant_config (QuantConfig) – Configures the types of quant observer and quant settings of weight and activation. Note that, QuantConfig is a special namedtuple, which is designed for quantization and can be generated by mindspore.compression.quant.create_quant_config() method. Default: QuantConfig with both items set to default FakeQuantWithMinMaxObserver.

  • quant_dtype (QuantDtype) – Specifies the FakeQuant datatype. Default: QuantDtype.INT8.

Inputs:
  • x1 (Tensor) - The first tensor of MulQuant. The input dimension is preferably 2D or 4D.

  • x2 (Tensor) - The second tensor of MulQuant. Has the same shape with x1.

Outputs:

Tensor, with the same type and shape as the x1.

Raises
  • TypeError – If ema_decay is not a float.

  • ValueError – If the shape of x2 is different with x1.

Supported Platforms:

Ascend GPU

Examples

>>> import mindspore
>>> from mindspore.compression import quant
>>> from mindspore import Tensor
>>> qconfig = quant.create_quant_config()
>>> mul_quant = nn.MulQuant(quant_config=qconfig)
>>> x1 = Tensor(np.array([[1, 2, 1], [-2, 0, -1]]), mindspore.float32)
>>> x2 = Tensor(np.ones((2, 3)) * 2, mindspore.float32)
>>> output = mul_quant(x1, x2)
>>> print(output)
[[ 1.9764705  4.0000005  1.9764705]
 [-4.         0.        -1.9764705]]