Skip to content

Commit a7aa25d

Browse files
dlibenzifrankchn
authored andcommitted
Allow users passing master argument to avoid instantiating a TPUClusterResolver (tensorflow#3845)
* Fix MNIST to allow master=local to work again. * Update mnist_tpu.py
1 parent 03bf0d3 commit a7aa25d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

official/mnist/mnist_tpu.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
"metadata.")
4747

4848
# Model specific parameters
49+
tf.flags.DEFINE_string(
50+
"master", default=None,
51+
help="GRPC URL of the master (e.g. grpc://ip.address.of.tpu:8470). You "
52+
"must specify either this flag or --tpu.")
4953
tf.flags.DEFINE_string("data_dir", "",
5054
"Path to directory containing the MNIST dataset")
5155
tf.flags.DEFINE_string("model_dir", None, "Estimator model_dir")
@@ -132,11 +136,24 @@ def main(argv):
132136
del argv # Unused.
133137
tf.logging.set_verbosity(tf.logging.INFO)
134138

135-
tpu_cluster_resolver = tf.contrib.cluster_resolver.TPUClusterResolver(
136-
FLAGS.tpu, zone=FLAGS.tpu_zone, project=FLAGS.gcp_project)
139+
if FLAGS.master is None and FLAGS.tpu is None:
140+
raise RuntimeError('You must specify either --master or --tpu.')
141+
if FLAGS.master is not None:
142+
if FLAGS.tpu is not None:
143+
tf.logging.warn('Both --master and --tpu are set. Ignoring '
144+
'--tpu and using --master.')
145+
tpu_grpc_url = FLAGS.master
146+
else:
147+
tpu_cluster_resolver = (
148+
tf.contrib.cluster_resolver.TPUClusterResolver(
149+
FLAGS.tpu,
150+
zone=FLAGS.tpu_zone,
151+
project=FLAGS.gcp_project))
152+
tpu_grpc_url = tpu_cluster_resolver.get_master()
137153

138154
run_config = tf.contrib.tpu.RunConfig(
139-
cluster=tpu_cluster_resolver,
155+
master=tpu_grpc_url,
156+
evaluation_master=tpu_grpc_url,
140157
model_dir=FLAGS.model_dir,
141158
session_config=tf.ConfigProto(
142159
allow_soft_placement=True, log_device_placement=True),

0 commit comments

Comments
 (0)