Mamba的论文:https://arxiv.org/abs/2312.00752
Mamba的github:https://github.com/state-spaces/mamba
一、Ubuntu安装
直接新建一个环境是最好的,不然很容易产生各种冲突
bash
# 创建环境和相关包
conda create -n mamba python=3.10.13
conda activate mamba
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
# 安装conv1d和mamba
git clone https://github.com/Dao-AILab/causal-conv1d.git
cd causal-conv1d
git checkout v1.2.0 # 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.2.0 # current latest version tag
MAMBA_FORCE_BUILD=TRUE pip install .
中间只是需要等待一些时间,结束完就可以测试使用啦,官方提供的测试代码如下:
python
import torch
from mamba_ssm import Mamba
batch, length, dim = 2, 64, 16
x = torch.randn(batch, length, dim).to("cuda")
model = Mamba(
# This module uses roughly 3 * expand * d_model^2 parameters
d_model=dim, # Model dimension d_model
d_state=16, # SSM state expansion factor
d_conv=4, # Local convolution width
expand=2, # Block expansion factor
).to("cuda")
y = model(x)
assert y.shape == x.shape
二、Windows安装
- 相关包下载
Mamba主要涉及到四个包,packaging、triton、conv1d、mamba,其中第一个是windows可用的,直接安装就行,后三个是linux版本,但是有大佬们提供了编译好的文件。
triton:https://hf-mirror.com/r4ziel/xformers_pre_built/blob/main/triton-2.0.0-cp310-cp310-win_amd64.whl
conv1d和mamba:Mamba-Packages,这里面也包括了triton。
下载好三个.whl
文件后,就可以开始一路安装了
- 安装
bash
# 环境创建和基础安装
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
# 包安装,记得先进入whl对应的目录
pip install triton-2.0.0-cp310-cp310-win_amd64.whl
pip install causal_conv1d-1.1.1-cp310-cp310-win_amd64.whl
pip install mamba_ssm-1.2.0.post1-py3-none-any.whl
接下来就是等待安装完毕
参考链接
Windows和Linux系统上的Mamba_ssm环境配置