Explicitly set reentrant to False for torch checkpointing#528
Open
an1lam wants to merge 1 commit intoaqlaboratory:pl_upgradesfrom
Open
Explicitly set reentrant to False for torch checkpointing#528an1lam wants to merge 1 commit intoaqlaboratory:pl_upgradesfrom
False for torch checkpointing#528an1lam wants to merge 1 commit intoaqlaboratory:pl_upgradesfrom
Conversation
* Explicitly set reentrant to False for torch checkpointing As discussed [here](https://pytorch.org/docs/2.6/checkpoint.html#torch.utils.checkpoint.checkpoint), torch 2.4 and newer require explicitly passing to the checkpointing function. Prior to torch 2.4 (e.g. 2.2), use_reentrant defaulted to True, however we have found that reentrant checkpointing does not work with DDP and torch.compile [1]. As a result, this change forces use_reentrant=False to enable us to use torch.compile with our structure models. * Update version * Update checkpointing.py * Update setup.py * Update setup.py
Author
|
@jnwei apologies for the ping out of nowhere, but are you the right person to be requesting review from? I see you're the most recent person to merge a PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The purpose of this PR is to set up OpenFold to be compatible with torch 2.6 (technically >=2.4), in particular for using
torch.compileon modules that do activation checkpointing.As discussed here, torch 2.4 and newer require explicitly passing
use_reentrantto the checkpointing function. Prior to torch 2.4 (e.g. 2.2),use_reentrantdefaulted toTrue, however we have found that non-reentrant checkpointing works better with DDP and torch.compile. This is surprisingly hard to find documentation for, but seems to match anecdotal experience of others (ex). As a result, this change forcesuse_reentrant=False, enabling the use oftorch.compilewith our structure models.For Discussion
If maintainers strongly prefer and are concerned about backwards compatibility, we could adapt this PR to have
checkpoint_blockstakeuse_reentrantas a user-specified kwarg that defaults toTrueand then gets passed toget_checkpoint_fn. Let me know!