钜形不锈钢水箱 发表于 2024-7-17 05:11:23

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

基于 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 权重
https://img-blog.csdnimg.cn/direct/736b5031d87b4bcfa5929561f1e1f52d.png
3.数据预备

https://img-blog.csdnimg.cn/direct/81c108ca8eef4106a8713f8275f1220c.png
微调

1.练习启动



[*]使用XTuner启动基于Llama3的LLaVA练习
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 https://img-blog.csdnimg.cn/direct/d03685a6e1e04f509c9dbb92b887d7d2.png
必要先安装deepspeed,重试
https://img-blog.csdnimg.cn/direct/2192025c1151487b9471431a3eabb969.png
30%的A100好像不太够用,加上offload重试,启动成功
https://img-blog.csdnimg.cn/direct/1823631b168b47c3898ada52afe9a83b.png
大约用时4个小时左右


[*]将原始 image projector 和 我们微调得到的 image projector 都转换为 HuggingFace 格式
xtuner convert pth_to_hf ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py \
~/model/llama3-llava-iter_2181.pth \
~/llama3_llava_pth/pretrain_iter_2181_hf

xtuner convert pth_to_hf ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py \
~/llama3_llava_pth/iter_1200.pth \
~/llama3_llava_pth/iter_1200_hf 2.结果比对

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

https://img-blog.csdnimg.cn/direct/48bef31b1cf24012aa6cbe1f44ab15b6.png
https://img-blog.csdnimg.cn/direct/5d25d89ad96f4586b76ab254321b225f.png
Finetune 后 模型

export MKL_SERVICE_FORCE_INTEL=1
xtuner chat /root/model/Meta-Llama-3-8B-Instruct \
--visual-encoder /root/model/clip-vit-large-patch14-336 \
--llava /root/llama3_llava_pth/iter_1200_hf \
--prompt-template llama3_chat \
--image /root/tutorial/xtuner/llava/llava_data/test_img/oph.jpg https://img-blog.csdnimg.cn/direct/d1c8e27d11f746529f2f1016325fdfea.png
原始模型回答不出第二个标题,经过微调后可以回答出来

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 五一 Llama 3 超级讲堂 | XTuner 微调 Llama3 图片明白多模态 实践笔记