Text Generation
Transformers
Safetensors
gemma4
image-text-to-text
gemma
gemma-4
coder
mixture-of-experts
mxfp4
thinking
tool-use
long-context
conversational
8-bit precision
Instructions to use LLMWildling/gemma-4-180b-a42b-coder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LLMWildling/gemma-4-180b-a42b-coder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="LLMWildling/gemma-4-180b-a42b-coder") 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, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("LLMWildling/gemma-4-180b-a42b-coder") model = AutoModelForMultimodalLM.from_pretrained("LLMWildling/gemma-4-180b-a42b-coder") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use LLMWildling/gemma-4-180b-a42b-coder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LLMWildling/gemma-4-180b-a42b-coder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LLMWildling/gemma-4-180b-a42b-coder", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/LLMWildling/gemma-4-180b-a42b-coder
- SGLang
How to use LLMWildling/gemma-4-180b-a42b-coder 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 "LLMWildling/gemma-4-180b-a42b-coder" \ --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": "LLMWildling/gemma-4-180b-a42b-coder", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "LLMWildling/gemma-4-180b-a42b-coder" \ --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": "LLMWildling/gemma-4-180b-a42b-coder", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use LLMWildling/gemma-4-180b-a42b-coder with Docker Model Runner:
docker model run hf.co/LLMWildling/gemma-4-180b-a42b-coder
Update Gemma4 chat template
Browse files- chat_template.jinja +48 -8
chat_template.jinja
CHANGED
|
@@ -172,11 +172,17 @@
|
|
| 172 |
{{- argument -}}
|
| 173 |
{%- endif -%}
|
| 174 |
{%- endmacro -%}
|
| 175 |
-
{%- macro
|
| 176 |
-
{%- set
|
|
|
|
| 177 |
{%- for part in text.split('<channel|>') -%}
|
| 178 |
{%- if '<|channel>' in part -%}
|
| 179 |
-
{%- set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
{%- else -%}
|
| 181 |
{%- set ns.result = ns.result + part -%}
|
| 182 |
{%- endif -%}
|
|
@@ -216,7 +222,16 @@
|
|
| 216 |
{%- endif -%}
|
| 217 |
|
| 218 |
{%- if messages[0]['role'] in ['system', 'developer'] -%}
|
| 219 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
{%- set loop_messages = messages[1:] -%}
|
| 221 |
{%- endif -%}
|
| 222 |
|
|
@@ -232,18 +247,43 @@
|
|
| 232 |
{{- '<turn|>\n' -}}
|
| 233 |
{%- endif %}
|
| 234 |
|
| 235 |
-
{#- Pre-scan: find last user
|
| 236 |
-
{%- set ns_turn = namespace(last_user_idx=-1) -%}
|
| 237 |
{%- for i in range(loop_messages | length) -%}
|
| 238 |
{%- if loop_messages[i]['role'] == 'user' -%}
|
| 239 |
{%- set ns_turn.last_user_idx = i -%}
|
| 240 |
{%- endif -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
{%- endfor -%}
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
{#- Loop through messages -#}
|
| 244 |
{%- for message in loop_messages -%}
|
| 245 |
{%- if message['role'] != 'tool' -%}
|
| 246 |
{%- set ns.prev_message_type = None -%}
|
|
|
|
| 247 |
{%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
|
| 248 |
{#- Detect continuation: suppress duplicate <|turn>model when previous non-tool message was also assistant -#}
|
| 249 |
{%- set prev_nt = namespace(role=None, found=false) -%}
|
|
@@ -328,7 +368,7 @@
|
|
| 328 |
|
| 329 |
{%- if message['content'] is string -%}
|
| 330 |
{%- if role == 'model' -%}
|
| 331 |
-
{{-
|
| 332 |
{%- else -%}
|
| 333 |
{{- message['content'] | trim -}}
|
| 334 |
{%- endif -%}
|
|
@@ -336,7 +376,7 @@
|
|
| 336 |
{%- for item in message['content'] -%}
|
| 337 |
{%- if item['type'] == 'text' -%}
|
| 338 |
{%- if role == 'model' -%}
|
| 339 |
-
{{-
|
| 340 |
{%- else -%}
|
| 341 |
{{- item['text'] | trim -}}
|
| 342 |
{%- endif -%}
|
|
|
|
| 172 |
{{- argument -}}
|
| 173 |
{%- endif -%}
|
| 174 |
{%- endmacro -%}
|
| 175 |
+
{%- macro render_assistant_text(text, keep_reasoning=false) -%}
|
| 176 |
+
{%- set total_blocks = (text.split('<channel|>') | length) - 1 -%}
|
| 177 |
+
{%- set ns = namespace(result='', seen=0) -%}
|
| 178 |
{%- for part in text.split('<channel|>') -%}
|
| 179 |
{%- if '<|channel>' in part -%}
|
| 180 |
+
{%- set pieces = part.split('<|channel>') -%}
|
| 181 |
+
{%- set ns.result = ns.result + pieces[0] -%}
|
| 182 |
+
{%- set ns.seen = ns.seen + 1 -%}
|
| 183 |
+
{%- if keep_reasoning and ns.seen == total_blocks -%}
|
| 184 |
+
{%- set ns.result = ns.result + '<|channel>' + pieces[1] + '<channel|>' -%}
|
| 185 |
+
{%- endif -%}
|
| 186 |
{%- else -%}
|
| 187 |
{%- set ns.result = ns.result + part -%}
|
| 188 |
{%- endif -%}
|
|
|
|
| 222 |
{%- endif -%}
|
| 223 |
|
| 224 |
{%- if messages[0]['role'] in ['system', 'developer'] -%}
|
| 225 |
+
{%- set system_content = messages[0]['content'] -%}
|
| 226 |
+
{%- if system_content is string -%}
|
| 227 |
+
{{- system_content | trim -}}
|
| 228 |
+
{%- elif system_content is sequence -%}
|
| 229 |
+
{%- for item in system_content -%}
|
| 230 |
+
{%- if item['type'] == 'text' -%}
|
| 231 |
+
{{- item['text'] | trim -}}
|
| 232 |
+
{%- endif -%}
|
| 233 |
+
{%- endfor -%}
|
| 234 |
+
{%- endif -%}
|
| 235 |
{%- set loop_messages = messages[1:] -%}
|
| 236 |
{%- endif -%}
|
| 237 |
|
|
|
|
| 247 |
{{- '<turn|>\n' -}}
|
| 248 |
{%- endif %}
|
| 249 |
|
| 250 |
+
{#- Pre-scan: find last user and last tagged reasoning block. -#}
|
| 251 |
+
{%- set ns_turn = namespace(last_user_idx=-1, last_reasoning_idx=-1, reasoning_blocks=0) -%}
|
| 252 |
{%- for i in range(loop_messages | length) -%}
|
| 253 |
{%- if loop_messages[i]['role'] == 'user' -%}
|
| 254 |
{%- set ns_turn.last_user_idx = i -%}
|
| 255 |
{%- endif -%}
|
| 256 |
+
{%- if loop_messages[i]['role'] == 'assistant' -%}
|
| 257 |
+
{%- set msg_content = loop_messages[i]['content'] -%}
|
| 258 |
+
{%- if msg_content is string -%}
|
| 259 |
+
{%- set block_count = (msg_content.split('<channel|>') | length) - 1 -%}
|
| 260 |
+
{%- if block_count > 0 and '<|channel>' in msg_content -%}
|
| 261 |
+
{%- set ns_turn.reasoning_blocks = ns_turn.reasoning_blocks + block_count -%}
|
| 262 |
+
{%- set ns_turn.last_reasoning_idx = i -%}
|
| 263 |
+
{%- endif -%}
|
| 264 |
+
{%- elif msg_content is sequence -%}
|
| 265 |
+
{%- for item in msg_content -%}
|
| 266 |
+
{%- if item['type'] == 'text' -%}
|
| 267 |
+
{%- set item_text = item['text'] | default('') -%}
|
| 268 |
+
{%- set block_count = (item_text.split('<channel|>') | length) - 1 -%}
|
| 269 |
+
{%- if block_count > 0 and '<|channel>' in item_text -%}
|
| 270 |
+
{%- set ns_turn.reasoning_blocks = ns_turn.reasoning_blocks + block_count -%}
|
| 271 |
+
{%- set ns_turn.last_reasoning_idx = i -%}
|
| 272 |
+
{%- endif -%}
|
| 273 |
+
{%- endif -%}
|
| 274 |
+
{%- endfor -%}
|
| 275 |
+
{%- endif -%}
|
| 276 |
+
{%- endif -%}
|
| 277 |
{%- endfor -%}
|
| 278 |
+
{%- if keep_last_reasoning is not defined -%}
|
| 279 |
+
{%- set keep_last_reasoning = false -%}
|
| 280 |
+
{%- endif -%}
|
| 281 |
|
| 282 |
{#- Loop through messages -#}
|
| 283 |
{%- for message in loop_messages -%}
|
| 284 |
{%- if message['role'] != 'tool' -%}
|
| 285 |
{%- set ns.prev_message_type = None -%}
|
| 286 |
+
{%- set message_idx = loop.index0 -%}
|
| 287 |
{%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
|
| 288 |
{#- Detect continuation: suppress duplicate <|turn>model when previous non-tool message was also assistant -#}
|
| 289 |
{%- set prev_nt = namespace(role=None, found=false) -%}
|
|
|
|
| 368 |
|
| 369 |
{%- if message['content'] is string -%}
|
| 370 |
{%- if role == 'model' -%}
|
| 371 |
+
{{- render_assistant_text(message['content'], keep_last_reasoning and message_idx == ns_turn.last_reasoning_idx) -}}
|
| 372 |
{%- else -%}
|
| 373 |
{{- message['content'] | trim -}}
|
| 374 |
{%- endif -%}
|
|
|
|
| 376 |
{%- for item in message['content'] -%}
|
| 377 |
{%- if item['type'] == 'text' -%}
|
| 378 |
{%- if role == 'model' -%}
|
| 379 |
+
{{- render_assistant_text(item['text'], keep_last_reasoning and message_idx == ns_turn.last_reasoning_idx) -}}
|
| 380 |
{%- else -%}
|
| 381 |
{{- item['text'] | trim -}}
|
| 382 |
{%- endif -%}
|