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 detials about Quantilization, please refer to mindspore.nn.FakeQuantWithMinMaxObserver.

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

  • quant_config (QuantConfig) – Configures the oberser types and quant settings of weight and activation. Can be generated by compression.quant.create_quant_config method. Default: both set to default FakeQuantWithMinMaxObserver.

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

Inputs:
  • input_x1 (Tensor) - The first tensor of TensorAddQuant.

  • input_x2 (Tensor) - The second tensor of TensorAddQuant.

Outputs:

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

Raises

TypeError – If ema_decay is not a float.

Supported Platforms:

Ascend GPU

Examples

>>> qconfig = compression.quant.create_quant_config()
>>> add_quant = nn.TensorAddQuant(quant_config=qconfig)
>>> input_x1 = Tensor(np.array([[1, 2, 1], [-2, 0, -1]]), mindspore.float32)
>>> input_x2 = Tensor(np.ones((2, 3)), mindspore.float32)
>>> output = add_quant(input_x1, input_x2)
>>> print(output)
[[ 1.9764705  3.011765   1.9764705]
 [-0.9882355  0.9882355  0.       ]]