Skip to content

retain_grad() documentation misleading about non-leaf tensors #3652

@wubloverse

Description

@wubloverse

The documentation says:

"If you call retain_grad() on a non-leaf node, it results in a no-op."

This is misleading or incomplete.
retain_grad() on a non-leaf tensor with requires_grad=True does not result in a no-op — it correctly retains gradients.

Only calling retain_grad() on:

a leaf tensor is a no-op

a tensor with requires_grad=False throws an error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions