RaushanTurganbay HF staff commited on
Commit
e38be7a
1 Parent(s): 0fef07c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +106 -3
README.md CHANGED
@@ -1,3 +1,106 @@
1
- ---
2
- license: llama3
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama3
3
+ tags:
4
+ - vision
5
+ - image-text-to-text
6
+ ---
7
+
8
+ # LLaVa-Next, leveraging [liuhaotian/llava-v1.6-vicuna-7b](https://huggingface.co/liuhaotian/llava-v1.6-vicuna-7b) as LLM
9
+
10
+ The LLaVA-NeXT model was proposed in [LLaVA-NeXT: Stronger LLMs Supercharge Multimodal Capabilities in the Wild
11
+ ](https://llava-vl.github.io/blog/2024-05-10-llava-next-stronger-llms/) by Bo Li, Kaichen Zhang, Hao Zhang, Dong Guo, Renrui Zhang, Feng Li, Yuanhan Zhang, Ziwei Liu, Chunyuan Li.
12
+ These LLaVa-NeXT series improves upon [LLaVa-1.6](https://llava-vl.github.io/blog/2024-01-30-llava-next/) by training with stringer language backbones, improving the
13
+ performance.
14
+
15
+ Disclaimer: The team releasing LLaVa-NeXT did not write a model card for this model so this model card has been written by the Hugging Face team.
16
+
17
+ ## Model description
18
+
19
+ LLaVa combines a pre-trained large language model with a pre-trained vision encoder for multimodal chatbot use cases. LLaVA NeXT Llama3 improves on LLaVA 1.6 BY:
20
+ - More diverse and high quality data mixture
21
+ - Better and bigger language backbone
22
+
23
+ Base LLM: [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct)
24
+
25
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/62441d1d9fdefb55a0b7d12c/FPshq08TKYD0e-qwPLDVO.png)
26
+
27
+ ## Intended uses & limitations
28
+
29
+ You can use the raw model for tasks like image captioning, visual question answering, multimodal chatbot use cases. See the [model hub](https://huggingface.co/models?search=llava-hf) to look for
30
+ other versions on a task that interests you.
31
+
32
+ ### How to use
33
+
34
+ Here's the prompt template for this model:
35
+ ```
36
+ "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions. USER: <image>\nWhat is shown in this image? ASSISTANT:"
37
+ ```
38
+ You can load and use the model like following:
39
+ ```python
40
+ from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
41
+ import torch
42
+ from PIL import Image
43
+ import requests
44
+
45
+ processor = LlavaNextProcessor.from_pretrained("llava-hf/llama3-llava-next-8b-hf")
46
+ model = LlavaNextForConditionalGeneration.from_pretrained("llava-hf/llama3-llava-next-8b-hf", torch_dtype=torch.float16, device_map="auto")
47
+
48
+ # prepare image and text prompt, using the appropriate prompt template
49
+ url = "https://github.com/haotian-liu/LLaVA/blob/1a91fc274d7c35a9b50b3cb29c4247ae5837ce39/images/llava_v1_5_radar.jpg?raw=true"
50
+ image = Image.open(requests.get(url, stream=True).raw)
51
+ prompt = "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions. USER: <image>\nWhat is shown in this image? ASSISTANT:"
52
+
53
+ inputs = processor(prompt, image, return_tensors="pt").to(model.device)
54
+
55
+ # autoregressively complete prompt
56
+ output = model.generate(**inputs, max_new_tokens=100)
57
+
58
+ print(processor.decode(output[0], skip_special_tokens=True))
59
+ ```
60
+
61
+ ### Model optimization
62
+
63
+ #### 4-bit quantization through `bitsandbytes` library
64
+
65
+ First make sure to install `bitsandbytes`, `pip install bitsandbytes` and make sure to have access to a CUDA compatible GPU device. Simply change the snippet above with:
66
+
67
+ ```diff
68
+ model = LlavaNextForConditionalGeneration.from_pretrained(
69
+ model_id,
70
+ torch_dtype=torch.float16,
71
+ low_cpu_mem_usage=True,
72
+ + load_in_4bit=True
73
+ )
74
+ ```
75
+
76
+ #### Use Flash-Attention 2 to further speed-up generation
77
+
78
+ First make sure to install `flash-attn`. Refer to the [original repository of Flash Attention](https://github.com/Dao-AILab/flash-attention) regarding that package installation. Simply change the snippet above with:
79
+
80
+ ```diff
81
+ model = LlavaNextForConditionalGeneration.from_pretrained(
82
+ model_id,
83
+ torch_dtype=torch.float16,
84
+ low_cpu_mem_usage=True,
85
+ + use_flash_attention_2=True
86
+ ).to(0)
87
+ ```
88
+ ### Training Data
89
+ - 558K filtered image-text pairs from LAION/CC/SBU, captioned by BLIP.
90
+ - 158K GPT-generated multimodal instruction-following data.
91
+ - 500K academic-task-oriented VQA data mixture.
92
+ - 50K GPT-4V data mixture.
93
+ - 40K ShareGPT data.
94
+
95
+
96
+ ### BibTeX entry and citation info
97
+
98
+ ```bibtex
99
+ @misc{li2024llavanext-strong,
100
+ title={LLaVA-NeXT: Stronger LLMs Supercharge Multimodal Capabilities in the Wild},
101
+ url={https://llava-vl.github.io/blog/2024-05-10-llava-next-stronger-llms/},
102
+ author={Li, Bo and Zhang, Kaichen and Zhang, Hao and Guo, Dong and Zhang, Renrui and Li, Feng and Zhang, Yuanhan and Liu, Ziwei and Li, Chunyuan},
103
+ month={May},
104
+ year={2024}
105
+ }
106
+ ```