# Slicer 5.9.0 with libtorch

**URL:** <https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319>\
**Category:** Development\
**Tags:** pytorch\
**Created:** [June 11, 2025, 3:59pm UTC](https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319 "2025-06-11T15:59:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haoyin\_Zhou](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/haoyin_zhou/32/3420_2.png) [@Haoyin\_Zhou](https://discourse.slicer.org/u/Haoyin_Zhou)\
**Post date:** [June 11, 2025, 3:59pm UTC](https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319/1 "2025-06-11T15:59:17Z")

</div>

hi, I am developing a c++ module on Slicer 5.9.0. I have a lot of confusion to use libtorch together with Slicer. I can compile the code but when I call a libtorch function, such as torch::jit::load(path), it crashes without given any error message.

In the past I used an older version Slicer (4.13.0) and it works well with libtorch.

Do you have any success experience to use libtorch with Slicer 5.9.0? I have tried many versions of libtorch but none of them works.

Thanks.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [June 11, 2025, 6:13pm UTC](https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319/2 "2025-06-11T18:13:33Z")

</div>

Is this on Linux, and what version of torch? Perhaps you are hitting the ABI issue with torch 2.7?

> <https://github.com/Slicer/Slicer/issues/8468>
>
> Request for PyTorch 2.7 Support in 3D Slicer for NVIDIA Blackwell GPUs
> 
> System I…nformation:
> \- GPU: NVIDIA GeForce RTX 5070 Ti
> \- Architecture: NVIDIA Blackwell
> \- OS: Linux Unbutu 24.04.2 LTS
> 
> PyTorch version 2.7 introduces support for the Blackwell architecture, which is required for compatibility with this GPU. Earlier versions of PyTorch (≤2.6) do not support it, resulting in the following error:
> \- “The current PyTorch install supports CUDA capabilities sm\_50 sm\_60 sm\_70 sm\_75 sm\_80 sm\_86 sm\_90.”
> 
> Unfortunately, the PyTorch version currently available in 3D Slicer is limited to 2.6
> 
> xref https://discourse.slicer.org/t/pytorch-cuda-incompatibility-with-nvidia-rtx-5070-ti/43233

---

<div class="post-metadata">

**Author:** ![Haoyin\_Zhou](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/haoyin_zhou/32/3420_2.png) [@Haoyin\_Zhou](https://discourse.slicer.org/u/Haoyin_Zhou)\
**Post date:** [June 11, 2025, 6:33pm UTC](https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319/3 "2025-06-11T18:33:41Z")

</div>

Thanks for your reply. I am using Ubuntu 20.04 + CUDA 12.8. My CMakeLists.txt sets C++ 17.

I downloaded libtorch from the following link (may need to change number)  
[https://download.pytorch.org/libtorch/cu126/](https://download.pytorch.org/libtorch/cu126/)

I have tried the following libtorch versions:  
libtorch-cxx11-abi-shared-with-deps-2.7.0+cu128  
libtorch-cxx11-abi-shared-with-deps-1.13.0+cu117  
libtorch-cxx11-abi-shared-without-deps-1.13.0+cu117  
[libtorch-win-shared-with-deps-2.6.0%2Bcu126

Is there another version I should give a try? Thanks.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [June 11, 2025, 6:55pm UTC](https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319/4 "2025-06-11T18:55:46Z")

</div>

> [@Haoyin\_Zhou](#):
>
> libtorch-cxx11-abi-shared-with-deps-2.7.0+cu128

I don’t think this works with Slicer, which uses an older glibc then 2.7 and cu128 requires.

> [@Haoyin\_Zhou](#):
>
> [libtorch-win-shared-with-deps-2.6.0%2Bcu126

I think this is for windows, not linux?

For the rest, someone with more C++ knowledge needs to chime in.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 11, 2025, 7:07pm UTC](https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319/5 "2025-06-11T19:07:43Z")

</div>

> [@Haoyin\_Zhou](#):
>
> torch::jit::load(path)

You usually can’t mix and match C++ compiled libraries so it’s not surprising that this crashes. It would be best if you could compile everything from source with the same compiler (i.e. look at compiling libtorch and your other code as a [superbuild extension](https://slicer.readthedocs.io/en/latest/developer_guide/extensions.html)).

But also using Python is the suggested method of accessing torch features. Is there a reason you want to use C++?

---

<div class="post-metadata">

**Author:** ![Haoyin\_Zhou](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/haoyin_zhou/32/3420_2.png) [@Haoyin\_Zhou](https://discourse.slicer.org/u/Haoyin_Zhou)\
**Post date:** [June 13, 2025, 2:21pm UTC](https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319/6 "2025-06-13T14:21:25Z")

</div>

Thank you Steve. Because there are a large amount of algorithms were implemented using C++, it is not possible for me to convert the code to Python.

I tried to compile libtorch from source but there are many version conflicts.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 13, 2025, 2:50pm UTC](https://discourse.slicer.org/t/slicer-5-9-0-with-libtorch/43319/7 "2025-06-13T14:50:01Z")

</div>

You could build a Python wheel that uses the same build environment as PyTorch, which would ensure ABI compatibility. I would recommend this if you want to distribute your solution as a Slicer extension.

For a custom application, it could be enough to build a standalone version of your software that runs in a separate process. Slicer can launch it using its original startup environment, so there would be no conflict with PyTorch or any other binaries. For non-interactive use cases you can simply pass all inputs as files and fetch output from files. For interactive use cases you can communicate with the started process via web requests (for 3D images or non-time-critical applications) or OpenIGTLink (for real-time processing of image streams). There are examples for all these in existing extensions.
