项目场景:
最近Mamba
有关的论文引起了众多人的关注,虽然Mamba
论文自身被ICLR 2024拒稿,但是其衍生的模型层出不穷,诸如 Vim 和 Umamba 等。笔者在配置相关环境(版本安装要求:PyTorch 1.12+;CUDA 11.6+)时,发现按照他们给的安装方法12安装时会遇到非常多的bug,主要集中在causal-conv1d
和mamba-ssm
上,原因都是版本兼容问题,特此记录。
问题描述
直接 pip 安装或者下载工程文件再setup,出现了以下报错但不限于:
Building wheel for causal-conv1d (setup.py) ... error
error: command '/usr/bin/gcc' failed with exit code 1
RuntimeError: Error compiling objects for extension
ERROR: Could not build wheels for causal-conv1d, which is required to install pyproject.toml-based projects
Connection timed out> [end of output]
ModuleNotFoundError: No module named 'packaging'
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/cuda/bin/nvcc'
error: subprocess-exited-with-error
原因分析:
大部分原因是CUDA版本不匹配,有部分是网络原因。
解决方案:
-
使用网友配置好的Docker环境,参考:解决causal_conv1d和mamba_ssm无法安装 -> 直接使用Mamba基础环境docker镜像。
DockHub仓库地址:https://hub.docker.com/repository/docker/kom4cr0/cuda11.7-pytorch1.13-mamba1.1.1/general
代码:docker pull kom4cr0/cuda11.7-pytorch1.13-mamba1.1.1:1.1.1
-
直接下载工程文件,再setup。具体可参考:运行Mamba项目时无法直接用pip install安装causal_conv1d和mamba_ssm 和复现U-Mamba(笔者依然未安装成功,但是原作者以及GitHub issue 里有部分人可以安装成功)
参考步骤为:git clone https://github.com/Dao-AILab/causal-conv1d.git cd causal-conv1d git checkout v1.1.1 # current latest version tag CAUSAL_CONV1D_FORCE_BUILD=TRUE pip install . cd .. git clone https://github.com/state-spaces/mamba.git cd mamba git checkout v1.1.1 # current latest version tag pip install .
-
受博文 “flash-attention踩坑:使用conda管理CUDA”启发,合理调整按照顺利,先安装CUDA,并且安装cuda-nvcc,正确的安装步骤如下:
conda create -n your_env_name python=3.10.13 conda activate your_env_name conda install cudatoolkit==11.8 -c nvidia pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu118 conda install -c "nvidia/label/cuda-11.8.0" cuda-nvcc conda install packaging pip install causal-conv1d==1.1.1 pip install mamba-ssm
https://github.com/bowang-lab/U-Mamba ↩︎
https://github.com/hustvl/Vim ↩︎