Temporarily stops recording operations on this tape. Operations executed while this context manager is active will not be recorded on the tape. This is useful for reducing the memory used by tracing all computations. For example: ``` with tf.GradientTape(persistent=True)
(self)
| 862 | |
| 863 | @tf_contextlib.contextmanager |
| 864 | def stop_recording(self): |
| 865 | """Temporarily stops recording operations on this tape. |
| 866 | |
| 867 | Operations executed while this context manager is active will not be |
| 868 | recorded on the tape. This is useful for reducing the memory used by tracing |
| 869 | all computations. |
| 870 | |
| 871 | For example: |
| 872 | |
| 873 | ``` |
| 874 | with tf.GradientTape(persistent=True) as t: |
| 875 | loss = compute_loss(model) |
| 876 | with t.stop_recording(): |
| 877 | # The gradient computation below is not traced, saving memory. |
| 878 | grads = t.gradient(loss, model.variables) |
| 879 | ``` |
| 880 | |
| 881 | Yields: |
| 882 | None |
| 883 | Raises: |
| 884 | RuntimeError: if the tape is not currently recording. |
| 885 | """ |
| 886 | if self._tape is None: |
| 887 | raise RuntimeError( |
| 888 | "Trying to stop recording a tape which is not recording.") |
| 889 | self._pop_tape() |
| 890 | try: |
| 891 | yield |
| 892 | finally: |
| 893 | self._push_tape() |
| 894 | |
| 895 | def reset(self): |
| 896 | """Clears all information stored in this tape. |