Thank you, @smth
Here is a minor fix to catch exceptions, since hasattr(obj, 'data')
triggers all kinds of failures in python modules unrelated to pytorch and its tensors:
import torch
import gc
for obj in gc.get_objects():
try:
if torch.is_tensor(obj) or (hasattr(obj, 'data') and torch.is_tensor(obj.data)):
print(type(obj), obj.size())
except: pass
edit: oh, only now noticed a follow up from @Ben_Usman, that suggested the same.