Quantize

Quantize // Maps real input to quantized output

Description

Produces a tensor of element type type and the same shape as input where the value of each coordinate \(i\) of output is the corresponding coordinate of input divided by scale rounded as specified by round_mode plus zero_point. The coordinate \(j\) of scale and zero_point is the coordinate of output projected onto axes.

Inputs

Name

Element Type

Shape

input

Any real type

Any

scale

Same as input

input shape projected onto axes

zero_point

Same as output

input shape projected onto axes

Attributes

Name

Description

type

output element type; any quantized type

axes

Axis positions on which scale and zero_point are specified

round_mode

ROUND_NEAREST_TOWARD_INFINITY: round to nearest integer in case of two equidistant integers round away from zero e.g. 2.5 -> 3 -3.5 -> -4

ROUND_NEAREST_TOWARD_ZERO: round to nearest integer in case of two equidistant integers round toward zero e.g. 2.5 -> 2 -3.5 to -3

ROUND_NEAREST_UPWARD: round to nearest integer in case of two equidistant integers round up e.g. 2.5 to 3 -3.5 to -3

ROUND_NEAREST_DOWNWARD: round to nearest integer in case of two equidistant integers round down e.g. 2.5 to 2 -3.5 to -4

ROUND_NEAREST_TOWARD_EVEN: round to nearest integer in case of two equidistant integers round to even e.g. 2.5 to 2 -3.5 to -4

ROUND_TOWARD_INFINITY: round to nearest integer away from zero

ROUND_TOWARD_ZERO: round to nearest integer toward zero

ROUND_UP: round to nearest integer toward infinity (ceiling)

ROUND_DOWN: round to nearest integer toward negative infinity (floor)

Outputs

Name

Element Type

Shape

output

type

Same as input

Mathematical Definition

\[\mathtt{output}_{i,j} = \mathtt{round}\left(\frac{\mathtt{input}_{i,j}}{\mathtt{scale}_{j}}\right) + \mathtt{zero_point}_{j}\]

C++ Interface

class Quantize : public ngraph::op::Op

Quantize operation Maps real input (r) to quantized output (q) using scale (s), zero point (z) and round mode: q = ROUND(r / s) + o.

Public Functions

const std::string &description() const

Get the string name for the type of the node, such as Add or Multiply. The class name, must not contain spaces as it is used for codegen.

Return

A const reference to the node’s type name

Quantize(const Output<Node> &input, const Output<Node> &scale, const Output<Node> &zero_point, const ngraph::element::Type &type, const ngraph::AxisSet &axes, RoundMode round_mode)

Constructs a Quantize operation.

Parameters
  • input: real input

  • scale: scale used for mapping

  • zero_point: zero point used for mapping

  • type: output element type

  • axes: axis positions on which scale and zero_point are specified

  • round_mode: describes how to perform ROUND function (see above)

void validate_and_infer_types()

Throws if the node is invalid.