Skip to content

Commit

Permalink
[tools/mec] Add input arguments name to each operator node (#14476)
Browse files Browse the repository at this point in the history
It adds the name of the inputs defined for each operator.

ONE-DCO-1.0-Signed-off-by: Jonghwa Lee <[email protected]>
  • Loading branch information
batcheu authored Dec 18, 2024
1 parent 5887d4c commit b68e7b4
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"]
}
9 changes: 9 additions & 0 deletions tools/model_explorer_circle/src/model_explorer_circle/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b68e7b4

Please sign in to comment.