How can i get access to first and second Tensor from Tuple, returned from forward() method in Libtorch C\C++

AlexT: <p>Hello Team, it is my code.<br>
I’m using Jit generated model with Libtorch in C\C++ in Ubuntu 18.04, with CUDA 10.2</p>
<p>I get correct result form my first call     <em>result  = mE.forward(x);</em></p>
<pre><code class="lang-auto">    torch::Tensor tensor_image = ...
    torch::IValue result;   // it is standard return of forward() in JIT traced model

    std::vector&lt;torch::jit::IValue&gt; x;
    x.push_back(tensor_image);
    result  = mE.forward(x);
    std::cout &lt;&lt; sp_and_gl_output_CUDA &lt;&lt; std::endl;
    std::vector&lt;torch::IValue&gt; in_to_G;
    in_to_G.push_back(result);
    img_tensor = mG.forward(in_to_G);
</code></pre>
<p>On the image print of result  variable, returned by forward() method.</p>
<p><code>  std::cout &lt;&lt; sp_and_gl_output_CUDA &lt;&lt; std::endl;</code></p>
<p>The result contained, two Tensors, but i can’t to pass it in next forward(), in right form.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/c/2cde7dbe2326a5b1a5d9149999f4cc515e710b59.png" data-download-href="https://discuss.pytorch.org/uploads/default/2cde7dbe2326a5b1a5d9149999f4cc515e710b59" title="изображение"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/c/2cde7dbe2326a5b1a5d9149999f4cc515e710b59_2_690x461.png" alt="изображение" data-base62-sha1="6oVH1ceg2wvyZukKNJZgR4tTM7f" width="690" height="461" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/c/2cde7dbe2326a5b1a5d9149999f4cc515e710b59_2_690x461.png, https://discuss.pytorch.org/uploads/default/optimized/3X/2/c/2cde7dbe2326a5b1a5d9149999f4cc515e710b59_2_1035x691.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/2/c/2cde7dbe2326a5b1a5d9149999f4cc515e710b59_2_1380x922.png 2x" data-dominant-color="575757"><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">изображение</span><span class="informations">1757×1174 164 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>The result of execution:</p>
<pre><code class="lang-auto">mG.forward load spatial and global:

forward() Expected a value of type 'Tensor' for argument 'v' but instead found type 'Tuple[Tensor, Tensor]'.
Position: 1
Declaration: forward(__torch__.models.networks.generator.StyleGAN2ResnetGenerator self, Tensor v, Tensor v0) -&gt; (Tensor)
Exception raised from checkArg at ../aten/src/ATen/core/function_schema_inl.h:184 (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 (0x7f1c5d0290db in /home/interceptor/Документы/Git_Medium_repo/Binary_search_engine_CUDA/torch_to_cpp/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 (0x7f1c5d024d2e in /home/interceptor/Документы/Git_Medium_repo/Binary_search_engine_CUDA/torch_to_cpp/libtorch/lib/libc10.so)
frame #2: &lt;unknown function&gt; + 0x128d542 (0x7f1c473af542 in /home/interceptor/Документы/Git_Medium_repo/Binary_search_engine_CUDA/torch_to_cpp/libtorch/lib/libtorch_cpu.so)
frame #3: &lt;unknown function&gt; + 0x12918c1 (0x7f1c473b38c1 in /home/interceptor/Документы/Git_Medium_repo/Binary_search_engine_CUDA/torch_to_cpp/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 (0x7f1c49c97b2d in /home/interceptor/Документы/Git_Medium_repo/Binary_search_engine_CUDA/torch_to_cpp/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;) const + 0x175 (0x7f1c49ca7235 in /home/interceptor/Документы/Git_Medium_repo/Binary_search_engine_CUDA/torch_to_cpp/libtorch/lib/libtorch_cpu.so)
frame #6: &lt;unknown function&gt; + 0x6266 (0x564143038266 in ./particle_cuda_test)
frame #7: &lt;unknown function&gt; + 0x47af (0x5641430367af in ./particle_cuda_test)
frame #8: __libc_start_main + 0xe7 (0x7f1bf9682bf7 in /lib/x86_64-linux-gnu/libc.so.6)
frame #9: &lt;unknown function&gt; + 0x4daa (0x564143036daa in ./particle_cuda_test)

Main module:  torch_and_cuda_call.cpp  completed. 
ok!
</code></pre>

AlexT: <p>This <strong>placeholder</strong> for second call:</p>
<pre><code class="lang-auto">   in_to_G.push_back(torch::ones({1, 8,8,8}).to(at::kCUDA));
   in_to_G.push_back(torch::ones({1, 2048}).to(at::kCUDA));
   img_tensor = mG.forward(in_to_G);
</code></pre>
<p><strong>worked!</strong><br>
How can i get two Tensors  for create new input vector from it?<br>
<strong>i need to parse this result, to get Tensor in it:</strong><br>
<code>torch::IValue result;</code></p>
<p>There are somethink like this issues on the stack and github:</p>
<ol>
<li><a href="https://stackoverflow.com/questions/68796689/how-to-get-values-return-by-tuple-object-in-maskcrnn-libtorch" class="inline-onebox" rel="noopener nofollow ugc">c++ - How to get values return by Tuple Object in Maskcrnn libtorch - Stack Overflow</a></li>
<li><a href="https://github.com/pytorch/pytorch/issues/48691" class="inline-onebox" rel="noopener nofollow ugc">C++ Convert c10::IValue to tensor or tuple or to TensorList failed · Issue #48691 · pytorch/pytorch · GitHub</a></li>
</ol>

AlexT: <p>Seems it WORKED</p>
<pre><code class="lang-auto">    auto output1_sp = sp_and_gl_output_CUDA.toTuple()-&gt;elements()[0].toTensor();
    auto output2_gl = sp_and_gl_output_CUDA.toTuple()-&gt;elements()[1].toTensor();
    //-------------------------------------------------------------------------------------------------------------------
    in_to_G.push_back(output1_sp.to(at::kCUDA));
    in_to_G.push_back(output2_gl.to(at::kCUDA));
    //-------------------------------------------------------------------------------------------------------------------
    img_tensor = mG.forward(in_to_G);

</code></pre>