Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[autograd][docs] Add more details on why save_for_backward is important in extending autograd note#153005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@soulitzer
Copy link
Contributor

@soulitzersoulitzer commentedMay 6, 2025
edited
Loading

…nt in extending autograd note[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-botbot commentedMay 6, 2025
edited
Loading

🔗 Helpful Links

🧪 See artifacts and rendered test results athud.pytorch.org/pr/153005

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 1 Unrelated Failure

As of commit73394bc with merge basee2c7ae5 (image):

NEW FAILURE - The following job has failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

… is important in extending autograd note"[ghstack-poisoned]
@soulitzersoulitzer requested a review fromalbanD as acode ownerMay 6, 2025 23:35
soulitzer added a commit that referenced this pull requestMay 6, 2025
…nt in extending autograd noteghstack-source-id:7b86a46Pull Requestresolved:#153005
@soulitzersoulitzer added the release notes: autogradrelease notes category labelMay 6, 2025
@pytorchpytorch deleted a comment fromgithub-actionsbotMay 6, 2025
Comment on lines 115 to 124
Saving tensors via ``save_for_backward`` allows the autograd engine to clear
them as soon as the backward computation of the ``autograd.Function`` completes.
(If a tensor is stored directly on ``ctx``
it will unnecessarily remain alive for the lifetime of the autograd graph --
typically until the end of the iteration.) Using ``save_for_backward``
also helps avoid certain reference cycles, (e.g., since the tensor
output of the ``autograd.Function`` itself keeps a reference to the ctx).
Saving via ``save_for_backward`` is also important for compatibility with
features like activation checkpointing and offloading that rely on
:class:`torch.autograd.graph.saved_tensors_hooks`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A possible readability improvement - not sure if I formatted it correctly - been a while since I touched rst.

Suggested change
Saving tensors via ``save_for_backward`` allows the autograd engine to clear
them as soon as the backward computation of the ``autograd.Function`` completes.
(If a tensor is stored directly on ``ctx``
it will unnecessarily remain alive for the lifetime of the autograd graph --
typically until the end of the iteration.) Using ``save_for_backward``
also helps avoid certain reference cycles, (e.g., since the tensor
output of the ``autograd.Function`` itself keeps a reference to the ctx).
Saving via ``save_for_backward`` is also important for compatibility with
features like activation checkpointing and offloading that rely on
:class:`torch.autograd.graph.saved_tensors_hooks`.
Saving tensors via ``save_for_backward``:
1. allows the autograd engine to clear
them as soon as the backward computation of the ``autograd.Function`` completes.
(If a tensor is stored directly on ``ctx``
it will unnecessarily remain alive for the lifetime of the autograd graph --
typically until the end of the iteration.)
2. it helps avoid certain reference cycles, (e.g., since the tensor
output of the ``autograd.Function`` itself keeps a reference to the ctx).
3. it is also important for compatibility with
features like activation checkpointing and offloading that rely on
:class:`torch.autograd.graph.saved_tensors_hooks`.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks, updated. Will double check the rendered results

stas00 reacted with heart emoji
… is important in extending autograd note"cc stas00 [ghstack-poisoned]
soulitzer added a commit that referenced this pull requestMay 7, 2025
…nt in extending autograd noteghstack-source-id:1c0c478Pull Requestresolved:#153005
Copy link
Collaborator

@albanDalbanD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks!

@soulitzer
Copy link
ContributorAuthor

@pytorchbot merge

pytorch-bot[bot] reacted with thumbs up emoji

@pytorch-botpytorch-botbot added the ciflow/trunkTrigger trunk jobs on your pull request labelMay 8, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in thewiki.

Questions? Feedback? Please reach out to thePyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are:trunk / win-vs2022-cpu-py3 / test (default, 1, 3, ephemeral.windows.4xlarge.nonephemeral)

Details for Dev Infra teamRaised byworkflow job

@soulitzer
Copy link
ContributorAuthor

@pytorchbot merge -i

pytorch-bot[bot] reacted with thumbs up emoji

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks:trunk / macos-py3-arm64 / test (default, 3, 3, macos-m1-stable),trunk / win-vs2022-cpu-py3 / test (default, 1, 3, ephemeral.windows.4xlarge.nonephemeral)

Learn more about merging in thewiki.

Questions? Feedback? Please reach out to thePyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Starting merge as part of PR stack under#153094

pytorchmergebot pushed a commit that referenced this pull requestMay 12, 2025
@github-actionsgithub-actionsbot deleted the gh/soulitzer/360/head branchJune 14, 2025 02:15
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@albanDalbanDalbanD approved these changes

+1 more reviewer

@stas00stas00stas00 left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

ciflow/trunkTrigger trunk jobs on your pull requestMergedrelease notes: autogradrelease notes category

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@soulitzer@pytorchmergebot@albanD@stas00

[8]ページ先頭

©2009-2025 Movatter.jp