mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-06 04:28:32 +00:00
Type and Shape inference for QuantizeLinear and DeQuantizeLinear Ops (#408)
* Type and Shape inference for QuantizeeLinear and DeQuantizeLinear Ops * removing redundant type checking for some inputs and outputs * remove unnecessary type check deom type inference
This commit is contained in:
parent
60cdb79204
commit
93bcd9beb6
1 changed files with 22 additions and 2 deletions
|
|
@ -522,7 +522,16 @@ activation and leaky_relu_alpha.)DOC")
|
|||
.SetDoc(R"DOC(
|
||||
The linear quantization operator. It consumes a full precision data, a scale, a zero point and computes the quantized data.
|
||||
The quantization formula is y = (x / y_scale) + y_zero_point. For (x / y_scale), it computes the nearest integer value to arg (in floating-point format),
|
||||
rounding halfway cases away from zero. Scale and zero point must have same shape. They must be either scalar (per tensor) or 1-D tensor (per 'axis').)DOC");
|
||||
rounding halfway cases away from zero. Scale and zero point must have same shape. They must be either scalar (per tensor) or 1-D tensor (per 'axis').)DOC")
|
||||
.TypeAndShapeInferenceFunction([](ONNX_NAMESPACE::InferenceContext& ctx) {
|
||||
propagateElemTypeFromInputToOutput(ctx, 2, 0);
|
||||
|
||||
if (!hasInputShape(ctx, 0))
|
||||
return;
|
||||
|
||||
auto& input_shape = getInputShape(ctx, 0);
|
||||
updateOutputShape(ctx, 0, input_shape);
|
||||
});
|
||||
|
||||
ONNX_CONTRIB_OPERATOR_SCHEMA(DequantizeLinear)
|
||||
.SetDomain(kMSDomain)
|
||||
|
|
@ -543,7 +552,18 @@ The quantization formula is y = (x / y_scale) + y_zero_point. For (x / y_scale),
|
|||
.SetDoc(R"DOC(
|
||||
The linear de-quantization operator. It consumes a quantized data, a scale, a zero point and computes the full precision data.
|
||||
The dequantization formula is y = (x - x_zero_point) * x_scale.
|
||||
Scale and zero point must have same shape. They must be either scalar (per tensor) or 1-D tensor (per 'axis').)DOC");
|
||||
Scale and zero point must have same shape. They must be either scalar (per tensor) or 1-D tensor (per 'axis').)DOC")
|
||||
.TypeAndShapeInferenceFunction([](ONNX_NAMESPACE::InferenceContext& ctx) {
|
||||
auto y_type = ctx.getOutputType(0);
|
||||
// only float is supported
|
||||
y_type->mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto::FLOAT);
|
||||
|
||||
if (!hasInputShape(ctx, 0))
|
||||
return;
|
||||
|
||||
auto& input_shape = getInputShape(ctx, 0);
|
||||
updateOutputShape(ctx, 0, input_shape);
|
||||
});
|
||||
|
||||
ONNX_CONTRIB_OPERATOR_SCHEMA(QLinearMatMul)
|
||||
.SetDomain(kMSDomain)
|
||||
|
|
|
|||
Loading…
Reference in a new issue