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++