Instructions to use OpenGVLab/InternVL2_5-2B-MPO-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2_5-2B-MPO-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2_5-2B-MPO-hf") 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("OpenGVLab/InternVL2_5-2B-MPO-hf") model = AutoModelForImageTextToText.from_pretrained("OpenGVLab/InternVL2_5-2B-MPO-hf") 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 OpenGVLab/InternVL2_5-2B-MPO-hf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2_5-2B-MPO-hf" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenGVLab/InternVL2_5-2B-MPO-hf", "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/OpenGVLab/InternVL2_5-2B-MPO-hf
- SGLang
How to use OpenGVLab/InternVL2_5-2B-MPO-hf 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 "OpenGVLab/InternVL2_5-2B-MPO-hf" \ --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": "OpenGVLab/InternVL2_5-2B-MPO-hf", "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 "OpenGVLab/InternVL2_5-2B-MPO-hf" \ --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": "OpenGVLab/InternVL2_5-2B-MPO-hf", "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 OpenGVLab/InternVL2_5-2B-MPO-hf with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2_5-2B-MPO-hf
Commit ·
0b8190c
1
Parent(s): b8a2143
update
Browse files- added_tokens.json +1 -0
- chat_template.jinja +1 -1
- processor_config.json +0 -2
- special_tokens_map.json +2 -1
- tokenizer.json +2 -2
- tokenizer_config.json +12 -2
added_tokens.json
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
"<img>": 92544,
|
| 9 |
"<quad>": 92547,
|
| 10 |
"<ref>": 92549,
|
|
|
|
| 11 |
"<|action_end|>": 92540,
|
| 12 |
"<|action_start|>": 92541,
|
| 13 |
"<|im_end|>": 92542,
|
|
|
|
| 8 |
"<img>": 92544,
|
| 9 |
"<quad>": 92547,
|
| 10 |
"<ref>": 92549,
|
| 11 |
+
"<video>": 92553,
|
| 12 |
"<|action_end|>": 92540,
|
| 13 |
"<|action_start|>": 92541,
|
| 14 |
"<|im_end|>": 92542,
|
chat_template.jinja
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{% for message in messages %}{{'<|im_start|>' + message['role'] + '
|
| 2 |
-
'}}{% if message['content'] is string %}{{ message['content'] }}{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' %}{{ '<
|
| 3 |
' }}{% elif content['type'] == 'video' %}{{ '<video>
|
| 4 |
' }}{% elif content['type'] == 'text' %}{{ content['text'] }}{% endif %}{% endfor %}{% endif %}{{'<|im_end|>
|
| 5 |
'}}{% endfor %}{% if add_generation_prompt %}{{'<|im_start|>assistant
|
|
|
|
| 1 |
{% for message in messages %}{{'<|im_start|>' + message['role'] + '
|
| 2 |
+
'}}{% if message['content'] is string %}{{ message['content'] }}{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' %}{{ '<IMG_CONTEXT>
|
| 3 |
' }}{% elif content['type'] == 'video' %}{{ '<video>
|
| 4 |
' }}{% elif content['type'] == 'text' %}{{ content['text'] }}{% endif %}{% endfor %}{% endif %}{{'<|im_end|>
|
| 5 |
'}}{% endfor %}{% if add_generation_prompt %}{{'<|im_start|>assistant
|
processor_config.json
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"fake_image_token": "<image>",
|
| 3 |
-
"fake_video_token": "<video>",
|
| 4 |
"image_seq_length": 256,
|
| 5 |
"processor_class": "InternVLProcessor"
|
| 6 |
}
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
| 2 |
"image_seq_length": 256,
|
| 3 |
"processor_class": "InternVLProcessor"
|
| 4 |
}
|
special_tokens_map.json
CHANGED
|
@@ -46,5 +46,6 @@
|
|
| 46 |
"normalized": false,
|
| 47 |
"rstrip": false,
|
| 48 |
"single_word": false
|
| 49 |
-
}
|
|
|
|
| 50 |
}
|
|
|
|
| 46 |
"normalized": false,
|
| 47 |
"rstrip": false,
|
| 48 |
"single_word": false
|
| 49 |
+
},
|
| 50 |
+
"video_token": "<video>"
|
| 51 |
}
|
tokenizer.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ab3c9a9a9b96c4b6c042fd747c62d971b6b3475e6d6804ac77ce49c3e26876b7
|
| 3 |
+
size 10578541
|
tokenizer_config.json
CHANGED
|
@@ -1634,6 +1634,14 @@
|
|
| 1634 |
"rstrip": false,
|
| 1635 |
"single_word": false,
|
| 1636 |
"special": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1637 |
}
|
| 1638 |
},
|
| 1639 |
"additional_special_tokens": [
|
|
@@ -1667,7 +1675,8 @@
|
|
| 1667 |
"extra_special_tokens": {
|
| 1668 |
"context_image_token": "<IMG_CONTEXT>",
|
| 1669 |
"end_image_token": "</img>",
|
| 1670 |
-
"start_image_token": "<img>"
|
|
|
|
| 1671 |
},
|
| 1672 |
"legacy": false,
|
| 1673 |
"model_max_length": 8192,
|
|
@@ -1679,5 +1688,6 @@
|
|
| 1679 |
"start_image_token": "<img>",
|
| 1680 |
"tokenizer_class": "LlamaTokenizer",
|
| 1681 |
"unk_token": "<unk>",
|
| 1682 |
-
"use_default_system_prompt": false
|
|
|
|
| 1683 |
}
|
|
|
|
| 1634 |
"rstrip": false,
|
| 1635 |
"single_word": false,
|
| 1636 |
"special": true
|
| 1637 |
+
},
|
| 1638 |
+
"92553": {
|
| 1639 |
+
"content": "<video>",
|
| 1640 |
+
"lstrip": false,
|
| 1641 |
+
"normalized": false,
|
| 1642 |
+
"rstrip": false,
|
| 1643 |
+
"single_word": false,
|
| 1644 |
+
"special": true
|
| 1645 |
}
|
| 1646 |
},
|
| 1647 |
"additional_special_tokens": [
|
|
|
|
| 1675 |
"extra_special_tokens": {
|
| 1676 |
"context_image_token": "<IMG_CONTEXT>",
|
| 1677 |
"end_image_token": "</img>",
|
| 1678 |
+
"start_image_token": "<img>",
|
| 1679 |
+
"video_token": "<video>"
|
| 1680 |
},
|
| 1681 |
"legacy": false,
|
| 1682 |
"model_max_length": 8192,
|
|
|
|
| 1688 |
"start_image_token": "<img>",
|
| 1689 |
"tokenizer_class": "LlamaTokenizer",
|
| 1690 |
"unk_token": "<unk>",
|
| 1691 |
+
"use_default_system_prompt": false,
|
| 1692 |
+
"video_token": "<video>"
|
| 1693 |
}
|