Instructions to use google/paligemma2-3b-pt-896 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/paligemma2-3b-pt-896 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/paligemma2-3b-pt-896")# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("google/paligemma2-3b-pt-896") model = AutoModelForMultimodalLM.from_pretrained("google/paligemma2-3b-pt-896", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use google/paligemma2-3b-pt-896 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/paligemma2-3b-pt-896" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/paligemma2-3b-pt-896", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/google/paligemma2-3b-pt-896
- SGLang
How to use google/paligemma2-3b-pt-896 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/paligemma2-3b-pt-896" \ --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/paligemma2-3b-pt-896", "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/paligemma2-3b-pt-896" \ --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/paligemma2-3b-pt-896", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use google/paligemma2-3b-pt-896 with Docker Model Runner:
docker model run hf.co/google/paligemma2-3b-pt-896
processor = PaliGemmaProcessor.from_pretrained(model_id) issue
Traceback (most recent call last):
File "/Disk/lfc/paligemma2/inference.py", line 13, in
processor = PaliGemmaProcessor.from_pretrained(model_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Disk/Miniforge3/envs/lfc_test/lib/python3.11/site-packages/transformers/processing_utils.py", line 892, in from_pretrained
args = cls._get_arguments_from_pretrained(pretrained_model_name_or_path, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Disk/Miniforge3/envs/lfc_test/lib/python3.11/site-packages/transformers/processing_utils.py", line 938, in _get_arguments_from_pretrained
args.append(attribute_class.from_pretrained(pretrained_model_name_or_path, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Disk/Miniforge3/envs/lfc_test/lib/python3.11/site-packages/transformers/tokenization_utils_base.py", line 2271, in from_pretrained
return cls._from_pretrained(
^^^^^^^^^^^^^^^^^^^^^
File "/Disk/Miniforge3/envs/lfc_test/lib/python3.11/site-packages/transformers/tokenization_utils_base.py", line 2505, in _from_pretrained
tokenizer = cls(*init_inputs, **init_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Disk/Miniforge3/envs/lfc_test/lib/python3.11/site-packages/transformers/models/gemma/tokenization_gemma_fast.py", line 103, in init
super().init(
File "/Disk/Miniforge3/envs/lfc_test/lib/python3.11/site-packages/transformers/tokenization_utils_fast.py", line 115, in init
fast_tokenizer = TokenizerFast.from_file(fast_tokenizer_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: data did not match any variant of untagged enum ModelWrapper at line 2591977 column 3
Hi @lvfengchun ,
I didn't encounter an error, could you please refer to this gist file.
Getting an error because the PaliGemmaProcessor is unable to load the tokenizer due to an issue with the tokenizer file (tokenizer.json) got corrupted, incompatible, or incorrectly formatted.
To solve this issue, please make sure that use the PaliGemmaProcessor and model from the same checkpoint.
model_id = "google/paligemma2-3b-pt-896"
processor = PaliGemmaProcessor.from_pretrained(model_id)
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id)
Suppose, if your working on your local system then delete the local cache of the tokenizer files for the model and redownload them.
If you still persists an issue, please let me know.
Thank you.
This is most likely due to an outdated version of transformers/tokenizers. Upgrading should fix the issue!
Hi @GopiUppari I loaded the model and tokenizer locally, and I have re-downloaded the tokenizer.json file, but I still have this error.
Happy to help!