diff --git a/tools/model_explorer_circle/src/model_explorer_circle/circle_metadata.py b/tools/model_explorer_circle/src/model_explorer_circle/circle_metadata.py new file mode 100644 index 00000000000..e0c93017362 --- /dev/null +++ b/tools/model_explorer_circle/src/model_explorer_circle/circle_metadata.py @@ -0,0 +1,183 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Metatdata for circle model format """ + +# This is generated by circle_input_names command line tool +input_args_dict = { + "ABS": ["x"], + "ADD": ["x", "y"], + "ADD_N": ["inputs"], + "ARG_MAX": ["input", "dimension"], + "ARG_MIN": ["input", "dimension"], + "AVERAGE_POOL_2D": ["value"], + "BATCH_TO_SPACE_ND": ["input", "block_shape", "crops"], + "BATCH_MATMUL": ["x", "y"], + "BIDIRECTIONAL_SEQUENCE_LSTM": [ + "input", "fw_input_to_input_weights", "fw_input_to_forget_weights", + "fw_input_to_cell_weights", "fw_input_to_output_weights", + "fw_recurrent_to_input_weights", "fw_recurrent_to_forget_weights", + "fw_recurrent_to_cell_weights", "fw_recurrent_to_output_weights", + "fw_cell_to_input_weights", "fw_cell_to_forget_weights", + "fw_cell_to_output_weights", "fw_input_gate_bias", "fw_forget_gate_bias", + "fw_cell_gate_bias", "fw_output_gate_bias", "fw_projection_weights", + "fw_projection_bias", "bw_input_to_input_weights", "bw_input_to_forget_weights", + "bw_input_to_cell_weights", "bw_input_to_output_weights", + "bw_recurrent_to_input_weights", "bw_recurrent_to_forget_weights", + "bw_recurrent_to_cell_weights", "bw_recurrent_to_output_weights", + "bw_cell_to_input_weights", "bw_cell_to_forget_weights", + "bw_cell_to_output_weights", "bw_input_gate_bias", "bw_forget_gate_bias", + "bw_cell_gate_bias", "bw_output_gate_bias", "bw_projection_weights", + "bw_projection_bias", "fw_activation_state", "fw_cell_state", + "bw_activation_state", "bw_cell_state", "auxillary_input", + "fw_auxillary_input_to_input_weights", "fw_auxillary_input_to_forget_weights", + "fw_auxillary_input_to_cell_weights", "fw_auxillary_input_to_output_weights", + "bw_auxillary_input_to_input_weights", "bw_auxillary_input_to_forget_weights", + "bw_auxillary_input_to_cell_weights", "bw_auxillary_input_to_output_weights" + ], + "BROADCAST_TO": ["input", "shape"], + "CAST": ["x"], + "CEIL": ["x"], + "CONCATENATION": ["values"], + "CONV_2D": ["input", "filter", "bias"], + "COS": ["x"], + "CUMSUM": ["input", "axis"], + "CUSTOM": ["input0"], + "DENSIFY": ["input"], + "DEPTH_TO_SPACE": ["input"], + "DEPTHWISE_CONV_2D": ["input", "filter", "bias"], + "DEQUANTIZE": ["input"], + "DIV": ["x", "y"], + "ELU": ["features"], + "EQUAL": ["x", "y"], + "EXP": ["x"], + "EXPAND_DIMS": ["input", "axis"], + "FAKE_QUANT": ["inputs"], + "FILL": ["dims", "value"], + "FLOOR": ["x"], + "FLOOR_DIV": ["x", "y"], + "FLOOR_MOD": ["x", "y"], + "FULLY_CONNECTED": ["input", "weights", "bias"], + "GATHER": ["params", "indices"], + "GATHER_ND": ["params", "indices"], + "GELU": ["features"], + "GREATER": ["x", "y"], + "GREATER_EQUAL": ["x", "y"], + "GRU": [ + "input", "hidden_hidden", "hidden_hidden_bias", "hidden_input", + "hidden_input_bias", "state" + ], + "HARD_SWISH": ["features"], + "IF": ["cond", "input"], + "L2_NORMALIZATION": ["x"], + "L2_POOL_2D": ["value"], + "LEAKY_RELU": ["features"], + "LESS": ["x", "y"], + "LESS_EQUAL": ["x", "y"], + "LOCAL_RESPONSE_NORMALIZATION": ["input"], + "LOG": ["x"], + "LOGICAL_AND": ["x", "y"], + "LOGICAL_NOT": ["x"], + "LOGICAL_OR": ["x", "y"], + "LOGISTIC": ["x"], + "LOG_SOFTMAX": ["logits"], + "MATRIX_DIAG": ["diagonal"], + "MAX_POOL_2D": ["value"], + "MATRIX_SET_DIAG": ["input", "diagonal"], + "MAXIMUM": ["x", "y"], + "MEAN": ["input", "reduction_indices"], + "MINIMUM": ["x", "y"], + "MIRROR_PAD": ["input", "paddings"], + "MUL": ["x", "y"], + "NEG": ["x"], + "NON_MAX_SUPPRESSION_V4": + ["boxes", "scores", "max_output_size", "iou_threshold", "score_threshold"], + "NON_MAX_SUPPRESSION_V5": [ + "boxes", "scores", "max_output_size", "iou_threshold", "score_threshold", + "soft_nms_sigma" + ], + "NOT_EQUAL": ["x", "y"], + "ONE_HOT": ["indices", "depth", "on_value", "off_value"], + "PACK": ["values"], + "PAD": ["input", "paddings"], + "PADV2": ["input", "paddings", "constant_values"], + "POW": ["x", "y"], + "PRELU": ["input", "alpha"], + "QUANTIZE": ["input"], + "RANGE": ["start", "limit", "delta"], + "RANK": ["input"], + "REDUCE_ANY": ["input", "reduction_indices"], + "REDUCE_MAX": ["input", "reduction_indices"], + "REDUCE_MIN": ["input", "reduction_indices"], + "REDUCE_PROD": ["input", "reduction_indices"], + "RELU": ["features"], + "RELU_0_TO_1": ["features"], + "RELU6": ["features"], + "RELU_N1_TO_1": ["features"], + "RESHAPE": ["tensor", "shape"], + "RESIZE_BILINEAR": ["input", "size"], + "RESIZE_NEAREST_NEIGHBOR": ["input", "size"], + "REVERSE_SEQUENCE": ["input", "seq_lengths"], + "REVERSE_V2": ["tensor", "axis"], + "ROUND": ["x"], + "RSQRT": ["x"], + "SCATTER_ND": ["indices", "updates", "shape"], + "SEGMENT_SUM": ["input", "segment_ids"], + "SELECT": ["condition", "t", "e"], + "SELECT_V2": ["condition", "t", "e"], + "SHAPE": ["input"], + "SIN": ["x"], + "SLICE": ["input", "begin", "size"], + "SOFTMAX": ["logits"], + "SPACE_TO_BATCH_ND": ["input", "block_shape", "paddings"], + "SPACE_TO_DEPTH": ["input"], + "SPARSE_TO_DENSE": ["indices", "output_shape", "values", "default_value"], + "SPLIT": ["split_dim", "input"], + "SPLIT_V": ["input", "size_splits", "split_dim"], + "SQRT": ["x"], + "SQUARE": ["x"], + "SQUARED_DIFFERENCE": ["x", "y"], + "SQUEEZE": ["input"], + "STRIDED_SLICE": ["input", "begin", "end", "strides"], + "SUB": ["x", "y"], + "SUM": ["input", "reduction_indices"], + "SVDF": ["input", "weight_feature", "weight_time", "bias", "State"], + "TANH": ["x"], + "TILE": ["input", "multiples"], + "TOPK_V2": ["input", "k"], + "TRANSPOSE": ["a", "perm"], + "TRANSPOSE_CONV": ["inputSizes", "filter", "outBackProp", "bias"], + "UNIDIRECTIONAL_SEQUENCE_LSTM": [ + "input", "input_to_input_weights", "input_to_forget_weights", + "input_to_cell_weights", "input_to_output_weights", "recurrent_to_input_weights", + "recurrent_to_forget_weights", "recurrent_to_cell_weights", + "recurrent_to_output_weights", "cell_to_input_weights", "cell_to_forget_weights", + "cell_to_output_weights", "input_gate_bias", "forget_gate_bias", "cell_gate_bias", + "output_gate_bias", "projection_weights", "projection_bias", "output_state", + "cell_state", "input_layer_norm_coefficients", "forget_layer_norm_coefficients", + "cell_layer_norm_coefficients", "output_layer_norm_coefficients" + ], + "UNIQUE": ["input"], + "UNPACK": ["value"], + "WHERE": ["condition"], + "WHILE": ["input"], + "ZEROS_LIKE": ["input"], + "BCQ_FULLY_CONNECTED": + ["input", "weights_scales", "weights_binary", "bias", "weights_clusters"], + "BCQ_GATHER": ["input_scales", "input_binary", "indices", "input_clusters"], + "INSTANCE_NORM": ["input", "gamma", "beta"], + "RMS_NORM": ["input", "gamma"], + "ROPE": ["input", "sin_table", "cos_table"] +} diff --git a/tools/model_explorer_circle/src/model_explorer_circle/main.py b/tools/model_explorer_circle/src/model_explorer_circle/main.py index 1efc470e29d..469b529342a 100644 --- a/tools/model_explorer_circle/src/model_explorer_circle/main.py +++ b/tools/model_explorer_circle/src/model_explorer_circle/main.py @@ -18,6 +18,7 @@ from typing import Dict, Optional from model_explorer import Adapter, AdapterMetadata, ModelExplorerGraphs, graph_builder from model_explorer_circle import circle_schema_generated as circle_schema +from model_explorer_circle import circle_metadata class CircleAdapter(Adapter): @@ -43,6 +44,7 @@ def __init__(self): # Number of elements to show in tensor values (default: 16) self.const_element_count_limit = 16 self.graph = None + self.input_args = circle_metadata.input_args_dict def load_model(self, model_path: str) -> None: """Load the model from the given path.""" @@ -77,6 +79,13 @@ def add_incoming_edge(self, me_node: graph_builder.GraphNode, tensor_id: int, graph_builder.IncomingEdge(sourceNodeId=sid, sourceNodeOutputId=soid, targetNodeInputId=f'{input_id}')) + # Add input metadata of the node if it exists + if self.input_args.get(me_node.label) is not None: + arg_name = self.input_args[me_node.label][input_id] + me_node.inputsMetadata.append( + graph_builder.MetadataItem( + id=f'{input_id}', + attrs=[graph_builder.KeyValue(key='__tensor_tag', value=arg_name)])) def add_tensor_value_attribute(self, me_node: graph_builder.GraphNode, tensor_id: int) -> None: