Libtorch error only in Release build

ivankrylatskoe: <p>Hi!<br>
The following program works fine using Debug build. But on Release build it gives the runtime error:</p>
<pre><code class="lang-auto">Unhandled exception thrown: read access violation:
_Right was 0x10.
</code></pre>
<p>I tried to compile the program with different compiler options (using Microsoft Visual C++ compiler). It works with /MDd option (debug run-time library), and fails with /MD option (release run-time library)</p>
<p>What can be the reason for that?<br>
Here is full program code:</p>
<pre><code class="lang-auto">#include &lt;torch/torch.h&gt;

int main() {
    torch::nn::Sequential(torch::nn::Linear(1, 1));
}
</code></pre>
<p>Stacktrace:</p>
<pre><code class="lang-auto">&gt;	MyChessCpp.exe!std::operator==&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;(const std::string &amp; _Left, const std::string &amp; _Right)Line 4378	C++
 	[Embedded frame] MyChessCpp.exe!std::equal_to&lt;std::string&gt;::operator()(const std::string &amp;)Line 91	C++
 	[Embedded frame] MyChessCpp.exe!std::_Uhash_compare&lt;std::string,std::hash&lt;std::string&gt;,std::equal_to&lt;std::string&gt;&gt;::operator()(const std::string &amp;)Line 164	C++
 	[Embedded frame] MyChessCpp.exe!std::_Hash&lt;std::_Umap_traits&lt;std::string,unsigned __int64,std::_Uhash_compare&lt;std::string,std::hash&lt;std::string&gt;,std::equal_to&lt;std::string&gt;&gt;,std::allocator&lt;std::pair&lt;std::string const ,unsigned __int64&gt;&gt;,0&gt;&gt;::_Find_last(const std::string &amp;)Line 1677	C++
 	MyChessCpp.exe!std::_Hash&lt;std::_Umap_traits&lt;std::string,unsigned __int64,std::_Uhash_compare&lt;std::string,std::hash&lt;std::string&gt;,std::equal_to&lt;std::string&gt;&gt;,std::allocator&lt;std::pair&lt;std::string const ,unsigned __int64&gt;&gt;,0&gt;&gt;::count&lt;void&gt;(const std::string &amp; _Keyval)Line 1360	C++
 	MyChessCpp.exe!torch::OrderedDict&lt;std::string,std::shared_ptr&lt;torch::nn::Module&gt;&gt;::insert&lt;std::string,std::shared_ptr&lt;torch::nn::Module&gt;&gt;(std::string &amp;&amp; key, std::shared_ptr&lt;torch::nn::Module&gt; &amp;&amp; value)Line 363	C++
 	MyChessCpp.exe!torch::OrderedDict&lt;std::string,std::shared_ptr&lt;torch::nn::Module&gt;&gt;::insert(std::string key, std::shared_ptr&lt;torch::nn::Module&gt; &amp;&amp; value)Line 373	C++
 	MyChessCpp.exe!torch::nn::Module::register_module&lt;torch::nn::Module&gt;(std::string name, std::shared_ptr&lt;torch::nn::Module&gt; module)Line 649	C++
 	MyChessCpp.exe!torch::nn::SequentialImpl::push_back(std::string name, torch::nn::AnyModule any_module)Line 255	C++
 	[Embedded frame] MyChessCpp.exe!torch::nn::SequentialImpl::push_back(std::string)Line 203	C++
 	MyChessCpp.exe!torch::nn::SequentialImpl::push_back&lt;torch::nn::ReLUImpl&gt;(std::string name, const torch::nn::ModuleHolder&lt;torch::nn::ReLUImpl&gt; &amp; module_holder)Line 236	C++
 	[Embedded frame] MyChessCpp.exe!torch::nn::SequentialImpl::push_back(const torch::nn::ModuleHolder&lt;torch::nn::ReLUImpl&gt; &amp;)Line 229	C++
 	[Embedded frame] MyChessCpp.exe!torch::nn::SequentialImpl::{ctor}(torch::nn::ReLU &amp;&amp;)Line 103	C++
 	[Embedded frame] MyChessCpp.exe!torch::nn::ModuleHolder&lt;torch::nn::SequentialImpl&gt;::{ctor}(torch::nn::ReLU &amp;&amp;)Line 64	C++
 	MyChessCpp.exe!torch::nn::Sequential::Sequential&lt;torch::nn::ReLU,void&gt;(torch::nn::ReLU &amp;&amp; __param0)Line 20	C++
 	MyChessCpp.exe!main()Line 4	C++
 	[External code]	
</code></pre>

glaringlee: <p><a class="mention" href="/u/ivankrylatskoe">@ivankrylatskoe</a><br>
This might related to how you build the libtorch.<br>
Please create an issue at <a href="https://github.com/pytorch/pytorch/issues" rel="nofollow noopener">https://github.com/pytorch/pytorch/issues</a>.<br>
Please provide more info such as what is your operating system, your complier version, your setup, full error logs, etc.<br>
We will have people who is working on build look into this. thx</p>