File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ def maybe_convert_to_variable(tensor):
58
58
return the original input tensor.
59
59
"""
60
60
op = tensor .op
61
+ if is_on_cpu () and tensor in var_store :
62
+ return var_store [tensor ]
61
63
if op .type != 'ReadVariableOp' :
62
64
# No need to convert.
63
65
return tensor
@@ -102,7 +104,9 @@ def write_to_variable(tensor):
102
104
use_resource = True )
103
105
var_store [tensor ] = variable
104
106
with tf .control_dependencies ([variable .assign (tensor )]):
105
- return tf .identity (tensor )
107
+ tensor_copy = tf .identity (tensor )
108
+ var_store [tensor_copy ] = variable
109
+ return tensor_copy
106
110
107
111
108
112
def read_from_variable (tensor ):
@@ -113,3 +117,8 @@ def read_from_variable(tensor):
113
117
else :
114
118
# Current read, but only works on TPU.
115
119
return tensor
120
+
121
+
122
+ def is_intermediate_var (v ):
123
+ """Returns True if `v` was created by `write_to_variable` above."""
124
+ return v in var_store .values ()
You can’t perform that action at this time.
0 commit comments