Instructions to use OpenGVLab/InternVL3-1B-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL3-1B-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL3-1B-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/InternVL3-1B-hf") model = AutoModelForImageTextToText.from_pretrained("OpenGVLab/InternVL3-1B-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
- vLLM
How to use OpenGVLab/InternVL3-1B-hf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL3-1B-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/InternVL3-1B-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/InternVL3-1B-hf
- SGLang
How to use OpenGVLab/InternVL3-1B-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/InternVL3-1B-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/InternVL3-1B-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/InternVL3-1B-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/InternVL3-1B-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/InternVL3-1B-hf with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL3-1B-hf
Commit ·
c0531b9
1
Parent(s): 8f04f44
update
Browse files- added_tokens.json +1 -0
- chat_template.jinja +1 -1
- processor_config.json +0 -2
- special_tokens_map.json +11 -64
- tokenizer.json +2 -2
- tokenizer_config.json +12 -2
added_tokens.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
| 10 |
"<quad>": 151668,
|
| 11 |
"<ref>": 151670,
|
| 12 |
"<tool_call>": 151657,
|
|
|
|
| 13 |
"<|box_end|>": 151649,
|
| 14 |
"<|box_start|>": 151648,
|
| 15 |
"<|endoftext|>": 151643,
|
|
|
|
| 10 |
"<quad>": 151668,
|
| 11 |
"<ref>": 151670,
|
| 12 |
"<tool_call>": 151657,
|
| 13 |
+
"<video>": 151674,
|
| 14 |
"<|box_end|>": 151649,
|
| 15 |
"<|box_start|>": 151648,
|
| 16 |
"<|endoftext|>": 151643,
|
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
|
@@ -13,69 +13,15 @@
|
|
| 13 |
"<|vision_pad|>",
|
| 14 |
"<|image_pad|>",
|
| 15 |
"<|video_pad|>",
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
"lstrip": false,
|
| 26 |
-
"normalized": false,
|
| 27 |
-
"rstrip": false,
|
| 28 |
-
"single_word": false
|
| 29 |
-
},
|
| 30 |
-
{
|
| 31 |
-
"content": "<IMG_CONTEXT>",
|
| 32 |
-
"lstrip": false,
|
| 33 |
-
"normalized": false,
|
| 34 |
-
"rstrip": false,
|
| 35 |
-
"single_word": false
|
| 36 |
-
},
|
| 37 |
-
{
|
| 38 |
-
"content": "<quad>",
|
| 39 |
-
"lstrip": false,
|
| 40 |
-
"normalized": false,
|
| 41 |
-
"rstrip": false,
|
| 42 |
-
"single_word": false
|
| 43 |
-
},
|
| 44 |
-
{
|
| 45 |
-
"content": "</quad>",
|
| 46 |
-
"lstrip": false,
|
| 47 |
-
"normalized": false,
|
| 48 |
-
"rstrip": false,
|
| 49 |
-
"single_word": false
|
| 50 |
-
},
|
| 51 |
-
{
|
| 52 |
-
"content": "<ref>",
|
| 53 |
-
"lstrip": false,
|
| 54 |
-
"normalized": false,
|
| 55 |
-
"rstrip": false,
|
| 56 |
-
"single_word": false
|
| 57 |
-
},
|
| 58 |
-
{
|
| 59 |
-
"content": "</ref>",
|
| 60 |
-
"lstrip": false,
|
| 61 |
-
"normalized": false,
|
| 62 |
-
"rstrip": false,
|
| 63 |
-
"single_word": false
|
| 64 |
-
},
|
| 65 |
-
{
|
| 66 |
-
"content": "<box>",
|
| 67 |
-
"lstrip": false,
|
| 68 |
-
"normalized": false,
|
| 69 |
-
"rstrip": false,
|
| 70 |
-
"single_word": false
|
| 71 |
-
},
|
| 72 |
-
{
|
| 73 |
-
"content": "</box>",
|
| 74 |
-
"lstrip": false,
|
| 75 |
-
"normalized": false,
|
| 76 |
-
"rstrip": false,
|
| 77 |
-
"single_word": false
|
| 78 |
-
}
|
| 79 |
],
|
| 80 |
"context_image_token": "<IMG_CONTEXT>",
|
| 81 |
"end_image_token": "</img>",
|
|
@@ -93,5 +39,6 @@
|
|
| 93 |
"rstrip": false,
|
| 94 |
"single_word": false
|
| 95 |
},
|
| 96 |
-
"start_image_token": "<img>"
|
|
|
|
| 97 |
}
|
|
|
|
| 13 |
"<|vision_pad|>",
|
| 14 |
"<|image_pad|>",
|
| 15 |
"<|video_pad|>",
|
| 16 |
+
"<img>",
|
| 17 |
+
"</img>",
|
| 18 |
+
"<IMG_CONTEXT>",
|
| 19 |
+
"<quad>",
|
| 20 |
+
"</quad>",
|
| 21 |
+
"<ref>",
|
| 22 |
+
"</ref>",
|
| 23 |
+
"<box>",
|
| 24 |
+
"</box>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
],
|
| 26 |
"context_image_token": "<IMG_CONTEXT>",
|
| 27 |
"end_image_token": "</img>",
|
|
|
|
| 39 |
"rstrip": false,
|
| 40 |
"single_word": false
|
| 41 |
},
|
| 42 |
+
"start_image_token": "<img>",
|
| 43 |
+
"video_token": "<video>"
|
| 44 |
}
|
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:7cc80b7e20adf8bf6f6ca442bf1abfac8056bb3b7d3e0b11c9d497d3e79398c9
|
| 3 |
+
size 11423732
|
tokenizer_config.json
CHANGED
|
@@ -249,6 +249,14 @@
|
|
| 249 |
"rstrip": false,
|
| 250 |
"single_word": false,
|
| 251 |
"special": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
}
|
| 253 |
},
|
| 254 |
"additional_special_tokens": [
|
|
@@ -284,7 +292,8 @@
|
|
| 284 |
"extra_special_tokens": {
|
| 285 |
"context_image_token": "<IMG_CONTEXT>",
|
| 286 |
"end_image_token": "</img>",
|
| 287 |
-
"start_image_token": "<img>"
|
|
|
|
| 288 |
},
|
| 289 |
"model_max_length": 8192,
|
| 290 |
"pad_token": "<|endoftext|>",
|
|
@@ -292,5 +301,6 @@
|
|
| 292 |
"split_special_tokens": false,
|
| 293 |
"start_image_token": "<img>",
|
| 294 |
"tokenizer_class": "Qwen2Tokenizer",
|
| 295 |
-
"unk_token": null
|
|
|
|
| 296 |
}
|
|
|
|
| 249 |
"rstrip": false,
|
| 250 |
"single_word": false,
|
| 251 |
"special": true
|
| 252 |
+
},
|
| 253 |
+
"151674": {
|
| 254 |
+
"content": "<video>",
|
| 255 |
+
"lstrip": false,
|
| 256 |
+
"normalized": false,
|
| 257 |
+
"rstrip": false,
|
| 258 |
+
"single_word": false,
|
| 259 |
+
"special": true
|
| 260 |
}
|
| 261 |
},
|
| 262 |
"additional_special_tokens": [
|
|
|
|
| 292 |
"extra_special_tokens": {
|
| 293 |
"context_image_token": "<IMG_CONTEXT>",
|
| 294 |
"end_image_token": "</img>",
|
| 295 |
+
"start_image_token": "<img>",
|
| 296 |
+
"video_token": "<video>"
|
| 297 |
},
|
| 298 |
"model_max_length": 8192,
|
| 299 |
"pad_token": "<|endoftext|>",
|
|
|
|
| 301 |
"split_special_tokens": false,
|
| 302 |
"start_image_token": "<img>",
|
| 303 |
"tokenizer_class": "Qwen2Tokenizer",
|
| 304 |
+
"unk_token": null,
|
| 305 |
+
"video_token": "<video>"
|
| 306 |
}
|