Image-Text-to-Text
Transformers
PyTorch
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL2-2B-AWQ with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-2B-AWQ with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-2B-AWQ", 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-AWQ", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL2-2B-AWQ with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-2B-AWQ" # 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-AWQ", "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-AWQ
- SGLang
How to use OpenGVLab/InternVL2-2B-AWQ 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-AWQ" \ --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-AWQ", "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-AWQ" \ --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-AWQ", "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-AWQ with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-2B-AWQ
fix compatibility issue for transformers 4.46+
Browse files- configuration_internvl_chat.py +3 -3
- conversation.py +1 -1
configuration_internvl_chat.py
CHANGED
|
@@ -47,12 +47,12 @@ class InternVLChatConfig(PretrainedConfig):
|
|
| 47 |
logger.info('llm_config is None. Initializing the LlamaConfig config with default values (`LlamaConfig`).')
|
| 48 |
|
| 49 |
self.vision_config = InternVisionConfig(**vision_config)
|
| 50 |
-
if llm_config.get('architectures'
|
| 51 |
self.llm_config = LlamaConfig(**llm_config)
|
| 52 |
-
elif llm_config.get('architectures'
|
| 53 |
self.llm_config = InternLM2Config(**llm_config)
|
| 54 |
else:
|
| 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
|
|
|
|
| 47 |
logger.info('llm_config is None. Initializing the LlamaConfig config with default values (`LlamaConfig`).')
|
| 48 |
|
| 49 |
self.vision_config = InternVisionConfig(**vision_config)
|
| 50 |
+
if llm_config.get('architectures')[0] == 'LlamaForCausalLM':
|
| 51 |
self.llm_config = LlamaConfig(**llm_config)
|
| 52 |
+
elif llm_config.get('architectures')[0] == 'InternLM2ForCausalLM':
|
| 53 |
self.llm_config = InternLM2Config(**llm_config)
|
| 54 |
else:
|
| 55 |
+
raise ValueError('Unsupported architecture: {}'.format(llm_config.get(['architectures'])[0]))
|
| 56 |
self.use_backbone_lora = use_backbone_lora
|
| 57 |
self.use_llm_lora = use_llm_lora
|
| 58 |
self.select_layer = select_layer
|
conversation.py
CHANGED
|
@@ -9,7 +9,7 @@ Modified from https://github.com/lm-sys/FastChat/blob/main/fastchat/conversation
|
|
| 9 |
|
| 10 |
import dataclasses
|
| 11 |
from enum import IntEnum, auto
|
| 12 |
-
from typing import
|
| 13 |
|
| 14 |
|
| 15 |
class SeparatorStyle(IntEnum):
|
|
|
|
| 9 |
|
| 10 |
import dataclasses
|
| 11 |
from enum import IntEnum, auto
|
| 12 |
+
from typing import Dict, List, Tuple, Union
|
| 13 |
|
| 14 |
|
| 15 |
class SeparatorStyle(IntEnum):
|