Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL2-1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-1B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-1B", 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-1B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL2-1B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-1B" # 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-1B", "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-1B
- SGLang
How to use OpenGVLab/InternVL2-1B 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-1B" \ --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-1B", "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-1B" \ --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-1B", "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-1B with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-1B
Update modeling_intern_vit.py (#4)
Browse files- Update modeling_intern_vit.py (188f686e8863f48f045de9508e6035f37809e1fd)
Co-authored-by: Roy Hvaara <hvaara@users.noreply.huggingface.co>
- modeling_intern_vit.py +5 -4
modeling_intern_vit.py
CHANGED
|
@@ -15,17 +15,18 @@ from transformers.activations import ACT2FN
|
|
| 15 |
from transformers.modeling_outputs import (BaseModelOutput,
|
| 16 |
BaseModelOutputWithPooling)
|
| 17 |
from transformers.modeling_utils import PreTrainedModel
|
|
|
|
| 18 |
from transformers.utils import logging
|
| 19 |
|
| 20 |
from .configuration_intern_vit import InternVisionConfig
|
| 21 |
|
| 22 |
try:
|
| 23 |
-
|
| 24 |
-
from flash_attn.flash_attn_interface import \
|
| 25 |
-
flash_attn_unpadded_qkvpacked_func
|
| 26 |
-
except: # v2
|
| 27 |
from flash_attn.flash_attn_interface import \
|
| 28 |
flash_attn_varlen_qkvpacked_func as flash_attn_unpadded_qkvpacked_func
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
from flash_attn.bert_padding import pad_input, unpad_input
|
| 31 |
|
|
|
|
| 15 |
from transformers.modeling_outputs import (BaseModelOutput,
|
| 16 |
BaseModelOutputWithPooling)
|
| 17 |
from transformers.modeling_utils import PreTrainedModel
|
| 18 |
+
from transformers.utils.import_utils import is_flash_attn_greater_or_equal
|
| 19 |
from transformers.utils import logging
|
| 20 |
|
| 21 |
from .configuration_intern_vit import InternVisionConfig
|
| 22 |
|
| 23 |
try:
|
| 24 |
+
if is_flash_attn_greater_or_equal("2.0.0"):
|
|
|
|
|
|
|
|
|
|
| 25 |
from flash_attn.flash_attn_interface import \
|
| 26 |
flash_attn_varlen_qkvpacked_func as flash_attn_unpadded_qkvpacked_func
|
| 27 |
+
else:
|
| 28 |
+
from flash_attn.flash_attn_interface import \
|
| 29 |
+
flash_attn_unpadded_qkvpacked_func
|
| 30 |
|
| 31 |
from flash_attn.bert_padding import pad_input, unpad_input
|
| 32 |
|