onnx_light.tools.pretty_print#

Pretty-print an ONNX proto in a compact, human-readable form.

The renderer mirrors the style of yobx.helpers.onnx_helper.pretty_onnx (see xadupre/yet-another-onnx-builder): each node is rendered as OpType(inputs) -> outputs (optionally prefixed by the node domain), value infos as dtype[shape] name and graphs/models as a “simple text plot” listing opsets, inputs, initializers, nodes and outputs.

The implementation is pure Python and duck-typed against the standard ONNX message API (ModelProto, GraphProto, FunctionProto, NodeProto, ValueInfoProto, TensorProto, TypeProto, AttributeProto and TensorShapeProto); it therefore works both with messages built by onnx_light and with messages built by the upstream onnx package.

Example:

from onnx_light.tools import pretty_onnx

print(pretty_onnx(model))
onnx_light.tools.pretty_print.pretty_onnx(onx: Any, with_attributes: bool = False, highlight: set[str] | None = None, shape_inference: bool = False, include_node_tags: bool = False, include_inplace: bool = False, include_release: bool = False) str#

Returns a compact, human-readable string for any ONNX proto.

The argument may be a ModelProto, GraphProto, FunctionProto, NodeProto, ValueInfoProto, TypeProto, AttributeProto, TensorProto or a file path (str). The rendering style mirrors yobx.helpers.onnx_helper.pretty_onnx: nodes appear as OpType(inputs) -> outputs, value infos as dtype[shape] name, and graphs/models as a list of opsets, inputs, initializers, nodes and outputs.

Parameters:
  • onx – ONNX proto, or a path to a model file.

  • with_attributes – when True, node attributes are appended to the node line (each name=value pair on its own line, or inline after --- when there is a single attribute).

  • highlight – optional set of tensor names to wrap in ** markers in the rendered I/O lists.

  • shape_inference – when True and onx is a model, run onnx_light shape inference before rendering.

  • include_node_tags – when True, nodes that carry a onnx_light.node_tag metadata entry (shape, axes or weight) are prefixed with [tag] in the rendered output.

  • include_inplace – when True, nodes that carry onnx_light.inplace_reuse metadata have the inplace reuse opportunities appended to their line, e.g. inplace: out0=in0(equal).

  • include_release – when True, nodes that carry onnx_light.release_after metadata have the release hints appended to their line, e.g. release: A, B.

Returns:

the formatted text.

See also

pretty_onnx: shape info, shape tags, inplace and release annotations — end-to-end example showing pretty_onnx with shape info, shape tags, inplace and release annotations.