【Mamba】Mamba的部署

news/2024/8/26 13:12:40 标签: 人工智能

ubuntu系统安装11.6+版本的cuda

可以参考这两篇博客
ubuntu22.04多版本安装cuda及快速切换(cuda11.1和11.8)_ubuntu调整cuda版本
【Linux】在一台机器上同时安装多个版本的CUDA(切换CUDA版本)_linux安装多个cuda

安装CUDA

https://developer.nvidia.com/cuda-toolkit-archive

找到11.8版本的cuda
依次选择Linux x86_64 Ubuntu 22.04 runfile(local)

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.runsudo sh cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run

运行上述两个命令
在这里插入图片描述
用enter把Driver去掉勾选 然后用方向键移动到最下面的enter然后回车

在这里插入图片描述选择no

在这里插入图片描述

出现这样说明cuda安装成功
我们暂时先不去修改环境变量,为了不影响现有的CUDA环境。之后会用脚本进行切换

安装cuDNN

https://developer.nvidia.com/rdp/cudnn-archive

从这里下载cuDNN

在这里插入图片描述
我们输入

cd /usr/local/
ls

现在有三个版本的cuda文件

我们将下载的cudnn解压到对应的文件夹下面并且赋予执行权限

在这里插入图片描述

sudo cp include/cudnn.h /usr/local/cuda-11.8/include
sudo cp lib/libcudnn*   /usr/local/cuda-11.8/lib64
sudo chmod a+r /usr/local/cuda-11.8/include/cudnn.h
sudo chmod a+r /usr/local/cuda-11.8/lib64/libcudnn*

切换CUDA版本

我们使用以下命令在/usr/local/ 目录下新建一个switch-cuda的脚本

sudo vim /usr/local/switch-cuda.sh

把以下代码复制粘贴进去

	#!/usr/bin/env bash
	
	# Copyright (c) 2018 Patrick Hohenecker
	#
	# Permission is hereby granted, free of charge, to any person obtaining a copy
	# of this software and associated documentation files (the "Software"), to deal
	# in the Software without restriction, including without limitation the rights
	# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	# copies of the Software, and to permit persons to whom the Software is
	# furnished to do so, subject to the following conditions:
	#
	# The above copyright notice and this permission notice shall be included in all
	# copies or substantial portions of the Software.
	#
	# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	# SOFTWARE.
	
	# author:   Patrick Hohenecker <mail@paho.at>
	# version:  2018.1
	# date:     May 15, 2018
	
	
	set -e
	
	
	# ensure that the script has been sourced rather than just executed
	if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then
	    echo "Please use 'source' to execute switch-cuda.sh!"
	    exit 1
	fi
	
	INSTALL_FOLDER="/usr/local"  # the location to look for CUDA installations at
	TARGET_VERSION=${1}          # the target CUDA version to switch to (if provided)
	
	# if no version to switch to has been provided, then just print all available CUDA installations
	if [[ -z ${TARGET_VERSION} ]]; then
	    echo "The following CUDA installations have been found (in '${INSTALL_FOLDER}'):"
	    ls -l "${INSTALL_FOLDER}" | egrep -o "cuda-[0-9]+\\.[0-9]+$" | while read -r line; do
	        echo "* ${line}"
	    done
	    set +e
	    return
	# otherwise, check whether there is an installation of the requested CUDA version
	elif [[ ! -d "${INSTALL_FOLDER}/cuda-${TARGET_VERSION}" ]]; then
	    echo "No installation of CUDA ${TARGET_VERSION} has been found!"
	    set +e
	    return
	fi
	
	# the path of the installation to use
	cuda_path="${INSTALL_FOLDER}/cuda-${TARGET_VERSION}"
	
	# filter out those CUDA entries from the PATH that are not needed anymore
	path_elements=(${PATH//:/ })
	new_path="${cuda_path}/bin"
	for p in "${path_elements[@]}"; do
	    if [[ ! ${p} =~ ^${INSTALL_FOLDER}/cuda ]]; then
	        new_path="${new_path}:${p}"
	    fi
	done
	
	# filter out those CUDA entries from the LD_LIBRARY_PATH that are not needed anymore
	ld_path_elements=(${LD_LIBRARY_PATH//:/ })
	new_ld_path="${cuda_path}/lib64:${cuda_path}/extras/CUPTI/lib64"
	for p in "${ld_path_elements[@]}"; do
	    if [[ ! ${p} =~ ^${INSTALL_FOLDER}/cuda ]]; then
	        new_ld_path="${new_ld_path}:${p}"
	    fi
	done
	
	# update environment variables
	export CUDA_HOME="${cuda_path}"
	export CUDA_ROOT="${cuda_path}"
	export LD_LIBRARY_PATH="${new_ld_path}"
	export PATH="${new_path}"
	
	echo "Switched to CUDA ${TARGET_VERSION}."
	
	set +e
	return

按ESC 输入:x 回车保存退出

然后我们再进入/usr/local/

/usr/local/
source switch-cuda.sh

在这里插入图片描述

自动显示我们目前已经安装的CUDA版本
然后我们输入以下命令切换到刚才安装的11.8版本

source switch-cuda.sh 11.8

然后我们看到系统提示我们已经切换到了11.8版本的cuda,为了确认,我们再检查一下
在这里插入图片描述
输入命令

nvcc -V

显示已经切换了版本

Mamba安装

参考教程
【Mamba安装】99%的人都出错!带你手把手解决selective_scan_cuda冲突问题

环境要求

GitHub - state-spaces/s4: Structured state space sequence models

这个是原始版本的Mamba的环境要求
在这里插入图片描述

可以看到,他的要求是

  • Python 3.9+
  • Pytorch 1.10+
  • cuda 11.6+

GitHub - hustvl/Vim: [ICML 2024] Vision Mamba: Efficient Visual Representation Learning with Bidirectional State Space Model

这个是Vim(Vision Mamba)的部署要求

在这里插入图片描述

我们这里以Vim的安装部署要求来,因为Vim依赖于Mamba

  • Python 3.10
  • Pytorch 2.1.1
  • cuda 11.8

新建一个虚拟环境

我们新建一个叫做Vim的虚拟环境

 conda create -n Vim python=3.10
  conda activate Vim
  

在这里去找pytorch的安装版本

https://pytorch.org/

在这里插入图片描述

找到2.1.1版本的pytorch

conda install pytorch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 pytorch-cuda=11.8 -c pytorch -c nvidia

安装packaging

conda install packaging

安装causal-conv1d和mamba-ssm(重点!!!)

首先可以参考一下以前的一些经验和踩坑记录

[最佳实践] conda环境内安装cuda 和 Mamba的安装

运行Mamba项目时无法直接用pip install安装causal_conv1d和mamba_ssm_pip install causal-conv1d

总结一下,常规的方法是直接用pip install
命令如下:

pip install causal_conv1d
python setup.py install

但是有特别大的概率会报各种错误,比如:

  1. Building wheel for causal-conv1d (setup.py) ... error
  2. error: command '/usr/bin/gcc' failed with exit code 1
  3. RuntimeError: Error compiling objects for extension
  4. ERROR: Could not build wheels for causal-conv1d, which is required to install pyproject.toml-based projects
    一种解决方案是git clone源码然后编译

另外一个办法是下载编译好的whl在本地安装或者直接下载源码编译

Releases · Dao-AILab/causal-conv1d

在这里插入图片描述

下载了causal_con1d 的v1.2.0版本的whl

以及

GitHub - state-spaces/mamba: Mamba SSM architecture

在这里插入图片描述
下载了mamba-ssm1.2.0的源码

在这里插入图片描述
放到虚拟环境的文件夹下,打开mamba-1.2.0文件夹

在这里插入图片描述

打开setup.py

修改。
在这里插入图片描述
首先把这三行给注释掉

在这里插入图片描述
然后再加上这三行

然后是第264行 修改

在这里插入图片描述

改成下面的

在这里插入图片描述
不用ninja去构建

保存退出

然后安装causal_conv1d

 pip install causal_conv1d-1.2.0.post2+cu118torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl

在这里插入图片描述

显示成功了

为了验证是否成功

import causal_conv1d

在这里插入图片描述

目测是没有问题的,但是很多博客显示这里还会报错,如果报错,就下载causal_conv1d的源码进行编译

编译的时候
Anaconda3/envs/Vim/lib/python3.10/site-packages/torch/utils下

找到cpp_extension.py 修改

手动加入11.8

在这里插入图片描述
修改后

在这里插入图片描述
然后我们编译 mamba-ssm

安装命令是

pip install . --no-cache-dir --verbose

在这里插入图片描述

报错

显示是cuda版本的问题

在Vim虚拟环境下输入nvcc -V,显示的cuda 版本是11.1
很奇怪
然后在Vim的环境下 cd /usr/local/
source switch-cuda.sh 11.8 就是运行之前写的那个切换cuda版本的脚本
然后再输入nvcc -V,显示的cuda 版本是11.8
然后重新编译,OK了

编译好了

在这里插入图片描述
在这里插入图片描述


http://www.niftyadmin.cn/n/5557999.html

相关文章

防火墙-NAT策略和智能选路

一、背景技术 在日常网络环境&#xff0c;内部网络想要访问外网无法直接进行通信&#xff0c;这时候就需要进行NAT地址转换&#xff0c;而在防火墙上配置NAT和路由器上有点小区别&#xff0c;思路基本一致&#xff0c;这次主要就以防火防火墙配置NAT策略为例&#xff0c;防火墙…

神经网络类型

卷积神经网络 卷积神经网络的概述 一种带有卷积结构的深度神经网络&#xff0c;通过特征提取和分类识别完成对输入数据的判别 卷积神经网络的层级结构 输入层即接收数据的输入&#xff0c;可以处理多维数据&#xff0c;也能对输入特征进行标准化处理&#xff0c;有利于提升…

前后端工作重点小结

前端和后端的区分 前端&#xff08;Frontend&#xff09; 和 后端&#xff08;Backend&#xff09; 是 Web 开发中的两个主要部分&#xff0c;它们有不同的职责和技术栈。 前端&#xff08;Frontend&#xff09; 职责&#xff1a;负责用户界面的呈现和用户交互。主要语言&am…

【瑞吉外卖 | day07】移动端菜品展示、购物车、下单

文章目录 瑞吉外卖 — day71. 导入用户地址簿相关功能代码1.1 需求分析1.2 数据模型1.3 代码开发 2. 菜品展示2.1 需求分析2.2 代码开发 3. 购物车3.1 需求分析3.2 数据模型3.3 代码开发 4. 下单4.1 需求分析4.2 数据模型4.3 代码开发 瑞吉外卖 — day7 移动端相关业务功能 —…

深度解析:disableHostCheck: true引发的安全迷局与解决之道

在Web开发的浩瀚星空中&#xff0c;开发者们时常会遇到各种配置与调优的挑战&#xff0c;其中disableHostCheck: true这一选项&#xff0c;在提升开发效率的同时&#xff0c;也悄然埋下了安全隐患的伏笔。本文将深入探讨这一配置背后的原理、为何会引发报错&#xff0c;以及如何…

vue仿甘特图开发工程施工进度表

前言 本文是根据项目实际开发中一个需求开发的demo&#xff0c;仅用了elementUI&#xff0c;可当作独立组件使用&#xff0c;C V即用。 当然没考虑其他的扩展性和一些数据的校验&#xff0c;主要是提供一个处理思路&#xff0c;有需要的小伙伴可以直接复制&#xff1b;本demo的…

linux学习笔记整理: 关于linux系统操作/安装软件 2024/7/16;

安装软件 安装方式: 二进制安装。---只需要解压就可以。 只针对特殊平台。 比如jdk tomcat RPM&#xff1a; 按照一定的规范就可以按照该软件。 无法安装依赖的文件。 mysql yum 远程安装 基于RPM 帮你把依赖的文件安装上去。 必须联网。 安装源码安装。 查看端口插件: 下载…

新版本WPS不登录无法编辑的解决办法

原因分析&#xff1a;新版本的WPS因加入多种在线功能&#xff0c;建议登录账号获得更加体验 解决办法&#xff1a;首选第一种修改注册表后重启WPS&#xff0c;第二种仅作为临时满足工作需求&#xff0c;过一段时间会自动失效 方法一&#xff1a;键盘同时按下WINR键&#xff0c;…