Repository navigation
Fixes memory leak in async_save in distributed checkpoint - #170431
arkadip-maitra wants to merge 4 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/170431
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 94d5d07 with merge base b71eaf9 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
The label |
|
The label |
|
Garbage collection is the default behavior. How much is the typical memory occupied by the closed |
|
Without explicit garbage collection call the pattern of memory accumulation is this: Memory accumulates ~2GB per step |
|
@pytorchbot merge |
Merge failedReason: Approvers from one of the following sets are needed:
|
Okay, the real bug is with this PR then: #169613 |
|
FYI: @ankitageorge for a proper GC fix |
|
@Skylion007 can you approve pls. seems like this change is not related to #169613 |
LucasLLC
left a comment
There was a problem hiding this comment.
Tysm for looking into this! Some qq's if you don't mind
| staging_future_or_state_dict = stage_state_dict() | ||
|
|
||
| if _internally_created_stager: | ||
| async_stager.close() |
There was a problem hiding this comment.
curious -- why not always call async_stager.close here?
There was a problem hiding this comment.
if async_stager is user provided it can be used across checkpoints.
Looking at the docstring explaining close function i think its better to move this close call at the end since "After calling close(), the stager should not be used for further staging operations"
|
Successfully rebased |
fa6f263 to
94d5d07
Compare
|
@cyyever @Skylion007 @daulet-askarov |
This PR was reopened (likely due to being reverted), so your approval was removed. Please request another review.
daulet-askarov
left a comment
There was a problem hiding this comment.
Thanks for getting to the bottom of this reference cycle and fixing it!
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…0431) Fixes pytorch#170163 **Cause** When `async_save` is called without a user-provided `async_stager`, it creates an internal `DefaultStager` that caches CPU storage copies. This cache wasn't being cleared, and the stager went out of scope without cleanup **Changes** _1. _traverse.py: del _traverse_obj, _is_terminal _2. state_dict_saver.py: clear _deepcopy_dispatch in close() Tracked the memory leak and used this changes to fix it Pull Request resolved: pytorch#170431 Approved by: https://github.com/LucasLLC, https://github.com/daulet-askarov, https://github.com/Skylion007
…0431) Fixes pytorch#170163 **Cause** When `async_save` is called without a user-provided `async_stager`, it creates an internal `DefaultStager` that caches CPU storage copies. This cache wasn't being cleared, and the stager went out of scope without cleanup **Changes** _1. _traverse.py: del _traverse_obj, _is_terminal _2. state_dict_saver.py: clear _deepcopy_dispatch in close() Tracked the memory leak and used this changes to fix it Pull Request resolved: pytorch#170431 Approved by: https://github.com/LucasLLC, https://github.com/daulet-askarov, https://github.com/Skylion007
Fixes #183413 DefaultStager stopped being reusable because DefaultStager._stage() closed its internal StateDictStager after every stage, because of my earlier pr [#170431](#170431) that fixed issue #170163 This fixes that by keeping user provided stagers alive across saves and moving cleanup of internally created default stagers into `async_save()`. Added test to verify re-usability of `DefaultStager` and verified to regression. Pull Request resolved: #183424 Approved by: https://github.com/fegin
Fixes pytorch#183413 DefaultStager stopped being reusable because DefaultStager._stage() closed its internal StateDictStager after every stage, because of my earlier pr [pytorch#170431](pytorch#170431) that fixed issue pytorch#170163 This fixes that by keeping user provided stagers alive across saves and moving cleanup of internally created default stagers into `async_save()`. Added test to verify re-usability of `DefaultStager` and verified to regression. Pull Request resolved: pytorch#183424 Approved by: https://github.com/fegin
Fixes pytorch#183413 DefaultStager stopped being reusable because DefaultStager._stage() closed its internal StateDictStager after every stage, because of my earlier pr [pytorch#170431](pytorch#170431) that fixed issue pytorch#170163 This fixes that by keeping user provided stagers alive across saves and moving cleanup of internally created default stagers into `async_save()`. Added test to verify re-usability of `DefaultStager` and verified to regression. Pull Request resolved: pytorch#183424 Approved by: https://github.com/fegin
Fixes #170163
Cause
When
async_saveis called without a user-providedasync_stager, it creates an internalDefaultStagerthat caches CPU storage copies. This cache wasn't being cleared, and the stager went out of scope without cleanupChanges
_1. _traverse.py: del _traverse_obj, _is_terminal
_2. state_dict_saver.py: clear _deepcopy_dispatch in close()
Tracked the memory leak and used this changes to fix it
cc @LucasLLC @pradeepfn @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta @msaroufim @dcci