From d05bec095e4a99d9b152ca960abeacee4b9f1ea5 Mon Sep 17 00:00:00 2001 From: Jonghwa Lee Date: Fri, 22 Nov 2024 19:11:16 +0900 Subject: [PATCH] [tools/mec] Add namespace to operator (#14354) It adds a namespace to the operator node based on the name of its output tensor. It helps to graph folded with grouping of operators that uses same namespace. ONE-DCO-1.0-Signed-off-by: Jonghwa Lee --- tools/model_explorer_circle/src/circle_adapter/main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/model_explorer_circle/src/circle_adapter/main.py b/tools/model_explorer_circle/src/circle_adapter/main.py index 3a6c871fa0d..7bd8a9074b3 100644 --- a/tools/model_explorer_circle/src/circle_adapter/main.py +++ b/tools/model_explorer_circle/src/circle_adapter/main.py @@ -104,7 +104,15 @@ def build_graph(self, me_graph: graph_builder.Graph) -> None: for idx, op in enumerate(sub_graph.operators): name = self.opcode_to_name( self.model.operatorCodes[op.opcodeIndex].builtinCode) - me_node = graph_builder.GraphNode(id=f'{idx}', label=name) + # Construct namespace following output tensor's name + output_tensor_id = op.outputs[0] + output_tensor = sub_graph.tensors[output_tensor_id] + ns = output_tensor.name.decode("utf-8") + if '/' in ns: + # Let's take maximum 2 depths of the tensor name + # '/A/B/C/D' becomes 'A/B' + ns = '/'.join(ns.strip('/').split('/')[:2]) + me_node = graph_builder.GraphNode(id=f'{idx}', label=name, namespace=ns) me_graph.nodes.append(me_node) # Connect edges from inputs to this operator node for i, tensor_id in enumerate(op.inputs):