Instructions to use google/gemma-4-31B-it-qat-q4_0-unquantized-assistant with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-4-31B-it-qat-q4_0-unquantized-assistant 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-qat-q4_0-unquantized-assistant") 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 AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("google/gemma-4-31B-it-qat-q4_0-unquantized-assistant") model = AutoModelForCausalLM.from_pretrained("google/gemma-4-31B-it-qat-q4_0-unquantized-assistant", 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 = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use google/gemma-4-31B-it-qat-q4_0-unquantized-assistant 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-qat-q4_0-unquantized-assistant" # 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-qat-q4_0-unquantized-assistant", "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-qat-q4_0-unquantized-assistant
- SGLang
How to use google/gemma-4-31B-it-qat-q4_0-unquantized-assistant 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-qat-q4_0-unquantized-assistant" \ --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-qat-q4_0-unquantized-assistant", "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-qat-q4_0-unquantized-assistant" \ --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-qat-q4_0-unquantized-assistant", "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-qat-q4_0-unquantized-assistant with Docker Model Runner:
docker model run hf.co/google/gemma-4-31B-it-qat-q4_0-unquantized-assistant
Commit ·
96d4c8c
1
Parent(s): cd038d0
Add response_template to tokenizer_config.json (#6)
Browse files- Add response_template to tokenizer_config.json (ff54284cd034b8a59f9939bd6bbb2ad00fc42719)
- Update README.md (5520cf733af1b4d958b048dabe9be4b7beb03f3c)
Co-authored-by: Matthew Carrigan <Rocketknight1@users.noreply.huggingface.co>
- README.md +4 -4
- tokenizer_config.json +46 -0
README.md
CHANGED
|
@@ -181,7 +181,7 @@ outputs = model.generate(**inputs, max_new_tokens=1024)
|
|
| 181 |
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
|
| 182 |
|
| 183 |
# Parse output
|
| 184 |
-
processor.parse_response(response)
|
| 185 |
```
|
| 186 |
|
| 187 |
To enable reasoning, set `enable_thinking=True` and the `parse_response` function will take care of parsing the thinking output.
|
|
@@ -241,7 +241,7 @@ outputs = model.generate(**inputs, max_new_tokens=512)
|
|
| 241 |
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
|
| 242 |
|
| 243 |
# Parse output
|
| 244 |
-
processor.parse_response(response)
|
| 245 |
```
|
| 246 |
|
| 247 |
</details>
|
|
@@ -299,7 +299,7 @@ outputs = model.generate(**inputs, max_new_tokens=512)
|
|
| 299 |
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
|
| 300 |
|
| 301 |
# Parse output
|
| 302 |
-
processor.parse_response(response)
|
| 303 |
```
|
| 304 |
|
| 305 |
</details>
|
|
@@ -358,7 +358,7 @@ outputs = model.generate(**inputs, max_new_tokens=512)
|
|
| 358 |
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
|
| 359 |
|
| 360 |
# Parse output
|
| 361 |
-
processor.parse_response(response)
|
| 362 |
```
|
| 363 |
|
| 364 |
</details>
|
|
|
|
| 181 |
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
|
| 182 |
|
| 183 |
# Parse output
|
| 184 |
+
processor.parse_response(response, prefix=inputs["input_ids"])
|
| 185 |
```
|
| 186 |
|
| 187 |
To enable reasoning, set `enable_thinking=True` and the `parse_response` function will take care of parsing the thinking output.
|
|
|
|
| 241 |
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
|
| 242 |
|
| 243 |
# Parse output
|
| 244 |
+
processor.parse_response(response, prefix=inputs["input_ids"])
|
| 245 |
```
|
| 246 |
|
| 247 |
</details>
|
|
|
|
| 299 |
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
|
| 300 |
|
| 301 |
# Parse output
|
| 302 |
+
processor.parse_response(response, prefix=inputs["input_ids"])
|
| 303 |
```
|
| 304 |
|
| 305 |
</details>
|
|
|
|
| 358 |
response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
|
| 359 |
|
| 360 |
# Parse output
|
| 361 |
+
processor.parse_response(response, prefix=inputs["input_ids"])
|
| 362 |
```
|
| 363 |
|
| 364 |
</details>
|
tokenizer_config.json
CHANGED
|
@@ -60,6 +60,52 @@
|
|
| 60 |
"type": "object",
|
| 61 |
"x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
|
| 62 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
"soc_token": "<|channel>",
|
| 64 |
"sot_token": "<|turn>",
|
| 65 |
"stc_token": "<|tool_call>",
|
|
|
|
| 60 |
"type": "object",
|
| 61 |
"x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
|
| 62 |
},
|
| 63 |
+
"response_template": {
|
| 64 |
+
"defaults": {
|
| 65 |
+
"role": "assistant"
|
| 66 |
+
},
|
| 67 |
+
"fields": {
|
| 68 |
+
"content": {
|
| 69 |
+
"close": [
|
| 70 |
+
"<turn|>",
|
| 71 |
+
"<|tool_response>",
|
| 72 |
+
"<eos>"
|
| 73 |
+
],
|
| 74 |
+
"content": "text"
|
| 75 |
+
},
|
| 76 |
+
"thinking": {
|
| 77 |
+
"close": "<channel|>",
|
| 78 |
+
"content": "text",
|
| 79 |
+
"open": "<|channel>thought\n"
|
| 80 |
+
},
|
| 81 |
+
"tool_calls": {
|
| 82 |
+
"close": "<tool_call|>",
|
| 83 |
+
"content": "json",
|
| 84 |
+
"content_args": {
|
| 85 |
+
"string_delims": [
|
| 86 |
+
[
|
| 87 |
+
"<|\"|>",
|
| 88 |
+
"<|\"|>"
|
| 89 |
+
]
|
| 90 |
+
],
|
| 91 |
+
"unquoted_keys": true
|
| 92 |
+
},
|
| 93 |
+
"open_pattern": "<\\|tool_call>call:(?P<name>\\w+)",
|
| 94 |
+
"repeats": true,
|
| 95 |
+
"transform": {
|
| 96 |
+
"function": {
|
| 97 |
+
"arguments": "{content}",
|
| 98 |
+
"name": "{name}"
|
| 99 |
+
},
|
| 100 |
+
"type": "function"
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
},
|
| 104 |
+
"start_anchor": [
|
| 105 |
+
"<|turn>model\n",
|
| 106 |
+
"<tool_response|>"
|
| 107 |
+
]
|
| 108 |
+
},
|
| 109 |
"soc_token": "<|channel>",
|
| 110 |
"sot_token": "<|turn>",
|
| 111 |
"stc_token": "<|tool_call>",
|