Image-Text-to-Text
Transformers
Safetensors
multilingual
internvl_chat
image-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 Settings
- 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
Fix remaining Transformers v5 crash: guard llm_config and to_dict() for None (follow-up to `e980c02`)
#13
by KBayoud - opened
configuration_internvl_chat.py
CHANGED
|
@@ -51,16 +51,19 @@ class InternVLChatConfig(PretrainedConfig):
|
|
| 51 |
self.vision_config = InternVisionPatchConfig(**vision_config)
|
| 52 |
else:
|
| 53 |
self.vision_config = None
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
self.llm_config = LlamaConfig(**llm_config)
|
| 56 |
-
elif
|
| 57 |
self.llm_config = InternLM2Config(**llm_config)
|
| 58 |
-
elif
|
| 59 |
self.llm_config = InternLM2Config(**llm_config)
|
| 60 |
-
elif
|
| 61 |
self.llm_config = Qwen2Config(**llm_config)
|
| 62 |
else:
|
| 63 |
-
|
|
|
|
| 64 |
self.use_backbone_lora = use_backbone_lora
|
| 65 |
self.use_llm_lora = use_llm_lora
|
| 66 |
self.pad2square = pad2square
|
|
@@ -87,8 +90,8 @@ class InternVLChatConfig(PretrainedConfig):
|
|
| 87 |
`Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
|
| 88 |
"""
|
| 89 |
output = copy.deepcopy(self.__dict__)
|
| 90 |
-
output['vision_config'] = self.vision_config.to_dict()
|
| 91 |
-
output['llm_config'] = self.llm_config.to_dict()
|
| 92 |
output['model_type'] = self.__class__.model_type
|
| 93 |
output['use_backbone_lora'] = self.use_backbone_lora
|
| 94 |
output['use_llm_lora'] = self.use_llm_lora
|
|
|
|
| 51 |
self.vision_config = InternVisionPatchConfig(**vision_config)
|
| 52 |
else:
|
| 53 |
self.vision_config = None
|
| 54 |
+
|
| 55 |
+
arch = (llm_config.get("architectures") or [None])[0]
|
| 56 |
+
if arch == 'LlamaForCausalLM':
|
| 57 |
self.llm_config = LlamaConfig(**llm_config)
|
| 58 |
+
elif arch == 'InternLM2ForCausalLM':
|
| 59 |
self.llm_config = InternLM2Config(**llm_config)
|
| 60 |
+
elif arch == 'InternLM2VEForCausalLM':
|
| 61 |
self.llm_config = InternLM2Config(**llm_config)
|
| 62 |
+
elif arch == 'Qwen2ForCausalLM':
|
| 63 |
self.llm_config = Qwen2Config(**llm_config)
|
| 64 |
else:
|
| 65 |
+
self.llm_config = None
|
| 66 |
+
|
| 67 |
self.use_backbone_lora = use_backbone_lora
|
| 68 |
self.use_llm_lora = use_llm_lora
|
| 69 |
self.pad2square = pad2square
|
|
|
|
| 90 |
`Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
|
| 91 |
"""
|
| 92 |
output = copy.deepcopy(self.__dict__)
|
| 93 |
+
output['vision_config'] = self.vision_config.to_dict() if self.vision_config is not None else {}
|
| 94 |
+
output['llm_config'] = self.llm_config.to_dict() if self.llm_config is not None else {}
|
| 95 |
output['model_type'] = self.__class__.model_type
|
| 96 |
output['use_backbone_lora'] = self.use_backbone_lora
|
| 97 |
output['use_llm_lora'] = self.use_llm_lora
|