进阶岛 多模态模型部署微调实践

一、任务介绍

  • follow 教学文档和视频使用QLoRA进行微调模型,复现微调效果,并能成功讲出梗图.
  • 尝试使用LoRA,或调整xtuner的config,如LoRA rank,学习率。看模型Loss会如何变化,并记录调整后效果(选做,使用LoRA或调整config可以二选一)

二、根据文档搭建环境

Tutorial/docs/L2/InternVL/joke_readme.md at camp3 · InternLM/Tutorial · GitHub

三、使用InternVL 推理部署

3.1、使用pipeline进行推理

3.1.1、创建test_lmdeploy.py以及推理的图片

复制代码
from lmdeploy import pipeline
from lmdeploy.vl import load_image

pipe = pipeline('/root/model/InternVL2-2B')

image = load_image('/root/InternLM/007aPnLRgy1hb39z0im50j30ci0el0wm.jpg')
response = pipe(('请你根据这张图片,讲一个脑洞大开的梗', image))
print(response.text)

3.1.2、推理结果

四、InternVL 微调攻略

4.1、准备数据集

复制代码
# 为了高效训练,请确保数据格式为:
{
    "id": "000000033471",
    "image": ["coco/train2017/000000033471.jpg"], # 如果是纯文本,则该字段为 None 或者不存在
    "conversations": [
      {
        "from": "human",
        "value": "<image>\nWhat are the colors of the bus in the image?"
      },
      {
        "from": "gpt",
        "value": "The bus in the image is white and red."
      }
    ]
  }

4.2、配置微调参数

让我们一起修改XTuner下 InternVL的config,文件在: /root/InternLM/code/XTuner/xtuner/configs/internvl/v2/internvl_v2_internlm2_2b_qlora_finetune.py

4.3、开始训练

复制代码
NPROC_PER_NODE=1 xtuner train /root/InternLM/code/XTuner/xtuner/configs/internvl/v2/internvl_v2_internlm2_2b_qlora_finetune.py  --work-dir /root/InternLM/work_dir/internvl_ft_run_8_filter  --deepspeed deepspeed_zero1

30%资源无法训练

升级为50%资源训练

4.4、合并权重&&模型转换

复制代码
python3 xtuner/configs/internvl/v1_5/convert_to_official.py xtuner/configs/internvl/v2/internvl_v2_internlm2_2b_qlora_finetune.py /root/InternLM/work_dir/internvl_ft_run_8_filter/iter_3000.pth /root/InternLM/InternVL2-2B/

最后我们的模型在:/root/InternLM/convert_model/,文件格式:

.
|-- added_tokens.json
|-- config.json
|-- configuration_intern_vit.py
|-- configuration_internlm2.py
|-- configuration_internvl_chat.py
|-- conversation.py
|-- generation_config.json
|-- model.safetensors
|-- modeling_intern_vit.py
|-- modeling_internlm2.py
|-- modeling_internvl_chat.py
|-- special_tokens_map.json
|-- tokenization_internlm2.py
|-- tokenizer.model
`-- tokenizer_config.json

4.5、微调后效果对比

我们把下面的代码替换进test_lmdeploy.py中,然后跑一下效果。

复制代码
from lmdeploy import pipeline
from lmdeploy.vl import load_image

pipe = pipeline('/root/InternLM/InternVL2-2B')

image = load_image('/root/InternLM/007aPnLRgy1hb39z0im50j30ci0el0wm.jpg')
response = pipe(('请你根据这张图片,讲一个脑洞大开的梗', image))
print(response.text)
相关推荐
Alueaxten(上学版)1 小时前
【软考】程序设计语言基础
经验分享·笔记·学习·软件工程·软考
Super Minion1 小时前
Java重修笔记 第五十四天 坦克大战(四)多线程基础
java·jvm·笔记
&&Citrus2 小时前
【Petri网导论学习笔记】Petri网导论入门学习(三)
笔记·学习·算法·入门·petri网·petri
Fetters043 小时前
✨机器学习笔记(三)—— 多元线性回归、特征缩放、Scikit-Learn
笔记·机器学习·线性回归
Coder-thinking3 小时前
自定义Spring-start学习笔记
笔记·学习·spring·maven
X_StarX4 小时前
【软考中级攻略站】-软件设计师(5)- 软件工程
开发语言·笔记·学习·软件工程·软考·大学生·软件设计师
Kent_J_Truman4 小时前
Vim笔记
笔记·编辑器·vim
芝奥小婷5 小时前
javase笔记3----正则表达式
笔记
LN花开富贵5 小时前
单片机中为什么要使用5v转3.3v,不直接使用3.3V电压
笔记·单片机·嵌入式硬件·学习·物联网工程
LN花开富贵6 小时前
RZ7888电机驱动芯片
笔记·单片机·嵌入式硬件·学习·iot