985“互联网+”国奖保研小哥哥手把手教你运行年度最火推理分割大模型Lisa~

527 阅读2分钟

lisa.jpg

一、代码网址

dvlab-research/LISA: Project Page for "LISA: Reasoning Segmentation via Large Language Model" (github.com) image.png

二、文章网址

[2308.00692] LISA: Reasoning Segmentation via Large Language Model (arxiv.org) image.png

三、运行步骤

  1. 下载Lavva、SAM、Lisa等模型权重于本地,将权重本地地址放在train_ds.py(用于训练)、chat.py(用于推理)对应位置中
  2. 建立Conda Environment——Python version3.10
  3. 安装torch==1.3.1
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia
  1. 安装deepspeed==0.9.0
pip install deepspeed==0.9.0
  1. 安装transformers库
pip install transformers
  1. 安装peft库
pip install peft
  1. 安装tensorboard库
pip install tensorboard
  1. 此时会报llava名字冲突的错误
ValueError: 'llava' is already used by a Transformers config, pick another name.

是由于transformer版本问题,此时对transformers进行降级,降级到4.30.1或者4.30.0

pip install transformers==4.34.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. 安装einops库
pip install einops
  1. 安装opencv库
conda install opencv
  1. 安装pycocotools库
pip install pycocotools
  1. 安装skimage库
pip install scikit-image
  1. 此时会报SentencePiece库缺失的问题
LlamaTokenizer requires the SentencePiece library but it was not found in your environment. Checkout the instructions on the installation page of its repo: 
https://github.com/google/sentencepiece#installation and follow the ones that match your environment. Please note that you may need to restart your runtime after installation.

安装 SentencePiece 库

pip install sentencepiece
  1. 安装mpi4py库
conda install mpi4py
  1. 安装openmpi库
conda install openmpi
  1. 此时会报NumPy版本不匹配或者库兼容性问题的问题
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

更新NumPy版本

pip install --upgrade numpy

四、批量推理

我这里写了一个批量图像推理分割的函数,可用于对指定整个文件夹中的图像进行指定任务的推理分割。 image.png 我的电脑配置是Ubuntu22.04,4090显卡,GPU 24G显存,cuda11.7的,此处我用lavva-7b权重(且图像分辨率等都有调整降低)进行推理,显存占用已达到17+ G,大语言模型的威力还是顶奥~~

1709639894840.png

五、结语

        大语言模型能够生成连贯、有逻辑的文本,解答复杂的问题,甚至在艺术创作和编程等领域展现出惊人的能力。这些成就不仅展示了人工智能技术的迅猛进步,也为各行各业带来了新的可能性。大语言模型的训练需要大量数据,这引发了关于数据收集、处理和存储的隐私问题。此外,模型的滥用也可能导致安全风险,例如生成有害内容或进行社交工程攻击。
        总的来说,大语言模型的出现是人工智能领域的一次巨大飞跃,它们提供了前所未有的机会,同时也提出了新的挑战和责任。社会需要通过持续的研究、合作和政策制定,确保技术的发展能够惠及人类并保护我们的共同价值观。

image.png