Commit a7aa25d3 authored by dlibenzi's avatar dlibenzi Committed by Frank Chen
Browse files

Allow users passing master argument to avoid instantiating a TPUClusterResolver (#3845)

* Fix MNIST to allow master=local to work again.

* Update mnist_tpu.py
parent 03bf0d38
...@@ -46,6 +46,10 @@ tf.flags.DEFINE_string( ...@@ -46,6 +46,10 @@ tf.flags.DEFINE_string(
"metadata.") "metadata.")
# Model specific parameters # Model specific parameters
tf.flags.DEFINE_string(
"master", default=None,
help="GRPC URL of the master (e.g. grpc://ip.address.of.tpu:8470). You "
"must specify either this flag or --tpu.")
tf.flags.DEFINE_string("data_dir", "", tf.flags.DEFINE_string("data_dir", "",
"Path to directory containing the MNIST dataset") "Path to directory containing the MNIST dataset")
tf.flags.DEFINE_string("model_dir", None, "Estimator model_dir") tf.flags.DEFINE_string("model_dir", None, "Estimator model_dir")
...@@ -132,11 +136,24 @@ def main(argv): ...@@ -132,11 +136,24 @@ def main(argv):
del argv # Unused. del argv # Unused.
tf.logging.set_verbosity(tf.logging.INFO) tf.logging.set_verbosity(tf.logging.INFO)
tpu_cluster_resolver = tf.contrib.cluster_resolver.TPUClusterResolver( if FLAGS.master is None and FLAGS.tpu is None:
FLAGS.tpu, zone=FLAGS.tpu_zone, project=FLAGS.gcp_project) raise RuntimeError('You must specify either --master or --tpu.')
if FLAGS.master is not None:
if FLAGS.tpu is not None:
tf.logging.warn('Both --master and --tpu are set. Ignoring '
'--tpu and using --master.')
tpu_grpc_url = FLAGS.master
else:
tpu_cluster_resolver = (
tf.contrib.cluster_resolver.TPUClusterResolver(
FLAGS.tpu,
zone=FLAGS.tpu_zone,
project=FLAGS.gcp_project))
tpu_grpc_url = tpu_cluster_resolver.get_master()
run_config = tf.contrib.tpu.RunConfig( run_config = tf.contrib.tpu.RunConfig(
cluster=tpu_cluster_resolver, master=tpu_grpc_url,
evaluation_master=tpu_grpc_url,
model_dir=FLAGS.model_dir, model_dir=FLAGS.model_dir,
session_config=tf.ConfigProto( session_config=tf.ConfigProto(
allow_soft_placement=True, log_device_placement=True), allow_soft_placement=True, log_device_placement=True),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment