Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions beginner_source/understanding_leaf_vs_nonleaf_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@
#
# Computational graph after backward pass
#
# If you call ``retain_grad()`` on a non-leaf node, it results in a no-op.
# If we call ``retain_grad()`` on a node that has ``requires_grad=False``,
# If you call ``retain_grad()`` on a leaf tensor, it results in a no-op
# since leaf tensors already retain their gradients by default (when
# ``requires_grad=True``).
# If we call ``retain_grad()`` on a tensor that has ``requires_grad=False``,
# PyTorch actually throws an error, since it can’t store the gradient if
# it is never calculated.
#
Expand Down Expand Up @@ -298,13 +300,13 @@
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
# | ``is_leaf`` | ``requires_grad`` | ``retains_grad`` | ``require_grad()`` | ``retain_grad()`` |
# +================+========================+========================+===================================================+=====================================+
# | ``True`` | ``False`` | ``False`` | sets ``requires_grad`` to ``True`` or ``False`` | no-op |
# | ``True`` | ``False`` | ``False`` | sets ``requires_grad`` to ``True`` or ``False`` | throws error |
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
# | ``True`` | ``True`` | ``False`` | sets ``requires_grad`` to ``True`` or ``False`` | no-op |
# | ``True`` | ``True`` | ``False`` | sets ``requires_grad`` to ``True`` or ``False`` | no-op (already retains) |
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
# | ``False`` | ``True`` | ``False`` | no-op | sets ``retains_grad`` to ``True`` |
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
# | ``False`` | ``True`` | ``True`` | no-op | no-op |
# | ``False`` | ``True`` | ``True`` | no-op | no-op (already retains) |
# +----------------+------------------------+------------------------+---------------------------------------------------+-------------------------------------+
#

Expand Down