shimmyshimmer
commited on
Commit
•
3aeaf95
1
Parent(s):
64ed0b3
Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,174 @@
|
|
1 |
---
|
|
|
|
|
|
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
9 |
|
|
|
10 |
|
|
|
|
|
11 |
|
12 |
-
## Model Details
|
13 |
|
14 |
-
|
|
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
- **
|
23 |
-
- **
|
24 |
-
|
25 |
-
|
26 |
-
- **
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
|
|
|
|
31 |
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
-
|
37 |
|
38 |
-
|
|
|
|
|
39 |
|
40 |
-
|
|
|
41 |
|
42 |
-
|
|
|
43 |
|
44 |
-
|
45 |
|
46 |
-
|
|
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
|
|
|
|
|
|
53 |
|
54 |
-
|
|
|
|
|
|
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
|
60 |
-
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
|
64 |
-
|
65 |
|
66 |
-
|
|
|
|
|
67 |
|
68 |
-
|
|
|
69 |
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
|
73 |
|
74 |
-
|
|
|
|
|
|
|
75 |
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
|
|
|
|
|
79 |
|
80 |
-
|
81 |
|
82 |
-
|
83 |
|
84 |
-
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
|
|
1 |
---
|
2 |
+
base_model: llava-hf/llava-1.5-7b-hf
|
3 |
+
language:
|
4 |
+
- en
|
5 |
library_name: transformers
|
6 |
+
pipeline_tag: image-text-to-text
|
7 |
+
license: llama2
|
8 |
+
tags:
|
9 |
+
- multimodal
|
10 |
+
- llava
|
11 |
+
- vision
|
12 |
+
- unsloth
|
13 |
---
|
14 |
|
15 |
+
# Finetune Llama 3.2, Qwen 2.5, Gemma 2, Mistral 2-5x faster with 70% less memory via Unsloth!
|
16 |
|
17 |
+
We have a free Google Colab Tesla T4 notebook for Llava 1.5 (7B) here: https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing
|
18 |
|
19 |
+
And a free notebook for [Llama 3.2 Vision (11B) here](https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing)
|
20 |
|
21 |
+
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/Discord%20button.png" width="200"/>](https://discord.gg/unsloth)
|
22 |
+
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
23 |
|
|
|
24 |
|
25 |
+
# unsloth/llava-1.5-7b-hf-bnb-4bit
|
26 |
+
For more details on the model, please go to the original [model card](https://huggingface.co/llava-hf/llava-1.5-7b-hf/)
|
27 |
|
28 |
+
## ✨ Finetune for Free
|
29 |
|
30 |
+
All notebooks are **beginner friendly**! Add your dataset, click "Run All", and you'll get a 2x faster finetuned model which can be exported to GGUF, vLLM or uploaded to Hugging Face.
|
31 |
|
32 |
+
| Unsloth supports | Free Notebooks | Performance | Memory use |
|
33 |
+
|-----------------|--------------------------------------------------------------------------------------------------------------------------|-------------|----------|
|
34 |
+
| **Llama-3.2 (3B)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing) | 2.4x faster | 58% less |
|
35 |
+
| **Llama-3.2 (11B vision)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing) | 2x faster | 40% less |
|
36 |
+
| **Qwen2 VL (7B)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing) | 1.8x faster | 40% less |
|
37 |
+
| **Qwen2.5 (7B)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1Kose-ucXO1IBaZq5BvbwWieuubP7hxvQ?usp=sharing) | 2x faster | 60% less |
|
38 |
+
| **Llama-3.1 (8B)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing) | 2.4x faster | 58% less |
|
39 |
+
| **Phi-3.5 (mini)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1lN6hPQveB_mHSnTOYifygFcrO8C1bxq4?usp=sharing) | 2x faster | 50% less |
|
40 |
+
| **Gemma 2 (9B)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1vIrqH5uYDQwsJ4-OO3DErvuv4pBgVwk4?usp=sharing) | 2.4x faster | 58% less |
|
41 |
+
| **Mistral (7B)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1Dyauq4kTZoLewQ1cApceUQVNcnnNTzg_?usp=sharing) | 2.2x faster | 62% less |
|
42 |
+
| **DPO - Zephyr** | [▶️ Start on Colab](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing) | 1.9x faster | 19% less |
|
43 |
|
44 |
+
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="200"/>](https://docs.unsloth.ai)
|
45 |
|
46 |
+
- This [conversational notebook](https://colab.research.google.com/drive/1Aau3lgPzeZKQ-98h69CCu1UJcvIBLmy2?usp=sharing) is useful for ShareGPT ChatML / Vicuna templates.
|
47 |
+
- This [text completion notebook](https://colab.research.google.com/drive/1ef-tab5bhkvWmBOObepl1WgJvfvSzn5Q?usp=sharing) is for raw text. This [DPO notebook](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing) replicates Zephyr.
|
48 |
+
- \* Kaggle has 2x T4s, but we use 1. Due to overhead, 1x T4 is 5x faster.
|
49 |
|
|
|
|
|
|
|
50 |
|
51 |
+
### Llava 1.5 Details
|
52 |
|
53 |
+
**Model type:**
|
54 |
+
LLaVA is an open-source chatbot trained by fine-tuning LLaMA/Vicuna on GPT-generated multimodal instruction-following data.
|
55 |
+
It is an auto-regressive language model, based on the transformer architecture.
|
56 |
|
57 |
+
**Model date:**
|
58 |
+
LLaVA-v1.5-7B was trained in September 2023.
|
59 |
|
60 |
+
**Paper or resources for more information:**
|
61 |
+
https://llava-vl.github.io/
|
62 |
|
63 |
+
## How to use the model
|
64 |
|
65 |
+
First, make sure to have `transformers >= 4.35.3`.
|
66 |
+
The model supports multi-image and multi-prompt generation. Meaning that you can pass multiple images in your prompt. Make sure also to follow the correct prompt template (`USER: xxx\nASSISTANT:`) and add the token `<image>` to the location where you want to query images:
|
67 |
|
68 |
+
### Using `pipeline`:
|
69 |
|
70 |
+
Below we used [`"llava-hf/llava-1.5-7b-hf"`](https://huggingface.co/llava-hf/llava-1.5-7b-hf) checkpoint.
|
71 |
|
72 |
+
```python
|
73 |
+
from transformers import pipeline, AutoProcessor
|
74 |
+
from PIL import Image
|
75 |
+
import requests
|
76 |
|
77 |
+
model_id = "llava-hf/llava-1.5-7b-hf"
|
78 |
+
pipe = pipeline("image-to-text", model=model_id)
|
79 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
|
80 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
81 |
|
82 |
+
# Define a chat history and use `apply_chat_template` to get correctly formatted prompt
|
83 |
+
# Each value in "content" has to be a list of dicts with types ("text", "image")
|
84 |
+
conversation = [
|
85 |
+
{
|
86 |
+
"role": "user",
|
87 |
+
"content": [
|
88 |
+
{"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
|
89 |
+
{"type": "image"},
|
90 |
+
],
|
91 |
+
},
|
92 |
+
]
|
93 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
94 |
|
95 |
+
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
|
96 |
|
97 |
+
outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
|
98 |
+
print(outputs)
|
99 |
+
>>> {"generated_text": "\nUSER: What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nASSISTANT: Lava"}
|
100 |
+
```
|
101 |
|
102 |
+
### Using pure `transformers`:
|
103 |
|
104 |
+
Below is an example script to run generation in `float16` precision on a GPU device:
|
105 |
|
106 |
+
```python
|
107 |
+
import requests
|
108 |
+
from PIL import Image
|
109 |
|
110 |
+
import torch
|
111 |
+
from transformers import AutoProcessor, LlavaForConditionalGeneration
|
112 |
|
113 |
+
model_id = "llava-hf/llava-1.5-7b-hf"
|
114 |
+
model = LlavaForConditionalGeneration.from_pretrained(
|
115 |
+
model_id,
|
116 |
+
torch_dtype=torch.float16,
|
117 |
+
low_cpu_mem_usage=True,
|
118 |
+
).to(0)
|
119 |
|
120 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
121 |
|
122 |
+
# Define a chat histiry and use `apply_chat_template` to get correctly formatted prompt
|
123 |
+
# Each value in "content" has to be a list of dicts with types ("text", "image")
|
124 |
+
conversation = [
|
125 |
+
{
|
126 |
|
127 |
+
"role": "user",
|
128 |
+
"content": [
|
129 |
+
{"type": "text", "text": "What are these?"},
|
130 |
+
{"type": "image"},
|
131 |
+
],
|
132 |
+
},
|
133 |
+
]
|
134 |
+
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
|
135 |
+
|
136 |
+
image_file = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
137 |
+
raw_image = Image.open(requests.get(image_file, stream=True).raw)
|
138 |
+
inputs = processor(images=raw_image, text=prompt, return_tensors='pt').to(0, torch.float16)
|
139 |
|
140 |
+
output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
|
141 |
+
print(processor.decode(output[0][2:], skip_special_tokens=True))
|
142 |
+
```
|
143 |
|
144 |
+
### Model optimization
|
145 |
|
146 |
+
#### 4-bit quantization through `bitsandbytes` library
|
147 |
|
148 |
+
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:
|
149 |
|
150 |
+
```diff
|
151 |
+
model = LlavaForConditionalGeneration.from_pretrained(
|
152 |
+
model_id,
|
153 |
+
torch_dtype=torch.float16,
|
154 |
+
low_cpu_mem_usage=True,
|
155 |
+
+ load_in_4bit=True
|
156 |
+
)
|
157 |
+
```
|
158 |
+
|
159 |
+
#### Use Flash-Attention 2 to further speed-up generation
|
160 |
+
|
161 |
+
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:
|
162 |
+
|
163 |
+
```diff
|
164 |
+
model = LlavaForConditionalGeneration.from_pretrained(
|
165 |
+
model_id,
|
166 |
+
torch_dtype=torch.float16,
|
167 |
+
low_cpu_mem_usage=True,
|
168 |
+
+ use_flash_attention_2=True
|
169 |
+
).to(0)
|
170 |
+
```
|
171 |
+
|
172 |
+
## License
|
173 |
+
Llama 2 is licensed under the LLAMA 2 Community License,
|
174 |
+
Copyright (c) Meta Platforms, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|