diff options
author | 2017-09-14 11:14:06 -0700 | |
---|---|---|
committer | 2017-09-14 11:18:16 -0700 | |
commit | c66c5a95a12fe32dfd8df750ddb8b043344c94f2 (patch) | |
tree | 4fb6c04f93e5bd47ededff0db47a72a4fb6ca4bc /tensorflow/python/training/saver.py | |
parent | 08a40bdeb1fea3a4b6d7bae883015d39d412c64a (diff) |
Make Saver work with GPU variables in Eager mode.
PiperOrigin-RevId: 168714847
Diffstat (limited to 'tensorflow/python/training/saver.py')
-rw-r--r-- | tensorflow/python/training/saver.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/tensorflow/python/training/saver.py b/tensorflow/python/training/saver.py index dc9bd3a8c2..72ec106d2b 100644 --- a/tensorflow/python/training/saver.py +++ b/tensorflow/python/training/saver.py @@ -167,8 +167,17 @@ class BaseSaverBuilder(object): self.handle_op = var.op.inputs[0] tensor = var elif isinstance(var, resource_variable_ops.ResourceVariable): + + def _read_variable_closure(v): + def f(): + with ops.device(v.device): + x = v.read_value() + with ops.device("/device:CPU:0"): + return array_ops.identity(x) + return f + self.handle_op = var.handle - tensor = var.read_value + tensor = _read_variable_closure(var) else: raise ValueError( "Saveable is neither a resource variable nor a read operation." |