Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,206 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
|
7 |
|
8 |
-
|
9 |
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
##
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
<!-- Provide a longer summary of what this model is. -->
|
17 |
-
|
18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
-
|
20 |
-
- **Developed by:** [More Information Needed]
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
-
|
28 |
-
### Model Sources [optional]
|
29 |
-
|
30 |
-
<!-- Provide the basic links for the model. -->
|
31 |
-
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
## Uses
|
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 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
license: apache-2.0
|
4 |
+
datasets:
|
5 |
+
- HuggingFaceM4/the_cauldron
|
6 |
+
- HuggingFaceM4/Docmatix
|
7 |
+
- lmms-lab/LLaVA-OneVision-Data
|
8 |
+
- lmms-lab/M4-Instruct-Data
|
9 |
+
- HuggingFaceFV/finevideo
|
10 |
+
- MAmmoTH-VL/MAmmoTH-VL-Instruct-12M
|
11 |
+
- lmms-lab/LLaVA-Video-178K
|
12 |
+
- orrzohar/Video-STaR
|
13 |
+
- Mutonix/Vript
|
14 |
+
- TIGER-Lab/VISTA-400K
|
15 |
+
- Enxin/MovieChat-1K_train
|
16 |
+
- ShareGPT4Video/ShareGPT4Video
|
17 |
+
pipeline_tag: video-text-to-text
|
18 |
+
language:
|
19 |
+
- en
|
20 |
+
base_model:
|
21 |
+
- HuggingFaceTB/SmolVLM-256M-Instruct
|
22 |
---
|
23 |
|
24 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/SmolVLM2_banner.png" width="800" height="auto" alt="Image description">
|
25 |
|
26 |
+
# SmolVLM2-256M-Video
|
27 |
|
28 |
+
SmolVLM2-256M-Video is a lightweight multimodal model designed to analyze video content. The model processes videos, images, and text inputs to generate text outputs - whether answering questions about media files, comparing visual content, or transcribing text from images. Despite its compact size, requiring only 1.38GB of GPU RAM for video inference. This efficiency makes it particularly well-suited for on-device applications that require specific domain fine-tuning and computational resources may be limited.
|
29 |
+
## Model Summary
|
30 |
|
31 |
+
- **Developed by:** Hugging Face 🤗
|
32 |
+
- **Model type:** Multi-modal model (image/multi-image/video/text)
|
33 |
+
- **Language(s) (NLP):** English
|
34 |
+
- **License:** Apache 2.0
|
35 |
+
- **Architecture:** Based on [Idefics3](https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3) (see technical summary)
|
36 |
|
37 |
+
## Resources
|
38 |
|
39 |
+
- **Demo:** [Video Highlight Generator](https://huggingface.co/spaces/HuggingFaceTB/SmolVLM2-HighlightGenerator)
|
40 |
+
- **Blog:** [Blog post](https://huggingface.co/blog/smolvlm2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
## Uses
|
43 |
|
44 |
+
SmolVLM2 can be used for inference on multimodal (video / image / text) tasks where the input consists of text queries along with video or one or more images. Text and media files can be interleaved arbitrarily, enabling tasks like captioning, visual question answering, and storytelling based on visual content. The model does not support image or video generation.
|
45 |
+
|
46 |
+
To fine-tune SmolVLM2 on a specific task, you can follow [the fine-tuning tutorial](UPDATE).
|
47 |
+
|
48 |
+
## Evaluation
|
49 |
+
|
50 |
+
We evaluated the performance of the SmolVLM2 family on the following scientific benchmarks:
|
51 |
+
|
52 |
+
| Size | Video-MME | MLVU | MVBench |
|
53 |
+
|----------|-----------------|----------|---------------|
|
54 |
+
| 2.2B | 52.1 | 55.2 | 46.27 |
|
55 |
+
| 500M | 42.2 | 47.3 | 39.73 |
|
56 |
+
| 256M | 33.7 | 40.6 | 32.7 |
|
57 |
+
|
58 |
+
|
59 |
+
### How to get started
|
60 |
+
|
61 |
+
You can use transformers to load, infer and fine-tune SmolVLM. Make sure you have num2words, flash-attn and latest transformers installed.
|
62 |
+
You can load the model as follows.
|
63 |
+
|
64 |
+
```python
|
65 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
66 |
+
|
67 |
+
model_path = "HuggingFaceTB/SmolVLM2-256M-Video-Instruct"
|
68 |
+
processor = AutoProcessor.from_pretrained(model_path)
|
69 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
70 |
+
model_path,
|
71 |
+
torch_dtype=torch.bfloat16,
|
72 |
+
_attn_implementation="flash_attention_2"
|
73 |
+
).to("cuda")
|
74 |
+
```
|
75 |
+
|
76 |
+
#### Simple Inference
|
77 |
+
|
78 |
+
You preprocess your inputs directly using chat templates and directly passing them
|
79 |
+
|
80 |
+
```python
|
81 |
+
messages = [
|
82 |
+
{
|
83 |
+
"role": "user",
|
84 |
+
"content": [
|
85 |
+
{"type": "text", "text": "What is in this image?"},
|
86 |
+
{"type": "image", "path": "path_to_img.png"},
|
87 |
+
|
88 |
+
]
|
89 |
+
},
|
90 |
+
]
|
91 |
+
|
92 |
+
inputs = processor.apply_chat_template(
|
93 |
+
messages,
|
94 |
+
add_generation_prompt=True,
|
95 |
+
tokenize=True,
|
96 |
+
return_dict=True,
|
97 |
+
return_tensors="pt",
|
98 |
+
).to(model.device)
|
99 |
+
|
100 |
+
generated_ids = model.generate(**inputs, do_sample=False, max_new_tokens=64)
|
101 |
+
generated_texts = processor.batch_decode(
|
102 |
+
generated_ids,
|
103 |
+
skip_special_tokens=True,
|
104 |
+
)
|
105 |
+
print(generated_texts[0])
|
106 |
+
```
|
107 |
+
|
108 |
+
#### Video Inference
|
109 |
+
|
110 |
+
To use SmolVLM2 for video inference, make sure you have decord installed.
|
111 |
+
|
112 |
+
```python
|
113 |
+
messages = [
|
114 |
+
{
|
115 |
+
"role": "user",
|
116 |
+
"content": [
|
117 |
+
{"type": "video", "path": "path_to_video.mp4"},
|
118 |
+
{"type": "text", "text": "Describe this video in detail"}
|
119 |
+
]
|
120 |
+
},
|
121 |
+
]
|
122 |
+
|
123 |
+
inputs = processor.apply_chat_template(
|
124 |
+
messages,
|
125 |
+
add_generation_prompt=True,
|
126 |
+
tokenize=True,
|
127 |
+
return_dict=True,
|
128 |
+
return_tensors="pt",
|
129 |
+
).to(model.device)
|
130 |
+
|
131 |
+
generated_ids = model.generate(**inputs, do_sample=False, max_new_tokens=64)
|
132 |
+
generated_texts = processor.batch_decode(
|
133 |
+
generated_ids,
|
134 |
+
skip_special_tokens=True,
|
135 |
+
)
|
136 |
+
|
137 |
+
print(generated_texts[0])
|
138 |
+
```
|
139 |
+
#### Multi-image Interleaved Inference
|
140 |
+
|
141 |
+
You can interleave multiple media with text using chat templates.
|
142 |
+
|
143 |
+
```python
|
144 |
+
import torch
|
145 |
+
|
146 |
+
|
147 |
+
messages = [
|
148 |
+
{
|
149 |
+
"role": "user",
|
150 |
+
"content": [
|
151 |
+
{"type": "text", "text": "What is the similarity between this image <image>"},
|
152 |
+
|
153 |
+
{"type": "image", "path": "image_1.png"},
|
154 |
+
{"type": "text", "text": "and this image <image>"},
|
155 |
+
{"type": "image", "path": "image_2.png"},
|
156 |
+
]
|
157 |
+
},
|
158 |
+
]
|
159 |
+
inputs = processor.apply_chat_template(
|
160 |
+
messages,
|
161 |
+
add_generation_prompt=True,
|
162 |
+
tokenize=True,
|
163 |
+
return_dict=True,
|
164 |
+
return_tensors="pt",
|
165 |
+
).to(model.device)
|
166 |
+
|
167 |
+
generated_ids = model.generate(**inputs, do_sample=False, max_new_tokens=64)
|
168 |
+
generated_texts = processor.batch_decode(
|
169 |
+
generated_ids,
|
170 |
+
skip_special_tokens=True,
|
171 |
+
)
|
172 |
+
print(generated_texts[0])
|
173 |
+
```
|
174 |
+
|
175 |
+
|
176 |
+
### Model optimizations
|
177 |
+
|
178 |
+
## Misuse and Out-of-scope Use
|
179 |
+
|
180 |
+
SmolVLM is not intended for high-stakes scenarios or critical decision-making processes that affect an individual's well-being or livelihood. The model may produce content that appears factual but may not be accurate. Misuse includes, but is not limited to:
|
181 |
+
|
182 |
+
- Prohibited Uses:
|
183 |
+
- Evaluating or scoring individuals (e.g., in employment, education, credit)
|
184 |
+
- Critical automated decision-making
|
185 |
+
- Generating unreliable factual content
|
186 |
+
- Malicious Activities:
|
187 |
+
- Spam generation
|
188 |
+
- Disinformation campaigns
|
189 |
+
- Harassment or abuse
|
190 |
+
- Unauthorized surveillance
|
191 |
+
|
192 |
+
### License
|
193 |
+
|
194 |
+
SmolVLM2 is built upon [SigLIP](https://huggingface.co/google/siglip-base-patch16-512) as image encoder and [SmolLM2](https://huggingface.co/HuggingFaceTB/SmolLM2-360M-Instruct) for text decoder part.
|
195 |
+
|
196 |
+
We release the SmolVLM2 checkpoints under the Apache 2.0 license.
|
197 |
+
|
198 |
+
## Training Data
|
199 |
+
SmolVLM2 used 3.3M samples for training originally from ten different datasets: [LlaVa Onevision](https://huggingface.co/datasets/lmms-lab/LLaVA-OneVision-Data), [M4-Instruct](https://huggingface.co/datasets/lmms-lab/M4-Instruct-Data), [Mammoth](https://huggingface.co/datasets/MAmmoTH-VL/MAmmoTH-VL-Instruct-12M), [LlaVa Video 178K](https://huggingface.co/datasets/lmms-lab/LLaVA-Video-178K), [FineVideo](https://huggingface.co/datasets/HuggingFaceFV/finevideo), [VideoStar](https://huggingface.co/datasets/orrzohar/Video-STaR), [VRipt](https://huggingface.co/datasets/Mutonix/Vript), [Vista-400K](https://huggingface.co/datasets/TIGER-Lab/VISTA-400K), [MovieChat](https://huggingface.co/datasets/Enxin/MovieChat-1K_train) and [ShareGPT4Video](https://huggingface.co/datasets/ShareGPT4Video/ShareGPT4Video).
|
200 |
+
In the following plots we give a general overview of the samples across modalities and the source of those samples.
|
201 |
+
|
202 |
+
<center><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolvlm2_data_split.png" width="auto" height="auto" alt="Image description">
|
203 |
+
</center>
|
204 |
+
|
205 |
+
### Details
|
206 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolvlm2_datadetails.png" width="auto" height="auto" alt="Image description">
|