Cannot load tensor saved by torch.save() -- PytorchStreamReader failed reading zip archive: not a ZIP archive

username: aRibra
cooked: <p>Hi-</p>
<p>I cannot load a tensor saved with pytorch <code>torch.save()</code> in cpp. I am getting the following error:</p>
<pre><code class="lang-auto">terminate called after throwing an instance of 'c10::Error'
  what():  [enforce fail at inline_container.cc:145] . PytorchStreamReader failed reading zip archive: not a ZIP archive
frame #0: c10::ThrowEnforceNotMet(char const*, int, char const*, std::string const&amp;, void const*) + 0x47 (0x7f39e02e76a7 in /opt/project_cpp/test/include/libtorch/lib/libc10.so)
frame #1: caffe2::serialize::PyTorchStreamReader::valid(char const*, char const*) + 0x8b (0x7f39be4f272b in /opt/project_cpp/test/include/libtorch/lib/libtorch_cpu.so)
frame #2: caffe2::serialize::PyTorchStreamReader::init() + 0x9e (0x7f39be4f4a9e in /opt/project_cpp/test/include/libtorch/lib/libtorch_cpu.so)
frame #3: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::unique_ptr&lt;caffe2::serialize::ReadAdapterInterface, std::default_delete&lt;caffe2::serialize::ReadAdapterInterface&gt; &gt;) + 0x57 (0x7f39be4f7527 in /opt/project_cpp/test/include/libtorch/lib/libtorch_cpu.so)
frame #4: torch::jit::pickle_load(std::vector&lt;char, std::allocator&lt;char&gt; &gt; const&amp;) + 0xa3 (0x7f39bf7c07d3 in /opt/project_cpp/test/include/libtorch/lib/libtorch_cpu.so)
frame #5: torch::pickle_load(std::vector&lt;char, std::allocator&lt;char&gt; &gt; const&amp;) + 0x9 (0x7f39bfa27df9 in /opt/project_cpp/test/include/libtorch/lib/libtorch_cpu.so)
frame #6: &lt;unknown function&gt; + 0x6e10 (0x560f66cbce10 in ./trt_sample)
frame #7: &lt;unknown function&gt; + 0x8019 (0x560f66cbe019 in ./trt_sample)
frame #8: __libc_start_main + 0xe7 (0x7f397ea80b97 in /lib/x86_64-linux-gnu/libc.so.6)
frame #9: &lt;unknown function&gt; + 0x64da (0x560f66cbc4da in ./trt_sample)
</code></pre>
<p>I reinstalled LibTorch with cuda (Pre-cxx11 ABI &amp; cxx11 ABI) but still not working.<br>
I can use the torch library normally, but cannot load models/tensors/dicts saved with <code>torch.save()</code>.</p>
<p>Code to load <code>.pt</code> file:</p>
<pre><code class="lang-auto">torch::IValue loadPytorchTensor(string fname) {
  std::ifstream input_stream(fname);
  input_stream &gt;&gt; std::noskipws;
  std::vector&lt;char&gt; input;
  input.insert(
      input.begin(),
      std::istream_iterator&lt;char&gt;(input_stream),
      std::istream_iterator&lt;char&gt;());
  cout &lt;&lt; "Before -----"  &lt;&lt; endl; //Prints as expected
  torch::IValue ivalue = torch::pickle_load(input);
  cout &lt;&lt; "After  -----" &lt;&lt; endl; // Currently this never prints 

  return ivalue;
}

  string tensor_fn =  "input.pt";
  torch::IValue ivalue = loadPytorchTensor(tensor_fn);
</code></pre>

username: aRibra
cooked: <p><strong>Update</strong></p>
<p>The rig I am getting the error on has GeForce RTX 2060.<br>
I ran the same code and tried to load the same file on a pc having a GeForce RTX 2080 Ti and it worked properly.</p>

username: aRibra
cooked: <p>Issue was resolved. The path to the file was incorrect! This dir location confusion was because of working in the docker env. Mounting the correct folder solved the problem.</p>
<p>The error message <code>not a ZIP archive</code> is misleading though. It is better to add a more comprehensive and specified message like <code>File not found</code> or <code>wrong path</code>.</p>
<p>Thanks.</p>