Setting up PyTorch plugin “bias_act_plugin“... Failed!

python-linux,windowns环境下报错,解决思路


哇,出现了这一堆错误:

Setting up PyTorch plugin "bias_act_plugin"... Failed!
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.
ninja: build stopped: subcommand failed.

  • 具体错误如下

  • Setting up PyTorch plugin "bias_act_plugin"... Failed!
    
    Traceback (most recent call last):
      File "/home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1740, in _run_ninja_build
        subprocess.run(
      File "/home/yhx/anaconda3/envs/eg3D/lib/python3.9/subprocess.py", line 528, in run
        raise CalledProcessError(retcode, process.args,
    subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/home/yhx/PycharmProjects/eg3d/eg3d/eg3d/viz/renderer.py", line 143, in render
        self._render_impl(res, **args)
      File "/home/yhx/PycharmProjects/eg3d/eg3d/eg3d/viz/renderer.py", line 324, in _render_impl
        all_ws = G.mapping(z=all_zs, c=all_cs, truncation_psi=trunc_psi, truncation_cutoff=trunc_cutoff) - w_avg
      File "<string>", line 41, in mapping
      File "/home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
        return forward_call(*input, **kwargs)
      File "<string>", line 246, in forward
      File "/home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
        return forward_call(*input, **kwargs)
      File "<string>", line 124, in forward
      File "/home/yhx/PycharmProjects/eg3d/eg3d/eg3d/torch_utils/ops/bias_act.py", line 86, in bias_act
        if impl == 'cuda' and x.device.type == 'cuda' and _init():
      File "/home/yhx/PycharmProjects/eg3d/eg3d/eg3d/torch_utils/ops/bias_act.py", line 43, in _init
        _plugin = custom_ops.get_plugin(
      File "/home/yhx/PycharmProjects/eg3d/eg3d/eg3d/torch_utils/custom_ops.py", line 138, in get_plugin
        torch.utils.cpp_extension.load(name=module_name, build_directory=cached_build_dir,
      File "/home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1144, in load
        return _jit_compile(
      File "/home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1357, in _jit_compile
        _write_ninja_file_and_build_library(
      File "/home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1469, in _write_ninja_file_and_build_library
        _run_ninja_build(
      File "/home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1756, in _run_ninja_build
        raise RuntimeError(message) from e
    RuntimeError: Error building extension 'bias_act_plugin': [1/3] /usr/local/cuda-11.1/bin/nvcc  -DTORCH_EXTENSION_NAME=bias_act_plugin -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/TH -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/THC -isystem /usr/local/cuda-11.1/include -isystem /home/yhx/anaconda3/envs/eg3D/include/python3.9 -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 --compiler-options '-fPIC' --use_fast_math -std=c++14 -c /home/yhx/.cache/torch_extensions/py39_cu113/bias_act_plugin/b46266ff65f9fa53c32108953a1c6f16-nvidia-rtx-a6000/bias_act.cu -o bias_act.cuda.o 
    FAILED: bias_act.cuda.o 
    /usr/local/cuda-11.1/bin/nvcc  -DTORCH_EXTENSION_NAME=bias_act_plugin -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/TH -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/THC -isystem /usr/local/cuda-11.1/include -isystem /home/yhx/anaconda3/envs/eg3D/include/python3.9 -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 --compiler-options '-fPIC' --use_fast_math -std=c++14 -c /home/yhx/.cache/torch_extensions/py39_cu113/bias_act_plugin/b46266ff65f9fa53c32108953a1c6f16-nvidia-rtx-a6000/bias_act.cu -o bias_act.cuda.o 
    gcc: fatal error: cannot execute ‘cc1plus’: execvp: 没有那个文件或目录
    compilation terminated.
    nvcc fatal   : Failed to preprocess host compiler properties.
    [2/3] c++ -MMD -MF bias_act.o.d -DTORCH_EXTENSION_NAME=bias_act_plugin -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/TH -isystem /home/yhx/anaconda3/envs/eg3D/lib/python3.9/site-packages/torch/include/THC -isystem /usr/local/cuda-11.1/include -isystem /home/yhx/anaconda3/envs/eg3D/include/python3.9 -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -std=c++14 -c /home/yhx/.cache/torch_extensions/py39_cu113/bias_act_plugin/b46266ff65f9fa53c32108953a1c6f16-nvidia-rtx-a6000/bias_act.cpp -o bias_act.o 
    ninja: build stopped: subcommand failed.
    
    
    
    
    
    

  • 原因一:

    当前虚拟环境使用的cuda版本(11.1)与本地系统的cuda版本发生冲突
  • (在不改变环境配置的时候,默认使用的是,本地系统的cuda(我的是12.2)

    但是我跑的项目要求cudatoolkit=11.1,因此,你还需要在本地系统中重装一个cuda(cudatoolkit=11.1),如下,我已经有两个啦cuda安装参考链接

    在这里插入图片描述
    接下来要配置环境 vim ~/.bashrc (前面注释掉的那一堆是我头大了好久,苦苦借鉴他人设置的,对我都没有,哭晕~)

    vim ~/.bashrc 
    

    在这里插入图片描述
    编辑好后, source ~/.bashrc 应用更新一下。

     source ~/.bashrc
    
    

    进入到我项目的虚拟环境那nvcc -V ,可以看到cuda的版本已经变成cuda_11.1 啦 ,如果我不通过以上这么设置,我这里的是cuda_12.2,与我项目的不符合,因此报错:

    nvcc -V
    

    在这里插入图片描述

  • 原因二:

    gcc和cuda版本不符合
  • 如果通过以上,你还没有解决,那就是你gcc的版本不符合cuda的版本,cuda11.1 要求gcc的版本为10.x哦 ,别忘了升级一下,gcc升级参考链接

  • Linux 下使用 update-alternatives 管理gcc和g++多版本命令

  • 先将需要的版本添加到 update-alternatives 中,设置优先级

    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-10 100 
    
    sudo update-alternatives --config gcc
    
    

    在这里插入图片描述

    gcc --version
    
    

    在这里插入图片描述

    g++ --version
    
    

    在这里插入图片描述
    手动再执行以下命令修改一下,否则会不成功

    sudo ln -s /usr/bin/g++-10 /usr/bin/g++
    
    

    在这里插入图片描述

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小_喻

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值