How to list my objects in memory?

Hi all,

I hate to ask such a dumb question,
but I’ve been searching for a concise answer
for a good hour now.

After running some code, my
GPU’s memory is full.

On this pytorch thread, they discuss how to free up memory.

Check GPU memory using nvidia-smi

del a
torch.cuda.empty_cache()

Check GPU memory again using nvidia-smi

Works

However, in Python, how can I list all
my objects in memory that I’ve created, and
ideally, their size?

Without poking through my code?

Similar to ls for files on linux.
Or, ls() in R.

Thanks a lot

1 Like

I’d love to find out if there is an answer to this, but my bet is this won’t be easy or concise (I haven’t seen a solution myself). It’s definitely not a dumb question :slight_smile: Maybe check out pytorch profiler? https://pytorch.org/tutorials/recipes/recipes/profiler.html

Have you tried this link from the pytorch forums?

Best regards,
Butch

2 Likes