mindspore.nn.TensorAddQuant

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

Adds fake quantized operation after TensorAdd operation.

This part is a more detailed overview of TensorAdd 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 TensorAddQuant. The input dimension is preferably 2D or 4D.

  • x2 (Tensor) - The second tensor of TensorAddQuant. 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()
>>> add_quant = nn.TensorAddQuant(quant_config=qconfig)
>>> x1 = Tensor(np.array([[1, 2, 1], [-2, 0, -1]]), mindspore.float32)
>>> x2 = Tensor(np.ones((2, 3)), mindspore.float32)
>>> output = add_quant(x1, x2)
>>> print(output)
[[ 1.9764705  3.011765   1.9764705]
 [-0.9882355  0.9882355  0.       ]]