五一 Llama 3 超级讲堂 | XTuner 微调 Llama3 图片明白多模态 实践笔记 ...

打印 上一主题 下一主题

主题 529|帖子 529|积分 1587

基于 Llama3-8B-Instruct 和 XTuner 团队预练习好的 Image Projector 微调本身的多模态图文明白模型 LLaVA。
课程文档:Llama3-Tutorial/docs/llava.md at main · SmartFlowAI/Llama3-Tutorial · GitHub
环境、模型、数据预备

1.环境预备

使用之前课程中已经配置好的环境、XTuner和Llama3-Tutorial
2.模型预备



  • Llama3 权重:使用之前课程软链接过的Llama3-8B-Instruct
  • Visual Encoder 权重:Llava 所必要的 openai/clip-vit-large-patch14-336,权重,即 Visual Encoder 权重。(使用软链接)
  • Image Projector 权重

3.数据预备


微调

1.练习启动



  • 使用XTuner启动基于Llama3的LLaVA练习
  1. xtuner train ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py --work-dir ~/llama3_llava_pth --deepspeed deepspeed_zero2
复制代码

必要先安装deepspeed,重试

30%的A100好像不太够用,加上offload重试,启动成功

大约用时4个小时左右


  • 将原始 image projector 和 我们微调得到的 image projector 都转换为 HuggingFace 格式
  1. xtuner convert pth_to_hf ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py \
  2.   ~/model/llama3-llava-iter_2181.pth \
  3.   ~/llama3_llava_pth/pretrain_iter_2181_hf
  4. xtuner convert pth_to_hf ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py \
  5.   ~/llama3_llava_pth/iter_1200.pth \
  6.   ~/llama3_llava_pth/iter_1200_hf
复制代码
2.结果比对

检验模型结果
标题1:Describe this image. 标题2:What is the equipment in the image?
Pretrain 模型



Finetune 后 模型

  1. export MKL_SERVICE_FORCE_INTEL=1
  2. xtuner chat /root/model/Meta-Llama-3-8B-Instruct \
  3.   --visual-encoder /root/model/clip-vit-large-patch14-336 \
  4.   --llava /root/llama3_llava_pth/iter_1200_hf \
  5.   --prompt-template llama3_chat \
  6.   --image /root/tutorial/xtuner/llava/llava_data/test_img/oph.jpg
复制代码

原始模型回答不出第二个标题,经过微调后可以回答出来

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

钜形不锈钢水箱

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表