Public Member Functions | |
def | __init__ (self, Sequence[Node] nodes=None, Sequence[Tensor] inputs=None, Sequence[Tensor] outputs=None, name=None, doc_string=None, opset=None) |
def | __getattr__ (self, name) |
def | __setattr__ (self, name, value) |
def | __eq__ (self, "Graph" other) |
def | node_ids (self) |
def | cleanup (self, remove_unused_node_outputs=False) |
def | toposort (self) |
def | tensors (self, check_duplicates=False) |
def | fold_constants (self) |
def | layer (self, inputs=[], outputs=[], *args, **kwargs) |
def | __deepcopy__ (self, memo) |
def | __str__ (self) |
def | __repr__ (self) |
Static Public Member Functions | |
def | register (opsets=None) |
Public Attributes | |
nodes | |
inputs | |
outputs | |
name | |
doc_string | |
opset | |
name_idx | |
node | |
level | |
Static Public Attributes | |
int | DEFAULT_OPSET = 11 |
OPSET_FUNC_MAP = defaultdict(dict) | |
GLOBAL_FUNC_MAP = dict() | |
Private Member Functions | |
def | _get_node_id (self, node) |
def | _get_used_node_ids (self) |
def | _generate_name (self, prefix) |
Private Attributes | |
__name__ | |
Represents a graph containing nodes and tensors.
def onnx_graphsurgeon.ir.graph.Graph.__init__ | ( | self, | |
Sequence[Node] | nodes = None , |
||
Sequence[Tensor] | inputs = None , |
||
Sequence[Tensor] | outputs = None , |
||
name = None , |
|||
doc_string = None , |
|||
opset = None |
|||
) |
Args: nodes (Sequence[Node]): A list of the nodes in this graph. inputs (Sequence[Tensor]): A list of graph input Tensors. outputs (Sequence[Tensor]): A list of graph output Tensors. name (str): The name of the graph. Defaults to "onnx_graphsurgeon_graph". doc_string (str): A doc_string for the graph. Defaults to "".
|
static |
Registers a function with the Graph class for the specified group of opsets. After registering the function, it can be accessed like a normal member function. For example: :: @Graph.register() def add(self, a, b): return self.layer(op="Add", inputs=[a, b], outputs=["add_out_gs"]) graph.add(a, b) Args: opsets (Sequence[int]): A group of opsets for which to register the function. Multiple functions with the same name may be registered simultaneously if they are registered for different opsets. Registering a function with a duplicate name for the same opsets will overwrite any function previously registered for those opsets. By default, the function is registered for all opsets.
def onnx_graphsurgeon.ir.graph.Graph.__getattr__ | ( | self, | |
name | |||
) |
def onnx_graphsurgeon.ir.graph.Graph.__setattr__ | ( | self, | |
name, | |||
value | |||
) |
def onnx_graphsurgeon.ir.graph.Graph.__eq__ | ( | self, | |
"Graph" | other | ||
) |
def onnx_graphsurgeon.ir.graph.Graph.node_ids | ( | self | ) |
Returns a context manager that supplies unique integer IDs for Nodes in the Graph. For example: :: with graph.node_ids(): assert graph.nodes[0].id != graph.nodes[1].id Returns: NodeIDAdder: A context manager that supplies unique integer IDs for Nodes.
|
private |
|
private |
def onnx_graphsurgeon.ir.graph.Graph.cleanup | ( | self, | |
remove_unused_node_outputs = False |
|||
) |
Removes unused nodes and tensors from the graph. A node or tensor is considered unused if it does not contribute to any of the graph outputs. Additionally, any producer nodes of graph input tensors are removed from the graph. *Note: This function will never modify graph output tensors.* Args: remove_unused_node_outputs (bool): Whether to remove unused output tensors of nodes. This will never remove empty-tensor (i.e. optional, but omitted) outputs. Defaults to False. Returns: self
def onnx_graphsurgeon.ir.graph.Graph.toposort | ( | self | ) |
Topologically sort the graph in place. Returns: self
def onnx_graphsurgeon.ir.graph.Graph.tensors | ( | self, | |
check_duplicates = False |
|||
) |
Creates a tensor map of all the tensors in this graph by walking over all nodes. Empty tensors are omitted from this map. Tensors are guaranteed to be in order of the nodes in the graph. Hence, if the graph is topologically sorted, the tensor map will be too. Args: check_duplicates (bool): Whether to fail if multiple tensors with the same name are encountered. Raises: OnnxGraphSurgeonException: If check_duplicates is True, and multiple distinct tensors in the graph share the same name. Returns: OrderedDict[str, Tensor]: A mapping of tensor names to tensors.
def onnx_graphsurgeon.ir.graph.Graph.fold_constants | ( | self | ) |
Folds constants in-place in the graph. The graph must be topologically sorted prior to calling this function (see `toposort()`). This function will not remove constants after folding them. In order to get rid of these hanging nodes, you can run the `cleanup()` function. *Note: Due to how this function is implemented, the graph must be exportable to ONNX, and evaluable in ONNX-Runtime. Additionally, ONNX-Runtime must be installed.* Returns: self
|
private |
def onnx_graphsurgeon.ir.graph.Graph.layer | ( | self, | |
inputs = [] , |
|||
outputs = [] , |
|||
* | args, | ||
** | kwargs | ||
) |
Creates a node, adds it to this graph, and optionally creates its input and output tensors. The input and output lists can include various different types: - ``Tensor``: Any Tensors provided will be used as-is in the inputs/outputs of the node created. - ``str``: If a string is provided, this function will generate a new tensor using the string to generate a name. \ It will append an index to the end of the provided string to attempt to avoid duplicate tensor names, but since this \ doesn't guarantee that the name will be unique, you should try to ensure that the string provided is as unique as possible. - ``numpy.ndarray``: If a NumPy array is provided, this function will generate a Constant tensor using the name prefix: "onnx_graphsurgeon_constant" - ``Union[List[Number], Tuple[Number]]``: If a list or tuple of numbers (int or float) is provided, this function will generate a Constant tensor using the name prefix: "onnx_graphsurgeon_lst_constant" Args: inputs (List[Union[Tensor, str, numpy.ndarray]]): The list of inputs outputs (List[Union[Tensor, str, numpy.ndarray]]): The list of outputs args/kwargs: These are passed directly to the constructor of Node Returns: List[Tensor]: The output tensors of the node
def onnx_graphsurgeon.ir.graph.Graph.__deepcopy__ | ( | self, | |
memo | |||
) |
Makes a deep copy of this graph.
def onnx_graphsurgeon.ir.graph.Graph.__str__ | ( | self | ) |
def onnx_graphsurgeon.ir.graph.Graph.__repr__ | ( | self | ) |
|
static |
|
static |
|
static |
onnx_graphsurgeon.ir.graph.Graph.nodes |
onnx_graphsurgeon.ir.graph.Graph.inputs |
onnx_graphsurgeon.ir.graph.Graph.outputs |
onnx_graphsurgeon.ir.graph.Graph.name |
|
private |
onnx_graphsurgeon.ir.graph.Graph.doc_string |
onnx_graphsurgeon.ir.graph.Graph.opset |
onnx_graphsurgeon.ir.graph.Graph.name_idx |
onnx_graphsurgeon.ir.graph.Graph.node |
onnx_graphsurgeon.ir.graph.Graph.level |