310 questions
-1
votes
1
answer
102
views
Returning a torch::Tensor causes seg fault in Python when returning from a C++ binding with pybind11
I have data from a device that is being captured in Python as arrays and then sent to a C++ binding to speed up some post processing that must happen to format the data properly and convert into a ...
0
votes
1
answer
69
views
Linking matplot++ and Libtorch together in a program causes memory corruption problem
I made a minimal example that crashes. For the crash it is required that the torch libraries are linked. I made sure that GLIBCXX_USE_CXX11_ABI=0 for all 3 components. Setup is Ubuntu, g++, C++17.
Any ...
0
votes
0
answers
96
views
cmake libtorch include issue. only <torch/XXX.h> can be found by cmake
My C++ code is like this
#include <torch/torch.h>
#include <torch/script.h>
#include <torch/autograd/profiler.h>
and my CMakeLists.txt is writen like this
...
0
votes
1
answer
25k
views
CUDA error: no kernel image is available for execution on the device
Im using the latest LibTorch with CUDA 12.6 installed on Windows 10
Libtorch is showing CUDA is available, however, I get this error when I try to use
device = torch::Device(torch::kCUDA, 0);
...
3
votes
0
answers
121
views
How can I view the value of a LibTorch tensor in Visual Studio debugger
In the image below I am running the same PPO minimalist project. On the right side is the original code in python with PyTorch in VSCode. On the left side is the converted code in C++ with LibTorch in ...
3
votes
0
answers
81
views
Efficiency of torch matrix operations on CPU
I am currently working on optimizing PyTorch code running on CPU. On CUDA, you can write fused multiple operators into specialized kernels to reduce memory transfers, avoid intermediate data ...
1
vote
0
answers
129
views
Error loading model using Torch TensorRT in Libtorch on Windows
Environment
Libtorch 2.5.0.dev (latest nightly) (built with CUDA 12.4)
CUDA 12.4
TensorRT 10.1.0.27
PyTorch 2.4.0+cu124
Torch-TensorRT 2.4.0
Python 3.12.8
Windows 10
Compile Torch-TensorRT with ...
1
vote
0
answers
127
views
Is torch::jit::trace not available in libtorch?
I am using libtorch in c++.
In python, torch.jit.trace function exists and works fine.
However, torch::jit::trace does not work in libtorch.
It said there is no "trace" member in namespace ...
-2
votes
1
answer
163
views
Linking error when building libtorch on MacOS
I am going along the pytorch api tutorial and I get the following error
ld: unknown options: --no-as-needed --as-needed --no-as-needed --as-needed
c++: error: linker command failed with exit code 1 (...
1
vote
0
answers
46
views
Segmentation fault when trying to copy memory from Gst buffer to torch tensor using torch::from_blob::clone()
I'm getting a segmentation fault when I'm trying to copy memory from gst buffer to torch tensor. Here is code. I'll mark where the segfault originates from:
static GstPadProbeReturn on_probe(
...
1
vote
0
answers
116
views
Calculate accuracy in libtorch (C++) when using Softmax
The below code is able to learn the generic pattern and it is able to predict as expected:
torch::manual_seed(42);
torch::nn::Sequential net(
torch::nn::Linear(300, 301),
torch::nn::...
2
votes
1
answer
207
views
Can a PyTorch Model Built in Debug Mode Be Used in Release Mode? TorchScript Model Load Error in Release Mode but Works in Debug Mode
I'm encountering an issue when trying to load a TorchScript model in my C++ application using LibTorch. The model loads and works fine in debug mode, but I get an exception when switching to release ...
1
vote
1
answer
829
views
How to avoid find_package_handle_standard_args package name warning
In LibTorch 2.0.1 I was able to use the library without installing it (download library and set CMAKE_PREFIX_PATH to allow CMake to find the library). Using LibTorch 2.5.1 and CUDA 12.6 I have to ...
1
vote
0
answers
774
views
Building PyTorch 2.5.1 (libtorch + main PyTorch) with CUDA 12.6.3 and cuDNN 9.5.1
My goal is to build PyTorch from source for use in image generation AI workflows (e.g., ComfyUI).
I would like to request guidance on the correct method to build PyTorch 2.5.1 (both libtorch and the ...
1
vote
0
answers
192
views
std::bad_alloc when loading PyTorch model in C++ using LibTorch
I'm trying to load a traced PyTorch model in C++ using LibTorch but encountering a std::bad_alloc error. I've set up a minimal example to demonstrate the issue.
The Problem:
When running my C++ ...