onnx_array_api.graph_api#

GraphBuilder#

class onnx_array_api.graph_api.GraphBuilder(target_opset_or_existing_proto: int | Dict[str, int] | ModelProto | FunctionProto | None = None, input_names: Sequence[str] | None = None, as_function: bool = False, optimization_options: OptimizationOptions | None = None, args: List[Any] | None = None, verbose: int = 0, ir_version: int | None = None)[source]#
constant_folding()[source]#

Folds all constants. Constants are marked during the creation of the graph. There is no need to propagate this information.

is_constant(name: str) bool[source]#

Tells if a result is a constant.

make_nodes(builder: GraphBuilder, input_names: List[str], output_names: List[str], prefix: str = '') str | List[str][source]#

Appends all nodes and initializers from another builder. Handles the renaming of results. The content stored in ‘builder’ is modified inplace to avoid copying.

Parameters:
  • builder – other builder

  • input_names – input names

  • output_names – output names

  • prefix – prefix all name from this builder

Returns:

output names

np(index: int | None = None, op_type: str | None = None, name: str | None = None) NodePattern[source]#

Returns an instance of NodePattern.

remove_identity_nodes()[source]#

Removes identity nodes.

remove_unused()[source]#

Simple function to remove unused nodes. It does not look into subgraphs and assumes there is none. Everything is done in one pass.

update_attribute(pat: NodePattern, recursive: bool = False, **kwargs: Dict[str, Any]) int[source]#

Udates attributes for nodes matching the

Parameters:
  • pat – returned by method GraphBuilder.np()

  • recursive – walk through subgraph

  • kwargs – attributes to modify

Returns:

number of modified nodes

update_node(node: NodeProto, **kwargs) bool[source]#

Updates attributes of a node proto. Returns True if the node was updated.

NodePattern#

class onnx_array_api.graph_api.NodePattern(index: int | None = None, op_type: str | None = None, name: None = None)[source]#

Class defining a matching pattern able to find nodes in a set of nodes.

find(graph: GraphBuilder) Iterator[source]#

Iterates on nodes matching the pattern.

match(index, node: NodeProto) bool[source]#

Tells if a node is matching this pattern.

OptimizationOptions#

class onnx_array_api.graph_api.graph_builder.OptimizationOptions(remove_unused: bool = True, constant_folding: bool = False, constant_size: int = 1024)[source]#