INTERNAL ASSERT FAILED at "../aten/src/ATen/core/jit_type_base.h":172

username: Xonobo_Xonobo
cooked: <p>Here is the code snippet to make inference on torch script model.</p>
<pre><code class="lang-auto">	// Prepare inputs
	std::vector&lt;torch::jit::IValue&gt; input_tensor_list;
	for (int n=0; n&lt;input_list.size(); ++n)	{
		auto blob = mCPU ? input_list[n]-&gt;mutable_cpu_data() : input_list[n]-&gt;mutable_gpu_data();
		vector&lt;long&gt; long_shape(begin(input_list[n]-&gt;shape), end(input_list[n]-&gt;shape));
		at::IntArrayRef shape(long_shape.data(), long_shape.size());
		auto options = torch::TensorOptions().dtype(torch::kFloat32);
		input_tensor_list.emplace_back(torch::from_blob(blob, shape, options));
		// Debug
		cout &lt;&lt; input_tensor_list[n].toTensor() &lt;&lt; "\n";
	}

	// Make inference
//	try	{
		auto output = module-&gt;forward(input_tensor_list); //.toTensorVector();
</code></pre>
<p>I can print out the input tensor but get assertion fail. I am new to torch c++ api.</p>
<p>Is there any way to check whether the module is properly loaded or print it on screen like python?<br>
Any idea to point out the error is very welcome.</p>
<p>-0.1138 -0.1138 -0.0441 -0.0964 -0.1138 -0.0267  0.0431  0.1476<br>
0.2871  0.1825  0.1128  0.1302  0.2522  0.3393  0.3219  0.2696<br>
0.3742  0.2871  0.1651  0.1651  0.2348  0.2173  0.3045  0.2522<br>
0.3916  0.3045  0.2696  0.2348  0.2696  0.3045  0.2522  0.2348<br>
0.3568  0.2348  0.2173  0.1999  0.1302  0.1651  0.1128  0.1999<br>
0.5485  0.5311  0.4788  0.4091  0.2522  0.1128  0.0953  0.0605<br>
[ CPUFloatType{1,3,224,224} ]<br>
terminate called after throwing an instance of ‘c10::Error’<br>
what():  r INTERNAL ASSERT FAILED at “…/aten/src/ATen/core/jit_type_base.h”:172, please report a bug to PyTorch.<br>
Exception raised from expect at …/aten/src/ATen/core/jit_type_base.h:172 (most recent call first):<br>
frame <span class="hashtag">#0:</span> c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt;) + 0x69 (0x7fcba2b5ab29 in /opt/libtorch/lib/libc10.so)<br>
frame <span class="hashtag">#1:</span> std::shared_ptr<a>c10::ClassType</a> c10::Type::expect<a>c10::ClassType</a>() + 0xbd (0x7fcc3d8c3ead in /opt/libtorch/lib/libtorch_cpu.so)<br>
frame <span class="hashtag">#2:</span> c10::ivalue::Object::type() const + 0x21 (0x7fcc3d8b6341 in /opt/libtorch/lib/libtorch_cpu.so)<br>
frame <span class="hashtag">#3:</span> torch::jit::Object::find_method(std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; const&amp;) const + 0x4e (0x7fcc3ff1ceae in /opt/libtorch/lib/libtorch_cpu.so)<br>
frame <span class="hashtag">#4:</span> torch::jit::Object::get_method(std::__cxx11::basic_string&lt;char, std::char_traits, std::allocator &gt; const&amp;) const + 0x50 (0x7fccb45bc9c6 in /home/bozkalayci/workspace/ws_Puhu/xDNN/Debug/libxDNN_d.so)<br>
frame <span class="hashtag">#5:</span> torch::jit::Module::forward(std::vector&lt;c10::IValue, std::allocator<a>c10::IValue</a> &gt;) + 0x77 (0x7fccb45bcdf1 in /home/bozkalayci/workspace/ws_Puhu/xDNN/Debug/libxDNN_d.so)</p>

username: ptrblck
cooked: <p>Could you create an issue in <a href="https://github.com/pytorch/pytorch/issues">GitHub</a> as this seems to be an internal error, please?<br>
An executable code snippet to reproduce this issue would be great <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: Xonobo_Xonobo
cooked: <p>I found a work around but the problem I guess is in loading the module.</p>
<p>I got the above error when loaded the module to a pointer like this in an init function of a class instance.</p>
<pre><code class="lang-auto">auto *module = new torch::jit::script::Module;
*module = torch::jit::load(fileName);
</code></pre>
<p><code>module</code> is cast to void pointer and kept as a member variable of the class. I got the error in a class’ method call. I recast the void pointer to <code>torch::jit::script::Module</code> but some arrays are violated in this way I guess.</p>
<p>The work around is to use the conventional way</p>
<p><code>module = torch::jit::load(fileName);</code></p>
<p>What is your suggestion to keep a valid module pointer in a class member?</p>