Instructions to use tiny-random/gemma-4-dense with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/gemma-4-dense with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/gemma-4-dense") 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, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("tiny-random/gemma-4-dense") model = AutoModelForImageTextToText.from_pretrained("tiny-random/gemma-4-dense") 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
- vLLM
How to use tiny-random/gemma-4-dense with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/gemma-4-dense" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/gemma-4-dense", "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/tiny-random/gemma-4-dense
- SGLang
How to use tiny-random/gemma-4-dense 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 "tiny-random/gemma-4-dense" \ --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": "tiny-random/gemma-4-dense", "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 "tiny-random/gemma-4-dense" \ --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": "tiny-random/gemma-4-dense", "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 tiny-random/gemma-4-dense with Docker Model Runner:
docker model run hf.co/tiny-random/gemma-4-dense
Upload folder using huggingface_hub
Browse files- .meta.json +2 -2
- README.md +3 -3
- chat_template.jinja +9 -0
- config.json +1 -1
- generation_config.json +1 -1
.meta.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"torch": "2.
|
| 3 |
-
"transformers": "5.
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"torch": "2.10.0+cu130",
|
| 3 |
+
"transformers": "5.9.0"
|
| 4 |
}
|
README.md
CHANGED
|
@@ -28,7 +28,7 @@ messages = [
|
|
| 28 |
"content": [
|
| 29 |
{
|
| 30 |
"type": "image",
|
| 31 |
-
"url": "https://
|
| 32 |
},
|
| 33 |
{"type": "text", "text": "What is shown in this image?"},
|
| 34 |
],
|
|
@@ -318,5 +318,5 @@ Gemma4ForConditionalGeneration(
|
|
| 318 |
|
| 319 |
### Test environment:
|
| 320 |
|
| 321 |
-
- torch: 2.
|
| 322 |
-
- transformers: 5.
|
|
|
|
| 28 |
"content": [
|
| 29 |
{
|
| 30 |
"type": "image",
|
| 31 |
+
"url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG",
|
| 32 |
},
|
| 33 |
{"type": "text", "text": "What is shown in this image?"},
|
| 34 |
],
|
|
|
|
| 318 |
|
| 319 |
### Test environment:
|
| 320 |
|
| 321 |
+
- torch: 2.10.0+cu130
|
| 322 |
+
- transformers: 5.9.0
|
chat_template.jinja
CHANGED
|
@@ -295,6 +295,15 @@
|
|
| 295 |
{%- endif -%}
|
| 296 |
{%- endfor -%}
|
| 297 |
{{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
{%- else -%}
|
| 299 |
{{- format_tool_response_block(ns_tname.name, tool_body) -}}
|
| 300 |
{%- endif -%}
|
|
|
|
| 295 |
{%- endif -%}
|
| 296 |
{%- endfor -%}
|
| 297 |
{{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
|
| 298 |
+
{%- for part in tool_body -%}
|
| 299 |
+
{%- if part.get('type') == 'image' -%}
|
| 300 |
+
{{- '<|image|>' -}}
|
| 301 |
+
{%- elif part.get('type') == 'audio' -%}
|
| 302 |
+
{{- '<|audio|>' -}}
|
| 303 |
+
{%- elif part.get('type') == 'video' -%}
|
| 304 |
+
{{- '<|video|>' -}}
|
| 305 |
+
{%- endif -%}
|
| 306 |
+
{%- endfor -%}
|
| 307 |
{%- else -%}
|
| 308 |
{{- format_tool_response_block(ns_tname.name, tool_body) -}}
|
| 309 |
{%- endif -%}
|
config.json
CHANGED
|
@@ -72,7 +72,7 @@
|
|
| 72 |
"vocab_size_per_layer_input": 262144
|
| 73 |
},
|
| 74 |
"tie_word_embeddings": true,
|
| 75 |
-
"transformers_version": "5.
|
| 76 |
"video_token_id": 258884,
|
| 77 |
"vision_config": {
|
| 78 |
"_name_or_path": "",
|
|
|
|
| 72 |
"vocab_size_per_layer_input": 262144
|
| 73 |
},
|
| 74 |
"tie_word_embeddings": true,
|
| 75 |
+
"transformers_version": "5.9.0",
|
| 76 |
"video_token_id": 258884,
|
| 77 |
"vision_config": {
|
| 78 |
"_name_or_path": "",
|
generation_config.json
CHANGED
|
@@ -10,6 +10,6 @@
|
|
| 10 |
"temperature": 1.0,
|
| 11 |
"top_k": 64,
|
| 12 |
"top_p": 0.95,
|
| 13 |
-
"transformers_version": "5.
|
| 14 |
"trust_remote_code": true
|
| 15 |
}
|
|
|
|
| 10 |
"temperature": 1.0,
|
| 11 |
"top_k": 64,
|
| 12 |
"top_p": 0.95,
|
| 13 |
+
"transformers_version": "5.9.0",
|
| 14 |
"trust_remote_code": true
|
| 15 |
}
|