Instructions to use OpenGVLab/Mini-InternVL2-4B-DA-DriveLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/Mini-InternVL2-4B-DA-DriveLM 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-DriveLM", 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-DriveLM", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use OpenGVLab/Mini-InternVL2-4B-DA-DriveLM 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-DriveLM" # 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-DriveLM", "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-DriveLM
- SGLang
How to use OpenGVLab/Mini-InternVL2-4B-DA-DriveLM 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-DriveLM" \ --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-DriveLM", "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-DriveLM" \ --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-DriveLM", "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-DriveLM with Docker Model Runner:
docker model run hf.co/OpenGVLab/Mini-InternVL2-4B-DA-DriveLM
Cannot load vocab_file, Encounter TypeError and DecodeError related to the protobuf library when running the example code.
Issue Summary:
Cannot load vocab_file using LlamaTokenizer. Encounter TypeError and DecodeError related to the protobuf library when running the example code.
Environment:
Operating System: Ubuntu 20.04
Python Version: 3.9
Library Version: transformers 4.37.2
Steps to Reproduce
Clone the repository: git clone https://github.com/user/repo.git
Install dependencies.
Copy the example code in the README and run the script: python script.py
Encounter the following error:
"miniconda3/envs/internvl2/lib/python3.9/site-packages/transformers/models/llama/tokenization_llama.py", line 206, in get_spm_processor
with open(self.vocab_file, "rb") as f:
TypeError: expected str, bytes or os.PathLike object, not NoneTypeTo troubleshoot, I modified the code to explicitly load the vocab_file:
tokenizer = LlamaTokenizer.from_pretrained(path, vocab_file=vocab_file_path, trust_remote_code=True, use_fast=False)Run the script again: python script.py
Actual Behavior
Encounter the following traceback when running the modified script:
Traceback (most recent call last):
File "script.py", line X, in
tokenizer = LlamaTokenizer.from_pretrained(path, vocab_file=vocab_file_path, trust_remote_code=True, use_fast=False)
File "miniconda3/envs/internvl2/lib/python3.9/site-packages/transformers/models/llama/tokenization_llama.py", line 209, in get_spm_processor
model = model_pb2.ModelProto.FromString(sp_model)
google.protobuf.message.DecodeError: Error parsing message with type 'sentencepiece.ModelProto'
@YiRabbit Did you manage to resolve this issue TypeError: expected str, bytes or os.PathLike object, not NoneType?
Thanks
Also curious if anyone ended up resolving this. @risakri001 @YiRabbit
Edit: seems like removing use_fast=False resolves it!