HuggingFaceTB/SmolVLM-Instruct
59938k
1---2library_name: transformers3license: apache-2.04datasets:5- HuggingFaceM4/the_cauldron6- HuggingFaceM4/Docmatix7pipeline_tag: image-text-to-text8language:9- en10base_model:11- HuggingFaceTB/SmolLM2-1.7B-Instruct12- google/siglip-so400m-patch14-38413---14 15<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/SmolVLM.png" width="800" height="auto" alt="Image description">16 17# SmolVLM18 19SmolVLM is a compact open multimodal model that accepts arbitrary sequences of image and text inputs to produce text outputs. Designed for efficiency, SmolVLM can answer questions about images, describe visual content, create stories grounded on multiple images, or function as a pure language model without visual inputs. Its lightweight architecture makes it suitable for on-device applications while maintaining strong performance on multimodal tasks.20 21## Model Summary22 23- **Developed by:** Hugging Face 🤗24- **Model type:** Multi-modal model (image+text)25- **Language(s) (NLP):** English26- **License:** Apache 2.027- **Architecture:** Based on [Idefics3](https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3) (see technical summary)28 29## Resources30 31- **Demo:** [SmolVLM Demo](https://huggingface.co/spaces/HuggingFaceTB/SmolVLM)32- **Blog:** [Blog post](https://huggingface.co/blog/smolvlm)33 34## Uses35 36SmolVLM 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 38To fine-tune SmolVLM on a specific task, you can follow the fine-tuning tutorial.39<!-- todo: add link to fine-tuning tutorial -->40 41### Technical Summary42 43SmolVLM leverages the lightweight SmolLM2 language model to provide a compact yet powerful multimodal experience. It introduces several changes compared to previous Idefics models:44 45- **Image compression:** We introduce a more radical image compression compared to Idefics3 to enable the model to infer faster and use less RAM.46- **Visual Token Encoding:** SmolVLM uses 81 visual tokens to encode image patches of size 384×384. Larger images are divided into patches, each encoded separately, enhancing efficiency without compromising performance.47 48More details about the training and architecture are available in our technical report.49 50 51### How to get started52 53You can use transformers to load, infer and fine-tune SmolVLM.54 55```python56import torch57from PIL import Image58from transformers import AutoProcessor, AutoModelForVision2Seq59from transformers.image_utils import load_image60 61DEVICE = "cuda" if torch.cuda.is_available() else "cpu"62 63# Load images64image1 = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")65image2 = load_image("https://huggingface.co/spaces/merve/chameleon-7b/resolve/main/bee.jpg")66 67# Initialize processor and model68processor = AutoProcessor.from_pretrained("HuggingFaceTB/SmolVLM-Instruct")69model = AutoModelForVision2Seq.from_pretrained(70 "HuggingFaceTB/SmolVLM-Instruct",71 torch_dtype=torch.bfloat16,72 _attn_implementation="flash_attention_2" if DEVICE == "cuda" else "eager",73).to(DEVICE)74 75# Create input messages76messages = [77 {78 "role": "user",79 "content": [80 {"type": "image"},81 {"type": "image"},82 {"type": "text", "text": "Can you describe the two images?"}83 ]84 },85]86 87# Prepare inputs88prompt = processor.apply_chat_template(messages, add_generation_prompt=True)89inputs = processor(text=prompt, images=[image1, image2], return_tensors="pt")90inputs = inputs.to(DEVICE)91 92# Generate outputs93generated_ids = model.generate(**inputs, max_new_tokens=500)94generated_texts = processor.batch_decode(95 generated_ids,96 skip_special_tokens=True,97)98 99print(generated_texts[0])100"""101Assistant: The first image shows a green statue of the Statue of Liberty standing on a stone pedestal in front of a body of water. 102The statue is holding a torch in its right hand and a tablet in its left hand. The water is calm and there are no boats or other objects visible. 103The sky is clear and there are no clouds. The second image shows a bee on a pink flower. 104The bee is black and yellow and is collecting pollen from the flower. The flower is surrounded by green leaves.105"""106```107 108 109### Model optimizations110 111**Precision**: For better performance, load and run the model in half-precision (`torch.float16` or `torch.bfloat16`) if your hardware supports it.112 113```python114from transformers import AutoModelForVision2Seq115import torch116 117model = AutoModelForVision2Seq.from_pretrained(118 "HuggingFaceTB/SmolVLM-Instruct",119 torch_dtype=torch.bfloat16120).to("cuda")121```122 123You 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```python126from transformers import AutoModelForVision2Seq, BitsAndBytesConfig127import torch128 129quantization_config = BitsAndBytesConfig(load_in_8bit=True)130model = 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*384}` when initializing the processor, where N is your desired value. The default `N=4` works well, which results in input images of137size 1536×1536. For documents, `N=5` might be beneficial. 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 Use141 142SmolVLM 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-making147 - Generating unreliable factual content148- Malicious Activities:149 - Spam generation150 - Disinformation campaigns151 - Harassment or abuse152 - Unauthorized surveillance153 154### License155 156SmolVLM is built upon [the shape-optimized SigLIP](https://huggingface.co/google/siglip-so400m-patch14-384) as image encoder and [SmolLM2](https://huggingface.co/HuggingFaceTB/SmolLM2-1.7B-Instruct) for text decoder part.157 158We release the SmolVLM checkpoints under the Apache 2.0 license.159 160## Training Details161 162### Training Data163 164The 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## Evaluation171 172| Model | MMMU (val) | MathVista (testmini) | MMStar (val) | DocVQA (test) | TextVQA (val) | Min GPU RAM required (GB) |173|-------------------|------------|----------------------|--------------|---------------|---------------|---------------------------|174| SmolVLM | 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 |181 182# Citation information183You can cite us in the following way:184```bibtex185@article{marafioti2025smolvlm,186 title={SmolVLM: Redefining small and efficient multimodal models}, 187 author={Andrés Marafioti and Orr Zohar and Miquel Farré and Merve Noyan and Elie Bakouch and Pedro Cuenca and Cyril Zakka and Loubna Ben Allal and Anton Lozhkov and Nouamane Tazi and Vaibhav Srivastav and Joshua Lochner and Hugo Larcher and Mathieu Morlon and Lewis Tunstall and Leandro von Werra and Thomas Wolf},188 journal={arXiv preprint arXiv:2504.05299},189 year={2025}190}191```