def make_estimator_from_flags(bert_config, init_checkpoint):
  """Builds TPUEstimator from args, FLAGS, and the model_fn_builder method."""
  tpu_cluster_resolver = None
  if FLAGS.use_tpu and FLAGS.tpu_name:
    tpu_cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver(
        FLAGS.tpu_name, zone=FLAGS.tpu_zone, project=FLAGS.gcp_project)
  is_per_host = tf_estimator.tpu.InputPipelineConfig.PER_HOST_V2
  run_config = tf_estimator.tpu.RunConfig(
      cluster=tpu_cluster_resolver,
      master=FLAGS.session_master,
      model_dir=FLAGS.output_dir,
      tpu_config=tf_estimator.tpu.TPUConfig(
          iterations_per_loop=FLAGS.iterations_per_loop,
          tpu_job_name=FLAGS.tpu_job_name,
          num_shards=FLAGS.num_tpu_cores,
          experimental_host_call_every_n_steps=1000,
          per_host_input_for_training=is_per_host))
  model_fn = model_fn_builder(
      bert_config=bert_config,
      init_checkpoint=init_checkpoint,
      use_tpu=FLAGS.use_tpu,
      span_encoding=FLAGS.span_encoding,
      max_answer_length=FLAGS.max_answer_length,
      use_one_hot_embeddings=FLAGS.use_tpu)

  # If TPU is not available, this will fall back to normal Estimator on CPU
  # or GPU.
  return tf_estimator.tpu.TPUEstimator(
      use_tpu=FLAGS.use_tpu,
      model_fn=model_fn,
      config=run_config,
      train_batch_size=FLAGS.predict_batch_size,
      predict_batch_size=FLAGS.predict_batch_size)
Builds TPUEstimator from args, FLAGS, and the model_fn_builder method.
language/capwap/synthetic/generate_answers.py