code: def write_replay_spec(
      model_dir, filename, original_spec, search_architecture, hparams
  ):
      """Writes a replay spec to retrain the same model."""
      # Ensure the same search space as the original run
      replay_spec = copy.deepcopy(original_spec)
      # Remove user suggestions
      replay_spec.ClearField("user_suggestions")
      # If this is already a replay config
      replay_spec.ClearField("replay")
  
      dependency_file = os.path.join(
          model_dir, _PREVIOUS_DEPENDENCIES_FILENAME
      )
      if tf.io.gfile.exists(dependency_file):
          with tf.io.gfile.GFile(dependency_file, "r") as f:
              data = f.read().split("\n")
          for dependency in set(data):
              spec = phoenix_spec_pb2.PhoenixSpec()
              with tf.io.gfile.GFile(
                  os.path.join(dependency, filename), "r"
              ) as f:
                  text_format.Parse(f.read(), spec)
              for i, _ in enumerate(spec.replay.towers):
                  replay_spec.replay.towers.add().CopyFrom(
                      spec.replay.towers[i]
                  )
  
      # Currently we support non-ensembling models.
      search_tower = replay_spec.replay.towers.add()
  
      # Removing the "context" hparam. This hparam is added for tpu, by the tpu team
      # It is not compatible with the function "to_proto" used below.
      copy_hparams = hp.HParams(**hparams.values())
      if hasattr(copy_hparams, "context"):
          copy_hparams.del_hparam("context")
  
      # We sometimes (for some search algorithms) override the hparam
      # initial_architecture. Updating with the ground truth.
      # TODO(b/172564129): Make initial_architecture consistent everywhere.
      copy_hparams.set_hparam(
          "initial_architecture", search_architecture
      )
  
      search_tower.hparams.CopyFrom(copy_hparams.to_proto())
      search_tower.architecture[:] = search_architecture
      with tf.io.gfile.GFile(
          os.path.join(model_dir, filename), "w"
      ) as f:
          f.write(str(replay_spec))
  
imports: import copy
  import enum
  import os
  from model_search import hparam
  from model_search.architecture import architecture_utils
  from model_search.architecture import tower
  from model_search.generators import base_tower_generator
  from model_search.metadata import trial
  from model_search.proto import distillation_spec_pb2
  from model_search.proto import ensembling_spec_pb2
  from model_search.proto import phoenix_spec_pb2
  import tensorflow.compat.v2
  from google.protobuf import text_format
label_desc: Use image node_id 14 for calling a global function with example usage: write_replay_spec(model_dir, filename, original_spec, search_architecture, hparams) without return types