<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>
<p dir="auto"><code class="notranslate">torch.hub.load_state_dict_from_url</code> does not work with the new zip serialization with <code class="notranslate">torch.load</code>/<code class="notranslate">torch.save</code>. Loading from an url report the error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="RuntimeError: Only one file(not dir) is allowed in the zipfile"><pre class="notranslate"><code class="notranslate">RuntimeError: Only one file(not dir) is allowed in the zipfile
</code></pre></div>
<p dir="auto">I think it is due to the fact that before this serialization change, the weigths could be compressed into a zip file (minimizing download time). Now, we serialize everything as a zip bundle, an this is the reason it fails.</p>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">Steps to reproduce the behavior:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; from torch.hub import load_state_dict_from_url
&gt;&gt;&gt; load_state_dict_from_url('https://files.deeplar.tk/ark-weights/drn_d_38-imagenet-39a7863b82.pt') # for example
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-4-c0cdf3d7c81f&gt; in &lt;module&gt;
----&gt; 1 load_state_dict_from_url('https://files.deeplar.tk/ark-weights/drn_d_38-imagenet-39a7863b82.pt')

~/miniconda3/envs/torch/lib/python3.8/site-packages/torch/hub.py in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash, file_name)
    488             members = cached_zipfile.infolist()
    489             if len(members) != 1:
--&gt; 490                 raise RuntimeError('Only one file(not dir) is allowed in the zipfile')
    491             cached_zipfile.extractall(model_dir)
    492             extraced_name = members[0].filename

RuntimeError: Only one file(not dir) is allowed in the zipfile"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">from</span> <span class="pl-s1">torch</span>.<span class="pl-s1">hub</span> <span class="pl-k">import</span> <span class="pl-s1">load_state_dict_from_url</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-en">load_state_dict_from_url</span>(<span class="pl-s">'https://files.deeplar.tk/ark-weights/drn_d_38-imagenet-39a7863b82.pt'</span>) <span class="pl-c"># for example</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">RuntimeError</span>                              <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">&lt;</span><span class="pl-s1">ipython</span><span class="pl-c1">-</span><span class="pl-s1">input</span><span class="pl-c1">-</span><span class="pl-c1">4</span><span class="pl-c1">-</span><span class="pl-s1">c0cdf3d7c81f</span><span class="pl-c1">&gt;</span> <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-en">load_state_dict_from_url</span>(<span class="pl-s">'https://files.deeplar.tk/ark-weights/drn_d_38-imagenet-39a7863b82.pt'</span>)

<span class="pl-c1">~</span><span class="pl-c1">/</span><span class="pl-s1">miniconda3</span><span class="pl-c1">/</span><span class="pl-s1">envs</span><span class="pl-c1">/</span><span class="pl-s1">torch</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">8</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">torch</span><span class="pl-c1">/</span><span class="pl-s1">hub</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">load_state_dict_from_url</span>(<span class="pl-s1">url</span>, <span class="pl-s1">model_dir</span>, <span class="pl-s1">map_location</span>, <span class="pl-s1">progress</span>, <span class="pl-s1">check_hash</span>, <span class="pl-s1">file_name</span>)
    <span class="pl-c1">488</span>             <span class="pl-s1">members</span> <span class="pl-c1">=</span> <span class="pl-s1">cached_zipfile</span>.<span class="pl-en">infolist</span>()
    <span class="pl-c1">489</span>             <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-s1">members</span>) <span class="pl-c1">!=</span> <span class="pl-c1">1</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">490</span>                 <span class="pl-s1">raise</span> <span class="pl-v">RuntimeError</span>(<span class="pl-s">'Only one file(not dir) is allowed in the zipfile'</span>)
    <span class="pl-c1">491</span>             <span class="pl-s1">cached_zipfile</span>.<span class="pl-en">extractall</span>(<span class="pl-s1">model_dir</span>)
    <span class="pl-c1">492</span>             <span class="pl-s1">extraced_name</span> <span class="pl-c1">=</span> <span class="pl-s1">members</span>[<span class="pl-c1">0</span>].<span class="pl-s1">filename</span>

<span class="pl-v">RuntimeError</span>: <span class="pl-v">Only</span> <span class="pl-s1">one</span> <span class="pl-en">file</span>(<span class="pl-c1">not</span> <span class="pl-s1">dir</span>) <span class="pl-c1">is</span> <span class="pl-s1">allowed</span> <span class="pl-c1">in</span> <span class="pl-s1">the</span> <span class="pl-s1">zipfile</span></pre></div>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto"><code class="notranslate">load_state_dict_from_url</code> should load the files appropriately.</p>
<h2 dir="auto">Environment</h2>
<ul dir="auto">
<li>PyTorch Version (e.g., 1.7):</li>
<li>OS (e.g., Linux): OpenSuse Leap</li>
<li>How you installed PyTorch (<code class="notranslate">conda</code>, <code class="notranslate">pip</code>, source): conda</li>
<li>Python version: 3.8</li>
<li>CUDA/cuDNN version: 10.2</li>
</ul>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gchanan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gchanan">@gchanan</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ailzhang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ailzhang">@ailzhang</a></p>
<p dir="auto">The new theme of docs and tutorials is very confusing and makes it extreme difficult to read on a PC monitor. At very least please allow users to switch theme as they mat prefer.</p>