赞
踩
CogVideoX-2b是智谱ai开源的文生视频模型
使用diffusers可以在Windows上直接推理,如果使用sat就会报错,所以Windows上用sat有很多要注意的地方
先设置环境变量
- set DISTUTILS_USE_SDK=1
- set PL_TORCH_DISTRIBUTED_BACKEND=gloo
- set USE_LIBUV=0
让pytorch使用gloo,因为nccl不支持Windows,同时禁用libuv, pytorch的cuda版本要和本机cuda版本一样,不然无法编译成功,这里选择cuda12.4
- conda create -n cogvideo python=3.10
- conda activate cogvideo
- pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 -U
然后重头戏是Windows下deepspeed的编译,先拉取deepspeed的源码
- git clone https://github.com/microsoft/DeepSpeed
- cd DeepSpeed
64位Windows11用管理员权限打开x64 Native Tools Command Prompt for VS 2022(一定是x64不是x86)运行
build_win.bat
等到编译完成之后在dist目录下就是生成的whl文件,pip安装一下就完成了deepspeed的安装
我在win11+cuda12.4+python 3.10环境下编译好的whl文件链接caojiachen1/deepspeed_prebuilt · Hugging Face, 如果同环境可能可以跳过编译直接安装,不过我没试过.
剩下步骤和官方一样,在sat目录下创建inference.bat文件
- @echo off
-
- echo CUDA_VISIBLE_DEVICES=%CUDA_VISIBLE_DEVICES%
-
- set "WORLD_SIZE=1"
- set "RANK=0"
- set "LOCAL_RANK=0"
- set "LOCAL_WORLD_SIZE=1"
-
- set run_cmd=python sample_video.py --base configs/cogvideox_2b_infer.yaml
-
- echo %run_cmd%
- %run_cmd%
-
- echo DONE on %COMPUTERNAME%
运行inference.bat就能顺利在windows下用sat进行推理
如果仍然报错RuntimeError: Distributed package doesn't have NCCL built in,环境变量没有起作用,就在sat/arguments.py的函数initialize_distributed(args)下面加一句
args.distributed_backend = "gloo"
强制使用gloo.
C:\Users\UserName\.triton\autotune目录也要清空
Windows下使用diffusers和sat都比Linux下慢多了,极度不建议使用Windows,我亲测Windows可能要花费Linux下两倍的时间,所以Windows下还是最好用wsl.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。