code: def create_experiment(
      run_config,
      hparams,
      model_name,
      problem_name,
      data_dir,
      train_steps,
      eval_steps,
      min_eval_frequency=2000,
      eval_throttle_seconds=600,
      schedule="train_and_evaluate",
      export=False,
      decode_hparams=None,
      use_tfdbg=False,
      use_dbgprofile=False,
      eval_early_stopping_steps=None,
      eval_early_stopping_metric=None,
      eval_early_stopping_metric_delta=None,
      eval_early_stopping_metric_minimize=True,
      eval_timeout_mins=240,
      eval_use_test_set=False,
      use_tpu=False,
      use_tpu_estimator=False,
      use_xla=False,
      export_saved_model_api_version=1,
      use_guarantee_const_getter=False,
      additional_train_hooks=None,
      additional_eval_hooks=None,
      warm_start_from=None,
      decode_from_file="",
      decode_to_file="",
      decode_reference="",
      std_server_protocol=None,
  ):
      """Create Experiment."""
      # HParams
      hparams.add_hparam("model_dir", run_config.model_dir)
      hparams.add_hparam("data_dir", data_dir)
      hparams.add_hparam("train_steps", train_steps)
      hparams.add_hparam("eval_steps", eval_steps)
      hparams.add_hparam("schedule", schedule)
      hparams.add_hparam("warm_start_from", warm_start_from)
      hparams.add_hparam("std_server_protocol", std_server_protocol)
      hparams.add_hparam("eval_freq_in_steps", min_eval_frequency)
      hparams.add_hparam("eval_timeout_mins", eval_timeout_mins)
      if decode_hparams is not None:
          decode_hparams.add_hparam(
              "decode_from_file", decode_from_file
          )
          if decode_to_file and not decode_hparams.decode_to_file:
              decode_hparams.decode_to_file = decode_to_file
          if decode_reference and not decode_hparams.decode_reference:
              decode_hparams.decode_reference = decode_reference
      add_problem_hparams(hparams, problem_name)
  
      # Estimator
      estimator = create_estimator(
          model_name,
          hparams,
          run_config,
          schedule=schedule,
          decode_hparams=decode_hparams,
          use_tpu=use_tpu,
          use_tpu_estimator=use_tpu_estimator,
          use_xla=use_xla,
          export_saved_model_api_version=export_saved_model_api_version,
          use_guarantee_const_getter=use_guarantee_const_getter,
      )
  
      # Input fns from Problem
      problem = hparams.problem
      train_input_fn = problem.make_estimator_input_fn(
          tf_estimator.ModeKeys.TRAIN, hparams
      )
  
      dataset_split = "test" if eval_use_test_set else None
      dataset_kwargs = {"dataset_split": dataset_split}
      eval_input_fn = problem.make_estimator_input_fn(
          tf_estimator.ModeKeys.EVAL,
          hparams,
          dataset_kwargs=dataset_kwargs,
      )
  
      # Export
      exporter = None
      if export:
  
          def compare_fn(best_eval_result, current_eval_result):
              metric = eval_early_stopping_metric or "loss"
              return (
                  current_eval_result[metric] < best_eval_result[metric]
              )
  
          def serving_input_receiver_fn(
              hparams, decode_hparams, use_tpu
          ):
              return problem.serving_input_fn(
                  hparams, decode_hparams, use_tpu
              )
  
          exporter = tf_estimator.BestExporter(
              name="best",
              serving_input_receiver_fn=serving_input_receiver_fn,
              compare_fn=compare_fn,
              assets_extra=problem.export_assets,
          )
  
      # Hooks
      validation_monitor_kwargs = dict(
          input_fn=eval_input_fn,
          eval_steps=eval_steps,
          every_n_steps=min_eval_frequency,
          early_stopping_rounds=eval_early_stopping_steps,
          early_stopping_metric=eval_early_stopping_metric,
          early_stopping_metric_minimize=eval_early_stopping_metric_minimize,
      )
      dbgprofile_kwargs = {"output_dir": run_config.model_dir}
      early_stopping_kwargs = dict(
          events_dir=os.path.join(
              run_config.model_dir, "eval_continuous"
          ),
          tag=eval_early_stopping_metric,
          num_plateau_steps=eval_early_stopping_steps,
          plateau_decrease=eval_early_stopping_metric_minimize,
          plateau_delta=eval_early_stopping_metric_delta,
          every_n_steps=min_eval_frequency,
      )
  
      # Eval on TPU Pods is not supported yet
      if (
          use_tpu
          and run_config.tpu_config.num_shards > 8
          and "eval" in schedule
      ):
          raise ValueError(
              "Eval is not currently supported on a TPU Pod"
          )
  
      # In-process eval (and possible early stopping)
      if schedule == "continuous_train_and_eval" and min_eval_frequency:
          tf.logging.warn(
              "ValidationMonitor only works with "
              "--schedule=train_and_evaluate"
          )
      use_validation_monitor = (
          schedule == "train_and_evaluate" and min_eval_frequency
      )
      # Distributed early stopping
      local_schedules = [
          "train_and_evaluate",
          "continuous_train_and_eval",
      ]
      use_early_stopping = (
          schedule not in local_schedules and eval_early_stopping_steps
      )
      train_hooks, eval_hooks = create_hooks(
          use_tfdbg=use_tfdbg,
          use_dbgprofile=use_dbgprofile,
          dbgprofile_kwargs=dbgprofile_kwargs,
          use_validation_monitor=use_validation_monitor,
          validation_monitor_kwargs=validation_monitor_kwargs,
          use_early_stopping=use_early_stopping,
          early_stopping_kwargs=early_stopping_kwargs,
      )
  
      hook_context = HookContext(
          estimator=estimator, problem=problem, hparams=hparams
      )
  
      train_hooks += t2t_model.T2TModel.get_train_hooks(
          model_name, hook_context
      )
      eval_hooks += t2t_model.T2TModel.get_eval_hooks(
          model_name, hook_context
      )
      if additional_train_hooks:
          train_hooks += additional_train_hooks
      if additional_eval_hooks:
          eval_hooks += additional_eval_hooks
  
      train_hooks = (
          contrib.learn().monitors.replace_monitors_with_hooks(
              train_hooks, estimator
          )
      )
      eval_hooks = contrib.learn().monitors.replace_monitors_with_hooks(
          eval_hooks, estimator
      )
  
      train_spec = tf_estimator.TrainSpec(
          train_input_fn, max_steps=train_steps, hooks=train_hooks
      )
      eval_spec = tf_estimator.EvalSpec(
          eval_input_fn,
          steps=eval_steps,
          hooks=eval_hooks,
          start_delay_secs=0 if hparams.schedule == "evaluate" else 120,
          throttle_secs=eval_throttle_seconds,
          exporters=exporter,
      )
  
      return T2TExperiment(
          estimator,
          hparams,
          train_spec,
          eval_spec,
          use_validation_monitor,
          decode_hparams,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import contextlib
  import json
  import os
  import random
  import numpy
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import decoding
  from tensor2tensor.utils import devices
  from tensor2tensor.utils import hparams_lib
  from tensor2tensor.utils import metrics_hook
  from tensor2tensor.utils import mlperf_log
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  from tensorflow.core.protobuf import rewriter_config_pb2
  from tensorflow.python import debug
label_desc: Use image node_id 8 for calling a global function with example usage: create_experiment(run_config, hparams, model_name, problem_name, data_dir, train_steps, eval_steps, min_eval_frequency, eval_throttle_seconds, schedule, export, decode_hparams, use_tfdbg, use_dbgprofile, eval_early_stopping_steps, eval_early_stopping_metric, eval_early_stopping_metric_delta, eval_early_stopping_metric_minimize, eval_timeout_mins, eval_use_test_set, use_tpu, use_tpu_estimator, use_xla, export_saved_model_api_version, use_guarantee_const_getter, additional_train_hooks, additional_eval_hooks, warm_start_from, decode_from_file, decode_to_file, decode_reference, std_server_protocol) and returns: T2TExperiment, unknown, problem