Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
datasets:
|
| 3 |
+
- Lin-Chen/ShareGPT4V
|
| 4 |
+
pipeline_tag: image-to-text
|
| 5 |
+
library_name: xtuner
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
<div align="center">
|
| 9 |
+
<img src="https://github.com/InternLM/lmdeploy/assets/36994684/0cf8d00f-e86b-40ba-9b54-dc8f1bc6c8d8" width="600"/>
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
[](https://github.com/InternLM/xtuner)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
</div>
|
| 16 |
+
|
| 17 |
+
## Model
|
| 18 |
+
|
| 19 |
+
llava-phi-3-mini is a LLaVA model fine-tuned from [microsoft/Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct) and [CLIP-ViT-Large-patch14-336](https://huggingface.co/openai/clip-vit-large-patch14-336) with [ShareGPT4V-PT](https://huggingface.co/datasets/Lin-Chen/ShareGPT4V) and [InternVL-SFT](https://github.com/OpenGVLab/InternVL/tree/main/internvl_chat#prepare-training-datasets) by [XTuner](https://github.com/InternLM/xtuner).
|
| 20 |
+
|
| 21 |
+
**Note: This model is in HuggingFace LLaVA format. The models in xtuner LLaVA format and official LLaVA format can be found on [xtuner/llava-phi-3-mini-xtuner](https://huggingface.co/xtuner/llava-phi-3-mini-xtuner) and [xtuner/llava-phi-3-mini](https://huggingface.co/xtuner/llava-phi-3-mini).**
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
## Details
|
| 25 |
+
|
| 26 |
+
| Model | Visual Encoder | Projector | Resolution | Pretraining Strategy | Fine-tuning Strategy | Pretrain Dataset | Fine-tune Dataset |
|
| 27 |
+
| :-------------------- | ------------------: | --------: | ---------: | ---------------------: | ------------------------: | ------------------------: | -----------------------: |
|
| 28 |
+
| LLaVA-v1.5-7B | CLIP-L | MLP | 336 | Frozen LLM, Frozen ViT | Full LLM, Frozen ViT | LLaVA-PT (558K) | LLaVA-Mix (665K) |
|
| 29 |
+
| LLaVA-Llama-3-8B | CLIP-L | MLP | 336 | Frozen LLM, Frozen ViT | Full LLM, LoRA ViT | LLaVA-PT (558K) | LLaVA-Mix (665K) |
|
| 30 |
+
| LLaVA-Llama-3-8B-v1.1 | CLIP-L | MLP | 336 | Frozen LLM, Frozen ViT | Full LLM, LoRA ViT | ShareGPT4V-PT (1246K) | InternVL-SFT (1268K) |
|
| 31 |
+
| LLaVA-Phi-3-mini | CLIP-L | MLP | 336 | Frozen LLM, Frozen ViT | Full LLM, Full ViT | ShareGPT4V-PT (1246K) | InternVL-SFT (1268K) |
|
| 32 |
+
|
| 33 |
+
## Results
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
## Quickstart
|
| 37 |
+
|
| 38 |
+
### Chat with `pipeline`
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
from transformers import pipeline
|
| 43 |
+
from PIL import Image
|
| 44 |
+
import requests
|
| 45 |
+
|
| 46 |
+
model_id = "xtuner/llava-phi-3-mini-hf"
|
| 47 |
+
pipe = pipeline("image-to-text", model=model_id, device=0)
|
| 48 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
|
| 49 |
+
|
| 50 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 51 |
+
prompt = "<|user|>\n<image>\nWhat does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud<|end|>\n<|assistant|>\n"
|
| 52 |
+
|
| 53 |
+
outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
|
| 54 |
+
print(outputs)
|
| 55 |
+
>>> [{'generated_text': '\nWhat does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud (1) lava'}]
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
### Chat with pure `transformers`
|
| 59 |
+
|
| 60 |
+
```python
|
| 61 |
+
import requests
|
| 62 |
+
from PIL import Image
|
| 63 |
+
|
| 64 |
+
import torch
|
| 65 |
+
from transformers import AutoProcessor, LlavaForConditionalGeneration
|
| 66 |
+
|
| 67 |
+
model_id = "xtuner/llava-phi-3-mini-hf"
|
| 68 |
+
|
| 69 |
+
prompt = "<|user|>\n<image>\nWhat are these?<|end|>\n<|assistant|>\n"
|
| 70 |
+
image_file = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 71 |
+
|
| 72 |
+
model = LlavaForConditionalGeneration.from_pretrained(
|
| 73 |
+
model_id,
|
| 74 |
+
torch_dtype=torch.float16,
|
| 75 |
+
low_cpu_mem_usage=True,
|
| 76 |
+
).to(0)
|
| 77 |
+
|
| 78 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
raw_image = Image.open(requests.get(image_file, stream=True).raw)
|
| 82 |
+
inputs = processor(prompt, raw_image, return_tensors='pt').to(0, torch.float16)
|
| 83 |
+
|
| 84 |
+
output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
|
| 85 |
+
print(processor.decode(output[0][2:], skip_special_tokens=True))
|
| 86 |
+
>>> What are these? These are two cats sleeping on a pink couch.
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
### Reproduction
|
| 91 |
+
|
| 92 |
+
Please refer to [docs](https://github.com/InternLM/xtuner/tree/main/xtuner/configs/llava/phi3_mini_4k_instruct_clip_vit_large_p14_336#readme).
|
| 93 |
+
|
| 94 |
+
## Citation
|
| 95 |
+
|
| 96 |
+
```bibtex
|
| 97 |
+
@misc{2023xtuner,
|
| 98 |
+
title={XTuner: A Toolkit for Efficiently Fine-tuning LLM},
|
| 99 |
+
author={XTuner Contributors},
|
| 100 |
+
howpublished = {\url{https://github.com/InternLM/xtuner}},
|
| 101 |
+
year={2023}
|
| 102 |
+
}
|
| 103 |
+
```
|