Node

class onnx_graphsurgeon.Node(op: str, name: Optional[str] = None, attrs: Optional[Dict[str, object]] = None, inputs: Optional[List[onnx_graphsurgeon.ir.tensor.Tensor]] = None, outputs: Optional[List[onnx_graphsurgeon.ir.tensor.Tensor]] = None)

Bases: object

A node represents an operation in a graph, and consumes zero or more Tensors, and produces zero or more Tensors.

Parameters
  • op (str) – The operation this node performs.

  • name (str) – The name of this node.

  • attrs (Dict[str, object]) – A dictionary that maps attribute names to their values.

  • inputs (List[Tensor]) – A list of zero or more input Tensors.

  • outputs (List[Tensor]) – A list of zero or more output Tensors.

i(tensor_idx=0, producer_idx=0)

Convenience function to get a producer node of one of this node’s input tensors. Note that the parameters are swapped compared to the o() function; this is because tensors are likely to have only a single producer

For example:

assert node.i() == node.inputs[0].inputs[0]
assert node.i(1, 2) == node.inputs[1].inputs[2]
Parameters
  • tensor_idx (int) – The index of the input tensor of this node. Defaults to 0.

  • producer_idx (int) – The index of the producer of the input tensor, if the tensor has multiple producers. Defaults to 0

Returns

The specified producer (input) node.

Return type

Node

o(consumer_idx=0, tensor_idx=0)

Convenience function to get a consumer node of one of this node’s output tensors.

For example:

assert node.o() == node.outputs[0].outputs[0]
assert node.o(2, 1) == node.outputs[1].outputs[2]
Parameters
  • consumer_idx (int) – The index of the consumer of the input tensor. Defaults to 0.

  • tensor_idx (int) – The index of the output tensor of this node, if the node has multiple outputs. Defaults to 0.

Returns

The specified consumer (output) node

Return type

Node

copy(inputs: Optional[List[onnx_graphsurgeon.ir.tensor.Tensor]] = None, outputs: Optional[List[onnx_graphsurgeon.ir.tensor.Tensor]] = None, tensor_map=None)

Makes a shallow copy of this node, overriding input and output information.

Note: Generally, you should only ever make a copy of a Graph.