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 174
174
175
175
###############################################################
176
176
# 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
178
178
# ``with torch.no_grad():``
179
179
print (x .requires_grad )
180
180
print ((x ** 2 ).requires_grad )
181
181
182
182
with torch .no_grad ():
183
183
print ((x ** 2 ).requires_grad )
184
184
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
+
185
194
###############################################################
186
195
# **Read Later:**
187
196
#
You can’t perform that action at this time.
0 commit comments