Instructions to use google/paligemma-3b-pt-224 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/paligemma-3b-pt-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-pt-224")# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("google/paligemma-3b-pt-224") model = AutoModelForImageTextToText.from_pretrained("google/paligemma-3b-pt-224") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use google/paligemma-3b-pt-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-pt-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-pt-224", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/google/paligemma-3b-pt-224
- SGLang
How to use google/paligemma-3b-pt-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-pt-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-pt-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-pt-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-pt-224", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use google/paligemma-3b-pt-224 with Docker Model Runner:
docker model run hf.co/google/paligemma-3b-pt-224
ValueError: Custom 4D attention mask should be passed in inverted form with max==0
Hi,
I am trying to use the code by running the example code snippet in the Model Card.. but I am receiving the following error:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/transformers/generation/utils.py", line 1824, in generate
result = self._sample(
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/transformers/generation/utils.py", line 2463, in _sample
outputs = self(
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
return forward_call(*args, **kwargs)
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/transformers/models/paligemma/modeling_paligemma.py", line 468, in forward
outputs = self.language_model(
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
return forward_call(*args, **kwargs)
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/transformers/models/gemma/modeling_gemma.py", line 1113, in forward
outputs = self.model(
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
return forward_call(*args, **kwargs)
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/transformers/models/gemma/modeling_gemma.py", line 883, in forward
causal_mask = self._update_causal_mask(
File "/opt/conda/envs/paligemma-hf/lib/python3.10/site-packages/transformers/models/gemma/modeling_gemma.py", line 1003, in _update_causal_mask
raise ValueError("Custom 4D attention mask should be passed in inverted form with max==0`")
ValueError: Custom 4D attention mask should be passed in inverted form with max==0`
The shapes of model_inputs are:
input_ids torch.Size([1, 260])
attention_mask torch.Size([1, 260])
pixel_values torch.Size([1, 3, 224, 224])
Details of my environment:
Python version: 3.10.14
CUDA hardware: GPU A100
CUDA version: 12.0
Torch version: 2.3.0
Transformers version: 4.42.0.dev0
Note: Having the same versions, but with a CUDA hardware V100, I don't have this issue
Hi @brian-gordon , I came across the same issue while running paligemma model for vQA. Here https://github.com/huggingface/transformers/issues/31171#issuecomment-2145421881 it is mentioned it is a regression due to a merge which will be fixed. You can solve it for now by pinning the transformers library version to 4.41.1.
Hi @brian-gordon , Could you please refer this similar issue for paligemma inverted mask. and also PR is merged, added the mask inversion in this update PR. Kindly follow this and let me know if you have any concerns.
Thank you.