Instructions to use HuggingFaceTB/SmolVLM2-2.2B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceTB/SmolVLM2-2.2B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="HuggingFaceTB/SmolVLM2-2.2B-Base") 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("HuggingFaceTB/SmolVLM2-2.2B-Base") model = AutoModelForMultimodalLM.from_pretrained("HuggingFaceTB/SmolVLM2-2.2B-Base", device_map="auto") 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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use HuggingFaceTB/SmolVLM2-2.2B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceTB/SmolVLM2-2.2B-Base" # 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-2.2B-Base", "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-2.2B-Base
- SGLang
How to use HuggingFaceTB/SmolVLM2-2.2B-Base 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-2.2B-Base" \ --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-2.2B-Base", "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-2.2B-Base" \ --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-2.2B-Base", "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-2.2B-Base with Docker Model Runner:
docker model run hf.co/HuggingFaceTB/SmolVLM2-2.2B-Base
File size: 1,053 Bytes
cd3ead3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | {
"<end_of_utterance>": 49191,
"<fake_token_around_image>": 49189,
"<global-img>": 49152,
"<image>": 49190,
"<row_1_col_1>": 49153,
"<row_1_col_2>": 49154,
"<row_1_col_3>": 49155,
"<row_1_col_4>": 49156,
"<row_1_col_5>": 49157,
"<row_1_col_6>": 49158,
"<row_2_col_1>": 49159,
"<row_2_col_2>": 49160,
"<row_2_col_3>": 49161,
"<row_2_col_4>": 49162,
"<row_2_col_5>": 49163,
"<row_2_col_6>": 49164,
"<row_3_col_1>": 49165,
"<row_3_col_2>": 49166,
"<row_3_col_3>": 49167,
"<row_3_col_4>": 49168,
"<row_3_col_5>": 49169,
"<row_3_col_6>": 49170,
"<row_4_col_1>": 49171,
"<row_4_col_2>": 49172,
"<row_4_col_3>": 49173,
"<row_4_col_4>": 49174,
"<row_4_col_5>": 49175,
"<row_4_col_6>": 49176,
"<row_5_col_1>": 49177,
"<row_5_col_2>": 49178,
"<row_5_col_3>": 49179,
"<row_5_col_4>": 49180,
"<row_5_col_5>": 49181,
"<row_5_col_6>": 49182,
"<row_6_col_1>": 49183,
"<row_6_col_2>": 49184,
"<row_6_col_3>": 49185,
"<row_6_col_4>": 49186,
"<row_6_col_5>": 49187,
"<row_6_col_6>": 49188
}
|