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=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, )
- Parameters:
graph_like (ir.Graph | ir.Function | None)
- 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.
- initializer(tensor, name=None)[source]¶
- Parameters:
tensor (TensorProtocol)
name (str | None)
- Return type:
- op(op_type, inputs, attributes=None, *, domain='', overload='', version=None, graph=None, name=None, doc_string=None, metadata_props=None, output=None)[source]¶
- Parameters:
op_type (str)
attributes (Mapping[str, str | int | float | Sequence[int] | Sequence[float] | Sequence[str] | TensorProtocol | TensorProto | Attr | GraphProtocol | Sequence[GraphProtocol] | GraphProto | TypeProtocol | Sequence[TypeProtocol] | None] | None)
domain (str)
overload (str)
version (int | None)
graph (Graph | None)
name (str | None)
doc_string (str | None)
output (Value | None)
- Return type:
- op_multi_out(op_type, inputs, attributes=None, *, num_outputs=None, outputs=None, domain='', overload='', version=None, graph=None, name=None, doc_string=None, metadata_props=None)[source]¶
- Parameters:
op_type (str)
attributes (Mapping[str, str | int | float | Sequence[int] | Sequence[float] | Sequence[str] | TensorProtocol | TensorProto | Attr | GraphProtocol | Sequence[GraphProtocol] | GraphProto | TypeProtocol | Sequence[TypeProtocol] | None] | None)
num_outputs (int | None)
domain (str)
overload (str)
version (int | None)
graph (Graph | None)
name (str | None)
doc_string (str | None)
- Return type: