onnx_light.onnx.shape_inference#

onnx_light.onnx.shape_inference.infer_function_output_types(function, input_types: list, attributes: list) list#

Infers the output types of a FunctionProto given input types and attributes.

Calls the native C++ binding which runs per-node type and shape inference over the function body, resolving formal attribute references. Input TypeProto and AttributeProto objects are serialized to bytes before being passed to the C++ binding; the returned bytes are deserialized back to TypeProto objects.

Parameters:
  • function – A FunctionProto.

  • input_types – A list of TypeProto objects, one per function input.

  • attributes – A list of AttributeProto objects providing values for the function’s formal attribute parameters.

Returns:

A list of TypeProto objects, one per function output.

Raises:

InferenceError – If node-level type or shape inference fails.

onnx_light.onnx.shape_inference.infer_node_outputs(schema, node, input_types: dict, input_data: dict | None = None, input_sparse_data: dict | None = None, opset_imports: list | None = None, ir_version: int | None = None) dict#

Runs type and shape inference for a single ONNX node.

Accepts both onnx_light and reference-onnx schemas. When an onnx_light schema is given its native _infer_node_outputs method is used directly. When a reference-onnx schema is given the node and type protos are serialised to bytes, inference is delegated to the reference schema, and the returned bytes are deserialised back into onnx_light TypeProto objects.

Parameters:
  • schema – An onnx_light or reference-onnx OpSchema object.

  • node – A NodeProto (onnx_light or reference-onnx).

  • input_types – Mapping from input name to TypeProto.

  • input_data – Optional mapping from input name to TensorProto.

  • input_sparse_data – Optional mapping from input name to SparseTensorProto.

  • opset_imports – Optional list of OperatorSetIdProto.

  • ir_version – IR version to use (defaults to the onnx_light IR version).

Returns:

Dict mapping output name to inferred TypeProto.

onnx_light.onnx.shape_inference.infer_shapes(model)#

Runs whole-model shape inference in place on the given model.

Calls the native C++ shape_inference::InferShapes(ModelProto&) routine over the given ModelProto. The model is modified in place: shape and type information is populated on every intermediate ValueInfoProto and graph output. The same model object is returned for convenience.

Parameters:

model – A ModelProto.

Returns:

The same model with inferred shapes/types.

Raises:

InferenceError – If shape inference fails on any node.