导航
- Mamba 及 Vim 安装问题参看本人之前博客:Mamba 环境安装踩坑问题汇总及解决方法
- Windows 下 Mamba 的安装参看本人之前博客:Window 下Mamba 环境安装踩坑问题汇总及解决方法 (无需绕过selective_scan_cuda)
- Linux 下VMamba 安装教程参看本人之前博客:VMamba 安装教程(无需更改base环境中的cuda版本)
目录
背景
最近有不少小伙伴在 Linux 上安装 Vmamba (VMamba: Visual State Space Model)时,按照官方的安装命令会遇到各种各样的错误,Linux 版本的问题可参考本人之前的博客——Vmamba 安装教程(无需更改base环境中的cuda版本),本篇主要聚焦于 Windows 下 Vmamba 环境的安装,主要参考 issue。
Windows 下环境准备
- 运行之前需要下载好 Vmamba 官方的源码,用
git
下载方式如下:
git clone https://github.com/MzeroMiko/VMamba.git
cd VMamba
- 前期环境准备,同原来博客 “[Window 下Mamba 环境安装踩坑问题汇总及解决方法 (无需绕过selective_scan_cuda)]” ,具体为:
conda create -n mamba python=3.10
conda activate mamba
conda install cudatoolkit==11.8
pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu118
pip install setuptools==68.2.2
conda install nvidia/label/cuda-11.8.0::cuda-nvcc_win-64
conda install packaging
pip install triton-2.0.0-cp310-cp310-win_amd64.whl
- 安装 Vmamba 其他必须包,只留最后一步编译
pip install -r requirements.txt
cd kernels/selective_scan
Windows 下 selective_scan
的编译
- 将
kernels/selective_scan/csrc/selective_scan/static_switch.h
的BOOL_SWITCH
函数改为
#define BOOL_SWITCH(COND, CONST_NAME, ...) \
[&] { \
if (COND) { \
static constexpr bool CONST_NAME = true; \
return __VA_ARGS__(); \
} else { \
static constexpr bool CONST_NAME = false; \
return __VA_ARGS__(); \
} \
}()
这一步是将 constexpr
改为 static constexpr
。
- 在如下文件
kernels/selective_scan/csrc/selective_scan/cus/selective_scan_bwd_kernel.cuh
kernels/selective_scan/csrc/selective_scan/cus/selective_scan_fwd_kernel.cuh
kernels/selective_scan/csrc/selective_scan/cusoflex/selective_scan_bwd_kernel_oflex.cuh
kernels/selective_scan/csrc/selective_scan/cusoflex/selective_scan_fwd_kernel_oflex.cuh
开头加入:
#ifndef M_LOG2E
#define M_LOG2E 1.4426950408889634074
#endif
- 完成上述修改后,执行
pip install .
一般即可顺利编译,成功安装。 - 本人编译好的Windows 下的whl 也有:selective-scan-0.0.2 ,可直接下载安装或联系主页vx自取。利用 whl 安装命令为:
pip install selective-scan-0.0.2-cp310-cp310-win-amd64.whl
Windows 下 selective_scan
的编译出现的问题和解决(20240714)
1. error: identifier “M_LOG2E” is undefined
在Windows下会出现如下报错:
出现这种情况的原因,可参考 issue:
Note for the owners: The reason for needing #define is stated here: https://stackoverflow.com/a/56974843:
“On windows it is using the Microsoft compiler for that. So the Microsoft compiler is correct to disallow VLA, and there is no way to avoid this AFAIK. Your code works on linux, because on linux nvcc uses the g++ host compiler, and it allows (in a non-standard-compliant way) the use of a VLA in C++ host code.”
因此,只需在四个文件下加入以下代码即可
#ifndef M_LOG2E
#define M_LOG2E 1.4426950408889634074
#endif
具体文件和步骤参看前一节。
2. error C2975: “kDeltaSoftplus_”
在Windows下会出现如下大量报错:
error C2975: “kDeltaSoftplus_”:“Selective_Scan_bwd_kernel_traits”的模板参数无效,应为编译时常量表达式
如下图所示:
只需把static_switch.h
函数里的 constexpr
改为 static constexpr
,参考 issue。具体步骤参看前一节。