MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / reset

Method reset

tensorflow/python/eager/backprop.py:895–929  ·  view source on GitHub ↗

Clears all information stored in this tape. Equivalent to exiting and reentering the tape context manager with a new tape. For example, the two following code blocks are equivalent: ``` with tf.GradientTape() as t: loss = loss_fn() with tf.GradientTape() as t: loss

(self)

Source from the content-addressed store, hash-verified

893 self._push_tape()
894
895 def reset(self):
896 """Clears all information stored in this tape.
897
898 Equivalent to exiting and reentering the tape context manager with a new
899 tape. For example, the two following code blocks are equivalent:
900
901 ```
902 with tf.GradientTape() as t:
903 loss = loss_fn()
904 with tf.GradientTape() as t:
905 loss += other_loss_fn()
906 t.gradient(loss, ...) # Only differentiates other_loss_fn, not loss_fn
907
908
909 # The following is equivalent to the above
910 with tf.GradientTape() as t:
911 loss = loss_fn()
912 t.reset()
913 loss += other_loss_fn()
914 t.gradient(loss, ...) # Only differentiates other_loss_fn, not loss_fn
915 ```
916
917 This is useful if you don't want to exit the context manager for the tape,
918 or can't because the desired reset point is inside a control flow construct:
919
920 ```
921 with tf.GradientTape() as t:
922 loss = ...
923 if loss > k:
924 t.reset()
925 ```
926 """
927 self._pop_tape()
928 self._tape = None
929 self._push_tape()
930
931 def watched_variables(self):
932 """Returns variables watched by this tape in order of construction."""

Callers 9

pywrap_tfe_src.ccFile · 0.45
RecordGradientFunction · 0.45
ReadVariableOpFunction · 0.45
ConvertToTensorFunction · 0.45
TFE_Py_FastPathExecute_CFunction · 0.45
testTapeResetMethod · 0.45

Calls 2

_pop_tapeMethod · 0.95
_push_tapeMethod · 0.95

Tested by 3

testTapeResetMethod · 0.36