T - data type for output() output@Operator public final class QuantizeAndDequantizeV2<T extends Number> extends PrimitiveOp implements Operand<T>
This op simulates the precision loss from the quantized forward pass by:
1. Quantizing the tensor to fixed point numbers, which should match the target quantization method when it is used in inference. 2. Dequantizing it back to floating point numbers for the following ops, most likely matmul.
There are different ways to quantize. This version uses only scaling, so 0.0 maps to 0.
From the specified 'num_bits' in the quantized output type, it determines minimum and maximum representable quantized values.
e.g.
Note: If the input_min, input_max are specified, they do not need to equal the actual minimum and maximum values in the tensor. e.g. in some cases it may be beneficial to specify these values such that the low probability extremes of the input distribution are clipped.
This op determines the maximum scale_factor that would map the initial [input_min, input_max] range to a range that lies within the representable quantized range.
It determines the scale from one of input_min and input_max, then updates the other one to maximize the respresentable range.
e.g.
output = round(clamp(value, input_min, input_max) * scale_factor) / scale_factor.
The above round function rounds the value based on the given round_mode.
| Modifier and Type | Class and Description |
|---|---|
static class |
QuantizeAndDequantizeV2.Options
Optional attributes for
QuantizeAndDequantizeV2 |
operation| Modifier and Type | Method and Description |
|---|---|
Output<T> |
asOutput()
Returns the symbolic handle of a tensor.
|
static <T extends Number> |
create(Scope scope,
Operand<T> input,
Operand<T> inputMin,
Operand<T> inputMax,
QuantizeAndDequantizeV2.Options... options)
Factory method to create a class to wrap a new QuantizeAndDequantizeV2 operation to the graph.
|
static QuantizeAndDequantizeV2.Options |
numBits(Long numBits) |
Output<T> |
output() |
static QuantizeAndDequantizeV2.Options |
rangeGiven(Boolean rangeGiven) |
static QuantizeAndDequantizeV2.Options |
roundMode(String roundMode) |
static QuantizeAndDequantizeV2.Options |
signedInput(Boolean signedInput) |
equals, hashCode, toStringpublic static <T extends Number> QuantizeAndDequantizeV2<T> create(Scope scope, Operand<T> input, Operand<T> inputMin, Operand<T> inputMax, QuantizeAndDequantizeV2.Options... options)
scope - current graph scopeinput - Tensor to quantize and then dequantize.inputMin - If `range_given == True`, this specifies the minimum input value that needs to
be represented, otherwise it is determined from the min value of the `input`
tensor.inputMax - If `range_given == True`, this specifies the maximum input value that needs to
be represented, otherwise it is determined from the max value of the `input`
tensor.options - carries optional attributes valuespublic static QuantizeAndDequantizeV2.Options signedInput(Boolean signedInput)
signedInput - Whether the quantization is signed or unsigned. (actually this parameter should
have been called `signed_output`)public static QuantizeAndDequantizeV2.Options numBits(Long numBits)
numBits - The bitwidth of the quantization.public static QuantizeAndDequantizeV2.Options rangeGiven(Boolean rangeGiven)
rangeGiven - Whether the range is given or should be determined from the `input` tensor.public static QuantizeAndDequantizeV2.Options roundMode(String roundMode)
roundMode - The 'round_mode' attribute controls which rounding tie-breaking algorithm is
used when rounding float values to their quantized equivalents. The following
rounding modes are currently supported:
public Output<T> asOutput()
OperandInputs to TensorFlow operations are outputs of another TensorFlow operation. This method is used to obtain a symbolic handle that represents the computation of the input.
asOutput in interface Operand<T extends Number>OperationBuilder.addInput(Output)Copyright © 2015–2019. All rights reserved.