shape_quantization.h#
Shape-inference functions for ONNX operators in the quantization family.
-
namespace onnx_light
Alias that makes onnx-light headers compatible with code that references
ONNX_LIGHT_NAMESPACE(the macro used in the standard onnx package).Set to
ONNX_LIGHT_NAMESPACEso both names resolve to the same namespace.Symbol-visibility attribute for the public onnx-light C++ API.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_light(via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs fromonnx.-
namespace onnx_optim
-
namespace shapes
-
namespace quantization#
Functions
-
void ComputeShapeQuantizeLinear(ShapesContext &ctx, const NodeProto &node, const char *x, const char *y_zero_point)#
Computes the output :cpp:class:
OptimTensorof aQuantizeLinearnode and stores it inctx.QuantizeLinearproduces an outputythat always has the same shape as the inputx. The output element type is resolved as follows:when
y_zero_pointis supplied (third input, non-empty name) the output dtype is the dtype ofy_zero_point;otherwise, when the
output_dtypeinteger attribute is set (opset 23+), it is interpreted as aTensorProto::DataTypeand mapped to the matching :cpp:enum:TensorType;otherwise the output dtype defaults to
uint8.
The
axis,saturate,block_size, andprecisionattributes do not affect the output shape and are therefore not inspected by this function.- Parameters:
ctx – In/out context. Must already contain entries for
x,y_scale, andy_zero_pointwhen the latter is provided; on return it also contains an entry fornode.output(0).node – The
QuantizeLinearNodeProtowhose output should be described.node.op_type()must be"QuantizeLinear"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.y_zero_point – Name of the
y_zero_pointinput value, ornullptr/ empty string when the input is omitted. When non-empty it must be present inctx.
- Throws:
-
void ComputeShapeDequantizeLinear(ShapesContext &ctx, const NodeProto &node, const char *x, const char *x_scale)#
Computes the output :cpp:class:
OptimTensorof aDequantizeLinearnode and stores it inctx.DequantizeLinearproduces an outputythat always has the same shape as the inputx. The output element type is resolved as follows:when the
output_dtypeinteger attribute is set (opset 23+) it is interpreted as aTensorProto::DataTypeand mapped to the matching :cpp:enum:TensorType;otherwise, the output dtype is the dtype of
x_scale.
The
axisandblock_sizeattributes do not affect the output shape and are therefore not inspected by this function.- Parameters:
ctx – In/out context. Must already contain entries for
xandx_scale; on return it also contains an entry fornode.output(0).node – The
DequantizeLinearNodeProtowhose output should be described.node.op_type()must be"DequantizeLinear"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.x_scale – Name of the
x_scaleinput value, used to derive the default output element type. Must be present inctx.
- Throws:
-
void ComputeShapeDynamicQuantizeLinear(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorentries of aDynamicQuantizeLinearnode and stores them inctx.DynamicQuantizeLinearproduces three outputs (since opset 11 in the ai.onnx domain):y— same shape as the inputx, with dtypeuint8;y_scale— scalar (rank 0)float;y_zero_point— scalar (rank 0)uint8.
The operator takes no attributes that affect output shapes.
- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains entries for the (up to three) non-empty outputs ofnode.node – The
DynamicQuantizeLinearNodeProtowhose outputs should be described.node.op_type()must be"DynamicQuantizeLinear"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeQLinearConv(ShapesContext &ctx, const NodeProto &node, const char *x, const char *w, const char *y_zero_point)#
Computes the output :cpp:class:
OptimTensorof aQLinearConvnode and stores it inctx.The output shape rule matches :cpp:func:
ComputeShapeConvapplied to the quantized inputsx(input 0) andw(input 3). The output dtype is the dtype ofy_zero_point(input 7).- Parameters:
ctx – In/out context. Must already contain entries for
x,w, andy_zero_point; on return it also contains an entry fornode.output(0).node – The
QLinearConvNodeProtowhose output should be described.node.op_type()must be"QLinearConv"andnodemust declare at least one output.x – Name of the input data value (rank >= 3) in
ctx.w – Name of the weight value (rank >= 3) in
ctx.y_zero_point – Name of the
y_zero_pointinput value, used to derive the output element type. Must be present inctx.
- Throws:
-
void ComputeShapeQLinearMatMul(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b, const char *y_zero_point)#
Computes the output :cpp:class:
OptimTensorof aQLinearMatMulnode and stores it inctx.The output shape rule matches :cpp:func:
ComputeShapeMatMulapplied to the quantized inputsa(input 0) andb(input 3). The output dtype is the dtype ofy_zero_point(input 7).- Parameters:
ctx – In/out context. Must already contain entries for
a,b, andy_zero_point; on return it also contains an entry fornode.output(0).node – The
QLinearMatMulNodeProtowhose output should be described.node.op_type()must be"QLinearMatMul"andnodemust declare at least one output.a – Name of the input
avalue (rank >= 1) inctx.b – Name of the input
bvalue (rank >= 1) inctx.y_zero_point – Name of the
y_zero_pointinput value, used to derive the output element type. Must be present inctx.
- Throws:
-
void ComputeShapeQuantizeLinear(ShapesContext &ctx, const NodeProto &node, const char *x, const char *y_zero_point)#
-
namespace quantization#
-
namespace shapes
-
namespace onnx_optim