Instructions to use VLM2Vec/VLM2Vec-V2.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use VLM2Vec/VLM2Vec-V2.0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="VLM2Vec/VLM2Vec-V2.0") 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 AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("VLM2Vec/VLM2Vec-V2.0") model = AutoModelForMultimodalLM.from_pretrained("VLM2Vec/VLM2Vec-V2.0", device_map="auto") 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?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use VLM2Vec/VLM2Vec-V2.0 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "VLM2Vec/VLM2Vec-V2.0" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "VLM2Vec/VLM2Vec-V2.0", "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/VLM2Vec/VLM2Vec-V2.0
- SGLang
How to use VLM2Vec/VLM2Vec-V2.0 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 "VLM2Vec/VLM2Vec-V2.0" \ --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": "VLM2Vec/VLM2Vec-V2.0", "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 "VLM2Vec/VLM2Vec-V2.0" \ --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": "VLM2Vec/VLM2Vec-V2.0", "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 VLM2Vec/VLM2Vec-V2.0 with Docker Model Runner:
docker model run hf.co/VLM2Vec/VLM2Vec-V2.0
Update README.md
Browse files
README.md
CHANGED
|
@@ -92,4 +92,21 @@ inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
|
| 92 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 93 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 94 |
## tensor([[0.3223]], device='cuda:0', dtype=torch.bfloat16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
```
|
|
|
|
| 92 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 93 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 94 |
## tensor([[0.3223]], device='cuda:0', dtype=torch.bfloat16)
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
## Citation
|
| 98 |
+
```
|
| 99 |
+
@article{jiang2024vlm2vec,
|
| 100 |
+
title={VLM2Vec: Training Vision-Language Models for Massive Multimodal Embedding Tasks},
|
| 101 |
+
author={Jiang, Ziyan and Meng, Rui and Yang, Xinyi and Yavuz, Semih and Zhou, Yingbo and Chen, Wenhu},
|
| 102 |
+
journal={arXiv preprint arXiv:2410.05160},
|
| 103 |
+
year={2024}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
@article{meng2025vlm2vecv2,
|
| 107 |
+
title={VLM2Vec-V2: Advancing Multimodal Embedding for Videos, Images, and Visual Documents},
|
| 108 |
+
author={Rui Meng and Ziyan Jiang and Ye Liu and Mingyi Su and Xinyi Yang and Yuepeng Fu and Can Qin and Zeyuan Chen and Ran Xu and Caiming Xiong and Yingbo Zhou and Wenhu Chen and Semih Yavuz},
|
| 109 |
+
journal={arXiv preprint arXiv:2507.04590},
|
| 110 |
+
year={2025}
|
| 111 |
+
}
|
| 112 |
```
|