code: def copy_function_def_to_graph_def_recursively(
      func_name, graph_def, copied_functions, default_graph=None
  ):
      """Recursively copies `FunctionDef`s to `GraphDef`.
  
      It copies the outermost `FunctionDef` and all nested `FunctionDef`s to
      `graph_def`. The `copied_function` enforces that every `FunctionDef` will be
      copied at most once. The `FunctionDef`s will be found from `default_graph` if
      this function was called in graph mode or from eager context if this function
      was called in eager mode.
  
      Args:
        func_name: The signature name of FunctionDef to be copied to `graph_def`.
        graph_def: The GraphDef that will contain all `FunctionDef`s in its library.
        copied_functions: A set contains all copied function names.
        default_graph: The `tf.Graph` where all `FunctionDef`s will be found
          in graph mode. Not used in eager mode.
      """
      # Custom ops may contain a func attr with an empty fname.
      if func_name and not is_function(func_name, default_graph):
          raise ValueError(
              f"Function {func_name} was not found. Please make "
              "sure the FunctionDef `fdef` is correct."
          )
  
      # If `copied_functions` contains `func_name`, the FunctionDef has already
      # been added to GraphDef so we simply return here.
      if func_name in copied_functions:
          return
  
      copied_functions.add(func_name)
      func_def = get_function_def(func_name, default_graph)
      graph_def.library.function.add().CopyFrom(func_def)
  
      for node_def in func_def.node_def:
          op_def = default_graph.op_def_for_type(node_def.op)
          for attr in op_def.attr:
              if attr.type == "func":
                  func_name = node_def.attr[attr.name].func.name
                  copy_function_def_to_graph_def_recursively(
                      func_name,
                      graph_def,
                      copied_functions,
                      default_graph,
                  )
  
              elif attr.type == "list(func)":
                  for fn in node_def.attr[attr.name].list.func:
                      func_name = fn.name
                      copy_function_def_to_graph_def_recursively(
                          func_name,
                          graph_def,
                          copied_functions,
                          default_graph,
                      )
  
file_path: tensorflow/tensorflow/python/framework/function_def_to_graph.py
imports: import itertools
  from tensorflow.core.framework import function_pb2
  from tensorflow.core.framework import graph_pb2
  from tensorflow.core.framework import tensor_shape_pb2
  from tensorflow.core.framework import types_pb2
  from tensorflow.core.framework import versions_pb2
  from tensorflow.python.eager import context
  from tensorflow.python.framework import cpp_shape_inference_pb2
  from tensorflow.python.framework import importer
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import versions
  from tensorflow.python.framework.func_graph import FuncGraph
  from tensorflow.python.ops import resource_variable_ops
label_desc: Use image node_id 4 for calling a global function with example usage: copy_function_def_to_graph_def_recursively(func_name, graph_def, copied_functions, default_graph) without return types