Custom implementation of session() for XLA tests. We override the standard Tensorflow session() since it is too specific to CPU and GPU tests. In particular, we want to disable soft placement and explicitly assign ops to devices under test. Yields: A session to use when runni
(self)
| 202 | |
| 203 | @contextlib.contextmanager |
| 204 | def session(self): |
| 205 | """Custom implementation of session() for XLA tests. |
| 206 | |
| 207 | We override the standard Tensorflow session() since it is too |
| 208 | specific to CPU and GPU tests. In particular, we want to disable soft |
| 209 | placement and explicitly assign ops to devices under test. |
| 210 | |
| 211 | Yields: |
| 212 | A session to use when running a test case. |
| 213 | """ |
| 214 | graph = ops.Graph() |
| 215 | config = context.context().config |
| 216 | |
| 217 | # Grappler can constant fold TensorListFromTensor ops into DT_VARIANT |
| 218 | # constants which XLA does not understand. So disable constant folding in |
| 219 | # these tests. |
| 220 | config.graph_options.rewrite_options.constant_folding = ( |
| 221 | rewriter_config_pb2.RewriterConfig.OFF) |
| 222 | with session.Session( |
| 223 | graph=graph, config=config) as sess, graph.as_default(): |
| 224 | yield sess |
| 225 | |
| 226 | def cached_session(self): |
| 227 | raise NotImplementedError( |
no test coverage detected