RuntimeError: storage has wrong size: expected 0 got 1

username: flawnson
cooked: <p>I’m trying to load a .pt/.pth file with torch.load. Having worked perfectly previously, after adding another item to my instance before creating the .pt file again, this error popped up. Full error is:</p>
<p>Traceback (most recent call last):<br>
File “outcome.py”, line 12, in <br>
torch.load(r"path")<br>
File “C:\Users\Flawnson\Anaconda3\lib\site-packages\torch\serialization.py”, line 368, in load<br>
return _load(f, map_location, pickle_module)<br>
File “C:\Users\Flawnson\Anaconda3\lib\site-packages\torch\serialization.py”, line 549, in _load<br>
deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)<br>
RuntimeError: storage has wrong size: expected 0 got 1</p>

username: ptrblck
cooked: <p>By “adding another item to my instance” do you mean you’ve added another module to your model?<br>
Could you post some pseudo code so that we could see what’s going on?</p>

username: flawnson
cooked: <p>I did a little experimenting, and the root of the problem is actually a bit simpler. Every time I use torch.load on a .pt file, I get:</p>
<p>RuntimeError: storage has wrong size: expected 0 got 1</p>

username: ptrblck
cooked: <p>Could you upload such a file so that I could try to load it on my machine?<br>
Also, which PyTorch version are you using?</p>

username: flawnson
cooked: <p>I’m using version 1.0.1<br>
Here are two examples I’m working with. Earlier I tried loading vgg16 model, but it returned the same error.</p>
<p><a href="https://drive.google.com/file/d/1LGBELLn4bmwWwNMzIz5jXf75ZdFwXXFM/view?usp=sharing" class="onebox" target="_blank" rel="nofollow noopener">https://drive.google.com/file/d/1LGBELLn4bmwWwNMzIz5jXf75ZdFwXXFM/view?usp=sharing</a><br>
<a href="https://drive.google.com/file/d/1_w6TIVvSwHRwXS6-JxFYXIK6ENlcxRWQ/view?usp=sharing" class="onebox" target="_blank" rel="nofollow noopener">https://drive.google.com/file/d/1_w6TIVvSwHRwXS6-JxFYXIK6ENlcxRWQ/view?usp=sharing</a></p>

username: ptrblck
cooked: <p>Thanks for the files!<br>
Both throw an error:</p>
<blockquote>
<p>ModuleNotFoundError: No module named ‘torch_geometric’</p>
</blockquote>
<p>I’ll try to install the missing lib and try it again.</p>
<p>EDIT: After installing the missing lib, I could load the files:</p>
<pre data-code-wrap="python"><code class="lang-python">&gt;&gt;&gt; a = torch.load('data_0.pt')
&gt;&gt;&gt; a
Data(edge_attr=Unsupported attribute type., edge_index=Unsupported attribute type., x=Unsupported attribute type., y=Unsupported attribute type.)
&gt;&gt;&gt; b = torch.load('data_99.pth')
&gt;&gt;&gt; b
Data(edge_attr=Unsupported attribute type., edge_index=Unsupported attribute type., x=Unsupported attribute type., y=Unsupported attribute type.)
</code></pre>
<p>Could you re-download the files and try it again or did you just upload your local files?</p>

username: Culpritgene
cooked: <p>The same error with torch.load occurred to me after I mistakenly set the size of unused embedding layer to 0. This network consumed a day of computational time. Could there be a way to bypass the error and load it (maybe ignoring empty layer)?</p>

username: dejanbatanjac
cooked: <p>I got similar error and found out <code>torch.cuda.set_device(0)</code> fixed it:</p>
<pre><code class="lang-auto">import torch
torch.cuda.set_device(0)  # adding this line fixed it
model = torch.load('mod.pth')
</code></pre>
<p>Also it worked on CPU every time:</p>
<pre><code class="lang-auto">m = torch.load('mod.pth', map_location=torch.device('cpu'))
</code></pre>

username: Dtouch
cooked: <p>The same error with torch.load occurred to me.  Many methods were tried but all failed.  Finally, I downloaded the weight file &lt;xxx.pth&gt; again and succeeded…</p>