8000 Unable to find caffe2 when building libtorch from the source and then trying to use it in a cmake project · Issue #155512 · pytorch/pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unable to find caffe2 when building libtorch from the source and then trying to use it in a cmake project #155512
Open
@HugoPhibbs

Description

@HugoPhibbs

🐛 Describe the bug

I've cloned the pytorch repo, and then followed the instructions found at libtorch.rst.

I followed the cmake section. I'm configuring with:

cmake -DUSE_DISTRIBUTED=OFF   -DUSE_CUDA=ON   -DUSE_TENSORPIPE=OFF   -DUSE_SYSTEM_NCCL=ON   -DBUILD_TEST=OFF   -DMAX_JOBS=20   -DUSE_FLASH_ATTENTION=OFF   -DUSE_MEM_EFF_ATTENTION=OFF   -DUSE_MKLDNN=OFF   -DBUILD_SHARED_LIBS=ON   -DCMAKE_BUILD_TYPE=Release   -DPYTHON_EXECUTABLE=$(which python3) -GNinja  -DCMAKE_INSTALL_PREFIX=../pytorch-install   ../pytorch

Then building with:

cmake --build . --target install -j$(nproc)

Then when I try to include the torch module into my project with:

set(Torch_DIR "/opt/pytorch-build")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
find_package(Torch REQUIRED)

Then configuring my project with this preset:

"name": "default-debug",
            "displayName": "default-debug",
            "description": "Use g++13, Ninja, Mold and config CUDA",
            "generator": "Ninja",
            "binaryDir": "${sourceDir}/build-debug",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "/usr/bin/gcc-13",
                "CMAKE_C_COMPILER_LAUNCHER": "ccache",
                "CMAKE_CXX_COMPILER": "/usr/bin/g++-13",
                "CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
                "CMAKE_CUDA_HOST_COMPILER": "/usr/bin/g++-13",
                "CMAKE_EXE_LINKER_FLAGS": "-fuse-ld=mold",
                "CMAKE_SHARED_LINKER_FLAGS": "-fuse-ld=mold",
                "CMAKE_CUDA_COMPILER": "/usr/local/cuda/bin/nvcc",
                "CUDA_TOOLKIT_ROOT_DIR": "/usr/local/cuda",
                "CMAKE_BUILD_TYPE": "Debug",
                "CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
            }

I'm getting this when cmake tries to load in Torch:

CMake Error at /opt/pytorch-build/TorchConfig.cmake:68 (find_package):
  Could not find a package configuration file provided by "Caffe2" with any
  of the following names:

    Caffe2Config.cmake
    caffe2-config.cmake

  Add the installation prefix of "Caffe2" to CMAKE_PREFIX_PATH or set
  "Caffe2_DIR" to a directory containing one of the above files.  If "Caffe2"
  provides a separate development package or SDK, be sure it has been
  installed.
Call Stack (most recent call first):
  CMakeLists.txt:70 (find_package)

I've tried setting the caffe2_dir in cmake like:

set(Caffe2_DIR "${Torch_DIR}")

But then I get these errors:

CMake Error at /opt/pytorch-build/Caffe2Config.cmake:9 (include):
  include could not find requested file:

    /opt/pytorch-build/public/utils.cmake
Call Stack (most recent call first):
  /opt/pytorch-build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:70 (find_package)


CMake Error at /opt/pytorch-build/Caffe2Config.cmake:86 (include):
  include could not find requested file:

    /opt/pytorch-build/public/cuda.cmake
Call Stack (most recent call first):
  /opt/pytorch-build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:70 (find_package)


CMake Error at /opt/pytorch-build/Caffe2Config.cmake:114 (include):
  include could not find requested file:

    /opt/pytorch-build/Caffe2Targets.cmake
Call Stack (most recent call first):
  /opt/pytorch-build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:70 (find_package)

I suspect it has to do with how torch is being found by cmake, but I've been unable to find stuff in the docs on how to include after a custom build.

Versions

doesn't say below, but I'm using pytorch 2.7.1. Cuda is 12.6

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: version 4.0.0-rc3
Libc version: glibc-2.39

Python version: 3.13.0 | packaged by conda-forge | (main, Nov 27 2024, 19:18:50) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-139-generic-x86_64-with-glibc2.39
Is CUDA available: N/A
CUDA runtime version: 12.6.20
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090

Nvidia driver version: 565.57.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.3.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 43 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Vendor ID: AuthenticAMD
Model name: AMD Ryzen Threadripper 3970X 32-Core Processor
CPU family: 23
Model: 49
Thread(s) per core: 2
Core(s) per socket: 32
Socket(s): 1
Stepping: 0
Frequency boost: disabled
CPU(s) scaling MHz: 100%
CPU max MHz: 4000.0000
CPU min MHz: 2200.0000
BogoMIPS: 8000.25
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sme sev sev_es
Virtualization: AMD-V
L1d cache: 1 MiB (32 instances)
L1i cache: 1 MiB (32 instances)
L2 cache: 16 MiB (32 instances)
L3 cache: 128 MiB (8 instances)
NUMA node(s): 1
NUMA node0 CPU(s): 0-63
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec rstack overflow: Mitigation; safe RET
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Retpolines; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] No relevant packages
[conda] No relevant packages

cc @malfet @seemethere @jbschlosser

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: buildBuild system issuesmodule: cppRelated to C++ APItriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0