Image-Text-to-Text
Transformers
Safetensors
English
qwen2_vl
multimodal
qwen
qwen2
unsloth
vision
conversational
text-generation-inference
Instructions to use unsloth/Qwen2-VL-2B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/Qwen2-VL-2B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="unsloth/Qwen2-VL-2B-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, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("unsloth/Qwen2-VL-2B-Instruct") model = AutoModelForMultimodalLM.from_pretrained("unsloth/Qwen2-VL-2B-Instruct", 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/Qwen2-VL-2B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/Qwen2-VL-2B-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": "unsloth/Qwen2-VL-2B-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/unsloth/Qwen2-VL-2B-Instruct
- SGLang
How to use unsloth/Qwen2-VL-2B-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 "unsloth/Qwen2-VL-2B-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": "unsloth/Qwen2-VL-2B-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 "unsloth/Qwen2-VL-2B-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": "unsloth/Qwen2-VL-2B-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" } } ] } ] }' - Unsloth Studio
How to use unsloth/Qwen2-VL-2B-Instruct with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Qwen2-VL-2B-Instruct to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Qwen2-VL-2B-Instruct to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/Qwen2-VL-2B-Instruct to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/Qwen2-VL-2B-Instruct", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/Qwen2-VL-2B-Instruct with Docker Model Runner:
docker model run hf.co/unsloth/Qwen2-VL-2B-Instruct
Add files using upload-large-folder tool
Browse files- config.json +3 -3
- generation_config.json +1 -1
- preprocessor_config.json +2 -2
- tokenizer_config.json +1 -0
config.json
CHANGED
|
@@ -4,7 +4,6 @@
|
|
| 4 |
"Qwen2VLForConditionalGeneration"
|
| 5 |
],
|
| 6 |
"attention_dropout": 0.0,
|
| 7 |
-
"bos_token_id": 151643,
|
| 8 |
"eos_token_id": 151645,
|
| 9 |
"hidden_act": "silu",
|
| 10 |
"hidden_size": 1536,
|
|
@@ -32,7 +31,7 @@
|
|
| 32 |
"sliding_window": 32768,
|
| 33 |
"tie_word_embeddings": true,
|
| 34 |
"torch_dtype": "bfloat16",
|
| 35 |
-
"transformers_version": "4.
|
| 36 |
"unsloth_fixed": true,
|
| 37 |
"use_cache": true,
|
| 38 |
"use_sliding_window": false,
|
|
@@ -41,7 +40,8 @@
|
|
| 41 |
"hidden_size": 1536,
|
| 42 |
"in_chans": 3,
|
| 43 |
"model_type": "qwen2_vl",
|
| 44 |
-
"spatial_patch_size": 14
|
|
|
|
| 45 |
},
|
| 46 |
"vision_end_token_id": 151653,
|
| 47 |
"vision_start_token_id": 151652,
|
|
|
|
| 4 |
"Qwen2VLForConditionalGeneration"
|
| 5 |
],
|
| 6 |
"attention_dropout": 0.0,
|
|
|
|
| 7 |
"eos_token_id": 151645,
|
| 8 |
"hidden_act": "silu",
|
| 9 |
"hidden_size": 1536,
|
|
|
|
| 31 |
"sliding_window": 32768,
|
| 32 |
"tie_word_embeddings": true,
|
| 33 |
"torch_dtype": "bfloat16",
|
| 34 |
+
"transformers_version": "4.49.0",
|
| 35 |
"unsloth_fixed": true,
|
| 36 |
"use_cache": true,
|
| 37 |
"use_sliding_window": false,
|
|
|
|
| 40 |
"hidden_size": 1536,
|
| 41 |
"in_chans": 3,
|
| 42 |
"model_type": "qwen2_vl",
|
| 43 |
+
"spatial_patch_size": 14,
|
| 44 |
+
"torch_dtype": "bfloat16"
|
| 45 |
},
|
| 46 |
"vision_end_token_id": 151653,
|
| 47 |
"vision_start_token_id": 151652,
|
generation_config.json
CHANGED
|
@@ -10,5 +10,5 @@
|
|
| 10 |
"temperature": 0.01,
|
| 11 |
"top_k": 1,
|
| 12 |
"top_p": 0.001,
|
| 13 |
-
"transformers_version": "4.
|
| 14 |
}
|
|
|
|
| 10 |
"temperature": 0.01,
|
| 11 |
"top_k": 1,
|
| 12 |
"top_p": 0.001,
|
| 13 |
+
"transformers_version": "4.49.0"
|
| 14 |
}
|
preprocessor_config.json
CHANGED
|
@@ -22,8 +22,8 @@
|
|
| 22 |
"resample": 3,
|
| 23 |
"rescale_factor": 0.00392156862745098,
|
| 24 |
"size": {
|
| 25 |
-
"
|
| 26 |
-
"
|
| 27 |
},
|
| 28 |
"temporal_patch_size": 2
|
| 29 |
}
|
|
|
|
| 22 |
"resample": 3,
|
| 23 |
"rescale_factor": 0.00392156862745098,
|
| 24 |
"size": {
|
| 25 |
+
"longest_edge": 12845056,
|
| 26 |
+
"shortest_edge": 3136
|
| 27 |
},
|
| 28 |
"temporal_patch_size": 2
|
| 29 |
}
|
tokenizer_config.json
CHANGED
|
@@ -134,6 +134,7 @@
|
|
| 134 |
"clean_up_tokenization_spaces": false,
|
| 135 |
"eos_token": "<|im_end|>",
|
| 136 |
"errors": "replace",
|
|
|
|
| 137 |
"model_max_length": 32768,
|
| 138 |
"pad_token": "<|vision_pad|>",
|
| 139 |
"padding_side": "left",
|
|
|
|
| 134 |
"clean_up_tokenization_spaces": false,
|
| 135 |
"eos_token": "<|im_end|>",
|
| 136 |
"errors": "replace",
|
| 137 |
+
"extra_special_tokens": {},
|
| 138 |
"model_max_length": 32768,
|
| 139 |
"pad_token": "<|vision_pad|>",
|
| 140 |
"padding_side": "left",
|