Image-Text-to-Text
Transformers
Safetensors
English
xgenmm
feature-extraction
conversational
custom_code
Instructions to use Salesforce/xgen-mm-phi3-mini-instruct-r-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Salesforce/xgen-mm-phi3-mini-instruct-r-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Salesforce/xgen-mm-phi3-mini-instruct-r-v1", 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 AutoModelForVision2Seq model = AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-r-v1", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Salesforce/xgen-mm-phi3-mini-instruct-r-v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Salesforce/xgen-mm-phi3-mini-instruct-r-v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Salesforce/xgen-mm-phi3-mini-instruct-r-v1", "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/Salesforce/xgen-mm-phi3-mini-instruct-r-v1
- SGLang
How to use Salesforce/xgen-mm-phi3-mini-instruct-r-v1 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 "Salesforce/xgen-mm-phi3-mini-instruct-r-v1" \ --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": "Salesforce/xgen-mm-phi3-mini-instruct-r-v1", "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 "Salesforce/xgen-mm-phi3-mini-instruct-r-v1" \ --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": "Salesforce/xgen-mm-phi3-mini-instruct-r-v1", "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 Salesforce/xgen-mm-phi3-mini-instruct-r-v1 with Docker Model Runner:
docker model run hf.co/Salesforce/xgen-mm-phi3-mini-instruct-r-v1
The model does not currently support batch size more than 1
#6
by Napron - opened
I am trying to run inference with more than 1 image and it throws the error, could you please fix this.
Thanks in advance.
tokenizer.padding_side = "left"
#Adding one more img in the list
inputs = image_processor([img, img], return_tensors="pt", image_aspect_ratio='anyres') # image_aspect_ratio='anyres')
prompt = apply_prompt_template(sample['question'])
language_inputs = tokenizer([prompt], return_tensors="pt")
inputs.update(language_inputs)
#Batch size becomes 2
torch.Size([1, 2, 5, 3, 378, 378])
RuntimeError: Expected 3D (unbatched) or 4D (batched) input to conv2d, but got input of size: [2, 5, 3, 378, 378]
Hi @Napron , thank you for being patient. Check out our latest notebook for batch inference. Let us know if you have any questions.
Thank you, appreciate it!
Manli changed discussion status to closed