deepspeed训练模型提示:cpu_adam.so: cannot open shared object file: No such file or directory

  1. 背景

本人在安装deepspeed后遇到了这个报错,明眼人一看就是缺库,但是搜索到的解决方案(凌漪_, 2023)说是设置一个环境变量,实在是治标不治本,而且对本人来说连标都治不了。其他的博客尚未看到解决此问题的。

  1. 分析

这个so文件理论上应该在安装deepspeed的过程中就自动编译好了,但是现在没有,我们肯定需要找到编译这个so文件的地方。

  1. 解决过程
    通过认真阅读deepspeed的README,可以看到一句话:

If you would like to pre-install any of the DeepSpeed extensions/ops (instead of JIT compiling) or install pre-compiled ops via PyPI please see our advanced installation instructions.

我们打开deepspeed的高级安装指南,可以看到下列文字

DS_BUILD_CPU_ADAM builds the CPUAdam op.

我们只需要在安装deepspeed时设置DS_BUILD_CPU_ADAM=1即可。因此,我们卸载并重新安装deepspeed

pip uninstall deepspeed
pip cache remove deepspeed
DS_BUILD_CPU_ADAM=1 pip install deepspeed

然后就会自动编译出cpu_adam.so文件。

在编译过程中,你可能会遇到gcc不认--std=c++17这个错误,类似:unrecognized command line option ‘--std=c++17’,这说明你需要更高版本的gcc。如果你有root权限,你可以用root折腾安装,把系统弄坏了博主概不负责,如果你没有或者有但是不想用,可以参看本人之前的博客(王, 2024),使用conda安装。安装完毕后,记得将对应程序符号链接到PATH中,并将链接命名为gcc/g++,才能让编译脚本找到并优先使用。

如果编译或运行时遇到没有ninja的问题,你需要同时使用pip和conda安装ninja,pip安装的ninja是个python库,conda安装的ninja是个命令行程序,二者都被deepspeed需要。

posted @ 2024-07-17 20:10  王冰冰  阅读(162)  评论(2编辑  收藏  举报