Skip to content

Commit

Permalink
[tools/mec] Add namespace to operator
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
batcheu committed Nov 22, 2024
1 parent f092fe3 commit 49b13a0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tools/model_explorer_circle/src/circle_adapter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,17 @@ 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):
if tensor_id < 0:
Expand Down

0 comments on commit 49b13a0

Please sign in to comment.