Skip to content

Allow branching on whether you are in AC region with is_checkpoint_enabled - #160888

Open
soulitzer wants to merge 10 commits into
gh/soulitzer/375/basefrom
gh/soulitzer/375/head
Open

soulitzer wants to merge 10 commits into
gh/soulitzer/375/basefrom
gh/soulitzer/375/head

Conversation

@soulitzer

@soulitzer soulitzer commented Aug 18, 2025 •

Copy link
Copy Markdown
Contributor

[ghstack-poisoned]
@soulitzer
soulitzer requested a review from zou3519 as a code owner August 18, 2025 15:29
soulitzer added a commit that referenced this pull request Aug 18, 2025
@pytorch-bot

pytorch-bot Bot commented Aug 18, 2025 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/160888

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

❌ 1 New Failure

As of commit b397514 with merge base 4fd761f (image):

NEW FAILURE - The following job has failed:

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

@soulitzer soulitzer changed the title Wrap AC with a dynamo-traced wrapper which sets is_checkpoint_enabled Allow branching on whether you are in AC region with is_checkpoint_enabled Aug 18, 2025
@soulitzer soulitzer added release notes: autograd release notes category topic: new features topic category labels Aug 18, 2025
@pytorch pytorch deleted a comment from github-actions Bot Aug 18, 2025
@soulitzer

Copy link
Copy Markdown
Contributor Author

Now running AC does side effects!
This would (1) break existing HOPs, and (2) prevent AC from being used inside HOPs.

@soulitzer
soulitzer marked this pull request as draft August 18, 2025 19:09
@soulitzer

Copy link
Copy Markdown
Contributor Author

Could we give an exception to this side effect on the basis that it is not "externally visible"? (Since we promise to undo it before leaving the scope of the HOP.)

[ghstack-poisoned]
soulitzer added a commit that referenced this pull request Aug 18, 2025
Comment thread torch/utils/checkpoint.py
# utils.checkpoint innards.
@torch._disable_dynamo

_is_checkpoint_enabled = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You want this to be thread-local, right?

@zou3519 zou3519 Aug 18, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the only part I'm iffy about. Everything else looks good to me. Thoughts @albanD?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah... and probably needs to be part of the cpp thread_local_state (rather than threading.local in Python) if we care about the case where we do autograd inside an AC region

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From discussion with @albanD offline, adding to cpp thread_local_state sounds good, although it would mean that consistency between eager and compile can be tricky. Not sure how to go about this yet.

[ghstack-poisoned]
@soulitzer
soulitzer marked this pull request as ready for review August 19, 2025 20:49
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@github-actions github-actions Bot added the Stale label Nov 8, 2025
@pytorch pytorch deleted a comment from github-actions Bot Nov 11, 2025
@soulitzer soulitzer added no-stale and removed Stale labels Nov 11, 2025
Khanaksahu pushed a commit to Khanaksahu/pytorch that referenced this pull request Nov 17, 2025
@zou3519

zou3519 commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

btw I feel like a nonzero number of people have asked for this recently :P like @yanboliang

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants