Compatiability about using Libtorch to load pytorch model

username: Tumb1eweed
cooked: <p>Is there any forward-compatibility or backward-compatibility in pytorch-libtorch？<br>
When I use pytorch 1.11.0 (I print <strong>torch.version</strong> is 1.10.2) to build a model, and use libtorch 1.11.0 to load. (use torch::jit::save and use torch::jit::load), and It causes problem:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/a/1a3b2c6b41f5a2c68f16a79c0ba6d5ac1ac982d2.png" data-download-href="https://discuss.pytorch.org/uploads/default/1a3b2c6b41f5a2c68f16a79c0ba6d5ac1ac982d2" title="lALPJvuSz0Jz0c7Mjc0GFg_1558_141"><img src="https://discuss.pytorch.org/uploads/default/original/3X/1/a/1a3b2c6b41f5a2c68f16a79c0ba6d5ac1ac982d2.png" alt="lALPJvuSz0Jz0c7Mjc0GFg_1558_141" data-base62-sha1="3K3bXuqClsrQPUsLz0BbwedFbCG" width="690" height="62" data-dominant-color="2D2D2D"><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">lALPJvuSz0Jz0c7Mjc0GFg_1558_141</span><span class="informations">1558×141 9.79 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>

username: tom
cooked: <p>I think the problem here is specifically that your model wants GPU but you are running it on what looks like a CPU only version of libtorch.<br>
Typically forward compatibility is reasonable these days, but it is always good to do your own testing.<br>
(What is terrible is PyTorch ABI compatibility, but that is a different story.)</p>
<p>Best regards</p>
<p>Thomas</p>

username: Tumb1eweed
cooked: <p>Thanks for your reply！<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/8/2/824e2ee790775f02c33933667908b02bb9420d68.png" alt="image" data-base62-sha1="iAJzPAtqY3BQ3ZpMhDt10UJ811m" width="532" height="160"><br>
But I check my machine, it did running on GPU machine, and my libtorch verison is cxx11 with CUDA (<a href="https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.11.0%2Bcu113.zip" rel="noopener nofollow ugc">https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.11.0%2Bcu113.zip</a>)</p>

username: Tumb1eweed
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/6/56c8fc7daf19c5f261cea0bfc40444d21f80dd3c.png" data-download-href="https://discuss.pytorch.org/uploads/default/56c8fc7daf19c5f261cea0bfc40444d21f80dd3c" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/6/56c8fc7daf19c5f261cea0bfc40444d21f80dd3c_2_690x309.png" alt="image" data-base62-sha1="cnJFLkV8dMeqqVlCSkO1HKWteby" width="690" height="309" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/6/56c8fc7daf19c5f261cea0bfc40444d21f80dd3c_2_690x309.png, https://discuss.pytorch.org/uploads/default/original/3X/5/6/56c8fc7daf19c5f261cea0bfc40444d21f80dd3c.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/6/56c8fc7daf19c5f261cea0bfc40444d21f80dd3c.png 2x" data-dominant-color="F6E4E1"><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">image</span><span class="informations">902×405 29.2 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>

username: tom
cooked: <p>I cannot comment on your exact setup, but note that CUDA is suspiciously absent from the list of backends in the error message, so something is up with that.</p>
<p>Best regards</p>
<p>Thomas</p>

username: Tumb1eweed
cooked: <p>I find another curious thing.<br>
I use Pytorch to testify torch.cuda.is_available, it returns true;<br>
And I use libtorch - torch.cuda.is_available, it returns false, how can it happen?</p>
<pre><code class="lang-auto">import torch
print(torch.cuda.is_available())
</code></pre>
<pre><code class="lang-auto">#include &lt;torch/cuda.h&gt;
#include &lt;iostream&gt;

int main(void) {
  std::cout &lt;&lt; "CUDA DEVICE COUNT: " &lt;&lt; torch::cuda::device_count() &lt;&lt; std::endl;
  if (torch::cuda::is_available()) {
    std::cout &lt;&lt; "CUDA is available! Training on GPU." &lt;&lt; std::endl;
  }
  return 0;
}
</code></pre>

username: Tumb1eweed
cooked: <p>OK, I finally know what is happening!<br>
I use cuda 11.1 and libtorch 1.10.2+cuda 11.3, BUT！CUDA is backward compatiable, so maybe some abi incompatibility cause this situation.</p>