Ubuntu24.04环境下causal_conv1d和mamba_ssm安装
环境:WSL的Ubuntu24.04
1.创建conda环境,其中python版本为3.10.13
2.当前conda环境依次执行下面命令:
conda install cudatoolkit==11.8 -c nvidia
pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 -f https://mirrors.aliyun.com/pytorch-wheels/cu118
conda install -c "nvidia/label/cuda-11.8.0" cuda-nvcc
conda install packaging
3.安装causal_conv1d和mamba_ssm
3.1尝试使用pip线上安装causal_conv1d:
pip install causal-conv1d==1.5.2
失败。
3.2尝试本地安装:
在
https://github.com/Dao-AILab/causal-conv1d/releases/tag/v1.5.0
下载
causal_conv1d-1.5.0+cu118torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
在
https://github.com/state-spaces/mamba/releases/tag/v2.0.3
下载
mamba_ssm-2.0.3+cu118torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
注意这两个whl文件名中的“cu”后的数字(即cuda版本)要与上一步安装的cuda版本相同,“torch”后面的数字要与上一步安装的torch版本相同,“cp”后面的数字要与你当前环境的python版本相同。
在这两个whl文件所在目录下分别执行:
pip install 文件名
根据打印信息确定是否安装成功。
python导入:
from causal_conv1d import causal_conv1d_fn, causal_conv1d_update
但打印如下信息:
from causal_conv1d import causal_conv1d_fn, causal_conv1d_update
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.2.6 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
...
/miniconda3/envs/mapy31013/lib/python3.10/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:84.)
device: torch.device = torch.device(torch._C._get_default_device()), # torch.device('cpu'),
就是说当前虚拟环境的NumPy版本为numpy2+,需要使用numpy<2版本才能导入causal_conv1d。
于是先
pip uninstall numpy
在
https://pypi.org/project/numpy/
网页的左侧点击“Release history”找到合适的numpy版本(我选的是1.26.4),再执行
pip install numpy==1.26.4
顺利安装numpy1.26.4后再次执行
from causal_conv1d import causal_conv1d_fn, causal_conv1d_update
不报错则安装成功。
3.3python导入:
from mamba_ssm import Mamba, Mamba2
不报错则mamba安装成功。