You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a LightningModule, sys.getrefcount() returns 3 (vs. returning 2 for a conventional torch Module). In my particular case, for instance, this results in memory issues: even if I explicitly do del <LightningModule>, the memory is not released, and I believe this is the root of the issue.
I had originally discussed this problem on Slack. As discussed, I'm creating an issue for it and pinging @carmocca.
To Reproduce
Input:
import sys
import torch
import pytorch_lightning as pl
a = torch.nn.Module()
b = pl.LightningModule()
print(sys.getrefcount(b))
print(sys.getrefcount(a))
Output:
3
2
Expected behavior
Output:
2
2
Environment
PyTorch Lightning Version: 1.5.9
PyTorch Version: 1.10.2+cu113
Python version: 3.8.12
OS: Linux
CUDA/cuDNN version: 11.6
GPU models and configuration: Quadro RTX 8000
How you installed PyTorch: pip
Additional context
Per @carmocca's advice on Slack, a workaround is to do b._load_state_dict_pre_hooks.clear() before deleting the LightningModule. This indeed seems to work. However, I'm not sure about an explanation as to why.
Uh oh!
There was an error while loading. Please reload this page.
🐛 Bug
When creating a
LightningModule
,sys.getrefcount()
returns 3 (vs. returning 2 for a conventional torchModule
). In my particular case, for instance, this results in memory issues: even if I explicitly dodel <LightningModule>
, the memory is not released, and I believe this is the root of the issue.I had originally discussed this problem on Slack. As discussed, I'm creating an issue for it and pinging @carmocca.
To Reproduce
Input:
Output:
Expected behavior
Output:
Environment
Additional context
Per @carmocca's advice on Slack, a workaround is to do
b._load_state_dict_pre_hooks.clear()
before deleting theLightningModule
. This indeed seems to work. However, I'm not sure about an explanation as to why.Thanks!
cc @carmocca @justusschock @awaelchli @Borda @ananthsub @ninginthecloud @jjenniferdai @rohitgr7
The text was updated successfully, but these errors were encountered: