Instructions to use google/paligemma-3b-mix-224 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/paligemma-3b-mix-224 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/paligemma-3b-mix-224")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("google/paligemma-3b-mix-224") model = AutoModelForMultimodalLM.from_pretrained("google/paligemma-3b-mix-224", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use google/paligemma-3b-mix-224 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/paligemma-3b-mix-224" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/paligemma-3b-mix-224", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/google/paligemma-3b-mix-224
- SGLang
How to use google/paligemma-3b-mix-224 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 "google/paligemma-3b-mix-224" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/paligemma-3b-mix-224", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "google/paligemma-3b-mix-224" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/paligemma-3b-mix-224", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use google/paligemma-3b-mix-224 with Docker Model Runner:
docker model run hf.co/google/paligemma-3b-mix-224
Inference via sagemaker endpoint
Hi! How do i call this for inference with an image via a sagemaker endpoint?
send request
predictor.predict({
"inputs": "My name is Clara and I am", "parameters":parameters
})
This works, but how do i include an image in the input?
I tried this:
image_path ='./images/powercord.jpg'
with open(image_path, "rb") as f:
image = base64.b64encode(f.read()).decode("utf-8")
payload = { "inputs" :{
"prompt": "detect powercord",
"image": image
}}
query_response = predictor.predict(data=payload)
But im getting this error - An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (422) from primary with message "Failed to deserialize the JSON body into the target type: inputs: invalid type: map, expected a string at line 1 column 11".
Hi @shum123 ,
The model is expecting a JSON format where the inputs are passed in a way that it can deserialize into the expected structure. You're including both the prompt and the image in the inputs dictionary. You should pass the entire payload as a valid JSON string (json.dumps(payload)) in your request. Kindly use the below code.
payload = { "inputs": json.dumps({ "prompt": "detect powercord", "image": image }) }
Thank you.