What does torch.save actually saves?

gebrahimi: <p>I am facing a weird issue and i am trying to figure out why size of my save model is super big.<br>
I have the following net:</p>
<pre><code>AlexNetTransfer(
(fullnet): Sequential(
(0): Conv2d(3, 42, kernel_size=(11, 11), stride=(4, 4), padding=(2, 2))
(1): ReLU(inplace=True)
(2): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)
(3): Conv2d(42, 96, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
(4): ReLU(inplace=True)
(5): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)
(6): Conv2d(96, 190, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(7): ReLU(inplace=True)
(8): Conv2d(190, 169, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(9): ReLU(inplace=True)
(10): Conv2d(169, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(11): ReLU(inplace=True)
(12): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)
(13): AdaptiveAvgPool2d(output_size=(6, 6))
(14): Linear(in_features=2304, out_features=3487, bias=True)
(15): ReLU(inplace=True)
(16): Linear(in_features=3487, out_features=4096, bias=True)
(17): ReLU(inplace=True)
(18): Linear(in_features=4096, out_features=102, bias=True)
</code></pre>
<p>)<br>
)</p>
<p>which I trained. When I use <code>torch.save(net, 'a')</code> I get following warnings and the size of model is super huge: 15 GB.<br>
<code>/opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py:292: UserWarning: Couldn't   retrieve source code for container of type AlexNetTransfer. It won't be checked for correctness upon loading.   "type " + obj.__name__ + ". It won't be checked " /opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py:292: UserWarning: Couldn't retrieve source code for container of type Sequential. It won't be checked for correctness upon loading.   "type " + obj.__name__ + ". It won't be checked " /opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py:292: UserWarning: Couldn't retrieve source code for container of type Conv2d. It won't be checked for correctness upon loading.   "type " + obj.__name__ + ". It won't be checked " /opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py:292: UserWarning: Couldn't retrieve source code for container of type Linear. It won't be checked for correctness upon loading.   "type " + obj.__name__ + ". It won't be checked " /opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py:292: UserWarning: Couldn't retrieve source code for container of type ReLU. It won't be checked for correctness upon loading.   "type " + obj.__name__ + ". It won't be checked " /opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py:292: UserWarning: Couldn't retrieve source code for container of type MaxPool2d. It won't be checked for correctness upon loading.   "type " + obj.__name__ + ". It won't be checked " /opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py:292: UserWarning: Couldn't retrieve source code for container of type AdaptiveAvgPool2d. It won't be checked for correctness upon loading.   "type " + obj.__name__ + ". It won't be checked "</code></p>
<p>However if i use <code>torch.save(net.state_dict(), 'a')</code> the size is just 90 mb which is reasonable. Any how to figure out what else is being saved that makes the file that big?<br>
Thanks.</p>

G.M: <p><code>torch.save(net, 'a') </code> saves the code and the parameters using pickle. U can view this as saving a python function/object using pickle. U got the warnings probably because most pytorch functions are written in C++ instead of python.<br>
<code>torch.save(net.state_dict(), 'a')</code> saves the model’s parameters in the file. <code>net.state_dict()</code> returns the parameters in a <code>dict</code> object.</p>