Instructions to use google/gemma-4-31B-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-4-31B-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/gemma-4-31B-it") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("google/gemma-4-31B-it") model = AutoModelForImageTextToText.from_pretrained("google/gemma-4-31B-it") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use google/gemma-4-31B-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/gemma-4-31B-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/gemma-4-31B-it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/google/gemma-4-31B-it
- SGLang
How to use google/gemma-4-31B-it 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/gemma-4-31B-it" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/gemma-4-31B-it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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/gemma-4-31B-it" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/gemma-4-31B-it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use google/gemma-4-31B-it with Docker Model Runner:
docker model run hf.co/google/gemma-4-31B-it
Drops in performance randomly VLLM on H200 and B200 with 2 GPUs
#104
by jtvino - opened
Model seems to perform really well and then randomly will drop in t/s when using vllm when running on b200 or h200 with 2 GPUs
It will run at like 101 t/s and then drop to 0.1 tokens/s with only 2 reqs in queue while GPU KV cache usage is only showing 2.6%
vllm serve google/gemma-4-31B-it --served-model-name google/gemma-4-31B-it --kv-cache-dtype fp8 --max-model-len 200000 --dtype auto --async-scheduling --tensor-parallel-size 2 --trust-remote-code --gpu-memory-utilization 0.90 --enable-chunked-prefill --enable-auto-tool-choice --reasoning-parser gemma4 --tool-call-parser gemma4 --limit-mm-per-prompt '{"image": 2, "audio": 1}' --chat-template examples/tool_chat_template_gemma4.jinja --max-num-seqs 64
using vllm v0.20.0. Issue exists in v0.19.1 and v0.20.1
(APIServer pid=434) INFO 05-11 17:46:04 [loggers.py:271] Engine 000: Avg prompt throughput: 145.1 tokens/s, Avg generation throughput: 133.7 tokens/s, Running: 1 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.3%, Prefix cache hit rate: 89.3%, MM cache hit rate: 76.6%
(APIServer pid=434) INFO: 10.129.3.35:52484 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.129.3.35:34962 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.129.3.35:52484 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.129.3.35:52484 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:46:14 [loggers.py:271] Engine 000: Avg prompt throughput: 160.0 tokens/s, Avg generation throughput: 87.7 tokens/s, Running: 1 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.3%, Prefix cache hit rate: 89.6%, MM cache hit rate: 76.6%
(APIServer pid=434) INFO: 10.129.3.35:52484 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:46:24 [loggers.py:271] Engine 000: Avg prompt throughput: 38.9 tokens/s, Avg generation throughput: 23.7 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 89.6%, MM cache hit rate: 76.6%
(APIServer pid=434) INFO: 10.129.3.35:54410 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:46:34 [loggers.py:271] Engine 000: Avg prompt throughput: 32.4 tokens/s, Avg generation throughput: 18.3 tokens/s, Running: 1 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.3%, Prefix cache hit rate: 89.6%, MM cache hit rate: 76.6%
(APIServer pid=434) INFO: 10.129.3.35:54410 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.130.1.111:40524 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:46:44 [loggers.py:271] Engine 000: Avg prompt throughput: 131.8 tokens/s, Avg generation throughput: 101.2 tokens/s, Running: 1 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.2%, Prefix cache hit rate: 89.6%, MM cache hit rate: 76.6%
(APIServer pid=434) INFO: 10.130.1.111:33690 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:46:54 [loggers.py:271] Engine 000: Avg prompt throughput: 3.6 tokens/s, Avg generation throughput: 182.2 tokens/s, Running: 2 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.4%, Prefix cache hit rate: 89.6%, MM cache hit rate: 76.6%
(APIServer pid=434) INFO: 127.0.0.1:52124 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 127.0.0.1:52124 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:47:04 [loggers.py:271] Engine 000: Avg prompt throughput: 344.0 tokens/s, Avg generation throughput: 120.8 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 89.5%, MM cache hit rate: 76.6%
(APIServer pid=434) INFO: 127.0.0.1:52124 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.130.1.111:33690 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.129.3.35:54736 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:47:14 [loggers.py:271] Engine 000: Avg prompt throughput: 702.7 tokens/s, Avg generation throughput: 18.9 tokens/s, Running: 2 reqs, Waiting: 1 reqs, GPU KV cache usage: 2.2%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.129.3.35:59972 - "POST /v1/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:47:24 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.2 tokens/s, Running: 2 reqs, Waiting: 1 reqs, GPU KV cache usage: 2.5%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.130.1.111:58378 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.130.1.111:58396 - "POST /v1/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.129.3.35:52348 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:47:34 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 2 reqs, GPU KV cache usage: 2.6%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.129.3.35:52376 - "POST /v1/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.130.1.111:57256 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:47:44 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 3 reqs, GPU KV cache usage: 2.7%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.130.1.111:37562 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:47:54 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 6 reqs, GPU KV cache usage: 2.8%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.129.3.35:33876 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:48:04 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 5 reqs, GPU KV cache usage: 3.0%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:48:14 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 5 reqs, GPU KV cache usage: 3.1%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.129.3.35:46682 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.130.1.111:46832 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:48:24 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 4 reqs, GPU KV cache usage: 3.2%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.130.1.111:47290 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.129.3.35:46792 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:48:34 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 2 reqs, Waiting: 4 reqs, GPU KV cache usage: 3.2%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:48:44 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 5 reqs, GPU KV cache usage: 3.3%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:48:54 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 7 reqs, GPU KV cache usage: 3.5%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:49:04 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 2 reqs, Waiting: 7 reqs, GPU KV cache usage: 3.5%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.129.3.35:44674 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:49:14 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 2 reqs, Waiting: 5 reqs, GPU KV cache usage: 3.6%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:49:24 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 2 reqs, Waiting: 5 reqs, GPU KV cache usage: 3.6%, Prefix cache hit rate: 88.7%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:49:34 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 6 reqs, Waiting: 2 reqs, GPU KV cache usage: 4.0%, Prefix cache hit rate: 88.3%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:49:44 [loggers.py:271] Engine 000: Avg prompt throughput: 13094.9 tokens/s, Avg generation throughput: 1.5 tokens/s, Running: 6 reqs, Waiting: 1 reqs, GPU KV cache usage: 4.6%, Prefix cache hit rate: 88.3%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:49:54 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1.0 tokens/s, Running: 6 reqs, Waiting: 1 reqs, GPU KV cache usage: 4.9%, Prefix cache hit rate: 88.3%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:50:04 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1.0 tokens/s, Running: 6 reqs, Waiting: 1 reqs, GPU KV cache usage: 5.1%, Prefix cache hit rate: 88.3%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.130.1.111:34970 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 10.130.1.111:34986 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:50:14 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.5 tokens/s, Running: 6 reqs, Waiting: 1 reqs, GPU KV cache usage: 5.2%, Prefix cache hit rate: 88.3%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.129.3.35:54102 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:50:24 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.5 tokens/s, Running: 6 reqs, Waiting: 2 reqs, GPU KV cache usage: 5.4%, Prefix cache hit rate: 88.3%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:50:34 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.5 tokens/s, Running: 7 reqs, Waiting: 3 reqs, GPU KV cache usage: 6.0%, Prefix cache hit rate: 88.2%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.130.1.111:40082 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:50:44 [loggers.py:271] Engine 000: Avg prompt throughput: 9177.3 tokens/s, Avg generation throughput: 2.3 tokens/s, Running: 10 reqs, Waiting: 0 reqs, GPU KV cache usage: 7.6%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:50:54 [loggers.py:271] Engine 000: Avg prompt throughput: 222.1 tokens/s, Avg generation throughput: 74.7 tokens/s, Running: 9 reqs, Waiting: 0 reqs, GPU KV cache usage: 5.7%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 127.0.0.1:52124 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:51:04 [loggers.py:271] Engine 000: Avg prompt throughput: 342.4 tokens/s, Avg generation throughput: 289.3 tokens/s, Running: 7 reqs, Waiting: 0 reqs, GPU KV cache usage: 5.1%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 127.0.0.1:52124 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO: 127.0.0.1:52124 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:51:14 [loggers.py:271] Engine 000: Avg prompt throughput: 35.7 tokens/s, Avg generation throughput: 264.1 tokens/s, Running: 6 reqs, Waiting: 0 reqs, GPU KV cache usage: 4.9%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 127.0.0.1:52124 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:51:24 [loggers.py:271] Engine 000: Avg prompt throughput: 8.4 tokens/s, Avg generation throughput: 185.3 tokens/s, Running: 4 reqs, Waiting: 0 reqs, GPU KV cache usage: 4.3%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:51:34 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 135.9 tokens/s, Running: 1 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.6%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:51:44 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 74.6 tokens/s, Running: 1 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.6%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:51:54 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 44.7 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO 05-11 17:52:04 [loggers.py:271] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.130.1.111:58502 - "POST /v1/chat/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:52:24 [loggers.py:271] Engine 000: Avg prompt throughput: 172.9 tokens/s, Avg generation throughput: 48.0 tokens/s, Running: 1 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.2%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%
(APIServer pid=434) INFO: 10.130.1.111:53106 - "POST /v1/completions HTTP/1.1" 200 OK
(APIServer pid=434) INFO 05-11 17:52:34 [loggers.py:271] Engine 000: Avg prompt throughput: 99.4 tokens/s, Avg generation throughput: 36.8 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 88.1%, MM cache hit rate: 76.7%