onnx_ir.tape¶
Taping module to facilitate building IR graphs.
The onnx_ir.tape
module provides utilities for recording nodes and initializers to construct computational graphs or functions.
The Tape
class¶
The Tape
class is a recorder that collects nodes and initializers created during the construction of a graph or function. It supports creating nodes with single or multiple outputs and registering initializers.
- class onnx_ir.tape.Tape(graph_like: Graph | Function | None = None)¶
Tape class.
A tape is a recorder that collects nodes and initializers that are created so that they can be used for creating a graph.
Example:
import onnx_ir as ir tape = ir.tape.Tape() a = tape.initializer(ir.tensor([1, 2, 3], name="a")) b: ir.Value = ... c: ir.Value = ... x = tape.op("Add", [a, b], attributes={"alpha": 1.0}) y = tape.op("Mul", [x, c], attributes={"beta": 2.0}) model = ir.Model( graph := ir.Graph( inputs=[b, c], outputs=[y], nodes=tape.nodes, initializers=tape.initializers opset_imports={"": 20}, ), ir_version=10, )
- graph_like¶
The graph to append the new nodes and initializers to. When it is None, the nodes and initializers are creating without owned by a graph. Initializers will not be added to functions because it is not supported by ONNX.
- op(op_type: str, inputs: Sequence[Value | None], attributes: Mapping[str, str | int | float | Sequence[int] | Sequence[float] | Sequence[str] | TensorProtocol | TensorProto | Attr | GraphProtocol | Sequence[GraphProtocol] | GraphProto | TypeProtocol | Sequence[TypeProtocol] | None] | None = None, *, domain: str = '', overload: str = '', version: int | None = None, graph: Graph | None = None, name: str | None = None, doc_string: str | None = None, metadata_props: dict[str, str] | None = None, output: Value | None = None) Value [source]¶
- op_multi_out(op_type: str, inputs: Sequence[Value | None], attributes: Mapping[str, str | int | float | Sequence[int] | Sequence[float] | Sequence[str] | TensorProtocol | TensorProto | Attr | GraphProtocol | Sequence[GraphProtocol] | GraphProto | TypeProtocol | Sequence[TypeProtocol] | None] | None = None, *, num_outputs: int | None = None, outputs: Sequence[Value] | None = None, domain: str = '', overload: str = '', version: int | None = None, graph: Graph | None = None, name: str | None = None, doc_string: str | None = None, metadata_props: dict[str, str] | None = None) Sequence[Value] [source]¶