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
Error: model_kwargs["past_key_values"] is "None"
model_kwargs["past_key_values"] is "None"
The error content is as shown below:
utils.py path: xgen.venv\Lib\site-packages\transformers\generation\utils.py
I have installed: https://huggingface.co/Salesforce/xgen-mm-phi3-mini-instruct-r-v1#troubleshoot
And, I have installed the latest version of transformers 4.41.0:pip install transformers
Then I execute these codes: https://huggingface.co/Salesforce/xgen-mm-phi3-mini-instruct-r-v1#how-to-use
Then, I encountered the above error. I use Win10, PyCharm 2024.1.1 (Professional Edition).
Please help me solve this problem, many thanks.
Same thing happens using Ubuntu 20.04, Python 3.10.11...
Wow it works! Thank you so much.
you are a straight up genius
Hi @Jian8 @PeePants , and @RiverFlows , we have updated the inference code so that you don't need to hack the transformers's code. Our inference code is compatible with transformers==4.41.1. Please give it a try and let us know if you have any issues. Thanks!
