Text Generation
Transformers
PyTorch
Safetensors
English
phi3_v
Embedding
conversational
custom_code
Instructions to use TIGER-Lab/VLM2Vec-Full with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TIGER-Lab/VLM2Vec-Full with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TIGER-Lab/VLM2Vec-Full", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("TIGER-Lab/VLM2Vec-Full", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use TIGER-Lab/VLM2Vec-Full with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TIGER-Lab/VLM2Vec-Full" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TIGER-Lab/VLM2Vec-Full", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/TIGER-Lab/VLM2Vec-Full
- SGLang
How to use TIGER-Lab/VLM2Vec-Full 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 "TIGER-Lab/VLM2Vec-Full" \ --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": "TIGER-Lab/VLM2Vec-Full", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "TIGER-Lab/VLM2Vec-Full" \ --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": "TIGER-Lab/VLM2Vec-Full", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use TIGER-Lab/VLM2Vec-Full with Docker Model Runner:
docker model run hf.co/TIGER-Lab/VLM2Vec-Full
Update README.md
Browse files
README.md
CHANGED
|
@@ -48,6 +48,7 @@ Then you can enter the directory to run the following command.
|
|
| 48 |
```python
|
| 49 |
from src.model import MMEBModel
|
| 50 |
from src.arguments import ModelArguments
|
|
|
|
| 51 |
import torch
|
| 52 |
from transformers import HfArgumentParser, AutoProcessor
|
| 53 |
from PIL import Image
|
|
@@ -56,21 +57,20 @@ import numpy as np
|
|
| 56 |
model_args = ModelArguments(
|
| 57 |
model_name='TIGER-Lab/VLM2Vec-Full',
|
| 58 |
pooling='last',
|
| 59 |
-
normalize=True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
model = MMEBModel.load(model_args)
|
| 62 |
model.eval()
|
| 63 |
model = model.to('cuda', dtype=torch.bfloat16)
|
| 64 |
|
| 65 |
-
processor = AutoProcessor.from_pretrained(
|
| 66 |
-
model_args.model_name,
|
| 67 |
-
trust_remote_code=True,
|
| 68 |
-
model_backbone='phi3_v',
|
| 69 |
-
num_crops=4,
|
| 70 |
-
)
|
| 71 |
|
| 72 |
# Image + Text -> Text
|
| 73 |
-
inputs = processor('<|image_1|> Represent the given image with the following question: What is in the image', [Image.open(
|
|
|
|
| 74 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 75 |
qry_output = model(qry=inputs)["qry_reps"]
|
| 76 |
|
|
@@ -79,14 +79,14 @@ inputs = processor(string)
|
|
| 79 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 80 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 81 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 82 |
-
## A cat and a dog = tensor([[0.
|
| 83 |
|
| 84 |
string = 'A cat and a tiger'
|
| 85 |
inputs = processor(string)
|
| 86 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 87 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 88 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 89 |
-
## A cat and a tiger = tensor([[0.
|
| 90 |
|
| 91 |
# Text -> Image
|
| 92 |
inputs = processor('Find me an everyday image that matches the given caption: A cat and a dog.',)
|
|
@@ -98,7 +98,7 @@ inputs = processor(string, [Image.open('figures/example.jpg')])
|
|
| 98 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 99 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 100 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 101 |
-
## <|image_1|> Represent the given image. = tensor([[0.
|
| 102 |
|
| 103 |
inputs = processor('Find me an everyday image that matches the given caption: A cat and a tiger.',)
|
| 104 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
|
@@ -109,7 +109,7 @@ inputs = processor(string, [Image.open('figures/example.jpg')])
|
|
| 109 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 110 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 111 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 112 |
-
## <|image_1|> Represent the given image. = tensor([[0.
|
| 113 |
```
|
| 114 |
|
| 115 |
## Citation
|
|
|
|
| 48 |
```python
|
| 49 |
from src.model import MMEBModel
|
| 50 |
from src.arguments import ModelArguments
|
| 51 |
+
from src.utils import load_processor
|
| 52 |
import torch
|
| 53 |
from transformers import HfArgumentParser, AutoProcessor
|
| 54 |
from PIL import Image
|
|
|
|
| 57 |
model_args = ModelArguments(
|
| 58 |
model_name='TIGER-Lab/VLM2Vec-Full',
|
| 59 |
pooling='last',
|
| 60 |
+
normalize=True,
|
| 61 |
+
model_backbone='phi3_v',
|
| 62 |
+
num_crops=16)
|
| 63 |
+
|
| 64 |
+
processor = load_processor(model_args)
|
| 65 |
|
| 66 |
model = MMEBModel.load(model_args)
|
| 67 |
model.eval()
|
| 68 |
model = model.to('cuda', dtype=torch.bfloat16)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# Image + Text -> Text
|
| 72 |
+
inputs = processor('<|image_1|> Represent the given image with the following question: What is in the image', [Image.open(
|
| 73 |
+
'figures/example.jpg')])
|
| 74 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 75 |
qry_output = model(qry=inputs)["qry_reps"]
|
| 76 |
|
|
|
|
| 79 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 80 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 81 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 82 |
+
## A cat and a dog = tensor([[0.3008]], device='cuda:0', dtype=torch.bfloat16)
|
| 83 |
|
| 84 |
string = 'A cat and a tiger'
|
| 85 |
inputs = processor(string)
|
| 86 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 87 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 88 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 89 |
+
## A cat and a tiger = tensor([[0.2051]], device='cuda:0', dtype=torch.bfloat16)
|
| 90 |
|
| 91 |
# Text -> Image
|
| 92 |
inputs = processor('Find me an everyday image that matches the given caption: A cat and a dog.',)
|
|
|
|
| 98 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 99 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 100 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 101 |
+
## <|image_1|> Represent the given image. = tensor([[0.2930]], device='cuda:0', dtype=torch.bfloat16)
|
| 102 |
|
| 103 |
inputs = processor('Find me an everyday image that matches the given caption: A cat and a tiger.',)
|
| 104 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
|
|
|
| 109 |
inputs = {key: value.to('cuda') for key, value in inputs.items()}
|
| 110 |
tgt_output = model(tgt=inputs)["tgt_reps"]
|
| 111 |
print(string, '=', model.compute_similarity(qry_output, tgt_output))
|
| 112 |
+
## <|image_1|> Represent the given image. = tensor([[0.2012]], device='cuda:0', dtype=torch.bfloat16)
|
| 113 |
```
|
| 114 |
|
| 115 |
## Citation
|