code: def connect_global_initializer(graph):
      # In TF1, variable initialization (from frozen graph) is done by a
      # DAG in main function that is disconnected from the rest of the main
      # function. For example:
      #
      # Initialization DAG (disconnected from Main DAG):
      #   Const -> set_global(variable='v1')
      #
      # Main DAG:
      #   Placeholder               ---
      #                               |
      #   get_global(variable='v1') ----> some_output
      #
      # (Note that in this example there's no loop or other function.)
      #
      # If the variable does not cross block boundary, we can always represent
      # `get_global` by the input to `set_global`, which may or may not be
      # Const, following the control dependency.
      #
      # Note that this is incorrect if global variable crosses, say,
      # while_loop block boundary, which needs a more complex resource inference
      # to support and is not supported in this function.
      #
      # Due to the lack of control depeendency between thhe two DAG, we could be
      # converting `set_global` after `get_global`, which makes it impossible to
      # perform eager type inference, as type information (e.g., tensor shape)
      # is only provided by `set_global` (whether setting it to a const or a
      # non-const).
      #
      # Here we remedy the simpler case: when `set_global` takes in a Const,
      # we assume it's initialization and thus must
      # run before get_global, i.e. all get_global(variable='v1') must be a
      # control_output of set_global(variable='v1') where set_global's input is
      # Const (with and control_inputs set symmetrically). Note that multiple
      # `get_global(variable='v1')` might have dependences among themselves, but
      # they should all take the constant `set_global(variable='v1')` as control
      # dependency.
  
      # Phase 1: Collect get_global nodes for each variable.
      # variable name to list[ParsedTFNode]
      var_to_get_global_nodes = defaultdict(list)
      for node in graph.values():
          if node.op == "get_global":
              variable_name = node.attr["variable"]
              var_to_get_global_nodes[variable_name].append(node)
  
      # Phase 2: Find set_global with compile time values
      for node_name, node in graph.items():
          if node.op != "set_global":
              continue
          input_name = node.inputs[0]
          input_node = graph[input_name]
          if input_node.op != "Const":
              continue
          variable_name = node.attr["variable"]
          for get_node in var_to_get_global_nodes[variable_name]:
              logging.info(
                  "add {} as control inputs of {}".format(
                      node_name, get_node.name
                  )
              )
              get_node.control_inputs.append(node_name)
              node.control_outputs.append(get_node.name)
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/frontend/tensorflow/convert_utils.py
imports: import logging
  from .basic_graph_ops import topsort
  from coremltools.converters.mil.mil.types.symbolic import is_symbolic, any_variadic
  from coremltools.converters.mil.mil import types
  from .tf_op_registry import _TF_OPS_REGISTRY
  from coremltools.converters.mil.mil.var import ListVar
  from collections import defaultdict
  from tqdm import tqdm
label_desc: Use image node_id 3 for calling a global function with example usage: connect_global_initializer(graph) without return types