win10下cuda12.1 +troch2.4.1+vs2022环境下编译安装flash-attn

步骤一 下载项目

先下载 https://github.com/Dao-AILab/flash-attention,然后在conda环境中进入项目目录

步骤二 安装依赖项

执行以下命令,安装cutlass库,该库为编译flash-attn的必须依赖

复制代码
conda update --force conda 
conda install conda-forge::cutlass

conda下查找: https://anaconda.org/conda-forge/

步骤三 设置include目录

在flash-attention项目下,setup.py,第300行,添加 "c:/Users/Administrator/miniconda3/Library/include",这里为自己conda环境下的include目录,该命令下有conda安装的库文件,如cutlass。

具体修改效果如下

步骤四 突破vs2022与cuda版本限制

在cuda v12.1\include\crt\host_config.h下,表明不支持vs2022,强制进行编译会输出以下报错

txt 复制代码
error -- unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk

参考:https://blog.csdn.net/lishiyu93/article/details/114599859,修改_MSC_VER的版本范围 原先是1940,被博主修改成了2940

在C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\yvals_core.h中,表明只支持cuda12.4以上的版本,将原来的代码参考 https://blog.csdn.net/weixin_55361556/article/details/141465456 ,修改为 #if __CUDACC_VER_MAJOR__ < 10 || (__CUDACC_VER_MAJOR__ == 10 && __CUDACC_VER_MINOR__ < 1)

步骤五 进行编译

执行 python setup.py build,进行编译

步骤六 生成whl文件

执行python .\setup.py bdist_wheel生成whl文件,命令行输出如下

生成的whl文件在dist目录下

博主编译好的whl文件下载地址: https://download.csdn.net/download/a486259/89839302

步骤七 安装包

执行 pip install .\flash_attn-2.6.3-cp38-cp38-win_amd64.whl 安装包

相关推荐
殇淋狱陌几秒前
Python列表知识思维导图
开发语言·python·学习
Web极客码10 分钟前
如何通过 Python + LLM 用最少的 Token 完成精准推荐任务
开发语言·人工智能·python·ai
一晌小贪欢29 分钟前
第26节:自动化办公——利用 Python 自动生成动态分析报告 (PPT/PDF)
开发语言·python·数据分析·自动化·powerpoint·pandas·数据可视化
西西弗Sisyphus1 小时前
YOLO26 自定义损失函数 重写 init_criterion 方法 损失类不继承基类
pytorch·python·yolo·yolo11·yolo26
weixin_408266341 小时前
H20训练CPGNET环境搭建
深度学习
装不满的克莱因瓶1 小时前
RLHF中的PPO算法——大语言模型对齐优化的核心引擎
人工智能·python·深度学习·算法·机器学习·语言模型·自然语言处理
c_lb72881 小时前
期货主连研究具体月实盘:KQ 连续与标的月份偏差怎么记
python·区块链
绘梨衣5471 小时前
采集基类设计遇到的描述符bug
爬虫·python·bug
TechWayfarer1 小时前
IP精准定位服务在保险行业的接入实践:区域需求洞察与精准服务
数据库·python·tcp/ip·flask
Li#2 小时前
AI编写操作使用说明书需要用到的工具和能力
python·ai编程·ai写作