Instructions to use HuggingFaceTB/SmolVLM-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceTB/SmolVLM-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="HuggingFaceTB/SmolVLM-Instruct") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("HuggingFaceTB/SmolVLM-Instruct") model = AutoModelForImageTextToText.from_pretrained("HuggingFaceTB/SmolVLM-Instruct") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use HuggingFaceTB/SmolVLM-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceTB/SmolVLM-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HuggingFaceTB/SmolVLM-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/HuggingFaceTB/SmolVLM-Instruct
- SGLang
How to use HuggingFaceTB/SmolVLM-Instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "HuggingFaceTB/SmolVLM-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HuggingFaceTB/SmolVLM-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "HuggingFaceTB/SmolVLM-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HuggingFaceTB/SmolVLM-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use HuggingFaceTB/SmolVLM-Instruct with Docker Model Runner:
docker model run hf.co/HuggingFaceTB/SmolVLM-Instruct
Misc improvements
#1
by merve HF Staff - opened
README.md
CHANGED
|
@@ -1,14 +1,16 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
# Model Card for Model ID
|
| 7 |
|
| 8 |
SmolVLM 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.
|
| 9 |
|
| 10 |
-
We release the checkpoints under the Apache 2.0 license.
|
| 11 |
-
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
### Model Description
|
|
@@ -28,7 +30,7 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
| 28 |
|
| 29 |
- **Repository:** [More Information Needed]
|
| 30 |
- **Paper [optional]:** [More Information Needed]
|
| 31 |
-
- **Demo
|
| 32 |
|
| 33 |
## Uses
|
| 34 |
|
|
@@ -40,14 +42,16 @@ To fine-tune SmolVLM on a specific task, you can follow the fine-tuning tutorial
|
|
| 40 |
|
| 41 |
SmolVLM leverages the lightweight SmolLM2 language model to provide a compact yet powerful multimodal experience. It introduces several changes compared to previous models:
|
| 42 |
|
| 43 |
-
- Image compression: We introduce a more radical image compression compared to Idefics3 to enable the model to infer faster and use less RAM.
|
| 44 |
-
- Visual Token Encoding: It 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.
|
| 45 |
|
| 46 |
More details about the training and architecture are available in our technical report.
|
| 47 |
|
| 48 |
|
| 49 |
### How to get started
|
| 50 |
|
|
|
|
|
|
|
| 51 |
```python
|
| 52 |
import torch
|
| 53 |
from PIL import Image
|
|
@@ -108,13 +112,29 @@ print(generated_texts[0])
|
|
| 108 |
**Precision**: For better performance, load and run the model in half-precision (`torch.float16` or `torch.bfloat16`) if your hardware supports it.
|
| 109 |
|
| 110 |
```python
|
|
|
|
|
|
|
|
|
|
| 111 |
model = AutoModelForVision2Seq.from_pretrained(
|
| 112 |
"HuggingFaceTB/SmolVLM-Instruct",
|
| 113 |
torch_dtype=torch.bfloat16
|
| 114 |
-
).to(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
```
|
| 116 |
|
| 117 |
-
**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, but for documents, N=5 might be beneficial. Decreasing N can save GPU memory for lower-resolution images. This is also useful if you want to fine-tune on videos.
|
| 118 |
|
| 119 |
|
| 120 |
## Misuse and Out-of-scope Use
|
|
@@ -133,10 +153,7 @@ SmolVLM is not intended for high-stakes scenarios or critical decision-making pr
|
|
| 133 |
|
| 134 |
### License
|
| 135 |
|
| 136 |
-
SmolVLM is built upon the
|
| 137 |
-
|
| 138 |
-
https://huggingface.co/google/siglip-so400m-patch14-384
|
| 139 |
-
https://huggingface.co/HuggingFaceTB/SmolLM2-1.7B-Instruct
|
| 140 |
|
| 141 |
We release the SmolVLM checkpoints under the Apache 2.0 license.
|
| 142 |
|
|
@@ -155,5 +172,4 @@ TODO
|
|
| 155 |
|
| 156 |
## Evaluation
|
| 157 |
|
| 158 |
-
TODO
|
| 159 |
-
|
|
|
|
| 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 |
---
|
| 9 |
|
| 10 |
# Model Card for Model ID
|
| 11 |
|
| 12 |
SmolVLM 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.
|
| 13 |
|
|
|
|
|
|
|
| 14 |
## Model Details
|
| 15 |
|
| 16 |
### Model Description
|
|
|
|
| 30 |
|
| 31 |
- **Repository:** [More Information Needed]
|
| 32 |
- **Paper [optional]:** [More Information Needed]
|
| 33 |
+
- **Demo:** [SmolVLM Demo](https://huggingface.co/spaces/HuggingFaceTB/SmolVLM)
|
| 34 |
|
| 35 |
## Uses
|
| 36 |
|
|
|
|
| 42 |
|
| 43 |
SmolVLM leverages the lightweight SmolLM2 language model to provide a compact yet powerful multimodal experience. It introduces several changes compared to previous 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:** It 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 |
|
| 48 |
More details about the training and architecture are available in our technical report.
|
| 49 |
|
| 50 |
|
| 51 |
### How to get started
|
| 52 |
|
| 53 |
+
You can use transformers to load, infer and fine-tune SmolVLM.
|
| 54 |
+
|
| 55 |
```python
|
| 56 |
import torch
|
| 57 |
from PIL import Image
|
|
|
|
| 112 |
**Precision**: For better performance, load and run the model in half-precision (`torch.float16` or `torch.bfloat16`) if your hardware supports it.
|
| 113 |
|
| 114 |
```python
|
| 115 |
+
from transformers import AutoModelForVision2Seq
|
| 116 |
+
import torch
|
| 117 |
+
|
| 118 |
model = AutoModelForVision2Seq.from_pretrained(
|
| 119 |
"HuggingFaceTB/SmolVLM-Instruct",
|
| 120 |
torch_dtype=torch.bfloat16
|
| 121 |
+
).to("cuda")
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
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.
|
| 125 |
+
|
| 126 |
+
```python
|
| 127 |
+
from transformers import AutoModelForVision2Seq, BitsAndBytesConfig
|
| 128 |
+
import torch
|
| 129 |
+
|
| 130 |
+
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
| 131 |
+
model = AutoModelForVision2Seq.from_pretrained(
|
| 132 |
+
"HuggingFaceTB/SmolVLM-Instruct",
|
| 133 |
+
quantization_config=quantization_config
|
| 134 |
+
)
|
| 135 |
```
|
| 136 |
|
| 137 |
+
**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, but for documents, `N=5` might be beneficial. Decreasing N can save GPU memory 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
|
|
|
|
| 153 |
|
| 154 |
### License
|
| 155 |
|
| 156 |
+
SmolVLM 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 |
|
| 158 |
We release the SmolVLM checkpoints under the Apache 2.0 license.
|
| 159 |
|
|
|
|
| 172 |
|
| 173 |
## Evaluation
|
| 174 |
|
| 175 |
+
TODO
|
|
|