code: def remove_getattr_nodes(graph):
      """
      Remove the getattr nodes in the graph
      """
  
      getattr_nodes = []
      new_nodes = []
  
      for node in graph.nodes:
          for block in node.blocks:
              remove_getattr_nodes(block)
  
          if node.kind == "getattr":
              getattr_nodes.append(node)
          else:
              new_nodes.append(node)
  
      # check the getattr nodes not in the outputs
      for node in getattr_nodes:
          if node.name in graph.outputs:
              raise RuntimeError(
                  "{} should not be in the graph outputs.".format(
                      node.name
                  )
              )
  
      # remove the getattr nodes
      graph.nodes = new_nodes
  
file_path: coremltools/coremltools/converters/mil/frontend/torch/torchir_passes.py
imports: from collections import OrderedDict, defaultdict
  from coremltools import _logger
  from .internal_graph import InternalTorchIRGraph, InternalTorchIRNode
label_desc: Use image node_id 2 for calling a global function with example usage: remove_getattr_nodes(graph) without return types