Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
feature-extraction
internvl
vision
ocr
custom_code
Mixture of Experts
conversational
Instructions to use OpenGVLab/Mono-InternVL-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/Mono-InternVL-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/Mono-InternVL-2B", 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/Mono-InternVL-2B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/Mono-InternVL-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/Mono-InternVL-2B" # 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/Mono-InternVL-2B", "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/Mono-InternVL-2B
- SGLang
How to use OpenGVLab/Mono-InternVL-2B 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/Mono-InternVL-2B" \ --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/Mono-InternVL-2B", "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/Mono-InternVL-2B" \ --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/Mono-InternVL-2B", "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/Mono-InternVL-2B with Docker Model Runner:
docker model run hf.co/OpenGVLab/Mono-InternVL-2B
Update modeling_internlm2_ve.py
Browse files- modeling_internlm2_ve.py +11 -13
modeling_internlm2_ve.py
CHANGED
|
@@ -689,20 +689,18 @@ class InternLM2DecoderLayer(nn.Module):
|
|
| 689 |
hidden_states = self.ffn_norm(hidden_states)
|
| 690 |
|
| 691 |
if past_key_value is None:
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
# hidden_states[~visual_token_mask] = self.feed_forward(hidden_states[~visual_token_mask].reshape(-1,dim)).reshape(-1)
|
| 704 |
##############################################################################################################
|
| 705 |
-
hidden_states = self.feed_forward(hidden_states)*(1.-visual_token_mask)+ self.feed_forward_ve(hidden_states)*visual_token_mask
|
| 706 |
else:
|
| 707 |
hidden_states = self.feed_forward(hidden_states)
|
| 708 |
|
|
|
|
| 689 |
hidden_states = self.ffn_norm(hidden_states)
|
| 690 |
|
| 691 |
if past_key_value is None:
|
| 692 |
+
##########################################--modified by luogen--##############################################
|
| 693 |
+
if self.training:
|
| 694 |
+
hidden_states = self.feed_forward(hidden_states)*(1.-visual_token_mask)+ self.feed_forward_ve(hidden_states)*visual_token_mask
|
| 695 |
+
else:
|
| 696 |
+
dim=hidden_states.shape[-1]
|
| 697 |
+
visual_token_mask=visual_token_mask.repeat(1,1,dim).bool()
|
| 698 |
+
non_visual_token_mask=~visual_token_mask
|
| 699 |
+
if visual_token_mask.any():
|
| 700 |
+
hidden_states[visual_token_mask] = self.feed_forward_ve(hidden_states[visual_token_mask].reshape(-1,dim)).reshape(-1)
|
| 701 |
+
if (non_visual_token_mask).any():
|
| 702 |
+
hidden_states[non_visual_token_mask] = self.feed_forward(hidden_states[non_visual_token_mask].reshape(-1,dim)).reshape(-1)
|
|
|
|
| 703 |
##############################################################################################################
|
|
|
|
| 704 |
else:
|
| 705 |
hidden_states = self.feed_forward(hidden_states)
|
| 706 |
|