Instructions to use google/diffusiongemma-26B-A4B-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/diffusiongemma-26B-A4B-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/diffusiongemma-26B-A4B-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/diffusiongemma-26B-A4B-it") model = AutoModelForMultimodalLM.from_pretrained("google/diffusiongemma-26B-A4B-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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use google/diffusiongemma-26B-A4B-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/diffusiongemma-26B-A4B-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/diffusiongemma-26B-A4B-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/diffusiongemma-26B-A4B-it
- SGLang
How to use google/diffusiongemma-26B-A4B-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/diffusiongemma-26B-A4B-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/diffusiongemma-26B-A4B-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/diffusiongemma-26B-A4B-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/diffusiongemma-26B-A4B-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/diffusiongemma-26B-A4B-it with Docker Model Runner:
docker model run hf.co/google/diffusiongemma-26B-A4B-it
Add {% generation %} markers so SFT frameworks can extract the assistant mask
#26
by CristianoLin - opened
- chat_template.jinja +9 -2
chat_template.jinja
CHANGED
|
@@ -346,7 +346,6 @@
|
|
| 346 |
{%- endif -%}
|
| 347 |
{%- endset -%}
|
| 348 |
|
| 349 |
-
{{- captured_content -}}
|
| 350 |
{%- set has_content = captured_content | trim | length > 0 -%}
|
| 351 |
|
| 352 |
{#- Forward-scan: find next non-tool message role for continuation detection -#}
|
|
@@ -365,13 +364,21 @@
|
|
| 365 |
and next_nt.role == 'assistant'
|
| 366 |
and (not message.get('tool_calls') or ns_tr_out.flag)
|
| 367 |
) -%}
|
| 368 |
-
|
|
|
|
| 369 |
{%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
|
| 370 |
{{- '<|tool_response>' -}}
|
| 371 |
{%- elif continues_into_next -%}
|
| 372 |
{%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
|
| 373 |
{{- '<turn|>\n' -}}
|
| 374 |
{%- endif -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
{%- endif -%}
|
| 376 |
|
| 377 |
{#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
|
|
|
|
| 346 |
{%- endif -%}
|
| 347 |
{%- endset -%}
|
| 348 |
|
|
|
|
| 349 |
{%- set has_content = captured_content | trim | length > 0 -%}
|
| 350 |
|
| 351 |
{#- Forward-scan: find next non-tool message role for continuation detection -#}
|
|
|
|
| 364 |
and next_nt.role == 'assistant'
|
| 365 |
and (not message.get('tool_calls') or ns_tr_out.flag)
|
| 366 |
) -%}
|
| 367 |
+
|
| 368 |
+
{%- set captured_close -%}
|
| 369 |
{%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
|
| 370 |
{{- '<|tool_response>' -}}
|
| 371 |
{%- elif continues_into_next -%}
|
| 372 |
{%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
|
| 373 |
{{- '<turn|>\n' -}}
|
| 374 |
{%- endif -%}
|
| 375 |
+
{%- endset -%}
|
| 376 |
+
|
| 377 |
+
{%- if role == 'model' -%}
|
| 378 |
+
{% generation %}{{- captured_content -}}{{- captured_close -}}{% endgeneration %}
|
| 379 |
+
{%- else -%}
|
| 380 |
+
{{- captured_content -}}{{- captured_close -}}
|
| 381 |
+
{%- endif -%}
|
| 382 |
{%- endif -%}
|
| 383 |
|
| 384 |
{#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
|