Skip to content

Commit

Permalink
No longer assume that the default job is "localhost" in graph mode
Browse files Browse the repository at this point in the history
DistributionStrategy, since it depends on the session. Drop
"job:localhost" when canonicalizing in graph mode.

PiperOrigin-RevId: 199354215
  • Loading branch information
tensorflower-gardener committed Jun 5, 2018
1 parent c03d2c4 commit 12b20a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions tensorflow/python/training/device_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ def canonicalize(d, default=None):
"""Canonicalize device string.
If d has missing components, the rest would be deduced from the `default`
argument or from '/job:localhost/replica:0/task:0/device:CPU:0'. For example:
argument or from '/replica:0/task:0/device:CPU:0'. For example:
If d = '/cpu:0', default='/job:worker/task:1', it returns
'/job:worker/replica:0/task:1/device:CPU:0'.
If d = '/cpu:0', default='/job:worker', it returns
'/job:worker/replica:0/task:0/device:CPU:0'.
If d = '/gpu:0', default=None, it returns
'/job:localhost/replica:0/task:0/device:GPU:0'.
'/replica:0/task:0/device:GPU:0'.
Note: This uses "job:localhost" as the default if executing eagerly.
Args:
d: a device string.
Expand All @@ -47,7 +49,9 @@ def canonicalize(d, default=None):
"Device type '%s' must be all-caps." % (d.device_type,))
# Fill in missing device fields using defaults.
result = tf_device.DeviceSpec(
job="localhost", replica=0, task=0, device_type="CPU", device_index=0)
replica=0, task=0, device_type="CPU", device_index=0)
if context.executing_eagerly():
result.job = "localhost"
if default:
result.merge_from(tf_device.DeviceSpec.from_string(default))
result.merge_from(d)
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/python/training/device_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def testCurrentDeviceWithEager(self):
def testCanonicalizeWithoutDefaultDevice(self):
self.assertEqual(
device_util.canonicalize("/cpu:0"),
"/job:localhost/replica:0/task:0/device:CPU:0")
"/replica:0/task:0/device:CPU:0")
self.assertEqual(
device_util.canonicalize("/job:worker/cpu:0"),
"/job:worker/replica:0/task:0/device:CPU:0")
Expand Down

0 comments on commit 12b20a5

Please sign in to comment.