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 offset. The coordinate \(j\) of scale and offset 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
offset 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 offset 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{offset}_{j}\]

C++ Interface

class Quantize : public ngraph::op::Op

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

Public Functions

Quantize(std::shared_ptr<Node> input, std::shared_ptr<Node> scale, std::shared_ptr<Node> offset, 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
  • offset: offset used for mapping
  • type: output element type
  • axes: axis positions on which scale and offset are specified
  • round_mode: describes how to perform ROUND function (see above)

void validate_and_infer_types()

Throws if the node is invalid.