Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL2-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-4B", 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-4B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL2-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-4B" # 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-4B", "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-4B
- SGLang
How to use OpenGVLab/InternVL2-4B 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-4B" \ --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-4B", "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-4B" \ --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-4B", "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-4B with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-4B
Upload folder using huggingface_hub
Browse files- README.md +14 -22
- conversation.py +2 -1
README.md
CHANGED
|
@@ -290,30 +290,8 @@ print(f'Assistant: {response}')
|
|
| 290 |
|
| 291 |
### LMDeploy
|
| 292 |
|
| 293 |
-
LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams.
|
| 294 |
-
|
| 295 |
-
```sh
|
| 296 |
-
pip install lmdeploy
|
| 297 |
-
```
|
| 298 |
-
|
| 299 |
-
You can run batch inference locally with the following python code:
|
| 300 |
-
|
| 301 |
> Warning: This model is not yet supported by LMDeploy.
|
| 302 |
|
| 303 |
-
```python
|
| 304 |
-
from lmdeploy.vl import load_image
|
| 305 |
-
from lmdeploy import ChatTemplateConfig, pipeline
|
| 306 |
-
|
| 307 |
-
model = 'OpenGVLab/InternVL2-4B'
|
| 308 |
-
system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
|
| 309 |
-
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
|
| 310 |
-
chat_template_config = ChatTemplateConfig('phi-3')
|
| 311 |
-
chat_template_config.meta_instruction = system_prompt
|
| 312 |
-
pipe = pipeline(model, chat_template_config=chat_template_config)
|
| 313 |
-
response = pipe(('describe this image', image))
|
| 314 |
-
print(response)
|
| 315 |
-
```
|
| 316 |
-
|
| 317 |
## License
|
| 318 |
|
| 319 |
This project is released under the MIT license.
|
|
@@ -387,6 +365,20 @@ TBD
|
|
| 387 |
|
| 388 |
限制:尽管在训练过程中我们非常注重模型的安全性,尽力促使模型输出符合伦理和法律要求的文本,但受限于模型大小以及概率生成范式,模型可能会产生各种不符合预期的输出,例如回复内容包含偏见、歧视等有害内容,请勿传播这些内容。由于传播不良信息导致的任何后果,本项目不承担责任。
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
## 开源许可证
|
| 391 |
|
| 392 |
该项目采用 MIT 许可证发布。
|
|
|
|
| 290 |
|
| 291 |
### LMDeploy
|
| 292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
> Warning: This model is not yet supported by LMDeploy.
|
| 294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
## License
|
| 296 |
|
| 297 |
This project is released under the MIT license.
|
|
|
|
| 365 |
|
| 366 |
限制:尽管在训练过程中我们非常注重模型的安全性,尽力促使模型输出符合伦理和法律要求的文本,但受限于模型大小以及概率生成范式,模型可能会产生各种不符合预期的输出,例如回复内容包含偏见、歧视等有害内容,请勿传播这些内容。由于传播不良信息导致的任何后果,本项目不承担责任。
|
| 367 |
|
| 368 |
+
## 快速启动
|
| 369 |
+
|
| 370 |
+
我们提供了一个示例代码,用于使用 `transformers` 运行 InternVL2-2B。
|
| 371 |
+
|
| 372 |
+
> 请使用 transformers==4.37.2 以确保模型正常运行。
|
| 373 |
+
|
| 374 |
+
示例代码请[点击这里](#quick-start)。
|
| 375 |
+
|
| 376 |
+
## 部署
|
| 377 |
+
|
| 378 |
+
### LMDeploy
|
| 379 |
+
|
| 380 |
+
> 注意:此模型尚未被 LMDeploy 支持。
|
| 381 |
+
|
| 382 |
## 开源许可证
|
| 383 |
|
| 384 |
该项目采用 MIT 许可证发布。
|
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 |
)
|