Repository navigation
Fix activation offloading on torch < 2.4 - #7748
Merged
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
kashif
approved these changes
Oct 15, 2026
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.
This PR restores activation offloading on torch 2.2 and 2.3, which #7670 broke on main.
Motivation
#7670 calls
torch.get_device_moduleinOffloadActivations.__init__. That function only exists from torch 2.4, so #7670 relies on the torch floor from #7642, but it merged before #7642. TRL still allows torch 2.2 and 2.3 (transformers 4.56.2 requirestorch>=2.2). On those versions, building the activation offloading context manager raisesAttributeError: module 'torch' has no attribute 'get_device_module'. This affects SFT withactivation_offloading=Trueand direct calls toget_act_offloading_ctx_manager.#7670 is not released yet, but v1.16 is imminent, and #7642 can't merge before it. Without this fix, v1.16 would break activation offloading for users on torch 2.2 and 2.3, which v1.15 supports. On torch 2.3.1,
tests/test_activation_offloading.pypasses on v1.15.0 and fails on main.Solution
Below torch 2.4, the accelerator type is always
"cuda"(the existing fallback whentorch.acceleratoris missing), so the device module falls back totorch.cuda, as before #7670. #7642 removes this guard together with thetorch.acceleratorfallback.Changes
torch.cudaas the device module in activation offloading on torch < 2.4Note
Low Risk
Single version guard in offloading init; behavior on torch 2.4+ is unchanged and older torch regains the prior cuda device module path.
Overview
Restores activation offloading on PyTorch 2.2 and 2.3 after a recent change unconditionally called
torch.get_device_module, which only exists from 2.4 onward and causedAttributeErrorwhen constructingOffloadActivations(e.g. SFT withactivation_offloading=True).OffloadActivations.__init__now setsdevice_moduleviais_torch_version(">=", "2.4.0"): usetorch.get_device_moduleon 2.4+, otherwisetorch.cuda, matching the pre-change behavior whenaccelerator_typealready falls back to"cuda"withouttorch.accelerator.Reviewed by Cursor Bugbot for commit 67eec3e. Bugbot is set up for automated code reviews on this repo. Configure here.