class_docstr: A floder to fold a graph' nodes which has same scope into one node.
class_docstr_tok: ["A","floder","to","fold","a","graph","'","nodes","which","has","same","scope","into","one","node","."]
code: def fold(self):
      self.scope_level_name_map = (
          self._get_scope_level_name_dict()
      )  # level: scope_name set
  
      if self._scope_names:
          scope_names = self._scope_names
      else:
          if not self.scope_level_name_map:
              return
          scope_names = self.scope_level_name_map[0]
  
      for scope_name in scope_names:
          level = self._init_level
          sub_fold_level = self._fold_level_num
          while sub_fold_level >= 0:
              self._fold(
                  self._graph.topological_sort,
                  scope_name,
                  level,
                  level + sub_fold_level,
              )
              sub_fold_level -= 1
  
      # check the same pattern scope node whether have same inputs, outputs and weights.
      # For those don't have, rename their scope names.
      self.check_scope()
      self.check_weights()
  
      # clear out scope node, typically input constant node.
      self._graph.clear_out_scope_node()
  
file_path: MMdnn/mmdnn/conversion/rewriter/folder.py
imports: from mmdnn.conversion.common.IR.IR_graph import *
  import sys
  import re
  import numpy
  import collections
label_desc: Use image node_id 2 for calling the Folder obj's underlying member method code with example usage: obj.fold() without return types