Image-Text-to-Text
Transformers
PyTorch
multilingual
internvl_chat
feature-extraction
internvl
custom_code
conversational
Instructions to use OpenGVLab/InternVL2-8B-AWQ with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/InternVL2-8B-AWQ with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/InternVL2-8B-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)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenGVLab/InternVL2-8B-AWQ", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use OpenGVLab/InternVL2-8B-AWQ with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/InternVL2-8B-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-8B-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-8B-AWQ
- SGLang
How to use OpenGVLab/InternVL2-8B-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-8B-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-8B-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-8B-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-8B-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-8B-AWQ with Docker Model Runner:
docker model run hf.co/OpenGVLab/InternVL2-8B-AWQ
Upload folder using huggingface_hub
Browse filesFiles changed (2)
- README.md+1-1
- modeling_intern_vit.py+6-12
29 unmodified lines3031323334353629 unmodified linesBefore proceeding with the quantization and inference, please ensure that lmdeploy is installed.```shellpip install lmdeploy```This article comprises the following sections:29 unmodified lines3031323334353629 unmodified linesBefore proceeding with the quantization and inference, please ensure that lmdeploy is installed.```shellpip install lmdeploy==0.5.3```This article comprises the following sections:
19 unmodified lines20212223242526272829303132333435363736 unmodified lines747576777879803 unmodified lines848586878889902 unmodified lines9394959697989919 unmodified linesfrom .configuration_intern_vit import InternVisionConfigtry:try: # v1from flash_attn.flash_attn_interface import \flash_attn_unpadded_qkvpacked_funcexcept: # v2from flash_attn.flash_attn_interface import \flash_attn_varlen_qkvpacked_func as flash_attn_unpadded_qkvpacked_funcfrom flash_attn.bert_padding import pad_input, unpad_inputhas_flash_attn = Trueexcept:print('FlashAttention is not installed.')has_flash_attn = Falselogger = logging.get_logger(__name__)36 unmodified linesmax_s = seqlencu_seqlens = torch.arange(0, (batch_size + 1) * seqlen, step=seqlen, dtype=torch.int32,device=qkv.device)output = flash_attn_unpadded_qkvpacked_func(qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,softmax_scale=self.softmax_scale, causal=causal)3 unmodified linesx = rearrange(qkv, 'b s three h d -> b s (three h d)')x_unpad, indices, cu_seqlens, max_s = unpad_input(x, key_padding_mask)x_unpad = rearrange(x_unpad, 'nnz (three h d) -> nnz three h d', three=3, h=nheads)output_unpad = flash_attn_unpadded_qkvpacked_func(x_unpad, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,softmax_scale=self.softmax_scale, causal=causal)2 unmodified lines'b s (h d) -> b s h d', h=nheads)else:assert max_s is not Noneoutput = flash_attn_unpadded_qkvpacked_func(qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,softmax_scale=self.softmax_scale, causal=causal)19 unmodified lines20212223242526272829303136 unmodified lines686970717273743 unmodified lines787980818283842 unmodified lines8788899091929319 unmodified linesfrom .configuration_intern_vit import InternVisionConfigtry:from flash_attn.bert_padding import pad_input, unpad_inputfrom flash_attn.flash_attn_interface import \flash_attn_varlen_qkvpacked_funchas_flash_attn = Trueexcept:print('FlashAttention2 is not installed.')has_flash_attn = Falselogger = logging.get_logger(__name__)36 unmodified linesmax_s = seqlencu_seqlens = torch.arange(0, (batch_size + 1) * seqlen, step=seqlen, dtype=torch.int32,device=qkv.device)output = flash_attn_varlen_qkvpacked_func(qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,softmax_scale=self.softmax_scale, causal=causal)3 unmodified linesx = rearrange(qkv, 'b s three h d -> b s (three h d)')x_unpad, indices, cu_seqlens, max_s = unpad_input(x, key_padding_mask)x_unpad = rearrange(x_unpad, 'nnz (three h d) -> nnz three h d', three=3, h=nheads)output_unpad = flash_attn_varlen_qkvpacked_func(x_unpad, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,softmax_scale=self.softmax_scale, causal=causal)2 unmodified lines'b s (h d) -> b s h d', h=nheads)else:assert max_s is not Noneoutput = flash_attn_varlen_qkvpacked_func(qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,softmax_scale=self.softmax_scale, causal=causal)
README.md+1-1
modeling_intern_vit.py+6-12