Instructions to use HuggingFaceTB/SmolVLM2-500M-Video-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceTB/SmolVLM2-500M-Video-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="HuggingFaceTB/SmolVLM2-500M-Video-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/SmolVLM2-500M-Video-Instruct") model = AutoModelForImageTextToText.from_pretrained("HuggingFaceTB/SmolVLM2-500M-Video-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 Settings
- vLLM
How to use HuggingFaceTB/SmolVLM2-500M-Video-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceTB/SmolVLM2-500M-Video-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/SmolVLM2-500M-Video-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/SmolVLM2-500M-Video-Instruct
- SGLang
How to use HuggingFaceTB/SmolVLM2-500M-Video-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/SmolVLM2-500M-Video-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/SmolVLM2-500M-Video-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/SmolVLM2-500M-Video-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/SmolVLM2-500M-Video-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/SmolVLM2-500M-Video-Instruct with Docker Model Runner:
docker model run hf.co/HuggingFaceTB/SmolVLM2-500M-Video-Instruct
Upload processor
Browse files- preprocessor_config.json +8 -6
- special_tokens_map.json +7 -21
- tokenizer_config.json +11 -2
preprocessor_config.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
0.5,
|
| 11 |
0.5
|
| 12 |
],
|
| 13 |
-
"image_processor_type": "
|
| 14 |
"image_std": [
|
| 15 |
0.5,
|
| 16 |
0.5,
|
|
@@ -19,15 +19,17 @@
|
|
| 19 |
"max_image_size": {
|
| 20 |
"longest_edge": 512
|
| 21 |
},
|
| 22 |
-
"video_sampling": {
|
| 23 |
-
"fps": 1,
|
| 24 |
-
"max_frames": 64,
|
| 25 |
-
"video_size": {"longest_edge": 384}
|
| 26 |
-
},
|
| 27 |
"processor_class": "SmolVLMProcessor",
|
| 28 |
"resample": 1,
|
| 29 |
"rescale_factor": 0.00392156862745098,
|
| 30 |
"size": {
|
| 31 |
"longest_edge": 2048
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
}
|
|
|
|
| 10 |
0.5,
|
| 11 |
0.5
|
| 12 |
],
|
| 13 |
+
"image_processor_type": "SmolVLMImageProcessor",
|
| 14 |
"image_std": [
|
| 15 |
0.5,
|
| 16 |
0.5,
|
|
|
|
| 19 |
"max_image_size": {
|
| 20 |
"longest_edge": 512
|
| 21 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
"processor_class": "SmolVLMProcessor",
|
| 23 |
"resample": 1,
|
| 24 |
"rescale_factor": 0.00392156862745098,
|
| 25 |
"size": {
|
| 26 |
"longest_edge": 2048
|
| 27 |
+
},
|
| 28 |
+
"video_sampling": {
|
| 29 |
+
"fps": 1,
|
| 30 |
+
"max_frames": 64,
|
| 31 |
+
"video_size": {
|
| 32 |
+
"longest_edge": 384
|
| 33 |
+
}
|
| 34 |
}
|
| 35 |
}
|
special_tokens_map.json
CHANGED
|
@@ -1,26 +1,8 @@
|
|
| 1 |
{
|
| 2 |
"additional_special_tokens": [
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
"normalized": false,
|
| 7 |
-
"rstrip": false,
|
| 8 |
-
"single_word": false
|
| 9 |
-
},
|
| 10 |
-
{
|
| 11 |
-
"content": "<image>",
|
| 12 |
-
"lstrip": false,
|
| 13 |
-
"normalized": false,
|
| 14 |
-
"rstrip": false,
|
| 15 |
-
"single_word": false
|
| 16 |
-
},
|
| 17 |
-
{
|
| 18 |
-
"content": "<end_of_utterance>",
|
| 19 |
-
"lstrip": false,
|
| 20 |
-
"normalized": false,
|
| 21 |
-
"rstrip": false,
|
| 22 |
-
"single_word": false
|
| 23 |
-
}
|
| 24 |
],
|
| 25 |
"bos_token": {
|
| 26 |
"content": "<|im_start|>",
|
|
@@ -29,6 +11,7 @@
|
|
| 29 |
"rstrip": false,
|
| 30 |
"single_word": false
|
| 31 |
},
|
|
|
|
| 32 |
"eos_token": {
|
| 33 |
"content": "<end_of_utterance>",
|
| 34 |
"lstrip": false,
|
|
@@ -36,6 +19,9 @@
|
|
| 36 |
"rstrip": false,
|
| 37 |
"single_word": false
|
| 38 |
},
|
|
|
|
|
|
|
|
|
|
| 39 |
"pad_token": {
|
| 40 |
"content": "<|im_end|>",
|
| 41 |
"lstrip": false,
|
|
|
|
| 1 |
{
|
| 2 |
"additional_special_tokens": [
|
| 3 |
+
"<fake_token_around_image>",
|
| 4 |
+
"<image>",
|
| 5 |
+
"<end_of_utterance>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
],
|
| 7 |
"bos_token": {
|
| 8 |
"content": "<|im_start|>",
|
|
|
|
| 11 |
"rstrip": false,
|
| 12 |
"single_word": false
|
| 13 |
},
|
| 14 |
+
"end_of_utterance_token": "<end_of_utterance>",
|
| 15 |
"eos_token": {
|
| 16 |
"content": "<end_of_utterance>",
|
| 17 |
"lstrip": false,
|
|
|
|
| 19 |
"rstrip": false,
|
| 20 |
"single_word": false
|
| 21 |
},
|
| 22 |
+
"fake_image_token": "<fake_token_around_image>",
|
| 23 |
+
"global_image_token": "<global-img>",
|
| 24 |
+
"image_token": "<image>",
|
| 25 |
"pad_token": {
|
| 26 |
"content": "<|im_end|>",
|
| 27 |
"lstrip": false,
|
tokenizer_config.json
CHANGED
|
@@ -1170,12 +1170,21 @@
|
|
| 1170 |
"bos_token": "<|im_start|>",
|
| 1171 |
"chat_template": "<|im_start|>{% for message in messages %}{{message['role'] | capitalize}}{% if message['content'][0]['type'] == 'image' %}{{':'}}{% else %}{{': '}}{% endif %}{% for line in message['content'] %}{% if line['type'] == 'text' %}{{line['text']}}{% elif line['type'] == 'image' %}{{ '<image>' }}{% endif %}{% endfor %}<end_of_utterance>\n{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}",
|
| 1172 |
"clean_up_tokenization_spaces": false,
|
|
|
|
| 1173 |
"eos_token": "<end_of_utterance>",
|
| 1174 |
-
"extra_special_tokens": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1175 |
"legacy": false,
|
| 1176 |
"model_max_length": 8192,
|
| 1177 |
"pad_token": "<|im_end|>",
|
| 1178 |
-
"processor_class": "
|
| 1179 |
"tokenizer_class": "GPT2Tokenizer",
|
| 1180 |
"truncation_side": "left",
|
| 1181 |
"unk_token": "<|endoftext|>",
|
|
|
|
| 1170 |
"bos_token": "<|im_start|>",
|
| 1171 |
"chat_template": "<|im_start|>{% for message in messages %}{{message['role'] | capitalize}}{% if message['content'][0]['type'] == 'image' %}{{':'}}{% else %}{{': '}}{% endif %}{% for line in message['content'] %}{% if line['type'] == 'text' %}{{line['text']}}{% elif line['type'] == 'image' %}{{ '<image>' }}{% endif %}{% endfor %}<end_of_utterance>\n{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}",
|
| 1172 |
"clean_up_tokenization_spaces": false,
|
| 1173 |
+
"end_of_utterance_token": "<end_of_utterance>",
|
| 1174 |
"eos_token": "<end_of_utterance>",
|
| 1175 |
+
"extra_special_tokens": {
|
| 1176 |
+
"end_of_utterance_token": "<end_of_utterance>",
|
| 1177 |
+
"fake_image_token": "<fake_token_around_image>",
|
| 1178 |
+
"global_image_token": "<global-img>",
|
| 1179 |
+
"image_token": "<image>"
|
| 1180 |
+
},
|
| 1181 |
+
"fake_image_token": "<fake_token_around_image>",
|
| 1182 |
+
"global_image_token": "<global-img>",
|
| 1183 |
+
"image_token": "<image>",
|
| 1184 |
"legacy": false,
|
| 1185 |
"model_max_length": 8192,
|
| 1186 |
"pad_token": "<|im_end|>",
|
| 1187 |
+
"processor_class": "SmolVLMProcessor",
|
| 1188 |
"tokenizer_class": "GPT2Tokenizer",
|
| 1189 |
"truncation_side": "left",
|
| 1190 |
"unk_token": "<|endoftext|>",
|