Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
0 answers
60 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++ ...
works's user avatar
  • 107
1 vote
1 answer
50 views

Use Boost python with libtorch

I am trying to create a python package from C++ code with Boost python. However when including libtorchin the code, the resulting python package shows strange errors such as Boost.Python....
ppeloton's user avatar
0 votes
0 answers
42 views

Which api in `libtorch` corresponding the `ctx.needs_input_grad` in pytorch when to define custom `torch.autograd.Function`?

When I tanslate the following python code to cpp code with libtorch api class _SphericalHarmonics(torch.autograd.Function): """Spherical Harmonics""" @...
Zhiguo Tang's user avatar
0 votes
0 answers
58 views

Why can inconsistent function names be called correctly in the scenario of calling functions defined by c++in python code?

I saw a project on GitHub that involved Python code to call functions defined in C++. Strangely, the function name defined in C++ is A, but it can be called through the name B in Python, where A and B ...
DEAD SUMMER's user avatar
0 votes
0 answers
42 views

How to trace pytorch flow to CPP

My goal is being able to adjust the backend of distributed functions according to requirements. For example, I wish to be able to change a failed GPU to be substituted with a constant value tensor ...
Hod Badihi's user avatar
0 votes
0 answers
142 views

Loading traced pytorch model to C++

Will be grateful for any help :( I'm having a problem with using pytorch pretrained model in C++ via TorchLib. I've added Torchlib to Cmake and it successfully downloads the model and works until line:...
Pashar's user avatar
  • 1
0 votes
0 answers
244 views

Allowed data types in torch.jit.trace()

I want to save a segmentation model pipeline to a mobile optimized model that I can run on iOS or call from a C++ program. I am using two pretrained models, whose code I can not change. I am majorly ...
Nitya Patel's user avatar
0 votes
0 answers
89 views

Different results PyTorch vs Libtorch

I am trying to calculate a disparity image for the same traced model in python and c++ but I am getting different outputs. I tried and follow the same steps in c++ as in python but it seems I missed ...
anaandreea's user avatar
0 votes
1 answer
2k views

Using TorchScript model and got issue: RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu

I trained an ALEBF-based model on python, and I chose to reason it in c++ for overall efficiency reasons. I chose torch.jit.trace in python to save the model and loaded the corresponding .pt file in c+...
LZH's user avatar
  • 1
1 vote
0 answers
289 views

Problem using libtorch and pytorch at same time: Key already registered with the same priority: C10

I'm currently trying to implement a python torch model into a C++ application in VS22. Now the problem is that the C++ part uses libtorch and part of the python code uses pytorch. Libtorch version: ...
Aku's user avatar
  • 11
-1 votes
1 answer
2k views

Installation of transformer library not working in Apple M1

I'm attempting to install rust-bert. Unfortunately, I have an Apple M1 and the library isn't designed for the new ARM chip. Specifically, the pytorch and libtorch libraries aren't linked. The error is ...
yosemeti's user avatar
  • 228
2 votes
0 answers
55 views

libtorch Conv1D doesn't operate over signal length dimension

I have a torch model, that simply contains a conv1d (intended to be used to implement a STFT fourier transform). The model works fine in torch, and traced using torch.jit.load in Python. When I ...
bjp's user avatar
  • 21
1 vote
0 answers
866 views

TorchScript model output is not the same as Pytorch model output

I am trying to use pytorch (.pth) model in c++. The best way I found is to convert .pth to TorchScript module. I was able to convert .pth model to TorchScript module successfully, however converted ...
Karen Aleqsanyan's user avatar
2 votes
0 answers
452 views

Libtorch's CPU inference is much slower on Windows than on Linux

I found that PyTorch / LibTorch version 1.10 with certain topologies (classifiers with Fully-Connected/Dense-Layers) is during CPU inference significantly slower on Windows 10 than on Linux. The model ...
Bastian's user avatar
  • 1,593
0 votes
1 answer
6k views

pytorch can multithread so why not use python for inference?

I know python has a GIL, so it can only use one cpu for one processing. But pytorch use multi cpu because it uses C++ for multithreading. I guess it works for inference too. so I guess we can use ...
Jackiexiao's user avatar
4 votes
0 answers
1k views

Debugging C++ in VSCode - gdb attach fails to read the values inside custom class objects

I am working on a project that uses both Python and C++. Here is the launch.json file: { "logging": { "engineLogging": true }, "configurations": [ ...
anurag's user avatar
  • 1,872
1 vote
1 answer
4k views

undefined symbol error when importing libtorch function via pybind11

I am attempting to write a C++ function in libtorch, compile it with pybind11 and then import the .so file in a python file. The build seems to work fine (no errors are emitted) but, when I try to ...
anurag's user avatar
  • 1,872
1 vote
0 answers
180 views

How to sync the device setting between pytorch(python) and libtorch(C++)?

There is a annoying problem when using a libtorch function in pytorch(python). The device setting in libtorch is k:CUDA, and its default meaning is CUDA:0. But when I use it in python pytorch, I want ...
RickyYXY's user avatar
0 votes
0 answers
2k views

Google Colab: Nvidia-Smi and Libtorch not compatible anymore

The problem is new and has never happened before, so there might have been an update of the nvidia driver or libtorch. Problem: I am using Google Colab for additional GPU and want to install a ...
CanDo7777's user avatar
0 votes
1 answer
402 views

Difference In the output image when using traced model(.pt) with C++ and OpenCV

I have retrained the model based on EnlightenGAN. Further I have traced the model in order to execute it in a C++ application using libTorch v1.6. However, I am getting slightly different results as ...
CuriousCodes's user avatar
0 votes
0 answers
872 views

Python with C++: CUDA, cuSPARSE compilation gives an undefined symbol error

My goal is to run a Python function calling C++/CUDA functions, which use cuBLAS and cuSPARSE. First, I compile a custom library using setuptools with no errors. Then, I run a python script that ...
壞府_'s user avatar
  • 41
2 votes
1 answer
1k views

libtorch and pytorch cannot be installed simultaneously?

I am learning to develop with PyTorch as well as LibTorch. I have the following line in my ~/.bashrc for dynamic linking of libtorch libraries: # libtorch linking path export LD_LIBRARY_PATH=$...
ihdv's user avatar
  • 2,275
1 vote
0 answers
467 views

Utilizing Dynamic Parallelism in PyTorch C++ (LibTorch)

I am working on a project where we load a TorchScript model into C++. We have tried to make a model utilizing dynamic parallelism as described in this tutorial. When we do inference with the model in ...
Jim Totland's user avatar
1 vote
1 answer
6k views

I'm having issues uninstalling pytorch

So a while back I installed pytorch using pip and as a compute platform "CPU Only". Now I want to use torch on GPU but no matter how I try to install CUDA as a compute platform, it still ...
azhariamir01's user avatar
3 votes
1 answer
3k views

Pytorch C++ (Libtroch), using inter-op parallelism

I am working on a machine learning system using the C++ API of PyTorch (libtorch). One thing that I have been recently working on is researching performance, CPU utilization and GPU usage of libtorch. ...
Bohaterowicz's user avatar
0 votes
0 answers
710 views

Bazel - Pybind - Pytorch - Undefined Symbol

Attempting to write a toy example with Bazel, Pybind, Pytorch/Libtorch fails with the following error on import of the custom library import libTest undefined symbol: ...
raaj's user avatar
  • 3,251
0 votes
0 answers
488 views

Doubts about the address of the tensor on GPU

I used C++ and libtorch to debug tensor calculation. I put a tensor on the GPU and define its pointer and output its address. And next, I defined another pointer to point a numcpp array and output ...
517453088qqcom's user avatar
4 votes
1 answer
2k views

How to convert PyTorch tensor to C++ torch::Tensor vice versa?

I want to receive a dictionary includes PyTorch Tensor in C++ module using pybind11, and return the result dictionary with some modification that includes C++ torch::Tensor back. As far as I was ...
Jisung Kim's user avatar
9 votes
1 answer
4k views

What is the LibTorch equivalent to PyTorch's torch.no_grad?

When testing a network in PyTorch one can use with torch.no_grad():. What is the Libtorch (C++) equivalent? Thanks!
MD98's user avatar
  • 374
2 votes
1 answer
3k views

Is there an analogy for Python's array slicing in C++ (libtorch)?

In Python with PyTorch, if you have an array: torch.linspace(0, 10, 10) you can use e.g. only the first three elements by saying reduced_tensor = torch.linspace(0, 10, 10)[:4]. Is there an analog to ...
MD98's user avatar
  • 374
1 vote
0 answers
1k views

Model exported from python gives different results when loaded in C++

Problem description So I have model class written in python using PyTorch: class ResBlock(nn.Module, ABC): def __init__(self, in_channels: int, filters: int, conv_num: int): super(ResBlock,...
Magiczne's user avatar
  • 1,606
2 votes
2 answers
5k views

In the PyTorch C++ extension, how can I access a single element in a tensor and convert it to a standard c++ datatype?

I am writing a c++ extension for pytorch, in which I need to access the elements of a tensor by index, and I also need to convert the element to a standard c++ type. Here is a short example. Suppose I ...
ihdv's user avatar
  • 2,275
1 vote
0 answers
436 views

PyTorch training attribute doesn't exists in C++ module

I have a script that was traced and saved using torch.jit.save, when I load it in python using: net = torch.jit.load(r"script.pt") net.to('cuda') net.train() print(net.training) ...
La bla bla's user avatar
  • 8,698
3 votes
2 answers
1k views

slow Inference time for Neural Net

I have written a simple Fully connected Neural Network in Pytorch. I saved the model and loaded it in C++ using LibTorch but my inference time is pretty slow for my application field. Inference time ...
raghav sood's user avatar
1 vote
1 answer
2k views

Incorrect results obtained on running a model in LibTorch that was trained and exported from PyTorch

I am trying to export a trained model along with weights for inference in C++ using LibTorch. However, the output tensor results do not match. The shape of the output tensor is the same. model = FCN(...
Shayan's user avatar
  • 2,461
3 votes
1 answer
2k views

pytorch torch.jit.trace returns function instead of torch.jit.ScriptModule

I need to run in c++ a pre-trained pytorch nn model (trained in python) to make predictions. To do so, I'm following the instructions on how to load a pytorch model in c++ given here: https://pytorch....
Oleguer's user avatar
  • 55