Instructions to use OpenGVLab/Mini-InternVL2-4B-DA-BDD with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/Mini-InternVL2-4B-DA-BDD with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenGVLab/Mini-InternVL2-4B-DA-BDD", 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/Mini-InternVL2-4B-DA-BDD", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/Mini-InternVL2-4B-DA-BDD with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenGVLab/Mini-InternVL2-4B-DA-BDD" # 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/Mini-InternVL2-4B-DA-BDD", "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/Mini-InternVL2-4B-DA-BDD
- SGLang
How to use OpenGVLab/Mini-InternVL2-4B-DA-BDD 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/Mini-InternVL2-4B-DA-BDD" \ --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/Mini-InternVL2-4B-DA-BDD", "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/Mini-InternVL2-4B-DA-BDD" \ --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/Mini-InternVL2-4B-DA-BDD", "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/Mini-InternVL2-4B-DA-BDD with Docker Model Runner:
docker model run hf.co/OpenGVLab/Mini-InternVL2-4B-DA-BDD
Error when running the official demo codes
If I directly run the demo codes, tokenlizer will have TypeError like this:
Exception has occurred: TypeError
expected str, bytes or os.PathLike object, not NoneType
File "/mnt/training_yrfs/p8n/camera/personal/tengfei.da/aidrive_data_extract_0616/label_aeb_odd_data/Mini-InternVL2-4B-DA-BDD.py", line 93, in
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, use_fast=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected str, bytes or os.PathLike object, not NoneType
If remove use_fast=False from tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, use_fast=False), then model.chat will have such error:
Traceback (most recent call last):
File "", line 2, in
File "/root/.cache/huggingface/modules/transformers_modules/OpenGVLab/Mini-InternVL2-4B-DA-BDD/dc4724a225f46f6f8dd78db74d01730245b28ee1/modeling_internvl_chat.py", line 291, in chat
generation_output = self.generate(
^^^^^^^^^^^^^^
File "/mnt/training_yrfs/prediction/aidrive/miniconda3/envs/aidrive-torch26-py312/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/huggingface/modules/transformers_modules/OpenGVLab/Mini-InternVL2-4B-DA-BDD/dc4724a225f46f6f8dd78db74d01730245b28ee1/modeling_internvl_chat.py", line 340, in generate
outputs = self.language_model.generate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/training_yrfs/prediction/aidrive/miniconda3/envs/aidrive-torch26-py312/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1928, in getattr
raise AttributeError(
AttributeError: 'Phi3ForCausalLM' object has no attribute 'generate'
But it is OK to run with OpenGVLab/Mini-InternVL2-1B-DA-BDD. What's the cause to the problems?