During deserialization, torch::load fails at debug while it works fine in release mode (Unhandled exception at 0x00007FFF7DE1A308 in Test.exe: Microsoft C++ exception: c10::Error at memory location 0x000000CDEE5BD950. occurred)

Shisho_Sama: <p>Hello everyone.<br>
I faced something weird today. the release build works just fine, but whenever I switch to the debug build, the deserialization fails with the following error :</p>
<pre><code class="lang-auto">Unhandled exception at 0x00007FFF7DE1A308 in Test.exe: Microsoft C++ exception: c10::Error at memory location 0x000000CDEE5BD950. occurred
</code></pre>
<p>The exception is raised in this function :</p>
<pre data-code-wrap="cpp"><code class="lang-cpp">torch::Tensor deserialize_tensor(std::string input)
{
    torch::Tensor tensor;
    std::stringstream stream(input);
    torch::load(tensor, stream);
    return tensor;
}
</code></pre>
<p>and ultimately it fails inside the <code>torch::load()</code> inside <code>tensor.h</code>:</p>
<pre data-code-wrap="cpp"><code class="lang-cpp">#pragma once

#include &lt;torch/serialize/archive.h&gt;
#include &lt;torch/types.h&gt;

namespace torch {
inline serialize::OutputArchive&amp; operator&lt;&lt;(
    serialize::OutputArchive&amp; archive,
    const Tensor&amp; tensor) {
  archive.write("0", tensor);
  return archive;
}

inline serialize::InputArchive&amp; operator&gt;&gt;(
    serialize::InputArchive&amp; archive,
    Tensor&amp; tensor) {
  archive.read("0", tensor); // it crashes here!
  return archive;
}
} // namespace torch

</code></pre>
<p>here is the snapshot showing where exactly it failed :<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/e/ae53f80aa7594c51bd28c3d8589d9cc945e42b69.png" data-download-href="https://discuss.pytorch.org/uploads/default/ae53f80aa7594c51bd28c3d8589d9cc945e42b69" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/e/ae53f80aa7594c51bd28c3d8589d9cc945e42b69_2_690x316.png" alt="image" data-base62-sha1="oSaYUr3bWqI7ptkLE0DlGJI7a1r" width="690" height="316" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/e/ae53f80aa7594c51bd28c3d8589d9cc945e42b69_2_690x316.png, https://discuss.pytorch.org/uploads/default/optimized/3X/a/e/ae53f80aa7594c51bd28c3d8589d9cc945e42b69_2_1035x474.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/a/e/ae53f80aa7594c51bd28c3d8589d9cc945e42b69_2_1380x632.png 2x" data-dominant-color="E6E8EF"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1596×731 57.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Whats wrong here?<br>
Any help is greatly apprecaited.<br>
Thanks a lot in advance</p>

Shisho_Sama: <p>The reason was  the debug version of the lib was missing! (again!) moving the needed libs next to  the executable fixed the issue  (the release versions were added to the PATH, so at runtime, it would pick the release version and boom!)</p>