Please, tell me what I am missing and why is there is a massive increase in size when it is stored in a file?
P.S. Its quite obvious I am missing something obvious, just point to some article or something, or maybe in the PyTorch Codebase where this is implemented.
Okay, looks good.
But in that case the model will contain
>>> 24 * torch.numel(net.weight.data)
216
I am closer to 4000 bytes! But still far away!
My guess is that each parameter uses far more bytes than its showing up.
I am doing something wrong most likely.
du -h actually counts the size of the folder as well. Running “ls -lha” will show you that the empty folder takes 4K, not the .pth file which is only 515bytes.
sys.getsizeof() measure the size of the Python object. So it is very unreliable for most pytorch elements.
The storage format is not really optimized for space. You can actually “cat” the file and you’ll see that it contains more strings than actual data.
Using different pickle backend might improve that but I have never tried (pickle_module argument to the save function)
Okay, I didn’t knew that about du -h, now that you say so, I checked it though ls -lha and GUI and it shows to be of 5xx bytes, which is goood Thanks!
Maybe I will try changing the pickle_module once and play around with it a bit.
My main aim was to calculate what the size of a model is and so, getting the amount of memory it will take when I move it to GPU.
It should take around the same memory, right? (the size of the model as calculated based on the datatype of the model and the memory it consumes in the GPU when I move it to GPU? ) Should be, intuitively.
Please feel free to reply when free, I have no hurries.
Thanks a ton for getting back to me Really Appreciated