navya-encharge commented on code in PR #16171:
URL: https://github.com/apache/tvm/pull/16171#discussion_r1409977240


##########
python/tvm/relay/frontend/pytorch.py:
##########
@@ -5127,6 +5190,10 @@ def from_pytorch(
         During the conversion, variable names in torch._C.Graph will be 
assigned based on their op
         types. The exported text file can be the reference to spans.
 
+    preserve_pytorch_scopes : bool
+        When naming the different nodes in the TVM graph, use the "scope name" 
from the Pytorch graph.

Review Comment:
   Resolved in upcoming commit!



##########
python/tvm/relay/frontend/pytorch.py:
##########
@@ -4771,33 +4779,77 @@ def _get_constant(node):
         return None
 
 
-def _rename_outputs(node, source_map, op_type_dict, use_parser_friendly_name):
-    """Rewrite debug name of node outputs with its operator type"""
+class NodeNamer(ABC):
+    def __init__(self, op_counter_dict):
+        self.op_counter_dict = op_counter_dict
 
-    def _get_source_name(op_type):
+    def increment_counter(self, identifier):
         op_idx = 0
-        if op_type in op_type_dict:
-            op_idx = op_type_dict[op_type] + 1
-        op_type_dict[op_type] = op_idx
-        return "_".join([op_type, str(op_idx)])
+        if identifier in self.op_counter_dict:
+            op_idx = self.op_counter_dict[identifier] + 1
+        self.op_counter_dict[identifier] = op_idx
+        return op_idx
 
-    # get source name of operator and rename all of its outputs
+    def get_node_source_name(self, node):
+        raise NotImplementedError()
+
+    def get_node_output_name(self, node, node_source_name, index):
+        raise NotImplementedError()
+
+
+class DefaultNodeKindNamer(NodeNamer):
+    """
     # e.g. node.kind(): aten::adaptive_max_pool2d
     # node_src_name -> aten::adaptive_max_pool2d_x
     # output_1 -> aten::adaptive_max_pool2d_x_0
     # output_2 -> aten::adaptive_max_pool2d_x_1
+    """
+
+    def get_node_source_name(self, node):
+        op_idx = self.increment_counter(node.kind())
+        return "_".join([node.kind(), str(op_idx)])
+
+    def get_node_output_name(self, node, node_src_name, index):
+        return "_".join([node_src_name, str(index)])
+
+
+class PytorchScopePreservingNamer(NodeNamer):

Review Comment:
   Resolved in upcoming commit!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to