Python|Windows 安装 DeepSpeed 安装方法及报错 Unable to pre-compile async_io 处理
创始人
2024-11-06 05:09:16
0

前置文档:Python|Windows 安装 DeepSpeed 报错 Unable to pre-compile async_io 处理

直接 pip 安装 deepspeed 的报错信息

如果直接使用 pip install DeepSpeed 安装,会触发如下报错信息。出现后,需使用如下方法完成安装。

Collecting deepspeed   Downloading deepspeed-0.14.3.tar.gz (1.3 MB)      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 4.1 MB/s eta 0:00:00   Preparing metadata (setup.py) ... error   error: subprocess-exited-with-error    × python setup.py egg_info did not run successfully.   │ exit code: 1   ╰─> [15 lines of output]       test.c       LINK : fatal error LNK1181: 无法打开输入文件“aio.lib”       Traceback (most recent call last):         File "", line 2, in          File "", line 34, in          File "C:\Users\Changxing\AppData\Local\Temp\pip-install-m3_5w4lm\deepspeed_f82b888e581d4d19a24987ccd691885a\setup.py", line 181, in            abort(f"Unable to pre-compile {op_name}")         File "C:\Users\Changxing\AppData\Local\Temp\pip-install-m3_5w4lm\deepspeed_f82b888e581d4d19a24987ccd691885a\setup.py", line 53, in abort           assert False, msg       AssertionError: Unable to pre-compile async_io       DS_BUILD_OPS=1        [WARNING]  async_io requires the dev libaio .so object and headers but these were not found.        [WARNING]  If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.        [WARNING]  One can disable async_io with DS_BUILD_AIO=0        [ERROR]  Unable to pre-compile async_io       [end of output]    note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed  × Encountered error while generating package metadata. ╰─> See above for output.  note: This is an issue with the package mentioned above, not pip. hint: See above for details. 

Windows 安装 DeepSpeed 的方法

Step 1|克隆 DeepSpeed 仓库
git clone https://github.com/microsoft/DeepSpeed.git 
Step 2|使用 PowerShell,进入 DeepSpeed 仓库路径

在这里插入图片描述

PowerShell 可以通过 Win + r 搜索 powershell 启动。

cd DeepSpeed 
Step 3|设置环境变量
Set-Item Env:\DS_BUILD_OPS 0 
Step 4|修复 DeepSpeed 仓库 2024.06.01 提交引入的 Bug

此时如果直接执行 setup.py 编译 DeepSpeed,可能会触发如下报错,这是因为 2024.06.01 的提交引入的 Bug:

Traceback (most recent call last):   File "C:\Git-source\DeepSpeed\setup.py", line 212, in      shutil.copytree('.\\csrc', '.\\deepspeed\\ops')   File "C:\py\py311\Lib\shutil.py", line 561, in copytree     return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "C:\py\py311\Lib\shutil.py", line 459, in _copytree     os.makedirs(dst, exist_ok=dirs_exist_ok)   File "", line 225, in makedirs FileExistsError: [WinError 183] 当文件已存在时,无法创建该文件。: '.\\deepspeed\\ops' 

观察报错信息,可以看到是 setup.py 中的第 211 - 215 行,这段代码如下:

if sys.platform == "win32":     shutil.copytree('.\\csrc', '.\\deepspeed\\ops')     shutil.copytree('.\\op_builder', '.\\deepspeed\\ops')     shutil.copytree('.\\accelerator', '.\\deepspeed\\accelerator')     egg_info.manifest_maker.template = 'MANIFEST_win.in' 

可以看到,这三行尝试将 csrc 复制到 deepspeed/ops 下时,发现路径已存在。查看这 3 个文件,发现其中 Linux 中使用的重定向文件。但是,这里的用法时错误的,无法覆盖文件,且路径也是错误的。这个提交是 2024.06.01 的提交,对应的 Issue 是:https://github.com/microsoft/DeepSpeed/pull/5596。

在这里插入图片描述

而无法 Build 的问题也已经提交了 Issue:https://github.com/microsoft/DeepSpeed/issues/5679。

将 211 - 215 行修改为如下逻辑:

if sys.platform == "win32":     shutil.copytree('.\\csrc', '.\\deepspeed\\ops\\csrc')     shutil.copytree('.\\op_builder', '.\\deepspeed\\ops\\op_builder')     shutil.copytree('.\\accelerator', '.\\deepspeed\\accelerator')     egg_info.manifest_maker.template = 'MANIFEST_win.in' 

并且,因为 shutil.copytree 不会实现覆盖,所以需要手动删除掉 DeepSpeed/deepspeed/ops 下的 crscop_builder 文件,以及 DeepSpeed/deepspeed 路径下的 accelerator 文件。

在这里插入图片描述

在这里插入图片描述

Step 5|编译 DeepSpeed 仓库

执行 build_win.bat 脚本编译,其中在配置环境变量后,也是通过 setup.py 完成编译:

.\build_win.bat 

如果运行出现如下报错,则说明需要执行 Step 4 的步骤:

FileExistsError: [WinError 183] 当文件已存在时,无法创建该文件。: '.\\deepspeed\\ops' 
FileExistsError: [WinError 183] 当文件已存在时,无法创建该文件。: '.\\deepspeed\\accelerator' 

在这里插入图片描述

Step 6|进入 dist 路径

进入 dist 路径,查看其中文件,应已经包含刚才成功编译的包:

cd dist ls 
    目录: C:\Git-source\DeepSpeed\dist   Mode                 LastWriteTime         Length Name ----                 -------------         ------ ---- -a----         2024/6/17      8:34        1018363 deepspeed-0.14.4+eda5075b-py3-none-any.whl 
Step 7|安装编译生成的包
pip install deepspeed-0.14.4+eda5075b-py3-none-any.whl 

安装成功。

在这里插入图片描述

相关内容

热门资讯

八分钟了解!newpoker怎... 八分钟了解!newpoker怎么安装脚本,哈糖大菠萝能开挂吗,指南书教程(有挂分析)1、哈糖大菠萝能...
方案辅助!微信小程序微乐破解器... 方案辅助!微信小程序微乐破解器2024!解谜真的是有辅助教程(有挂细节)1、进入到微信小程序微乐破解...
第9分钟了解!德普之星有辅助软... 第9分钟了解!德普之星有辅助软件吗,德州局透视脚本,步骤教程(有挂神器)运德普之星有辅助软件吗辅助工...
窍要辅助!洞庭茶苑app辅助!... 窍要辅助!洞庭茶苑app辅助!关于存在有辅助神器(有挂辅助)1.洞庭茶苑app辅助 选牌创建新账号,...
七分钟了解!wepoker怎么... 七分钟了解!wepoker怎么开辅助,wepoker透视脚本免费app,绝活儿教程(有挂细节)1、w...
窍要辅助!嘟咪互动有挂吗!开挂... 窍要辅助!嘟咪互动有挂吗!开挂是有辅助软件(有挂总结)窍要辅助!嘟咪互动有挂吗!开挂是有辅助软件(有...
1分钟了解!wepoker辅助... 1分钟了解!wepoker辅助器最新版本更新内容,德普之星私人局辅助免费,办法教程(有挂辅助)wep...
大纲辅助!心悦海南苹果版辅助器... 大纲辅助!心悦海南苹果版辅助器!关于是有辅助工具(有挂攻略)1、玩家可以在心悦海南苹果版辅助器线上大...
指南辅助!小程序广东雀神智能插... 指南辅助!小程序广东雀神智能插件安装下载!解谜真的是有辅助技巧(新版有挂)运小程序广东雀神智能插件安...
第九分钟了解!wepoker作... 第九分钟了解!wepoker作弊辅助,wpk辅助购买,步骤教程(新版有挂)1、完成wepoker作弊...