Instructions to use google/t5gemma-2-4b-4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/t5gemma-2-4b-4b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/t5gemma-2-4b-4b")# Load model directly from transformers import AutoProcessor, AutoModelForSeq2SeqLM processor = AutoProcessor.from_pretrained("google/t5gemma-2-4b-4b") model = AutoModelForSeq2SeqLM.from_pretrained("google/t5gemma-2-4b-4b") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use google/t5gemma-2-4b-4b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/t5gemma-2-4b-4b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/t5gemma-2-4b-4b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/google/t5gemma-2-4b-4b
- SGLang
How to use google/t5gemma-2-4b-4b 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/t5gemma-2-4b-4b" \ --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/t5gemma-2-4b-4b", "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/t5gemma-2-4b-4b" \ --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/t5gemma-2-4b-4b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use google/t5gemma-2-4b-4b with Docker Model Runner:
docker model run hf.co/google/t5gemma-2-4b-4b
Running Lora+ T5 Gemma 2 on multi gpu results in error
Hello! 👋
I’m running into a DDP error when training google/t5gemma-2-4b-4b with LoRA+ on 4 GPUs. Training on a single GPU works fine, but distributed training fails consistently.
Model: https://huggingface.co/google/t5gemma-2-4b-4b
Environment
transformers: 5.0.0.dev0
accelerate: 1.12.0
peft: 0.18.1
torch: 2.9.1
CUDA: 12.4
GPUs: 4× NVIDIA RTX 6000
OS: Ubuntu 20.04.6 LTS
Here you can find the error I encounter, and a screenshot of the full one.
[rank1]: RuntimeError: Expected to mark a variable ready only once. This error is caused by one of the following reasons: 1) Use of a module parameter outside the forwardfunction. Please make sure model parameters are not shared across multiple concurrent forward-backward passes. or try to use _set_static_graph() as a workaround if this module graph does not change during training loop.2) Reused parameters in multiple reentrant backward passes. For example, if you use multiplecheckpoint functions to wrap the same part of your model, it would result in the same set of parameters been used by different reentrant backward passes multiple times, and hence marking a variable ready multiple times. DDP does not support such use cases in default. You can try to use _set_static_graph() as a workaround if your module graph does not change over iterations. [rank1]: Parameter at index 1275 with name base_model.model.model.decoder.layers.33.mlp.down_proj.lora_B.default.weight has been marked as ready twice. This means that multiple autograd engine hooks have fired for this particular parameter during this iteration.
Q: Is this a known incompatibility between LoRA and DDP / Transformers for T5Gemma, or is there a recommended configuration/workaround?
Thank you!
Hi @RomanatoS ,
This seems to be a conflict between DDP and the default 'reentrant' gradient checkpointing. The error Expected to amrk a variable ready only once occurs because reentrant checkpointing re-runs the forward pass during backprop, causing DDP to think the parameters are being synchronised twice in one step. This has nothing to do with T5Gemma.
You can try to force non-reentrant checkpointing: trying adding this to your Training Arguments: gradient_checkpointing_kwargs={"use_reentrant": False} which prevents the backward pass from traversing the graph a second time and it's also recommended across peft community to set ddp_find_unused_parameters=False to prevent DDP from crashing when scanning frozen LORA parameters.
Thank you!