‘’’

  • @Author: Ruochen Cui
  • @Date: 2024-04-12 07:46:27
  • @Last Modified by: Ruochen Cui
  • @Last Modified time: 2024-04-12 07:46:27
  • @Desc:
    ‘’’

anaconda 安装

从官网直接下载

1
2
wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh
bash Anaconda3-2023.09-0-Linux-x86_64.sh -p anaconda/ -u

一直yes, 包括添加到环境

1
2
echo 'export PATH="/home/cuiruochen/anaconda/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

此时输入conda env list, 能看到base环境

参考博客

conda 环境配置

LLaVA-1.5环境配置及运行

cuiruochen文件夹路径下, 下载LLaVA-1.5代码

1
2
git clone https://github.com/haotian-liu/LLaVA.git
cd LLaVA

git 无法连接, 输入以下指令更新代理

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

创建llava虚拟环境

1
2
3
conda create -n llava python=3.10 -y
conda activate llava
pip install --upgrade pip # enable PEP 660 support

模型预测安装

1
pip install -e .

模型训练环境安装

(若无需进一步训练,只是部署,则可暂时跳过本步骤)

1
2
pip install -e ".[train]"
pip install flash-attn --no-build-isolation # 可能安装失败

如果报错OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root., note: This is an issue with the package mentioned above, not pip.

一般是deepspeed库安装出错, 由于cuda重新安装或没有在默认路径/usr/local/下,因此没有找到系统环境变量CUDA_HOME.

命令行exportCUDA安装路径

找到自己的cuda安装路径后,使CUDA_HOME指向相应的位置即可:

1
export CUDA_HOME=/user_path/cuda-12.0/

需要自行找到cuda地址替换user_path

经检查, 具有/bin/nvcc的文件夹路径有/home/kongfei/lun/cuda-11.7, 使用export CUDA_HOME=/home/kongfei/lun/cuda-11.7

module load加载CUDA环境

可以通过指令module avail查找可用环境, 发现有cuda/11.3.1cuda/12.1.1两个环境, 再通过指令module load加载指定环境

module指令需要source /etc/profile后才能使用

想要每次登陆时自动输入指令, 可以在.bashrc文件末尾输入

参考博客1

参考博客2

本地电脑下载LLaVA-1.5 7B和CLIP-ViT的参数并上传

https://huggingface.co/liuhaotian/llava-v1.5-7b/tree/main下载LLaVA-1.5 7B的参数, 并上传至服务器model/llava-v1.5-7b/

https://huggingface.co/openai/clip-vit-large-patch14-336/tree/main下载CLIP-ViT的参数, 并上传至服务器model/clip-vit-large-patch14-336/

修改在llava-v1.5-7b/config.json文件, 把mm_vision_tower修改为刚刚上传的clip-vit-large-patch14-336文件夹路径

这里使用XShell和Xftp通过跳板机将文件传输到服务器上

运行demo

运行以下代码, –image-file后面可以换成你自己想要交流的图片, –load-4bit是使用量化位(4 位)启动模型工作线程, 减少GPU内存占用的情况下运行推理

1
CUDA_VISIBLE_DEVICES=7 python -m llava.serve.cli     --model-path /home/cuiruochen/model/llava-v1.5-7b     --image-file "https://llava-vl.github.io/static/images/view.jpg"     --load-4bit

HA-DPO 环境配置及运行

1
2
3
conda create -n hadpo python==3.9
conda activate hadpo
pip install -e .