Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL2-26B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-26B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-26B", trust_remote_code=True) 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 AutoModel model = AutoModel.from_pretrained("OpenGVLab/InternVL2-26B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL2-26B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-26B" # 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-26B", "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-26B
- SGLang
How to use OpenGVLab/InternVL2-26B 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-26B" \ --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-26B", "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-26B" \ --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-26B", "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-26B with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-26B
Upload folder using huggingface_hub
Browse files- configuration_internvl_chat.py +0 -3
- conversation.py +7 -1
configuration_internvl_chat.py
CHANGED
|
@@ -26,7 +26,6 @@ class InternVLChatConfig(PretrainedConfig):
|
|
| 26 |
llm_config=None,
|
| 27 |
use_backbone_lora=0,
|
| 28 |
use_llm_lora=0,
|
| 29 |
-
pad2square=False,
|
| 30 |
select_layer=-1,
|
| 31 |
force_image_size=None,
|
| 32 |
downsample_ratio=0.5,
|
|
@@ -56,7 +55,6 @@ class InternVLChatConfig(PretrainedConfig):
|
|
| 56 |
raise ValueError('Unsupported architecture: {}'.format(llm_config['architectures'][0]))
|
| 57 |
self.use_backbone_lora = use_backbone_lora
|
| 58 |
self.use_llm_lora = use_llm_lora
|
| 59 |
-
self.pad2square = pad2square
|
| 60 |
self.select_layer = select_layer
|
| 61 |
self.force_image_size = force_image_size
|
| 62 |
self.downsample_ratio = downsample_ratio
|
|
@@ -85,7 +83,6 @@ class InternVLChatConfig(PretrainedConfig):
|
|
| 85 |
output['model_type'] = self.__class__.model_type
|
| 86 |
output['use_backbone_lora'] = self.use_backbone_lora
|
| 87 |
output['use_llm_lora'] = self.use_llm_lora
|
| 88 |
-
output['pad2square'] = self.pad2square
|
| 89 |
output['select_layer'] = self.select_layer
|
| 90 |
output['force_image_size'] = self.force_image_size
|
| 91 |
output['downsample_ratio'] = self.downsample_ratio
|
|
|
|
| 26 |
llm_config=None,
|
| 27 |
use_backbone_lora=0,
|
| 28 |
use_llm_lora=0,
|
|
|
|
| 29 |
select_layer=-1,
|
| 30 |
force_image_size=None,
|
| 31 |
downsample_ratio=0.5,
|
|
|
|
| 55 |
raise ValueError('Unsupported architecture: {}'.format(llm_config['architectures'][0]))
|
| 56 |
self.use_backbone_lora = use_backbone_lora
|
| 57 |
self.use_llm_lora = use_llm_lora
|
|
|
|
| 58 |
self.select_layer = select_layer
|
| 59 |
self.force_image_size = force_image_size
|
| 60 |
self.downsample_ratio = downsample_ratio
|
|
|
|
| 83 |
output['model_type'] = self.__class__.model_type
|
| 84 |
output['use_backbone_lora'] = self.use_backbone_lora
|
| 85 |
output['use_llm_lora'] = self.use_llm_lora
|
|
|
|
| 86 |
output['select_layer'] = self.select_layer
|
| 87 |
output['force_image_size'] = self.force_image_size
|
| 88 |
output['downsample_ratio'] = self.downsample_ratio
|
conversation.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
Conversation prompt templates.
|
| 3 |
|
| 4 |
We kindly request that you import fastchat instead of copying this file if you wish to use it.
|
| 5 |
-
If you have
|
| 6 |
"""
|
| 7 |
|
| 8 |
import dataclasses
|
|
@@ -335,6 +335,8 @@ register_conv_template(
|
|
| 335 |
Conversation(
|
| 336 |
name='Hermes-2',
|
| 337 |
system_template='<|im_start|>system\n{system_message}',
|
|
|
|
|
|
|
| 338 |
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
| 339 |
roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
|
| 340 |
sep_style=SeparatorStyle.MPT,
|
|
@@ -354,6 +356,8 @@ register_conv_template(
|
|
| 354 |
Conversation(
|
| 355 |
name='internlm2-chat',
|
| 356 |
system_template='<|im_start|>system\n{system_message}',
|
|
|
|
|
|
|
| 357 |
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
| 358 |
roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
|
| 359 |
sep_style=SeparatorStyle.MPT,
|
|
@@ -371,6 +375,8 @@ register_conv_template(
|
|
| 371 |
Conversation(
|
| 372 |
name='phi3-chat',
|
| 373 |
system_template='<|system|>\n{system_message}',
|
|
|
|
|
|
|
| 374 |
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
| 375 |
roles=('<|user|>\n', '<|assistant|>\n'),
|
| 376 |
sep_style=SeparatorStyle.MPT,
|
|
|
|
| 2 |
Conversation prompt templates.
|
| 3 |
|
| 4 |
We kindly request that you import fastchat instead of copying this file if you wish to use it.
|
| 5 |
+
If you have changes in mind, please contribute back so the community can benefit collectively and continue to maintain these valuable templates.
|
| 6 |
"""
|
| 7 |
|
| 8 |
import dataclasses
|
|
|
|
| 335 |
Conversation(
|
| 336 |
name='Hermes-2',
|
| 337 |
system_template='<|im_start|>system\n{system_message}',
|
| 338 |
+
# note: The new system prompt was not used here to avoid changes in benchmark performance.
|
| 339 |
+
# system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。',
|
| 340 |
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
| 341 |
roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
|
| 342 |
sep_style=SeparatorStyle.MPT,
|
|
|
|
| 356 |
Conversation(
|
| 357 |
name='internlm2-chat',
|
| 358 |
system_template='<|im_start|>system\n{system_message}',
|
| 359 |
+
# note: The new system prompt was not used here to avoid changes in benchmark performance.
|
| 360 |
+
# system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。',
|
| 361 |
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
| 362 |
roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
|
| 363 |
sep_style=SeparatorStyle.MPT,
|
|
|
|
| 375 |
Conversation(
|
| 376 |
name='phi3-chat',
|
| 377 |
system_template='<|system|>\n{system_message}',
|
| 378 |
+
# note: The new system prompt was not used here to avoid changes in benchmark performance.
|
| 379 |
+
# system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。',
|
| 380 |
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
| 381 |
roles=('<|user|>\n', '<|assistant|>\n'),
|
| 382 |
sep_style=SeparatorStyle.MPT,
|