Run this model with HF Jobs
Run google/gemma-4-31B-it on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/google/gemma-4-31B-it. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/google/gemma-4-31B-it on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/google/gemma-4-31B-it. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/google/gemma-4-31B-it. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
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
Update chat_template.jinja
Browse filesThis updates the Gemma chat_template.jinja tool declaration rendering so nullable referenced JSON Schema fields (in common constructs likely to matter for tool declarations) are not collapsed into empty type declarations.
10 unmodified lines11121314151617181920212229 unmodified lines52535455565758596061625 unmodified lines686970717273743 unmodified lines78798081828384855 unmodified lines91929394959623 unmodified lines120121122123124125225 unmodified lines35135235335410 unmodified linesdescription:<|"|>{{ value['description'] }}<|"|>{%- set add_comma = true -%}{%- endif -%}{%- if value['type'] | upper == 'STRING' -%}{%- if value['enum'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}enum:{{ format_argument(value['enum']) }}{%- endif -%}{%- elif value['type'] | upper == 'ARRAY' -%}{%- if value['items'] is mapping and value['items'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}items:{29 unmodified lines}{%- endif -%}{%- endif -%}{%- if value['nullable'] %}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}nullable:true{%- endif -%}{%- if value['type'] | upper == 'OBJECT' -%}{%- if value['properties'] is defined and value['properties'] is mapping -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}properties:{5 unmodified lines{{- format_parameters(value, value['required'] | default([]), filter_keys=true) -}}}{%- endif -%}{%- if value['required'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}required:[{%- for item in value['required'] | default([]) -%}3 unmodified lines]{%- endif -%}{%- endif -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}type:<|"|>{{ value['type'] | upper }}<|"|>}{%- endif -%}{%- endfor -%}{%- endmacro -%}5 unmodified lines{%- if params['properties'] -%}properties:{ {{- format_parameters(params['properties'], params['required']) -}} },{%- endif -%}{%- if params['required'] -%}required:[{%- for item in params['required'] -%}23 unmodified lines{{- '<|"|>' + argument + '<|"|>' -}}{%- elif argument is boolean -%}{{- 'true' if argument else 'false' -}}{%- elif argument is mapping -%}{{- '{' -}}{%- set ns = namespace(found_first=false) -%}225 unmodified lines{{- '<|channel>thought\n<channel|>' -}}{%- endif -%}{%- endif -%}{%- endif -%}10 unmodified lines11121314151617181920212223242526272829303132333435363738394041424344454647484929 unmodified lines79808182838485868788895 unmodified lines95969798991001013 unmodified lines1051061071081091101111121131141151161171181195 unmodified lines12512612712812913013113213323 unmodified lines157158159160161162163164225 unmodified lines39039139239310 unmodified linesdescription:<|"|>{{ value['description'] }}<|"|>{%- set add_comma = true -%}{%- endif -%}{%- set type_names = namespace(names=[]) -%}{%- if value['type'] is defined and value['type'] -%}{%- if value['type'] is string -%}{%- set type_names.names = [value['type'] | upper] -%}{%- else -%}{%- set type_names.names = value['type'] | map('upper') | list -%}{%- endif -%}{%- endif -%}{%- if value['anyOf'] is defined and value['anyOf'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}anyOf:{{ format_argument(value['anyOf'], escape_keys=false) }}{%- endif -%}{%- if value['oneOf'] is defined and value['oneOf'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}oneOf:{{ format_argument(value['oneOf'], escape_keys=false) }}{%- endif -%}{%- if value['allOf'] is defined and value['allOf'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}allOf:{{ format_argument(value['allOf'], escape_keys=false) }}{%- endif -%}{%- if value['$ref'] is defined and value['$ref'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}$ref:<|"|>{{ value['$ref'] }}<|"|>{%- endif -%}{%- if value['enum'] is defined and value['enum'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}enum:{{ format_argument(value['enum']) }}{%- endif -%}{%- if value['const'] is defined -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}const:{{ format_argument(value['const'], escape_keys=false) }}{%- endif -%}{%- if 'ARRAY' in type_names.names -%}{%- if value['items'] is mapping and value['items'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}items:{29 unmodified lines}{%- endif -%}{%- endif -%}{%- if value['nullable'] is defined and value['nullable'] %}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}nullable:true{%- endif -%}{%- if 'OBJECT' in type_names.names -%}{%- if value['properties'] is defined and value['properties'] is mapping -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}properties:{5 unmodified lines{{- format_parameters(value, value['required'] | default([]), filter_keys=true) -}}}{%- endif -%}{%- if value['required'] is defined and value['required'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}required:[{%- for item in value['required'] | default([]) -%}3 unmodified lines]{%- endif -%}{%- endif -%}{%- if value['type'] is defined and value['type'] -%}{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}{%- if value['type'] is string -%}type:<|"|>{{ value['type'] | upper }}<|"|>{%- else -%}type:{{ format_argument(value['type'] | map('upper') | list) }}{%- endif -%}{%- endif -%}}{%- endif -%}{%- endfor -%}{%- endmacro -%}5 unmodified lines{%- if params['properties'] -%}properties:{ {{- format_parameters(params['properties'], params['required']) -}} },{%- endif -%}{%- if params['$defs'] is defined and params['$defs'] -%}$defs:{{ format_argument(params['$defs'], escape_keys=false) }},{%- endif -%}{%- if params['required'] -%}required:[{%- for item in params['required'] -%}23 unmodified lines{{- '<|"|>' + argument + '<|"|>' -}}{%- elif argument is boolean -%}{{- 'true' if argument else 'false' -}}{%- elif argument is none -%}{{- 'null' -}}{%- elif argument is mapping -%}{{- '{' -}}{%- set ns = namespace(found_first=false) -%}225 unmodified lines{{- '<|channel>thought\n<channel|>' -}}{%- endif -%}{%- endif -%}{%- endif -%}
chat_template.jinja+50-11