Skip to content

Commit 0a9e5cc

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents f4087e7 + f99e9e8 commit 0a9e5cc

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

beginner_source/understanding_leaf_vs_nonleaf_tutorial.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,10 @@
265265
#
266266
# Computational graph after backward pass
267267
#
268-
# If you call ``retain_grad()`` on a non-leaf node, it results in a no-op.
269-
# If we call ``retain_grad()`` on a node that has ``requires_grad=False``,
268+
# If you call ``retain_grad()`` on a leaf tensor, it results in a no-op
269+
# since leaf tensors already retain their gradients by default (when
270+
# ``requires_grad=True``).
271+
# If we call ``retain_grad()`` on a tensor that has ``requires_grad=False``,
270272
# PyTorch actually throws an error, since it can’t store the gradient if
271273
# it is never calculated.
272274
#
@@ -298,13 +300,13 @@
298300
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
299301
# | ``is_leaf`` | ``requires_grad`` | ``retains_grad`` | ``require_grad()`` | ``retain_grad()`` |
300302
# +================+========================+========================+===================================================+=====================================+
301-
# | ``True`` | ``False`` | ``False`` | sets ``requires_grad`` to ``True`` or ``False`` | no-op |
303+
# | ``True`` | ``False`` | ``False`` | sets ``requires_grad`` to ``True`` or ``False`` | throws error |
302304
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
303-
# | ``True`` | ``True`` | ``False`` | sets ``requires_grad`` to ``True`` or ``False`` | no-op |
305+
# | ``True`` | ``True`` | ``False`` | sets ``requires_grad`` to ``True`` or ``False`` | no-op (already retains) |
304306
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
305307
# | ``False`` | ``True`` | ``False`` | no-op | sets ``retains_grad`` to ``True`` |
306308
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
307-
# | ``False`` | ``True`` | ``True`` | no-op | no-op |
309+
# | ``False`` | ``True`` | ``True`` | no-op | no-op (already retains) |
308310
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
309311
#
310312

intermediate_source/torch_compile_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def timed(fn):
163163
result = fn()
164164
end.record()
165165
torch.cuda.synchronize()
166-
return result, start.elapsed_time(end) / 1024
166+
return result, start.elapsed_time(end) / 1000
167167

168168

169169
inp = torch.randn(4096, 4096).cuda()

0 commit comments

Comments
 (0)