libtorch cmake 配置提示 "Failed to compute shorthash for libnvrtc.so"

⚠️ 博主使用的 ​libtorch 版本为 libtorch-2.10.0-cu130,如果配置文件不同请谨慎修改。

该问题将在 2.11 版本解决,详见 RC 版本 TAG

根据官方 issue 的内容,原因为 CMake 配置文件没有正确调用 Python 解释器。打开 libtorch 目录下的 ./share/cmake/Caffe2/public/cuda.cmake 文件并作如下修改。

# find lbnvrtc.so
set(CUDA_NVRTC_LIB "${CUDA_nvrtc_LIBRARY}" CACHE FILEPATH "")
if(CUDA_NVRTC_LIB AND NOT CUDA_NVRTC_SHORTHASH)
  find_package(Python COMPONENTS Interpreter)
  execute_process(
    COMMAND Python::Interpreter -c  <-- 对该处进行更改
    "import hashlib;hash=hashlib.sha256();hash.update(open('${CUDA_NVRTC_LIB}','rb').read());print(hash.hexdigest()[:8])"
    RESULT_VARIABLE _retval
    OUTPUT_VARIABLE CUDA_NVRTC_SHORTHASH)
  if(NOT _retval EQUAL 0)
    message(WARNING "Failed to compute shorthash for libnvrtc.so")
    set(CUDA_NVRTC_SHORTHASH "XXXXXXXX")
  else()
    string(STRIP "${CUDA_NVRTC_SHORTHASH}" CUDA_NVRTC_SHORTHASH)
    message(STATUS "${CUDA_NVRTC_LIB} shorthash is ${CUDA_NVRTC_SHORTHASH}")
  endif()
endif()

COMMAND Python::Interpreter -c 修改为 COMMAND ${Python_EXECUTABLE} -c,该更改在一份 2 个月前的 PR 中已被官方采纳,但合并失败,后续应该会合入此项更改。

posted @ 2026-02-05 13:48  絵守辛玥  阅读(45)  评论(0)    收藏  举报