File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 174174
175175###############################################################
176176# You can also stop autograd from tracking history on Tensors
177- # with ``.requires_grad=True`` by wrapping the code block in
177+ # with ``.requires_grad=True`` either by wrapping the code block in
178178# ``with torch.no_grad():``
179179print (x .requires_grad )
180180print ((x ** 2 ).requires_grad )
181181
182182with torch .no_grad ():
183183 print ((x ** 2 ).requires_grad )
184184
185+ ###############################################################
186+ # Or by using ``.detach()`` to get a new Tensor with the same
187+ # content but that does not require gradients:
188+ print (x .requires_grad )
189+ y = x .detach ()
190+ print (y .requires_grad )
191+ print (x .eq (y ).all ())
192+
193+
185194###############################################################
186195# **Read Later:**
187196#
You can’t perform that action at this time.
0 commit comments