Anaconda:Windows下Accelerate+DeepSpeed安装(超详细版本)

创建虚拟环境,防止破坏原环境

创建新的虚拟环境

conda create -n yourEnv python=3.11.9  
#(推荐3.10或者3.11,因为Hugging-face上triton目前只适配到这个版本)

激活虚拟环境并进入

conda activate deepspeed #我的新虚拟环境命名为deepspeed

检查Pytorch是否安装,一定要安装相适配的GPU版本

检查torch版本,判断是否为GPU版本

import torch
print(torch.__version__)
print(torch.cuda.is_available())#GPU版本会返回True,否则返回False

若为GPU版本则需要卸载Pytorch并重新安装

GPU版本Pytorch安装

CUDA和cuDNN检查和安装

先查看设备上CUDA版本

打开命令行,并输入nvidia-smi查看设备

查看驱动版本和CUDA版本是否相匹配

官网文档:CUDA 12.6 Update 1 Release Notes (nvidia.com)

如果不匹配则需要更新驱动

参考文章:超实用总结!!显卡驱动无法支持cuda版本问题(终于捋清楚显卡驱动、cuda、pytorch的对应关系了)_cuda11.8支持11.7显卡吗-CSDN博客

如果设备没有安装CUDA,可以前往官网下载

注册账号后即可登录下载

下载完成后双击运行

这里是设置安装时缓存存放的位置,直接默认路径就行

选择自定义安装

全选所有组件

选择安装位置,一定要记住这个安装路径,之后要用到!

等待安装完毕,检查CUDA是否安装成功

打开命令行,输入nvcc -V查看

还可以试运行C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\extras\demo_suite下的测试文件deviceQuery.exe和bandwidthTest.exe

tips:直接cd到该目录会出现如下报错,此时需要在有空格的字段两旁加上" ",如“Program Files”

最后显示是PASS即安装成功

CUDA安装成功后安装cuDNN,前往官网下载合适的压缩包

下载成功后解压得到如下文件夹

将文件夹内的bin,include,lib文件夹的文件分别复制到CUDA安装路径下的bin,include,lib文件夹内。注意是将文件夹内的文件复制到目标文件夹内,而不是将文件夹复制过去

查看cuDNN是否安装成功

print(torch.backend.cudnn.is_available())

安装成功则会输出True

CUDA和cuDNN安装成功后,可以安装GPU版本的Pytorch了,否则会一直编译失败。

GPU版本Pytorch下载和安装

前往官网下载Pytorch:PyTorch

推荐conda下载,因为CUDA具有版本向下兼容性,选择不高于自己CUDA版本的Pytorch进行下载

在原先创建的虚拟环境下,输入官网根据选项自动给出的Command命令

耐心等待安装完成(我这里已经安装好了)

Accelerate安装

Accelerate安装

虚拟环境内输入

pip install accelerate

具体可以参考hugging-face官网给出的文档:Installation (huggingface.co)

安装完毕后对accelerate进行配置

直接复制官网的配置命令

python -c "from accelerate.utils import write_basic_config; write_basic_config(mixed_precision='fp16')"

输入accelerate env来查看具体配置情况

至此完成accelerate的安装

DeepSpeed安装

deepspeed官网文档:Installation Details - DeepSpeed

DeepSpeed在线安装

官网上直接pip install deepspeed即可安装

pip install deepspeed

但是绝大部分情况会出现报错

问题一:ModuleNotFoundError: No module named 'cpuinfo'

此时先pip install py-cpuinfo即可

pip install cpuinfo

安装成功后再次安装deepspeed

问题二:Setting accelerator to CPU. If you have GPU or other accelerator, we were unable to detect it.

没有安装GPU版本的Pytorch,或者Pytorch版本和CUDA版本不匹配,回到GPU版本Pytorch安装进行阅读。

问题三:OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.

这是因为存在两个libiomp5md.dll文件,在anaconda/env文件夹内找到虚拟环境,在其中搜索该文件,会发现确实存在两个libiomp5md.dll,将第二个文件剪切出去备份,或者直接删除。

问题四: LINK : fatal error LNK1181: 无法打开输入文件“aio.lib”  LINK : fatal error LNK1181: 无法打开输入文件“cufile.lib”

这是由于缺少async_io库导致的,设置DS_BUILD_AIO=0即可解决,遇到该问题则无法使用pip install deepspeed来进行安装,需要下载到本地进行编译和安装

DeepSpeed本地安装

git clone文件到本地

选择一个存放文件的路径,例如我存放在虚拟环境文件夹内

输入指令

git clone https://github.com/microsoft/DeepSpeed.git

tips:若没有安装git则会出现如下报错

此时需要输入conda install git进行安装

conda install git

等待安装完成

安装完成后即可下载deepspeed文件到目标路径

安装文件编译

接着在命令行内进入该文件夹,并且设置环境

cd DeepSpeed
Set-Item Env:\DS_BUILD_OPS 0

之后运行build_win.bat编译安装文件

直接将文件夹内的build_win.bat拖入命令行内

回车运行即可,等待编译完成

编译完成后,文件夹内会多出两个文件夹

dist文件夹内存放的编译好的whl文件,命令行内进入dist文件夹可以看到

编译包安装

接着直接安装编译好的包即可

pip install deepspeed-0.15.2+unknown-py3-none-any.whl

至此deepspeed便安装完成

问题一:The system cannot find the file specified.

[24 lines of output]
  The system cannot find the file specified.
  The system cannot find the file specified.
  The system cannot find the file specified.
  The system cannot find the file specified.
  Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "C:\Users\RGWyo\AppData\Local\Temp\pip-install-pdq_etar\deepspeed_5154de904eb44c55af7b10637df57bda\setup.py", line 152, in <module>
      abort(f"Unable to pre-compile {op_name}")
    File "C:\Users\RGWyo\AppData\Local\Temp\pip-install-pdq_etar\deepspeed_5154de904eb44c55af7b10637df57bda\setup.py", line 48, in abort
      assert False, msg
  AssertionError: Unable to pre-compile sparse_attn
  DS_BUILD_OPS=1
   [WARNING]  cpu_adam requires the 'lscpu' command, but it does not exist!
   [WARNING]  cpu_adam attempted to query 'lscpu' after failing to use py-cpuinfo to detect the CPU architecture. 'lscpu' does not appear to exist on your system, will fall back to use -march=native and non-vectorized execution.
   [WARNING]  cpu_adam requires the 'lscpu' command, but it does not exist!
   [WARNING]  cpu_adam attempted to query 'lscpu' after failing to use py-cpuinfo to detect the CPU architecture. 'lscpu' does not appear to exist on your system, will fall back to use -march=native and non-vectorized execution.
   [WARNING]  cpu_adagrad requires the 'lscpu' command, but it does not exist!
   [WARNING]  cpu_adagrad attempted to query 'lscpu' after failing to use py-cpuinfo to detect the CPU architecture. 'lscpu' does not appear to exist on your system, will fall back to use -march=native and non-vectorized execution.
   [WARNING]  cpu_adagrad requires the 'lscpu' command, but it does not exist!
   [WARNING]  cpu_adagrad attempted to query 'lscpu' after failing to use py-cpuinfo to detect the CPU architecture. 'lscpu' does not appear to exist on your system, will fall back to use -march=native and non-vectorized execution.
   [WARNING]  please install triton==1.0.0 if you want to use sparse attention
   [WARNING]  One can disable sparse_attn with DS_BUILD_SPARSE_ATTN=0
   [ERROR]  Unable to pre-compile sparse_attn
  [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

这是由于没有安装triton包或者是triton版本太低,可以在Hugging-face网站上下载对应Python版本的triton包

下载后得到whl包,直接pip install即可

pip install triton-2.1.0-cp311-cp311-win_amd64.whl

问题二:hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError:[WinError 2]系统找不到指定的文件

这是由于build_win.bat编译时,出现setup.py和subprocess.py无法识别CUDA路径

此时用文本编辑器打开build_win.bat文件,并将其中set CUDA_HOME=%CUDA_PATH%设置为CUDA的安装路径即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

搞定ML

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值