Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL2-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-2B", 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-2B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL2-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-2B" # 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-2B", "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-2B
- SGLang
How to use OpenGVLab/InternVL2-2B 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-2B" \ --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-2B", "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-2B" \ --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-2B", "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-2B with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-2B
Upload folder using huggingface_hub
Browse files- README.md +8 -0
- conversation.py +2 -1
README.md
CHANGED
|
@@ -464,6 +464,14 @@ TBD
|
|
| 464 |
|
| 465 |
限制:尽管在训练过程中我们非常注重模型的安全性,尽力促使模型输出符合伦理和法律要求的文本,但受限于模型大小以及概率生成范式,模型可能会产生各种不符合预期的输出,例如回复内容包含偏见、歧视等有害内容,请勿传播这些内容。由于传播不良信息导致的任何后果,本项目不承担责任。
|
| 466 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
## 部署
|
| 468 |
|
| 469 |
### LMDeploy
|
|
|
|
| 464 |
|
| 465 |
限制:尽管在训练过程中我们非常注重模型的安全性,尽力促使模型输出符合伦理和法律要求的文本,但受限于模型大小以及概率生成范式,模型可能会产生各种不符合预期的输出,例如回复内容包含偏见、歧视等有害内容,请勿传播这些内容。由于传播不良信息导致的任何后果,本项目不承担责任。
|
| 466 |
|
| 467 |
+
## 快速启动
|
| 468 |
+
|
| 469 |
+
我们提供了一个示例代码,用于使用 `transformers` 运行 InternVL2-2B。
|
| 470 |
+
|
| 471 |
+
> 请使用 transformers==4.37.2 以确保模型正常运行。
|
| 472 |
+
|
| 473 |
+
示例代码请[点击这里](#quick-start)。
|
| 474 |
+
|
| 475 |
## 部署
|
| 476 |
|
| 477 |
### LMDeploy
|
conversation.py
CHANGED
|
@@ -330,6 +330,7 @@ def get_conv_template(name: str) -> Conversation:
|
|
| 330 |
return conv_templates[name].copy()
|
| 331 |
|
| 332 |
|
|
|
|
| 333 |
register_conv_template(
|
| 334 |
Conversation(
|
| 335 |
name='Hermes-2',
|
|
@@ -343,7 +344,7 @@ register_conv_template(
|
|
| 343 |
6,
|
| 344 |
7,
|
| 345 |
8,
|
| 346 |
-
],
|
| 347 |
stop_str='<|endoftext|>',
|
| 348 |
)
|
| 349 |
)
|
|
|
|
| 330 |
return conv_templates[name].copy()
|
| 331 |
|
| 332 |
|
| 333 |
+
# Note that for inference, using the Hermes-2 and internlm2-chat templates is equivalent.
|
| 334 |
register_conv_template(
|
| 335 |
Conversation(
|
| 336 |
name='Hermes-2',
|
|
|
|
| 344 |
6,
|
| 345 |
7,
|
| 346 |
8,
|
| 347 |
+
],
|
| 348 |
stop_str='<|endoftext|>',
|
| 349 |
)
|
| 350 |
)
|