A context manager to allow setting the mode to EAGER/GRAPH.
(self, mode)
| 634 | |
| 635 | @tf_contextlib.contextmanager |
| 636 | def _mode(self, mode): |
| 637 | """A context manager to allow setting the mode to EAGER/GRAPH.""" |
| 638 | ctx = self._thread_local_data |
| 639 | old_mode = ctx.mode |
| 640 | old_is_eager = ctx.is_eager |
| 641 | ctx.mode = mode |
| 642 | ctx.is_eager = mode == EAGER_MODE |
| 643 | if mode == EAGER_MODE: |
| 644 | # Entering graph mode does not provide us with sufficient information to |
| 645 | # record a context switch; graph-based context switches are only logged |
| 646 | # when a graph is registered as the default graph. |
| 647 | self.context_switches.push(False, eager_mode, None) |
| 648 | try: |
| 649 | yield |
| 650 | finally: |
| 651 | ctx.is_eager = old_is_eager |
| 652 | ctx.mode = old_mode |
| 653 | if mode == EAGER_MODE: |
| 654 | self.context_switches.pop() |
| 655 | |
| 656 | def executing_eagerly(self): |
| 657 | """Returns True if current thread has eager executing enabled.""" |
no test coverage detected