Repository navigation
Fix (skip) cuda cache flush when origin device is cpu and offloaded to meta - #3796
Merged
Merged
Conversation
SunMarc
approved these changes
Sep 26, 2025
SunMarc
left a comment
Member
There was a problem hiding this comment.
Thanks a lot and nice report btw !
|
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. |
2 tasks
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 does this PR do?
Fix
disk_offload()api causingtorch.cuda.empty_cache()to be called when the module origin device iscpuand offloaded tometa(disk).Secondarily this also resolves a performance issue as
torch.cuda.empty_cache()is slow and calling it with no effect in a forwardig env where modules are dynamically (manually) offloaded is suboptimal.Given above nn.Module (linear) which is on
cpuand following this call, I did not expectacceleratecode paths to call anything cuda related. This (in-directly) triggered a cuda assert error in my GIL=0 env with multiple gpu and threads. I probably have thread ctx bug somehwere above the code but the main objective is that in this scenerio,torch.cuda.empty_cache()should never be called bydisk_offloadpaths.Stacktrace: Please note the crash is not caused by
accelerate. The stack shows the paths that triggered the invalidtorch.cuda.empty_cache()call.Who can review?
@SunMarc @zach-huggingface @BenjaminBossan