File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change 1
1
"""Utility functions for handling TPU graphs."""
2
2
3
- from __future__ import absolute_import
4
- from __future__ import division
5
- from __future__ import print_function
6
-
7
3
import contextlib2
8
4
import tensorflow .compat .v1 as tf
9
5
@@ -33,12 +29,19 @@ def is_on_cpu():
33
29
34
30
35
31
def get_variable_name (read_variable_op ):
32
+ """Obtains the name of the variable corresponding to ReadVariableOp."""
36
33
assert read_variable_op .type == 'ReadVariableOp'
37
34
op = read_variable_op
38
- while op .type != 'VarHandleOp' :
35
+ # Depending on whether we're on TPU or CPU, and whether control flow v2 is
36
+ # enabled, the graph will have different structure. This loop is written to
37
+ # support all known cases.
38
+ while True :
39
+ if op .type == 'VarHandleOp' :
40
+ return op .name
41
+ if op .type == 'Placeholder' :
42
+ return op .name .split ('/ReadVariableOp/' )[1 ]
39
43
assert len (op .inputs ) == 1
40
44
op = op .inputs [0 ].op
41
- return op .name
42
45
43
46
44
47
def maybe_convert_to_variable (tensor ):
You can’t perform that action at this time.
0 commit comments