安装torch出现如下错误make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath.cu.o] Error 1 CMak

本文介绍了解决torch安装过程中出现的关于half类型运算符重载冲突的问题,并提供了一种可行的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

torch安装地址

按照官网步骤

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch
bash install-deps
./install.sh

依赖保证安装完毕以后

执行最后一步后出现错误如下:

 

/home/brian/torch/extra/cutorch/lib/THC/generic/THCTensorMathPairwise.cu(66): error: more than one operator "!=" matches these operands:
            function "operator!=(const __half &, const __half &)"
            function "operator!=(half, half)"
            operand types are: half != half

1 error detected in the compilation of "/tmp/tmpxft_000078f9_00000000-6_THCTensorMathPairwise.cpp1.ii".
CMake Error at THC_generated_THCTensorMathPairwise.cu.o.cmake:267 (message):
  Error generating file
  /home/brian/torch/extra/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorMathPairwise.cu.o


lib/THC/CMakeFiles/THC.dir/build.make:140: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathPairwise.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathPairwise.cu.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/home/brian/torch/extra/cutorch/lib/THC/generic/THCTensorMath.cu(393): error: more than one operator "==" matches these operands:
            function "operator==(const __half &, const __half &)"
            function "operator==(half, half)"
            operand types are: half == half

/home/brian/torch/extra/cutorch/lib/THC/generic/THCTensorMath.cu(414): error: more than one operator "==" matches these operands:
            function "operator==(const __half &, const __half &)"
            function "operator==(half, half)"
            operand types are: half == half

2 errors detected in the compilation of "/tmp/tmpxft_00007911_00000000-6_THCTensorMath.cpp1.ii".
CMake Error at THC_generated_THCTensorMath.cu.o.cmake:267 (message):
  Error generating file
  /home/brian/torch/extra/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorMath.cu.o

lib/THC/CMakeFiles/THC.dir/build.make:112: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath.cu.o] Error 1
CMakeFiles/Makefile2:172: recipe for target 'lib/THC/CMakeFiles/THC.dir/all' failed
make[1]: *** [lib/THC/CMakeFiles/THC.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

 

此时尝试采用如下命令进行安装:

sudo su
export TORCH_NVCC_FLAGS="-D__CUDA_NO_HALF_OPERATORS__"
bash install-deps
yes | bash ./install.sh

按照此方法,对我来讲是有效的,已经成功安装torch 

 

注:如果上述方法还不行,那么建议重新安装ubuntu系统,安装ubuntu16版本的系统,兼容性可能更好。

错误信息"torch/lib/../../../../libmkl_gnu_thread.so: invalid ELF header"表示在导入torch库时发生了一个错误,提示ELF头部无效。ELF(Executable and Linkable Format)是一种用于二进制可执行文件和共享库的文件格式。 根据引用和引用,这个问题通常与缺少或损坏的库文件有关。解决这个问题的一种方法是重新安装或修复缺失的库文件。 根据引用的解决方法,您可以尝试以下步骤来解决该问题: 1. 找到libmkl_gf_lp64.so文件所在的路径,并复制该路径。 2. 在终端中输入以下命令以进入/etc/ld.so.conf.d目录:cd /etc/ld.so.conf.d 3. 创建一个新文件runtime-x86_64.conf,并使用sudo vi runtime-x86_64.conf命令进行编辑。 4. 在新建的文件中粘贴刚刚复制的路径。按下i键进入编辑模式,右键粘贴路径,然后按下Esc键,输入:wq保存并退出vi编辑器。 5. 运行sudo ldconfig命令以更新动态链接库缓存。 6. 输入ipython命令,然后尝试导入torch库,如果成功导入,则问题已解决。 这些步骤可以帮助您解决"torch/lib/../../../../libmkl_gnu_thread.so: invalid ELF header"错误。希望对您有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [invalid ELF header](https://blog.csdn.net/Jasonluo8/article/details/121263965)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [安装Pytorch之后出现问题](https://blog.csdn.net/qq_33289694/article/details/103858513)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值