Description
Installing google-genai[local-tokenizer] installs Pillow, PyTorch, Torchvision, Transformers, Triton and the Linux NVIDIA CUDA packages for every locally tokenised model.
However, models such as gemini-2.5-flash use the lightweight SentencePiece path. The Hugging Face AutoProcessor path is selected only for the Gemma 4 model mappings.
This makes local tokenisation unexpectedly expensive for applications that do not use Gemma 4.
Reproduction
Environment:
- Linux x86_64
- Python 3.14.2
- uv
google-genai==2.11.0
uv venv --python 3.14 base
uv pip install --python base/bin/python \
'google-genai[aiohttp]==2.11.0'
uv venv --python 3.14 local
uv pip install --python local/bin/python \
'google-genai[aiohttp,local-tokenizer]==2.11.0'
du -sh base local
Result:
Largest installed components:
1.1G torch
2.7G nvidia
689M triton
13M torchvision
The dependency count increases from 33 packages to 83.
Expected behaviour
Applications using the SentencePiece-backed local tokenizer should not need to install the Gemma 4 Hugging Face and PyTorch stack.
Could the extras be split, for example:
local-tokenizer = [
"sentencepiece>=0.2.0",
"protobuf",
]
local-tokenizer-gemma4 = [
"sentencepiece>=0.2.0",
"protobuf",
"pillow",
"torch",
"torchvision",
"transformers",
]
The implementation already imports AutoProcessor lazily inside the Gemma 4 path, so the runtime boundary largely exists.
It may also be worth checking whether AutoTokenizer could replace AutoProcessor for this text-only use case, potentially removing some image-related dependencies. That requires validation against Gemma 4.
Downstream impact
This caused one downstream production service environment to increase from approximately 626 MiB to 5.1 GiB. We had to remove the local-tokenizer extra from our shared library's base installation and fall back to the remote count_tokens endpoint.
Relevant code:
Description
Installing
google-genai[local-tokenizer]installs Pillow, PyTorch, Torchvision, Transformers, Triton and the Linux NVIDIA CUDA packages for every locally tokenised model.However, models such as
gemini-2.5-flashuse the lightweight SentencePiece path. The Hugging FaceAutoProcessorpath is selected only for the Gemma 4 model mappings.This makes local tokenisation unexpectedly expensive for applications that do not use Gemma 4.
Reproduction
Environment:
google-genai==2.11.0Result:
Largest installed components:
The dependency count increases from 33 packages to 83.
Expected behaviour
Applications using the SentencePiece-backed local tokenizer should not need to install the Gemma 4 Hugging Face and PyTorch stack.
Could the extras be split, for example:
The implementation already imports
AutoProcessorlazily inside the Gemma 4 path, so the runtime boundary largely exists.It may also be worth checking whether
AutoTokenizercould replaceAutoProcessorfor this text-only use case, potentially removing some image-related dependencies. That requires validation against Gemma 4.Downstream impact
This caused one downstream production service environment to increase from approximately 626 MiB to 5.1 GiB. We had to remove the local-tokenizer extra from our shared library's base installation and fall back to the remote
count_tokensendpoint.Relevant code: