File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
tensorflow/contrib/tpu/python/tpu Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 97
97
98
98
# TODO(b/114775106): temporary shim to optionally initialize the TPU
99
99
# This increases the odds our session is initialized, but shouldn't be needed.
100
+ _TEST_REWRITE_OP = None
101
+
102
+
100
103
def _maybe_initialize_tpu (session ):
101
104
"""Initialize the TPU if it has not already been initialized."""
105
+ global _TEST_REWRITE_OP
102
106
try :
107
+ # Try to use cached version to avoid another ground of graph optimization.
108
+ test_rewrite_op = _TEST_REWRITE_OP
109
+ if (test_rewrite_op is None or
110
+ test_rewrite_op [0 ].graph != ops .get_default_graph ()):
111
+
112
+ def test_op ():
113
+ return constant_op .constant (1 ) + constant_op .constant (1 )
103
114
104
- def test_op ():
105
- return constant_op . constant ( 1 ) + constant_op . constant ( 1 )
115
+ test_rewrite_op = tpu . rewrite ( test_op )
116
+ _TEST_REWRITE_OP = test_rewrite_op
106
117
107
- session .run (tpu . rewrite ( test_op ) )
118
+ session .run (test_rewrite_op )
108
119
except errors .FailedPreconditionError as _ :
109
120
session .run (tpu .initialize_system ())
110
121
You can’t perform that action at this time.
0 commit comments