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 11"""Utility functions for handling TPU graphs."""
22
3- from __future__ import absolute_import
4- from __future__ import division
5- from __future__ import print_function
6-
73import contextlib2
84import tensorflow .compat .v1 as tf
95
@@ -33,12 +29,19 @@ def is_on_cpu():
3329
3430
3531def get_variable_name (read_variable_op ):
32+ """Obtains the name of the variable corresponding to ReadVariableOp."""
3633 assert read_variable_op .type == 'ReadVariableOp'
3734 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 ]
3943 assert len (op .inputs ) == 1
4044 op = op .inputs [0 ].op
41- return op .name
4245
4346
4447def maybe_convert_to_variable (tensor ):
You can’t perform that action at this time.
0 commit comments