Segment fault when calling torch::jit::Module::forward

SJ_2020: <p>Hello! I was loading a nn.model generated by Gpytorch.</p>
<p>I am using the example here <a href="https://github.com/pytorch/pytorch/issues/url" rel="nofollow noopener">https://github.com/cornellius-gp/gpytorch/blob/master/examples/04_Variational_and_Approximate_GPs/Modifying_the_variational_strategy_and_distribution.ipynb</a> with CPU for training device.<br>
I traced the model with the same code here <a href="https://github.com/pytorch/pytorch/issues/url" rel="nofollow noopener">https://github.com/cornellius-gp/gpytorch/blob/master/examples/08_Advanced_Usage/TorchScript_Variational_Models.ipynb</a>. (CPU only)</p>
<p>The traced model works fine in python.</p>
<p>My c++ front-end implementation is<br>
torch::Device device_ = torch::kCPU<br>
try {<br>
torch_model_ = torch::jit::load(torch_model_file, torch::device_);<br>
} catch (const c10::Error&amp; e) {<br>
return;<br>
}<br>
std::vectortorch::jit::IValue torch_inputs;<br>
torch_inputs.push_back(torch::ones({1024, 18}));<br>
auto torch_output = torch_model_.forward(torch_inputs);<br>
I got a segment fault in the forward func.</p>
<p>Any suggestions? Thanks!</p>

SJ_2020: <p>Here is the gdb trace back results<br>
<em><span class="hashtag">#0</span> 0x00007ffff7445903 in spotrf</em> () from /opt/xxx/sysroot/lib/libqpOASES.so<br>
<span class="hashtag">#1</span> 0x00007fffe76f8615 in void at::native::lapackCholesky(char, int, float*, int, int*) ()<br>
from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#2</span> 0x00007fffe76ff13a in at::native::cholesky_helper_cpu(at::Tensor const&amp;, bool) ()<br>
from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#3</span> 0x00007fffe7cf0605 in at::CPUType::cholesky_helper(at::Tensor const&amp;, bool) ()<br>
from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#4</span> 0x00007fffe7d2d727 in c10::detail::wrap_kernel_functor_unboxed&lt;c10::detail::WrapRuntimeKernelFunctor&lt;at::Tensor ()(at::Tensor const&amp;, bool), at::Tensor, c10::guts::typelist::typelist&lt;at::Tensor const&amp;, bool&gt; &gt;, at::Tensor (at::Tensor const&amp;, bool)&gt;::call(c10::OperatorKernel, at::Tensor const&amp;, bool) () from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#5</span> 0x00007fffe770111a in at::native::cholesky(at::Tensor const&amp;, bool) ()<br>
from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#6</span> 0x00007fffe7dfeb35 in at::TypeDefault::cholesky(at::Tensor const&amp;, bool) ()<br>
from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#7</span> 0x00007fffe7d2d727 in c10::detail::wrap_kernel_functor_unboxed_&lt;c10::detail::WrapRuntimeKernelFunctor_&lt;at::Tensor ()(at::Tensor const&amp;, bool), at::Tensor, c10::guts::typelist::typelist&lt;at::Tensor const&amp;, bool&gt; &gt;, at::Tensor (at::Tensor const&amp;, bool)&gt;::call(c10::OperatorKernel, at::Tensor const&amp;, bool) () from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#8</span> 0x00007fffe97ee200 in torch::autograd::VariableType::cholesky(at::Tensor const&amp;, bool) ()<br>
from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#9</span> 0x00007fffe7d2d727 in c10::detail::wrap_kernel_functor_unboxed_&lt;c10::detail::WrapRuntimeKernelFunctor_&lt;at::Tensor ()(at::Tensor const&amp;, bool), at::Tensor, c10::guts::typelist::typelist&lt;at::Tensor const&amp;, bool&gt; &gt;, at::Tensor (at::Tensor const&amp;, bool)&gt;::call(c10::OperatorKernel, at::Tensor const&amp;, bool) () from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#10</span> 0x00007fffe96c289a in torch::jit::(anonymous namespace)::{lambda(std::vector&lt;c10::IValue, std::allocatorc10::IValue &gt;&amp;)<span class="hashtag">#108</span>}::_FUN () from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#11</span> 0x00007fffe9ac8c7d in torch::jit::InterpreterStateImpl::runImpl(std::vector&lt;c10::IValue, std::allocatorc10::IValue &gt;&amp;) () from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#12</span> 0x00007fffe9abf9d1 in torch::jit::InterpreterState::run(std::vector&lt;c10::IValue, std::allocatorc10::IValue &gt;&amp;) () from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#13</span> 0x00007fffe9a9d341 in torch::jit::GraphExecutorImplBase::run(std::vector&lt;c10::IValue, std::allocatorc10::IValue &gt;&amp;) () from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#14</span> 0x00007fffe9dbac0a in torch::jit::GraphFunction::operator()(std::vector&lt;c10::IValue, std::allocatorc10::IValue &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; const, c10::IValue&gt; &gt; &gt; const&amp;) ()<br>
from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#15</span> 0x00007fffe9d6f514 in torch::jit::Method::operator()(std::vector&lt;c10::IValue, std::allocatorc10::IValue &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; &gt;, std::allocator&lt;std::pair&lt;std::_<em>cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; const, c10::IValue&gt; &gt; &gt; const&amp;) () from /usr/local/libtorch_gpu/lib/libtorch_cpu.so<br>
<span class="hashtag">#16</span> 0x0000555555b2f22d in torch::jit::Module::forward (this=0x5555cb3673a0,<br>
inputs=std::vector of length 0, capacity 0)</em></p>

Loic: <p>Did you solve your problem? I have the same issue as you.</p>