Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL-Chat-V1-5-AWQ with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL-Chat-V1-5-AWQ 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-5-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/InternVL-Chat-V1-5-AWQ", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/InternVL-Chat-V1-5-AWQ 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-5-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/InternVL-Chat-V1-5-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/InternVL-Chat-V1-5-AWQ
- SGLang
How to use OpenGVLab/InternVL-Chat-V1-5-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/InternVL-Chat-V1-5-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/InternVL-Chat-V1-5-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/InternVL-Chat-V1-5-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/InternVL-Chat-V1-5-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/InternVL-Chat-V1-5-AWQ with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL-Chat-V1-5-AWQ
Upload folder using huggingface_hub
Browse files
modeling_internvl_chat.py
CHANGED
|
@@ -10,15 +10,14 @@ import torch.utils.checkpoint
|
|
| 10 |
import transformers
|
| 11 |
from torch import nn
|
| 12 |
from torch.nn import CrossEntropyLoss
|
| 13 |
-
from transformers import
|
| 14 |
-
LlamaTokenizer)
|
| 15 |
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 16 |
from transformers.modeling_utils import PreTrainedModel
|
| 17 |
from transformers.utils import ModelOutput, logging
|
| 18 |
|
| 19 |
from .configuration_internvl_chat import InternVLChatConfig
|
| 20 |
from .conversation import get_conv_template
|
| 21 |
-
from .modeling_intern_vit import InternVisionModel
|
| 22 |
from .modeling_internlm2 import InternLM2ForCausalLM
|
| 23 |
|
| 24 |
logger = logging.get_logger(__name__)
|
|
@@ -50,6 +49,7 @@ class InternVLChatModel(PreTrainedModel):
|
|
| 50 |
self.num_image_token = int((image_size // patch_size) ** 2 * (config.downsample_ratio ** 2))
|
| 51 |
self.downsample_ratio = config.downsample_ratio
|
| 52 |
self.ps_version = config.ps_version
|
|
|
|
| 53 |
config.vision_config.use_flash_attn = True if use_flash_attn else False
|
| 54 |
config.llm_config.attn_implementation = 'flash_attention_2' if use_flash_attn else 'eager'
|
| 55 |
|
|
|
|
| 10 |
import transformers
|
| 11 |
from torch import nn
|
| 12 |
from torch.nn import CrossEntropyLoss
|
| 13 |
+
from transformers import AutoModel, GenerationConfig, LlamaForCausalLM
|
|
|
|
| 14 |
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 15 |
from transformers.modeling_utils import PreTrainedModel
|
| 16 |
from transformers.utils import ModelOutput, logging
|
| 17 |
|
| 18 |
from .configuration_internvl_chat import InternVLChatConfig
|
| 19 |
from .conversation import get_conv_template
|
| 20 |
+
from .modeling_intern_vit import InternVisionModel, has_flash_attn
|
| 21 |
from .modeling_internlm2 import InternLM2ForCausalLM
|
| 22 |
|
| 23 |
logger = logging.get_logger(__name__)
|
|
|
|
| 49 |
self.num_image_token = int((image_size // patch_size) ** 2 * (config.downsample_ratio ** 2))
|
| 50 |
self.downsample_ratio = config.downsample_ratio
|
| 51 |
self.ps_version = config.ps_version
|
| 52 |
+
use_flash_attn = use_flash_attn if has_flash_attn else False
|
| 53 |
config.vision_config.use_flash_attn = True if use_flash_attn else False
|
| 54 |
config.llm_config.attn_implementation = 'flash_attention_2' if use_flash_attn else 'eager'
|
| 55 |
|