File tree 1 file changed +11
-10
lines changed
1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -94,20 +94,21 @@ def maybe_convert_to_variable(tensor):
94
94
var_store = {}
95
95
96
96
97
- def write_to_variable (tensor ):
97
+ def write_to_variable (tensor , fail_if_exists = True ):
98
98
"""Saves a tensor for later retrieval on CPU."""
99
99
# Only relevant for debugging.
100
100
debug_name = 'tpu_util__' + tensor .name .split (':' )[0 ].split ('/' )[- 1 ]
101
101
102
- # Note: reuse cannot be changed from True to False, so we just check if
103
- # the variable exists.
104
- with tf .variable_scope ('' , reuse = True ):
105
- try :
106
- tf .get_variable (debug_name )
107
- except ValueError :
108
- pass # Variable with name=debug_name does not exist; proceed.
109
- else :
110
- raise ValueError ('Variable %s already exists!' % debug_name )
102
+ if fail_if_exists :
103
+ # Note: reuse cannot be changed from True to False, so we just check if
104
+ # the variable exists.
105
+ with tf .variable_scope ('' , reuse = True ):
106
+ try :
107
+ tf .get_variable (debug_name )
108
+ except ValueError :
109
+ pass # Variable with name=debug_name does not exist; proceed.
110
+ else :
111
+ raise ValueError ('Variable %s already exists!' % debug_name )
111
112
112
113
with tf .variable_scope ('' , reuse = tf .compat .v1 .AUTO_REUSE ):
113
114
variable = tf .get_variable (
You can’t perform that action at this time.
0 commit comments