1. 环境
1.1 项目拉取
过早的文件结束符(EOF)
使用git clone时发现老是无法克隆项目:
1
2
3
4
5
6
7
8git clone https://github.com/guoyww/AnimateDiff.git
正克隆到 'AnimateDiff'...
remote: Enumerating objects: 718, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (26/26), done.
fatal: 远端意外挂断了/718), 46.53 MiB | 2.34 MiB/s
fatal: 过早的文件结束符(EOF)
fatal: index-pack网不好或者项目含有多个版本,一起下载空间较大,可以选择下载最新版本
1
git clone --depth 1 https://github.com/guoyww/AnimateDiff.git
1.2 环境配置
ImportError: cannot import name ‘cached_download’ from ‘huggingface_hub’
运行:
python -m scripts.animate --config configs/prompts/1_animate/1_1_animate_RealisticVision.yaml
出现错误:
1
ImportError: cannot import name 'cached_download' from 'huggingface_hub'
版本问题,项目中使用diffusers库下载了
huggingface_hub
,但是下载的最新版本,这个版本没有cached_download
解决
查看项目的requirement.txt:
1
2
3
4
5
6
7
8
9
10
11
12
13torch==2.3.1
torchvision==0.18.1
diffusers==0.11.1
transformers==4.25.1
xformers==0.0.27
imageio==2.27.0
imageio-ffmpeg==0.4.9
decord==0.6.0
omegaconf==2.3.0
gradio==3.36.1
safetensors
einops
wandb根据diffusers库的版本去github找源码
查看他的
setup.py
找到相关字段:1
"huggingface-hub>=0.10.0",
重新安装这个包
发现这个问题解决了,但是后面还有问题:
1
snapshot_download() got an unexpected keyword argument 'local_dir'
还是版本问题,刚刚安装0.10.0版本时发现有:
1
2
3ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
gradio 3.36.1 requires huggingface-hub>=0.14.0, but you have huggingface-hub 0.10.0 which is incompatible.
gradio-client 1.7.0 requires huggingface-hub>=0.19.3, but you have huggingface-hub 0.10.0 which is incompatible.换成0.19.3试试,问题解决
python: symbol lookup error: nvidia/cudnn/lib/libcudnn_cnn_infer.so.8: undefined symbol: _Z20traceback_iretf_implPKcRKN5cudnn16InternalStatus_tEb, version libcudnn_ops_infer.so.8
应该是cudnn的版本兼容问题
使用代码测试:
1
2
3
4
5import torch
print(torch.__version__)
print(torch.version.cuda)
print(torch.backends.cudnn.version())1
2
3
raise RuntimeError(
RuntimeError: cuDNN version incompatibility: PyTorch was compiled against (8, 9, 2) but found runtime version (8, 4, 0). PyTorch already comes bundled with cuDNN. One option to resolving this error is to ensure PyTorch can find the bundled cuDNN. Looks like your LD_LIBRARY_PATH contains incompatible version of cudnn. Please either remove it from the path or install cudnn (8, 9, 2)解决:
1
unset LD_LIBRARY_PATH
GPT解释:
LD_LIBRARY_PATH
是一个环境变量,用于指定 Linux 系统在运行时查找共享库(动态链接库)的路径。这个环境变量的作用主要是告诉操作系统,在哪些目录下寻找需要的共享库文件。主要作用:
- 库文件搜索路径:
LD_LIBRARY_PATH
指定了操作系统在执行程序时,搜索共享库(如.so
文件)的位置。当一个程序运行时,它可能依赖于多个共享库,这些库可能存放在不同的文件夹中。LD_LIBRARY_PATH
就是让操作系统知道应该在哪里查找这些库。 - 覆盖系统默认库路径:
如果
LD_LIBRARY_PATH
设置了特定的路径,操作系统就会优先在这些路径下查找所需的库,而不是系统默认的路径(如/lib
,/usr/lib
等)。
举例说明:
假设你安装了 CUDA 和 cuDNN,它们通常会安装在
/usr/local/cuda-11.6/lib64
目录下。如果你有多个版本的 CUDA 和 cuDNN,可能需要用LD_LIBRARY_PATH
来告诉操作系统使用哪个版本。例如:-- 设置
LD_LIBRARY_PATH
: export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64:$LD_LIBRARY_PATH这意味着,操作系统会首先在
/usr/local/cuda-11.6/lib64
目录下查找共享库文件。如果这个目录下没有找到,才会继续去其他默认路径查找。为什么你遇到的问题会与
LD_LIBRARY_PATH
相关?在你的情况中,PyTorch 是在 CUDA 12.1 和 cuDNN 8.9.2 上编译的,但是你的
LD_LIBRARY_PATH
环境变量指向了一个不兼容的 CUDA 11.6 目录,这导致系统加载了 cuDNN 8.4.0,与 PyTorch 所需的 cuDNN 8.9.2 版本不兼容,从而导致了运行时错误。当你
unset LD_LIBRARY_PATH
后,系统就不会加载指定的路径,而是使用 PyTorch 自带的 cuDNN 版本,解决了版本不匹配的问题。总结:
LD_LIBRARY_PATH
的作用是告诉操作系统在哪里查找共享库。- 它影响程序运行时使用的库版本,尤其在有多个版本的库时特别重要。
- 如果不小心设置了错误的路径(比如指向不兼容的 CUDA/cuDNN 版本),会导致库版本冲突,从而引发错误。
- 库文件搜索路径:
2. 运行
2.1 测试
- comunity models
1 | python -m scripts.animate --config configs/prompts/1_animate/1_1_animate_RealisticVision.yaml |
- MotionLoRA control
1 | python -m scripts.animate --config configs/prompts/2_motionlora/2_motionlora_RealisticVision.yaml |
- SparseCtrl RGB and sketch
1 | python -m scripts.animate --config configs/prompts/3_sparsectrl/3_1_sparsectrl_i2v.yaml |