Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,180 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
|
7 |
|
8 |
-
|
9 |
|
|
|
10 |
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
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 |
-
### Direct Use
|
41 |
-
|
42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
-
|
52 |
-
### Out-of-Scope Use
|
53 |
-
|
54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
-
|
58 |
-
## Bias, Risks, and Limitations
|
59 |
-
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
-
|
70 |
-
## How to Get Started with the Model
|
71 |
-
|
72 |
-
Use the code below to get started with the model.
|
73 |
-
|
74 |
-
[More Information Needed]
|
75 |
-
|
76 |
-
## Training Details
|
77 |
-
|
78 |
-
### Training Data
|
79 |
-
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
|
93 |
-
#### Training Hyperparameters
|
94 |
-
|
95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
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 |
-
### Model Architecture and Objective
|
156 |
|
157 |
-
|
158 |
|
159 |
-
|
160 |
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
-
|
|
|
|
|
|
|
|
|
164 |
|
165 |
-
|
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 |
-
|
188 |
|
189 |
-
|
|
|
190 |
|
191 |
-
[More Information Needed]
|
192 |
|
193 |
-
## Model Card Authors [optional]
|
194 |
|
195 |
-
[More Information Needed]
|
196 |
|
197 |
-
##
|
198 |
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
license: apache-2.0
|
4 |
+
datasets:
|
5 |
+
- HuggingFaceM4/the_cauldron
|
6 |
+
- HuggingFaceM4/Docmatix
|
7 |
+
pipeline_tag: image-text-to-text
|
8 |
+
language:
|
9 |
+
- en
|
10 |
+
base_model:
|
11 |
+
- HuggingFaceTB/SmolLM2-360M-Instruct
|
12 |
+
- google/siglip-base-patch16-512
|
13 |
---
|
14 |
|
15 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/SmolVLM.png" width="800" height="auto" alt="Image description">
|
16 |
|
17 |
+
# SmolVLM-256M
|
18 |
|
19 |
+
SmolVLM-256M is the smallest multimodal model in the world. It accepts arbitrary sequences of image and text inputs to produce text outputs. It's designed for efficiency. SmolVLM can answer questions about images, describe visual content, or transcribe text. Its lightweight architecture makes it suitable for on-device applications while maintaining strong performance on multimodal tasks. It can run inference on one image with under 1GB of GPU RAM.
|
20 |
|
21 |
+
## Model Summary
|
22 |
|
23 |
+
- **Developed by:** Hugging Face 🤗
|
24 |
+
- **Model type:** Multi-modal model (image+text)
|
25 |
+
- **Language(s) (NLP):** English
|
26 |
+
- **License:** Apache 2.0
|
27 |
+
- **Architecture:** Based on [Idefics3](https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3) (see technical summary)
|
28 |
|
29 |
+
## Resources
|
30 |
|
31 |
+
- **Demo:** [SmolVLM-256 Demo](https://huggingface.co/spaces/HuggingFaceTB/SmolVLM-256M-Demo)
|
32 |
+
- **Blog:** [Blog post](https://huggingface.co/blog/smolvlm)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
## Uses
|
35 |
|
36 |
+
SmolVLM can be used for inference on multimodal (image + text) tasks where the input comprises text queries along with one or more images. Text and images can be interleaved arbitrarily, enabling tasks like image captioning, visual question answering, and storytelling based on visual content. The model does not support image generation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
To fine-tune SmolVLM on a specific task, you can follow [the fine-tuning tutorial](https://github.com/huggingface/smollm/blob/main/vision/finetuning/Smol_VLM_FT.ipynb).
|
39 |
|
40 |
+
### Technical Summary
|
41 |
|
42 |
+
SmolVLM leverages the lightweight SmolLM2 language model to provide a compact yet powerful multimodal experience. It introduces several changes compared to the larger SmolVLM 2.2B model:
|
43 |
|
44 |
+
- **Image compression:** We introduce a more radical image compression compared to Idefics3 and SmolVLM-2.2B to enable the model to infer faster and use less RAM.
|
45 |
+
- **Visual Token Encoding:** SmolVLM-256 uses 64 visual tokens to encode image patches of size 512×512. Larger images are divided into patches, each encoded separately, enhancing efficiency without compromising performance.
|
46 |
+
- **New special tokens:** We added new special tokens to divide the subimages. This allows for more efficient tokenization of the images.
|
47 |
+
- **Smoller vision encoder:** We went from a 400M parameter siglip vision encoder to a much smaller 93M encoder.
|
48 |
+
- **Larger image patches:** We are now passing patches of 512x512 to the vision encoder, instead of 384x384 like the larger SmolVLM. This allows the information to be encoded more efficiently.
|
49 |
|
50 |
+
More details about the training and architecture are available in our technical report.
|
51 |
|
52 |
+
### How to get started
|
53 |
|
54 |
+
You can use transformers to load, infer and fine-tune SmolVLM.
|
55 |
|
56 |
+
```python
|
57 |
+
import torch
|
58 |
+
from PIL import Image
|
59 |
+
from transformers import AutoProcessor, AutoModelForVision2Seq
|
60 |
+
from transformers.image_utils import load_image
|
61 |
|
62 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
63 |
|
64 |
+
# Load images
|
65 |
+
image = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")
|
66 |
|
67 |
+
# Initialize processor and model
|
68 |
+
processor = AutoProcessor.from_pretrained("HuggingFaceTB/SmolVLM-500M-Instruct")
|
69 |
+
model = AutoModelForVision2Seq.from_pretrained(
|
70 |
+
"HuggingFaceTB/SmolVLM-500M-Instruct",
|
71 |
+
torch_dtype=torch.bfloat16,
|
72 |
+
_attn_implementation="flash_attention_2" if DEVICE == "cuda" else "eager",
|
73 |
+
).to(DEVICE)
|
74 |
|
75 |
+
# Create input messages
|
76 |
+
messages = [
|
77 |
+
{
|
78 |
+
"role": "user",
|
79 |
+
"content": [
|
80 |
+
{"type": "image"},
|
81 |
+
{"type": "text", "text": "Can you describe this image?"}
|
82 |
+
]
|
83 |
+
},
|
84 |
+
]
|
85 |
|
86 |
+
# Prepare inputs
|
87 |
+
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
|
88 |
+
inputs = processor(text=prompt, images=[image], return_tensors="pt")
|
89 |
+
inputs = inputs.to(DEVICE)
|
90 |
|
91 |
+
# Generate outputs
|
92 |
+
generated_ids = model.generate(**inputs, max_new_tokens=500)
|
93 |
+
generated_texts = processor.batch_decode(
|
94 |
+
generated_ids,
|
95 |
+
skip_special_tokens=True,
|
96 |
+
)
|
97 |
|
98 |
+
print(generated_texts[0])
|
99 |
+
"""
|
100 |
+
Assistant: The image depicts a large, historic statue of liberty, located in New York City. The statue is a green, cylindrical structure with a human figure at the top, holding a torch. The statue is situated on a pedestal that resembles the statue of liberty, which is located on a small island in the middle of a body of water. The water surrounding the island is calm, reflecting the blue sky and the statue.
|
101 |
+
In the background, there are several tall buildings, including the Empire State Building, which is visible in the distance. These buildings are made of glass and steel, and they are positioned in a grid-like pattern, giving them a modern look. The sky is clear, with a few clouds visible, indicating fair weather.
|
102 |
+
The statue is surrounded by trees, which are green and appear to be healthy. There are also some small structures, possibly houses or buildings, visible in the distance. The overall scene suggests a peaceful and serene environment, typical of a cityscape.
|
103 |
+
The image is taken during the daytime, likely during the day of the statue's installation. The lighting is bright, casting a strong shadow on the statue and the water, which enhances the visibility of the statue and the surrounding environment.
|
104 |
+
To summarize, the image captures a significant historical statue of liberty, situated on a small island in the middle of a body of water, surrounded by trees and buildings. The sky is clear, with a few clouds visible, indicating fair weather. The statue is green and cylindrical, with a human figure holding a torch, and is surrounded by trees, indicating a peaceful and well-maintained environment. The overall scene is one of tranquility and historical significance.
|
105 |
+
"""
|
106 |
+
```
|
107 |
|
108 |
|
109 |
+
### Model optimizations
|
110 |
|
111 |
+
**Precision**: For better performance, load and run the model in half-precision (`torch.bfloat16`) if your hardware supports it.
|
112 |
|
113 |
+
```python
|
114 |
+
from transformers import AutoModelForVision2Seq
|
115 |
+
import torch
|
116 |
|
117 |
+
model = AutoModelForVision2Seq.from_pretrained(
|
118 |
+
"HuggingFaceTB/SmolVLM-Instruct",
|
119 |
+
torch_dtype=torch.bfloat16
|
120 |
+
).to("cuda")
|
121 |
+
```
|
122 |
|
123 |
+
You can also load SmolVLM with 4/8-bit quantization using bitsandbytes, torchao or Quanto. Refer to [this page](https://huggingface.co/docs/transformers/en/main_classes/quantization) for other options.
|
124 |
|
125 |
+
```python
|
126 |
+
from transformers import AutoModelForVision2Seq, BitsAndBytesConfig
|
127 |
+
import torch
|
128 |
|
129 |
+
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
130 |
+
model = AutoModelForVision2Seq.from_pretrained(
|
131 |
+
"HuggingFaceTB/SmolVLM-Instruct",
|
132 |
+
quantization_config=quantization_config,
|
133 |
+
)
|
134 |
+
```
|
135 |
|
136 |
+
**Vision Encoder Efficiency**: Adjust the image resolution by setting `size={"longest_edge": N*512}` when initializing the processor, where N is your desired value. The default `N=4` works well, which results in input images of
|
137 |
+
size 2048×2048. Decreasing N can save GPU memory and is appropriate for lower-resolution images. This is also useful if you want to fine-tune on videos.
|
138 |
|
|
|
139 |
|
140 |
+
## Misuse and Out-of-scope Use
|
141 |
|
142 |
+
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:
|
143 |
|
144 |
+
- Prohibited Uses:
|
145 |
+
- Evaluating or scoring individuals (e.g., in employment, education, credit)
|
146 |
+
- Critical automated decision-making
|
147 |
+
- Generating unreliable factual content
|
148 |
+
- Malicious Activities:
|
149 |
+
- Spam generation
|
150 |
+
- Disinformation campaigns
|
151 |
+
- Harassment or abuse
|
152 |
+
- Unauthorized surveillance
|
153 |
|
154 |
+
### License
|
155 |
+
|
156 |
+
SmolVLM 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.
|
157 |
+
|
158 |
+
We release the SmolVLM checkpoints under the Apache 2.0 license.
|
159 |
|
160 |
+
## Training Details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
+
### Training Data
|
163 |
|
164 |
+
The training data comes from [The Cauldron](https://huggingface.co/datasets/HuggingFaceM4/the_cauldron) and [Docmatix](https://huggingface.co/datasets/HuggingFaceM4/Docmatix) datasets, with emphasis on document understanding (25%) and image captioning (18%), while maintaining balanced coverage across other crucial capabilities like visual reasoning, chart comprehension, and general instruction following.
|
165 |
+
<img src="https://huggingface.co/HuggingFaceTB/SmolVLM-Instruct/resolve/main/mixture_the_cauldron.png" alt="Example Image" style="width:90%;" />
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
170 |
+
## Evaluation
|
171 |
|
172 |
+
| Model | MMMU (val) | MathVista (testmini) | MMStar (val) | DocVQA (test) | TextVQA (val) | Min GPU RAM required (GB) |
|
173 |
+
|-------------------|------------|----------------------|--------------|---------------|---------------|---------------------------|
|
174 |
+
| SmolVLM 2.2B | 38.8 | 44.6 | 42.1 | 81.6 | 72.7 | 5.02 |
|
175 |
+
| Qwen-VL 2B | 41.1 | 47.8 | 47.5 | 90.1 | 79.7 | 13.70 |
|
176 |
+
| InternVL2 2B | 34.3 | 46.3 | 49.8 | 86.9 | 73.4 | 10.52 |
|
177 |
+
| PaliGemma 3B 448px| 34.9 | 28.7 | 48.3 | 32.2 | 56.0 | 6.72 |
|
178 |
+
| moondream2 | 32.4 | 24.3 | 40.3 | 70.5 | 65.2 | 3.87 |
|
179 |
+
| MiniCPM-V-2 | 38.2 | 39.8 | 39.1 | 71.9 | 74.1 | 7.88 |
|
180 |
+
| MM1.5 1B | 35.8 | 37.2 | 0.0 | 81.0 | 72.5 | NaN |
|