数据集:
- Lin-Chen/ShareGPT4V
任务类型: 图像转文本
模型
llava-phi-3-mini是基于microsoft/Phi-3-mini-4k-instruct和CLIP-ViT-Large-patch14-336微调的LLaVA模型,使用了ShareGPT4V-PT和InternVL-SFT数据集,通过XTuner工具完成训练。
注意:此模型采用HuggingFace LLaVA格式。
资源链接:
技术细节
模型 |
视觉编码器 |
投影器 |
分辨率 |
预训练策略 |
微调策略 |
预训练数据集 |
微调数据集 |
预训练周期 |
微调周期 |
LLaVA-v1.5-7B |
CLIP-L |
MLP |
336 |
冻结LLM,冻结ViT |
全参数LLM,冻结ViT |
LLaVA-PT (558K) |
LLaVA-Mix (665K) |
1 |
1 |
LLaVA-Llama-3-8B |
CLIP-L |
MLP |
336 |
冻结LLM,冻结ViT |
全参数LLM,LoRA ViT |
LLaVA-PT (558K) |
LLaVA-Mix (665K) |
1 |
1 |
LLaVA-Llama-3-8B-v1.1 |
CLIP-L |
MLP |
336 |
冻结LLM,冻结ViT |
全参数LLM,LoRA ViT |
ShareGPT4V-PT (1246K) |
InternVL-SFT (1268K) |
1 |
1 |
LLaVA-Phi-3-mini |
CLIP-L |
MLP |
336 |
冻结LLM,冻结ViT |
全参数LLM,全参数ViT |
ShareGPT4V-PT (1246K) |
InternVL-SFT (1268K) |
1 |
2 |
性能表现
模型 |
MMBench测试(英文) |
MMMU验证 |
SEED-IMG |
AI2D测试 |
ScienceQA测试 |
HallusionBench准确率 |
POPE |
GQA |
TextVQA |
MME |
MMStar |
LLaVA-v1.5-7B |
66.5 |
35.3 |
60.5 |
54.8 |
70.4 |
44.9 |
85.9 |
62.0 |
58.2 |
1511/348 |
30.3 |
LLaVA-Llama-3-8B |
68.9 |
36.8 |
69.8 |
60.9 |
73.3 |
47.3 |
87.2 |
63.5 |
58.0 |
1506/295 |
38.2 |
LLaVA-Llama-3-8B-v1.1 |
72.3 |
37.1 |
70.1 |
70.0 |
72.9 |
47.7 |
86.4 |
62.6 |
59.0 |
1469/349 |
45.1 |
LLaVA-Phi-3-mini |
69.2 |
41.4 |
70.0 |
69.3 |
73.7 |
49.8 |
87.3 |
61.5 |
57.8 |
1477/313 |
43.7 |
快速开始
使用pipeline
对话
from transformers import pipeline
from PIL import Image
import requests
model_id = "xtuner/llava-phi-3-mini-hf"
pipe = pipeline("image-to-text", model=model_id, device=0)
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
image = Image.open(requests.get(url, stream=True).raw)
prompt = "<|user|>\n<image>\n标签15代表什么?(1) 熔岩 (2) 地核 (3) 隧道 (4) 火山灰云<|end|>\n<|assistant|>\n"
outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
print(outputs)
>>> [{'generated_text': '\n标签15代表什么?(1) 熔岩 (2) 地核 (3) 隧道 (4) 火山灰云 (1) 熔岩'}]
使用原生transformers
对话
import requests
from PIL import Image
import torch
from transformers import AutoProcessor, LlavaForConditionalGeneration
model_id = "xtuner/llava-phi-3-mini-hf"
prompt = "<|user|>\n<image>\n这是什么?<|end|>\n<|assistant|>\n"
image_file = "http://images.cocodataset.org/val2017/000000039769.jpg"
model = LlavaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.float16,
low_cpu_mem_usage=True,
).to(0)
processor = AutoProcessor.from_pretrained(model_id)
raw_image = Image.open(requests.get(image_file, stream=True).raw)
inputs = processor(prompt, raw_image, return_tensors='pt').to(0, torch.float16)
output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
print(processor.decode(output[0][2:], skip_special_tokens=True))
>>> 这是什么?这是两只猫在粉色沙发上睡觉。
复现方法
请参考文档。
引用
@misc{2023xtuner,
title={XTuner: 高效微调大语言模型的工具包},
author={XTuner贡献者},
howpublished = {\url{https://github.com/InternLM/xtuner}},
year={2023}
}