编译pytorch时报错如下:
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
caffe2/CMakeFiles/torch_cpu.dir/build.make:3724: recipe for target 'caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/Functions.cpp.o' failed
make[2]: *** [caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/Functions.cpp.o] Error 4
CMakeFiles/Makefile2:2837: recipe for target 'caffe2/CMakeFiles/torch_cpu.dir/all' failed
make[1]: *** [caffe2/CMakeFiles/torch_cpu.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Traceback (most recent call last):
File "setup.py", line 727, in <module>
build_deps()
File "setup.py", line 319, in build_deps
cmake=cmake)
File "/home/casia/pytorch1.7/pytorch/tools/build_pytorch_libs.py", line 62, in build_caffe2
cmake.build(my_env)
File "/home/casia/pytorch1.7/pytorch/tools/setup_helpers/cmake.py", line 346, in build
self.run(build_args, my_env)
File "/home/casia/pytorch1.7/pytorch/tools/setup_helpers/cmake.py", line 141, in run
check_call(command, cwd=self.build_dir, env=env)
File "/home/casia/.conda/envs/py36/lib/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '1']' returned non-zero exit status 2.
问题解决
这个问题网上解决方案很多,在此总结一些
遇到此类问题,原因是内存不足,也就是交换空间不足
使用指令查看当前内存和交换空间情况:
free -m
total used free shared buff/cache available
Mem: 989 954 12 0 22 14
Swap: 0 0 0
可以看到我并没有启用swap空间,打开swap就可以解决这个问题
# 创建swap分区文件
sudo dd if=/dev/zero of=/root/swapfile bs=64M count=32
# swapfile格式化为交换分区文件
sudo mkswap /root/swapfile
# 启用交换空间
sudo swapon /root/swapfile
# 关闭交换空间
sudo swapoff /root/swapfile
# 若有需要,也可以删掉交换空间
sudo rm /root/swapfile
在上面的代码中,bs表示块的大小,swap空间的大小为:bs*count
通过上面的操作后,我们重新编译,应该可以成功编译,并且没有报错的!还报错的话,就请加大交换空间!