Image-Text-to-Text
Transformers
Safetensors
English
qwen2_vl
multimodal
qwen
qwen2
unsloth
vision
conversational
text-generation-inference
Instructions to use unsloth/Qwen2-VL-7B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/Qwen2-VL-7B-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-7B-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)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("unsloth/Qwen2-VL-7B-Instruct") model = AutoModelForMultimodalLM.from_pretrained("unsloth/Qwen2-VL-7B-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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/Qwen2-VL-7B-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-7B-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-7B-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-7B-Instruct
- SGLang
How to use unsloth/Qwen2-VL-7B-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-7B-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-7B-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-7B-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-7B-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 Desktop
- Docker Model Runner
How to use unsloth/Qwen2-VL-7B-Instruct with Docker Model Runner:
docker model run hf.co/unsloth/Qwen2-VL-7B-Instruct
Add files using upload-large-folder tool
Browse files- config.json +3 -3
- generation_config.json +1 -1
- model-00001-of-00005.safetensors +3 -0
- model-00002-of-00005.safetensors +3 -0
- model-00003-of-00005.safetensors +3 -0
- model-00004-of-00005.safetensors +3 -0
- model-00005-of-00005.safetensors +3 -0
- model.safetensors.index.json +0 -0
- 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": 3584,
|
|
@@ -32,7 +31,7 @@
|
|
| 32 |
"sliding_window": 32768,
|
| 33 |
"tie_word_embeddings": false,
|
| 34 |
"torch_dtype": "bfloat16",
|
| 35 |
-
"transformers_version": "4.
|
| 36 |
"unsloth_fixed": true,
|
| 37 |
"use_cache": true,
|
| 38 |
"use_sliding_window": false,
|
|
@@ -40,7 +39,8 @@
|
|
| 40 |
"vision_config": {
|
| 41 |
"in_chans": 3,
|
| 42 |
"model_type": "qwen2_vl",
|
| 43 |
-
"spatial_patch_size": 14
|
|
|
|
| 44 |
},
|
| 45 |
"vision_end_token_id": 151653,
|
| 46 |
"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": 3584,
|
|
|
|
| 31 |
"sliding_window": 32768,
|
| 32 |
"tie_word_embeddings": false,
|
| 33 |
"torch_dtype": "bfloat16",
|
| 34 |
+
"transformers_version": "4.49.0",
|
| 35 |
"unsloth_fixed": true,
|
| 36 |
"use_cache": true,
|
| 37 |
"use_sliding_window": false,
|
|
|
|
| 39 |
"vision_config": {
|
| 40 |
"in_chans": 3,
|
| 41 |
"model_type": "qwen2_vl",
|
| 42 |
+
"spatial_patch_size": 14,
|
| 43 |
+
"torch_dtype": "bfloat16"
|
| 44 |
},
|
| 45 |
"vision_end_token_id": 151653,
|
| 46 |
"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 |
}
|
model-00001-of-00005.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eab4f4dc1abf860794c98ce3759b4ace1059fc0fc041ede76b88988b3557c132
|
| 3 |
+
size 3898649896
|
model-00002-of-00005.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0546b7cd070ff239de0f61a28770de6a0ac517ad313071e151653e38911ffb25
|
| 3 |
+
size 3864726320
|
model-00003-of-00005.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:11368ea1e9c0039ca54012a74ac32d543a9e9d980b2d0ad7e93af0341ace1fe6
|
| 3 |
+
size 3864726424
|
model-00004-of-00005.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:381e110d74db594cc24956af0e74a01ae02104497113a78926990c5bd1f395f6
|
| 3 |
+
size 3864733680
|
model-00005-of-00005.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e76ec4dc2e7c0dcbe3432e58fae08e62204a2ef2323069d85c8fa0affb87332a
|
| 3 |
+
size 1089994880
|
model.safetensors.index.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
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",
|