Prevent activation_checkpoint_cpu_offload from silently no-op'ing on transformers >=5.0#373
Open
xylian86 wants to merge 1 commit into
Open
Prevent activation_checkpoint_cpu_offload from silently no-op'ing on transformers >=5.0#373xylian86 wants to merge 1 commit into
xylian86 wants to merge 1 commit into
Conversation
…trant gradient checkpointing
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.
What
When
activation_checkpoint_cpu_offloadis enabled, force HF'sgradient_checkpointing_enableto useuse_reentrant=True.Why
The CPU-offload activation checkpointing in
arctic_training.monkey_patchesreplacestorch.utils.checkpoint.CheckpointFunction, which is only used by the reentrant code path oftorch.utils.checkpoint.checkpoint. The non-reentrant path goes through_checkpoint_without_reentrant_generator+saved_tensors_hooksand never touchesCheckpointFunction, so the monkey patch becomes a silent no-op there.In current
transformers(4.x),model.gradient_checkpointing_enable()with no kwargs defaults touse_reentrant=True, so this happens to work. Starting withtransformersv5.0.0 ([huggingface/transformers#43203], merged Jan 2026), the default flips touse_reentrant=False. Once we bump the upper pin past<5.0.0, users settingactivation_checkpoint_cpu_offload: truewould get no offloading at all — long-sequence runs would OOM with no error or warning to indicate why.Note: tactical fix. The proper long-term solution is to replace the
CheckpointFunctionmonkey patch with asaved_tensors_hooks-based implementation (see torchtune reference inmonkey_patches.py), which would work regardless ofuse_reentrant. Out of scope here.