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)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("google/gemma-4-31B-it") model = AutoModelForMultimodalLM.from_pretrained("google/gemma-4-31B-it", device_map="auto") 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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- AMD Developer Cloud
- Local Apps Settings
- 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
Commit History
-
Add response_template to tokenizer_config.json (#130)
- Add response_template to tokenizer_config.json (f2cb94e0dce967802b93c95b10cdc2bf59a7afcc) - Update README.md (08d5db1410018ad0bcc6bcf5847b35d60e17c91e) Co-authored-by: Matthew Carrigan <Rocketknight1@users.noreply.huggingface.co>842da37
-
Update README (#133)
- Update README (f08e85854bc367e536aef4d09f130c67f90e4e08)b9ea41a -
fix: chat template — null handling, reasoning preservation, turn-tag balance, input validation (#118)
- fix: chat template — null handling, reasoning preservation, turn-tag balance, input validation (03cf5a160809660f3816aa2cf5e6f7dea502d33f) - fix: restore model turn + thinking cue after tool responses (ea43aec3dca438b8b9807890c686ec530f30eb48) - fix: emit empty thought-channel primer on historical assistant turns for APC (340d7b5d066f598ed877c2feebadcd4ba5242956) - fix: prevent extra <turn|> when assistant has content + tool_calls + continuation (27596f5f0c82ffc06b9d17eb28e268a39f2b3b1c) - fix: revert add_generation_prompt regression + preserve_thinking default (ee2de7dfcae07d6b3644da619974607ee8080a64) - fix: render thinking channel regardless of tool_calls presence (2dfa20d9da2d7d127bc499dd7de30ff34279ca9e) - fix: update stale comment — thinking channel no longer tool-call-only (0def573f1183891a2c86e0261db7291dd1545400) - fix: remove APC primer from history, scope preserve_thinking to tool-call turns (bbc9c682a1ef6088b754f9f347dd31c49eb5c153) - fix: remove APC primer from history, s…68abe48
-
Add Technical Report
Verified signature518276f
-
Update README.md
Verified signature3548789
-
Update README.md
Verified signatureec81324
-
Add MMMU-Pro evaluation result (#107)
- Add MMMU-Pro evaluation result (f5de7046b3824dadc016f39da633ebf587a04a59) Co-authored-by: Nathan Habib <SaylorTwift@users.noreply.huggingface.co>fb9ae26
-
fix(chat_template): Emit multimodal placeholders in tool response content-parts (#94)
- fix(chat_template): Emit multimodal placeholders in tool response content-parts (7d0815aac6c197933a8f76ef360a5e9d099264bf) Co-authored-by: Harshal Janjani <harshaljanjani@users.noreply.huggingface.co>fcf2302
-
Add proper metadata (#101)
- Add proper metadata (713023a367e6ca39033d51f69ac3940d91125932) Co-authored-by: Omar Sanseviero <osanseviero@users.noreply.huggingface.co>ba74f5b
-
fix(chat_template): update SI and tool call handling (#86)
- fix(chat_template): update SI and tool call handling (226996222a0d6835ed362dc7196ec543f43a8b77) Co-authored-by: Douglas Reid <dougreid@users.noreply.huggingface.co>145dc25
-
Update schema (#59)
- Update schema (198e9e0bbe4c8bed534093b16b852cc0a5f5c838) - Update tokenizer_config.json (552df617e18d35f97b3ef0ab4b75b00e154c6be7) Co-authored-by: Matthew Carrigan <Rocketknight1@users.noreply.huggingface.co>439edf5 -
fix: prefix-preserving tool calls + dialog compliance (#56)
- fix: prefix-preserving tool calls + dialog compliance (da355038c9ee68f0ff379e6abaa4de993afbe9ad) Co-authored-by: Luciano Martins <lucianommartins@users.noreply.huggingface.co>e51e7dc
-
Preparing for release!
Co-authored-by: Rocketknight1 <Rocketknight1@users.noreply.huggingface.co> Co-authored-by: dougreid <dougreid@users.noreply.huggingface.co> Co-authored-by: RyanMullins <RyanMullins@users.noreply.huggingface.co> Co-authored-by: pcuenq <pcuenq@users.noreply.huggingface.co> Co-authored-by: bebechien <bebechien@users.noreply.huggingface.co> Co-authored-by: osanseviero <osanseviero@users.noreply.huggingface.co> Co-authored-by: douglas reid <douglas reid@users.noreply.huggingface.co>419b2ef