Avoid RuntimeException if device placement is nop
This benefits colab tutorials, allowing a block of code to be re-run without throwing an exception. PiperOrigin-RevId: 247064427
This commit is contained in:
parent
86b2e49082
commit
49c8db3828
@ -1194,6 +1194,9 @@ class Context(object):
|
||||
|
||||
@log_device_placement.setter
|
||||
def log_device_placement(self, enabled):
|
||||
if self._log_device_placement == enabled:
|
||||
return
|
||||
|
||||
if self._context_handle is not None:
|
||||
raise RuntimeError(
|
||||
"Device placement logging must be set at program startup")
|
||||
|
@ -198,8 +198,10 @@ class ConfigTest(test.TestCase, parameterized.TestCase):
|
||||
|
||||
with self.assertRaises(RuntimeError):
|
||||
context.set_log_device_placement(True)
|
||||
with self.assertRaises(RuntimeError):
|
||||
context.set_log_device_placement(False)
|
||||
|
||||
# If the setting the device placement is a no-op, do not throw a runtime
|
||||
# exception.
|
||||
context.set_log_device_placement(False)
|
||||
|
||||
@test_util.run_gpu_only
|
||||
@reset_eager
|
||||
|
Loading…
Reference in New Issue
Block a user