-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Fix memory leak in ModuleTracker
#141960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory leak in ModuleTracker
#141960
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/141960
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit b6227e4 with merge base 78543e6 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "topic: bug fixes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make one of the test in test/test_module_tracker.py run on cuda device and enable leak detection on it to catch this. But might be a bit too much for this PR, it sounds ok as is if you don't have time.
|
@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 |
Thanks @drisspg and @albanD for finding the fix **TEST PLAN** ``` import gc import torch import torch.nn as nn from torch.utils.module_tracker import ModuleTracker class MyModel(nn.Module): def forward(self, x): return x * x print(f"torch=={torch.__version__}") m = MyModel() m.cuda() m.to(torch.bfloat16) mt = ModuleTracker() for i in range(1000): if i % 100 == 0: gc.collect() print("memory_allocated:", torch.cuda.memory_allocated()) x = torch.randn([128, 256], device="cuda", dtype=torch.bfloat16, requires_grad=True) with mt: m(x) ``` Pull Request resolved: pytorch#141960 Approved by: https://github.com/albanD
Thanks @drisspg and @albanD for finding the fix **TEST PLAN** ``` import gc import torch import torch.nn as nn from torch.utils.module_tracker import ModuleTracker class MyModel(nn.Module): def forward(self, x): return x * x print(f"torch=={torch.__version__}") m = MyModel() m.cuda() m.to(torch.bfloat16) mt = ModuleTracker() for i in range(1000): if i % 100 == 0: gc.collect() print("memory_allocated:", torch.cuda.memory_allocated()) x = torch.randn([128, 256], device="cuda", dtype=torch.bfloat16, requires_grad=True) with mt: m(x) ``` Pull Request resolved: pytorch#141960 Approved by: https://github.com/albanD
Thanks @drisspg and @albanD for finding the fix **TEST PLAN** ``` import gc import torch import torch.nn as nn from torch.utils.module_tracker import ModuleTracker class MyModel(nn.Module): def forward(self, x): return x * x print(f"torch=={torch.__version__}") m = MyModel() m.cuda() m.to(torch.bfloat16) mt = ModuleTracker() for i in range(1000): if i % 100 == 0: gc.collect() print("memory_allocated:", torch.cuda.memory_allocated()) x = torch.randn([128, 256], device="cuda", dtype=torch.bfloat16, requires_grad=True) with mt: m(x) ``` Pull Request resolved: pytorch#141960 Approved by: https://github.com/albanD (cherry picked from commit 9125e91)
) Thanks @drisspg and @albanD for finding the fix **TEST PLAN** ``` import gc import torch import torch.nn as nn from torch.utils.module_tracker import ModuleTracker class MyModel(nn.Module): def forward(self, x): return x * x print(f"torch=={torch.__version__}") m = MyModel() m.cuda() m.to(torch.bfloat16) mt = ModuleTracker() for i in range(1000): if i % 100 == 0: gc.collect() print("memory_allocated:", torch.cuda.memory_allocated()) x = torch.randn([128, 256], device="cuda", dtype=torch.bfloat16, requires_grad=True) with mt: m(x) ``` Pull Request resolved: pytorch#141960 Approved by: https://github.com/albanD (cherry picked from commit 9125e91) Fixes #ISSUE_NUMBER Co-authored-by: dan_the_3rd <43445237+danthe3rd@users.noreply.github.com>
Thanks @drisspg and @albanD for finding the fix
cc @pragupta
TEST PLAN