docstr: Parameters
  ----------
  ir_graph : Graph
      our ir graph representation
  targeted_type : str
      nodes with ```targeted_type``` will be removed from graph if their fanout is 0.
      ```None``` means removing all the nodes whose fanout is 0.
docstr_tok: ["Parameters","--","--","--","--","--","ir_graph",":","Graph","our","ir","graph","representation","targeted_type",":","str","nodes","with","``","`","targeted_type","``","`","will","be","removed","from","graph","if","their","fanout","is","0",".","``","`","None","``","`","means","removing","all","the","nodes","whose","fanout","is","0","."]
code: def remove_unconnected_nodes(self, ir_graph, targeted_type=None):
      """
      Parameters
      ----------
      ir_graph : Graph
          our ir graph representation
      targeted_type : str
          nodes with ```targeted_type``` will be removed from graph if their fanout is 0.
          ```None``` means removing all the nodes whose fanout is 0.
      """
      # build index of outputs of Node(s)
      node_fanout = set()
      for edge in ir_graph.edges:
          if edge.head.id not in node_fanout:
              node_fanout.add(edge.head.id)
  
      to_removes = []
      for hidden_node in ir_graph.hidden_nodes:
          if hidden_node.id not in node_fanout:
              assert isinstance(hidden_node, Node)
              if targeted_type is None:
                  to_removes.append(hidden_node)
              elif hidden_node.operation.type == targeted_type:
                  to_removes.append(hidden_node)
  
      for hidden_node in to_removes:
          hidden_node.remove()
  
imports: import re
  import torch
  from nni.nas.space.graph import Graph, GraphModelSpace, Node, Cell, Operation
  from nni.nas.nn.pytorch import InputChoice, MutationAnchor, LayerChoice, MutableModule, Repeat
  from nni.nas.utils import get_init_parameters_or_fail, get_importable_name
  from .op_types import MODULE_EXCEPT_LIST, OpTypeName
  from .utils import _convert_name, build_full_name, _without_shape_info, _extract_info_from_trace_node, get_full_name_by_scope_name, is_layerchoice_node, match_node, build_cand_name, build_python_name
label_desc: Use image node_id 7 for calling the GraphConverter obj's underlying member method code with example usage: obj.remove_unconnected_nodes(ir_graph, targeted_type) without return types