国内部署 LLaVA-v1.6

目录

一、安装

二、LLaVA-v1.6 模型下载 

三、ViT 模型下载

四、终端测试

五、Web 测试

六、作者文章引用


一、安装

  1. 克隆仓库并导航到 LLaVA 文件夹
    git clone https://github.com/haotian-liu/LLaVA.git
    cd LLaVA
  2. 安装软件包
    conda create -n llava python=3.10 -y
    conda activate llava
    pip install --upgrade pip  # enable PEP 660 support
    pip install -e .
  3. 为训练安装其他包(可选)
    pip install -e ".[train]"
    pip install flash-attn --no-build-isolation
  4. 升级 
    git pull
    pip install -e .
    
    # 如果在升级过程中报错,
    # 尝试运行以下代码 (注意删除 #)
    # pip install flash-attn --no-build-isolation --no-cache-dir

二、LLaVA-v1.6 模型下载 

  1. 使用 Hugging Face 的官方下载工具 cli
    pip install -U huggingface_hub
     
  2. 更换镜像源
    export HF_ENDPOINT=https://hf-mirror.com
     这里也可以直接写进~/.bashrc

  3.  下载模型
    huggingface-cli download --resume-download liuhaotian/llava-v1.6-vicuna-7b --local-dir /LLaVA/llava-v1.6-vicuna-7b
    
    #--local-dir后面的参数可以替换成自己的实际保存路径

    开始下载模型

三、ViT 模型下载

  1. 通过以下代码下载视觉编码权重
    huggingface-cli download --resume-download openai/clip-vit-large-patch14-336 --local-dir /LLaVA/clip-vit-large-patch14-336
    
    #--local-dir后面的参数可以替换成自己的实际保存路径
     正常运行示例:
  2. 修改 llava-v1.6-vicuna-7b/config.json 文件,将 "mm_vision_tower" 修改为 clip-vit-large-patch14-336 文件夹路径。

        

四、终端测试

  1. 在终端运行以下命令 
    python -m llava.serve.cli --model-path {模型权重路径} --image-file "https://llava-vl.github.io/static/images/view.jpg" --load-4bit
    
    #示例:python -m llava.serve.cli --model-path /LLaVA/llava-v1.6-vicuna-7b --image-file "https://llava-vl.github.io/static/images/view.jpg" --load-4bit
    
  2. 测试结果

五、Web 测试

注意:这里我们需要准备 3 个终端

  1. (终端1)启动控制器
    python3 -m llava.serve.controller --host 0.0.0.0 --port 20000
    
     运行结果:
  2. (终端2)终端启动 gradio Web 服务器
    python3 -m llava.serve.gradio_web_server --controller http://localhost:20000 --model-list-mode reload --share
    
    #在服务器中运行,应用服务器网址替换 0:0:0:0。
    #即在客户端浏览器中输入网址:服务器ip:端口号。

    注意:

    此处容易报错,如果在完成第 3 步后打开 Web 页面出现如下问题:

    SyntaxError: 意外的令牌 'I', “Internal S”...是无效的 JSON

    运行以下命令重新安装指定版本的 gradio :

    pip install gradio==4.43.0

    运行结果:

  3. 启动 Model Worker

    python3 -m llava.serve.model_worker --host 0.0.0.0 --controller http://localhost:20000 --port 40000 --worker http://localhost:40000 --model-path {模型权重路径} --load-4bit
    
    #这里注意更换模型权重路径

    运行结果:

  4. Web 运行示例

六、作者文章引用

@misc{liu2023improvedllava,
      title={Improved Baselines with Visual Instruction Tuning}, 
      author={Liu, Haotian and Li, Chunyuan and Li, Yuheng and Lee, Yong Jae},
      publisher={arXiv:2310.03744},
      year={2023},
}

@misc{liu2023llava,
      title={Visual Instruction Tuning}, 
      author={Liu, Haotian and Li, Chunyuan and Wu, Qingyang and Lee, Yong Jae},
      publisher={arXiv:2304.08485},
      year={2023},
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值