code: def replace_in_func(
      fn: F,
      field_reference_replace_map: MutableMapping[
          int, ml_collections.FieldReference
      ],
  ) -> F:
      """Replace the usages of the field references in the function closure."""
      # We need this function because the module `copy`'s functions don't actually
      # copy the function objects. See https://docs.python.org/3/library/copy.html
  
      closure_content = replace_in_config(
          (cell.cell_contents for cell in fn.__closure__),
          field_reference_replace_map,
      )
      new_closure = tuple(
          create_cell_object(x) for x in closure_content
      )
  
      new_fn = types.FunctionType(
          fn.__code__,
          fn.__globals__,
          fn.__name__,
          fn.__defaults__,
          new_closure,
      )
  
      # In case the function was given attrs (note this dict is a shallow copy):
      new_fn.__dict__.update(fn.__dict__)
  
      return new_fn
  
imports: from collections.abc import Callable
  from collections.abc import Iterable
  from collections.abc import Iterator
  from collections.abc import Mapping
  from collections.abc import MutableMapping
  from collections.abc import Sequence
  import copy
  import types
  from typing import Any
  from typing import Optional
  from typing import TypeVar
  from typing import Union
  from dmvr import tokenizers
  import jax
  import ml_collections
label_desc: Use image node_id 5 for calling a global function with example usage: replace_in_func(fn, field_reference_replace_map) and returns: new_fn