Image-Text-to-Text
Transformers
TensorBoard
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL-Chat-V1-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL-Chat-V1-2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL-Chat-V1-2", 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/InternVL-Chat-V1-2", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL-Chat-V1-2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL-Chat-V1-2" # 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/InternVL-Chat-V1-2", "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/InternVL-Chat-V1-2
- SGLang
How to use OpenGVLab/InternVL-Chat-V1-2 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/InternVL-Chat-V1-2" \ --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/InternVL-Chat-V1-2", "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/InternVL-Chat-V1-2" \ --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/InternVL-Chat-V1-2", "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/InternVL-Chat-V1-2 with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL-Chat-V1-2
add Hermes-2 in conversation.py
#4
by nemonameless - opened
- conversation.py +31 -1
conversation.py
CHANGED
|
@@ -30,7 +30,7 @@ class SeparatorStyle(IntEnum):
|
|
| 30 |
FALCON_CHAT = auto()
|
| 31 |
CHATGLM3 = auto()
|
| 32 |
INTERNVL_ZH = auto()
|
| 33 |
-
|
| 34 |
|
| 35 |
@dataclasses.dataclass
|
| 36 |
class Conversation:
|
|
@@ -234,6 +234,16 @@ class Conversation:
|
|
| 234 |
else:
|
| 235 |
ret += role + ':'
|
| 236 |
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
else:
|
| 238 |
raise ValueError(f'Invalid style: {self.sep_style}')
|
| 239 |
|
|
@@ -1213,6 +1223,26 @@ register_conv_template(
|
|
| 1213 |
)
|
| 1214 |
|
| 1215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1216 |
if __name__ == '__main__':
|
| 1217 |
from fastchat.conversation import get_conv_template
|
| 1218 |
|
|
|
|
| 30 |
FALCON_CHAT = auto()
|
| 31 |
CHATGLM3 = auto()
|
| 32 |
INTERNVL_ZH = auto()
|
| 33 |
+
MPT = auto()
|
| 34 |
|
| 35 |
@dataclasses.dataclass
|
| 36 |
class Conversation:
|
|
|
|
| 234 |
else:
|
| 235 |
ret += role + ':'
|
| 236 |
return ret
|
| 237 |
+
elif self.sep_style == SeparatorStyle.MPT:
|
| 238 |
+
ret = system_prompt + self.sep
|
| 239 |
+
for role, message in self.messages:
|
| 240 |
+
if message:
|
| 241 |
+
if type(message) is tuple:
|
| 242 |
+
message, _, _ = message
|
| 243 |
+
ret += role + message + self.sep
|
| 244 |
+
else:
|
| 245 |
+
ret += role
|
| 246 |
+
return ret
|
| 247 |
else:
|
| 248 |
raise ValueError(f'Invalid style: {self.sep_style}')
|
| 249 |
|
|
|
|
| 1223 |
)
|
| 1224 |
|
| 1225 |
|
| 1226 |
+
# Hermes-2 template
|
| 1227 |
+
register_conv_template(
|
| 1228 |
+
Conversation(
|
| 1229 |
+
name='Hermes-2',
|
| 1230 |
+
system_template='<|im_start|>system\n{system_message}',
|
| 1231 |
+
system_message='Answer the questions.',
|
| 1232 |
+
roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
|
| 1233 |
+
sep_style=SeparatorStyle.MPT,
|
| 1234 |
+
sep='<|im_end|>',
|
| 1235 |
+
stop_token_ids=[
|
| 1236 |
+
2,
|
| 1237 |
+
6,
|
| 1238 |
+
7,
|
| 1239 |
+
8,
|
| 1240 |
+
], # "<|endoftext|>", "<|im_start|>", "<|im_end|>", "<|im_sep|>"
|
| 1241 |
+
stop_str='<|endoftext|>',
|
| 1242 |
+
)
|
| 1243 |
+
)
|
| 1244 |
+
|
| 1245 |
+
|
| 1246 |
if __name__ == '__main__':
|
| 1247 |
from fastchat.conversation import get_conv_template
|
| 1248 |
|