[libtorch] passing a tuple of two tensors to forward

Taewoo_Lee: <p>Hi, I’ve traced my model as in <a href="https://github.com/pytorch/pytorch/issues/16453" rel="noopener nofollow ugc">TorchScript trace to support named tuple or dictionary i/o · Issue #16453 · pytorch/pytorch · GitHub</a></p>
<p>My question is how can I pass two tensors to forward()?</p>
<p>This is my code.</p>
<pre><code class="lang-auto">at::Tensor a = torch:tensor({1, 2,3});
at::Tensor b = torch:tensor({4});
auto inputList = c10::List&lt;torch::Tensor&gt;({a, b});
std::vector&lt;torch::jit::IValue&gt; inputs;
inputs.push_back(inputList);
auto out = moModel.forward(inputs).toTensor();
</code></pre>
<p>It gives this error.</p>
<pre><code class="lang-auto">terminate called after throwing an instance of 'c10::Error'
  what():  forward() Expected a value of type 'Tensor' for argument 'audio_signal' but instead found type 'List[Tensor]'.
Position: 1
Declaration: forward(__torch__.nemo.collections.asr.modules.conformer_encoder.ConformerEncoder self, Tensor audio_signal, Tensor length) -&gt; ((Tensor, Tensor))
Exception raised from checkArg at ../aten/src/ATen/core/function_schema_inl.h:162 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;) + 0x6b (0x7fec240b670b in /opt/libtorch/lib/libc10.so)
frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) + 0xce (0x7fec240b23ee in /opt/libtorch/lib/libc10.so)
frame #2: &lt;unknown function&gt; + 0xf39a22 (0x7feb7c73ca22 in /opt/libtorch/lib/libtorch_cpu.so)
frame #3: &lt;unknown function&gt; + 0xf3d0ec (0x7feb7c7400ec in /opt/libtorch/lib/libtorch_cpu.so)
frame #4: torch::jit::GraphFunction::operator()(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, c10::IValue&gt; &gt; &gt; const&amp;) + 0x2d (0x7feb7f04d7cd in /opt/libtorch/lib/libtorch_cpu.so)
frame #5: torch::jit::Method::operator()(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, c10::IValue&gt; &gt; &gt; const&amp;) + 0x161 (0x7feb7f05b351 in /opt/libtorch/lib/libtorch_cpu.so)
frame #6: &lt;unknown function&gt; + 0x13f9f (0x55e6e44d0f9f in ./demo_conformer)
frame #7: &lt;unknown function&gt; + 0xfbfb (0x55e6e44ccbfb in ./demo_conformer)
frame #8: &lt;unknown function&gt; + 0x70f9 (0x55e6e44c40f9 in ./demo_conformer)
frame #9: __libc_start_main + 0xf3 (0x7feb2eef20b3 in /usr/lib/x86_64-linux-gnu/libc.so.6)
frame #10: &lt;unknown function&gt; + 0x6aee (0x55e6e44c3aee in ./demo_conformer)
</code></pre>
<p>Thanks in advance.</p>

Xavier31: <pre><code class="lang-auto">at::Tensor a = torch:tensor({1, 2,3});
at::Tensor b = torch:tensor({4});
std::vector&lt;torch::jit::IValue&gt; inputs;
inputs.push_back(a);
inputs.push_back(b);
auto out = moModel.forward(inputs).toTensor();
</code></pre>
<p>This should work if you just want to pass two tensors to forward(). The issue you are mentioning is specific for named tensors/tuples</p>