code: def get_top(graph: Graph):
      """
      Given a graph, return top nodes of this graph.
      Note: If we remove ``root`` nodes, ``placeholder`` nodes, and ``output`` nodes from fx graph,
      we will get a normal DAG. Top nodes in this context means nodes with BFS level 0 in that DAG.
      """
      top_node_list = set()
      for node in graph.nodes:
          if node.op == "output":
              continue
          is_top = False
  
          def _get_top(node):
              nonlocal is_top
              if node.op == "placeholder":
                  is_top = True
  
          map_arg(node.args, lambda n: _get_top(n))
          map_arg(node.kwargs, lambda n: _get_top(n))
          if is_top:
              top_node_list.add(node)
      return list(top_node_list)
  
file_path: ColossalAI/colossalai/fx/passes/utils.py
imports: from typing import Dict
  import torch
  from torch.fx.graph import Graph
  from torch.fx.node import Node, map_arg
label_desc: Use image node_id 4 for calling a global function with example usage: get_top(graph) and returns: list