Hi, I am trying to understand the relationship between the libtorch and precomipled pytorch, thus figuring out whether I need Libtorch if I already have pytorch installed using pip.
Does pytorch already contain libtorch? I am asking this because “print(torch.utils.cmake_prefix_path)” gives me “home/weixuan/.local/lib/python3.6/site-packages/torch/share/cmake”, and I can also set this as the CMAKE_PREFIX_PATH and compile my C++ code. Also see the instruction here: Installing C++ Distributions of PyTorch — PyTorch master documentation
So what is the difference between the libtorch and the shared libraries inside the pytorch packages? The purpose of libtorch is for those who do not have pytorch installed on their system and therefore independant of the python?
In addition, it seems that the shared libraries in the pytorch 1.9.0 package are not compiled with cxx11-abi, as pointed out here: SOS! libtorch conflict with ROS! This leads to conflict with ROS package. Is there a way of revolving this without having to compile pytorch from source? Thanks!
Actually, there is no need to download c++ libtorch if you have already downloaded pytorch using pip. Assume that you are using conda, libtorch.so will be automatically installed in “/root/miniconda3/envs/your_env/lib/python3.10/site-packages/torch/lib”, alongside with many other libraries that c++ can use. Using this libtorch directly in your c++ code and cmake will cause no version confliction when importing it to python by pybind11, because they come from the same place. And pybind11 has no version issue, so any download method will be fine (git clone from source or pip) if you are using it.