code: def save_metadata(hparams):
      """Saves FLAGS and hparams to output_dir."""
      output_dir = os.path.expanduser(FLAGS.output_dir)
      if not tf.gfile.Exists(output_dir):
          tf.gfile.MakeDirs(output_dir)
  
      # Save FLAGS in txt file
      if hasattr(FLAGS, "flags_into_string"):
          flags_str = FLAGS.flags_into_string()
          t2t_flags_str = "\n".join(
              [
                  "--%s=%s" % (f.name, f.value)
                  for f in FLAGS.flags_by_module_dict()[
                      "tensor2tensor.utils.flags"
                  ]
              ]
          )
      else:
          flags_dict = FLAGS.__dict__["__flags"]
          flags_str = "\n".join(
              [
                  "--%s=%s" % (name, str(f))
                  for (name, f) in flags_dict.items()
              ]
          )
          t2t_flags_str = None
  
      flags_txt = os.path.join(output_dir, "flags.txt")
      with tf.gfile.Open(flags_txt, "w") as f:
          f.write(flags_str)
  
      if t2t_flags_str:
          t2t_flags_txt = os.path.join(output_dir, "flags_t2t.txt")
          with tf.gfile.Open(t2t_flags_txt, "w") as f:
              f.write(t2t_flags_str)
  
      # Save hparams as hparams.json
      new_hparams = hparams_lib.copy_hparams(hparams)
      # Modality class is not JSON serializable so remove.
      new_hparams.del_hparam("modality")
  
      hparams_fname = os.path.join(output_dir, "hparams.json")
      with tf.gfile.Open(hparams_fname, "w") as f:
          f.write(new_hparams.to_json(indent=0, sort_keys=True))
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import contextlib
  import os
  import sys
  from tensor2tensor import models
  from tensor2tensor import problems
  from tensor2tensor.data_generators import problem
  from tensor2tensor.utils import cloud_mlengine
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import decoding
  from tensor2tensor.utils import flags
  from tensor2tensor.utils import hparams_lib
  from tensor2tensor.utils import mlperf_log
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import trainer_lib
  from tensor2tensor.utils import usr_dir
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 9 for calling a global function with example usage: save_metadata(hparams) without return types