def get_estimator(model_fn, params):
  """Gets an instance of the TPU estimator.

  Args:
    model_fn: tf Estimator model function.
    params: Parameter dictionary for estimator.

  Returns:
    tf.estimator.tpu.TPUEstimator: tf.estimator.tpu.TPUEstimator instance.
  """
  # Validate settings for TPU inner loop.
  assert (FLAGS.tpu_iterations_per_loop or FLAGS.save_checkpoints_steps)
  tpu_iterations_per_loop = FLAGS.tpu_iterations_per_loop
  if not tpu_iterations_per_loop:
    tpu_iterations_per_loop = FLAGS.save_checkpoints_steps
  if FLAGS.save_checkpoints_steps % tpu_iterations_per_loop != 0:
    raise ValueError(
        "TPU iterations per loop should evenly divide checkpointing.")

  tpu_config = tf_estimator.tpu.TPUConfig(
      iterations_per_loop=tpu_iterations_per_loop,
      tpu_job_name=FLAGS.tpu_job_name)

  run_config = tf_estimator.tpu.RunConfig(
      master=FLAGS.session_master,
      model_dir=params.get("model_dir") or get_model_dir(),
      tf_random_seed=FLAGS.tf_random_seed,
      tpu_config=tpu_config,
      save_checkpoints_steps=FLAGS.save_checkpoints_steps,
      keep_checkpoint_max=FLAGS.keep_checkpoint_max)

  # Ugly removal from params. These need to be dynamically set by TPUEstimator.
  params = copy.copy(params)
  batch_size = params.pop("batch_size")
  eval_batch_size = params.pop("eval_batch_size")
  predict_batch_size = params.pop("predict_batch_size")
  estimator = tf_estimator.tpu.TPUEstimator(
      model_fn=model_fn,
      use_tpu=params["use_tpu"],
      config=run_config,
      params=params,
      train_batch_size=batch_size,
      eval_batch_size=eval_batch_size,
      predict_batch_size=predict_batch_size)

  return estimator
Gets an instance of the TPU estimator.

  Args:
    model_fn: tf Estimator model function.
    params: Parameter dictionary for estimator.

  Returns:
    tf.estimator.tpu.TPUEstimator: tf.estimator.tpu.TPUEstimator instance.
  
language/capwap/utils/experiment_utils.py