Explicitly set reentrant to False
for torch checkpointing
#528
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.compile
on modules that do activation checkpointing.As discussed here, torch 2.4 and newer require explicitly passing
use_reentrant
to the checkpointing function. Prior to torch 2.4 (e.g. 2.2),use_reentrant
defaulted 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.compile
with our structure models.For Discussion
If maintainers strongly prefer and are concerned about backwards compatibility, we could adapt this PR to have
checkpoint_blocks
takeuse_reentrant
as a user-specified kwarg that defaults toTrue
and then gets passed toget_checkpoint_fn
. Let me know!