Instructions to use trl-internal-testing/tiny-Gemma4ForConditionalGeneration with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use trl-internal-testing/tiny-Gemma4ForConditionalGeneration with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="trl-internal-testing/tiny-Gemma4ForConditionalGeneration") 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("trl-internal-testing/tiny-Gemma4ForConditionalGeneration") model = AutoModelForImageTextToText.from_pretrained("trl-internal-testing/tiny-Gemma4ForConditionalGeneration") 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 trl-internal-testing/tiny-Gemma4ForConditionalGeneration with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "trl-internal-testing/tiny-Gemma4ForConditionalGeneration" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "trl-internal-testing/tiny-Gemma4ForConditionalGeneration", "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/trl-internal-testing/tiny-Gemma4ForConditionalGeneration
- SGLang
How to use trl-internal-testing/tiny-Gemma4ForConditionalGeneration 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 "trl-internal-testing/tiny-Gemma4ForConditionalGeneration" \ --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": "trl-internal-testing/tiny-Gemma4ForConditionalGeneration", "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 "trl-internal-testing/tiny-Gemma4ForConditionalGeneration" \ --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": "trl-internal-testing/tiny-Gemma4ForConditionalGeneration", "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 trl-internal-testing/tiny-Gemma4ForConditionalGeneration with Docker Model Runner:
docker model run hf.co/trl-internal-testing/tiny-Gemma4ForConditionalGeneration
Upload Gemma4ForConditionalGeneration
Browse files- chat_template.jinja +16 -9
- config.json +5 -5
- generation_config.json +1 -1
- model.safetensors +2 -2
- processor_config.json +3 -3
- tokenizer.json +2 -2
- tokenizer_config.json +3 -0
chat_template.jinja
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
-
{%- macro format_parameters(properties, required) -%}
|
| 2 |
{%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
|
| 3 |
{%- set ns = namespace(found_first=false) -%}
|
| 4 |
{%- for key, value in properties | dictsort -%}
|
| 5 |
{%- set add_comma = false -%}
|
| 6 |
-
{%- if key not in standard_keys -%}
|
| 7 |
{%- if ns.found_first %},{% endif -%}
|
| 8 |
{%- set ns.found_first = true -%}
|
| 9 |
{{ key }}:{
|
|
@@ -65,7 +65,7 @@
|
|
| 65 |
{%- elif value is mapping -%}
|
| 66 |
{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
|
| 67 |
properties:{
|
| 68 |
-
{{- format_parameters(value, value['required'] | default([])) -}}
|
| 69 |
}
|
| 70 |
{%- endif -%}
|
| 71 |
{%- if value['required'] -%}
|
|
@@ -178,18 +178,21 @@
|
|
| 178 |
{#- Handle System/Tool Definitions Block -#}
|
| 179 |
{%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
|
| 180 |
{{- '<|turn>system\n' -}}
|
| 181 |
-
|
| 182 |
{#- Inject Thinking token at the very top of the FIRST system turn -#}
|
| 183 |
{%- if enable_thinking is defined and enable_thinking -%}
|
| 184 |
{{- '<|think|>\n' -}}
|
| 185 |
{%- set ns.prev_message_type = 'think' -%}
|
| 186 |
{%- endif -%}
|
| 187 |
-
|
| 188 |
{%- if messages[0]['role'] in ['system', 'developer'] -%}
|
| 189 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
{%- set loop_messages = messages[1:] -%}
|
| 191 |
{%- endif -%}
|
| 192 |
-
|
| 193 |
{%- if tools -%}
|
| 194 |
{%- for tool in tools %}
|
| 195 |
{{- '<|tool>' -}}
|
|
@@ -198,7 +201,6 @@
|
|
| 198 |
{%- endfor %}
|
| 199 |
{%- set ns.prev_message_type = 'tool' -%}
|
| 200 |
{%- endif -%}
|
| 201 |
-
|
| 202 |
{{- '<turn|>\n' -}}
|
| 203 |
{%- endif %}
|
| 204 |
|
|
@@ -302,6 +304,7 @@
|
|
| 302 |
{%- endfor -%}
|
| 303 |
{%- endif -%}
|
| 304 |
|
|
|
|
| 305 |
{%- if message['content'] is string -%}
|
| 306 |
{%- if role == 'model' -%}
|
| 307 |
{{- strip_thinking(message['content']) -}}
|
|
@@ -328,10 +331,14 @@
|
|
| 328 |
{%- endif -%}
|
| 329 |
{%- endfor -%}
|
| 330 |
{%- endif -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
|
| 332 |
{%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
|
| 333 |
{{- '<|tool_response>' -}}
|
| 334 |
-
{%- elif not (ns_tr_out.flag and not
|
| 335 |
{{- '<turn|>\n' -}}
|
| 336 |
{%- endif -%}
|
| 337 |
{%- endif -%}
|
|
|
|
| 1 |
+
{%- macro format_parameters(properties, required, filter_keys=false) -%}
|
| 2 |
{%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
|
| 3 |
{%- set ns = namespace(found_first=false) -%}
|
| 4 |
{%- for key, value in properties | dictsort -%}
|
| 5 |
{%- set add_comma = false -%}
|
| 6 |
+
{%- if not filter_keys or key not in standard_keys -%}
|
| 7 |
{%- if ns.found_first %},{% endif -%}
|
| 8 |
{%- set ns.found_first = true -%}
|
| 9 |
{{ key }}:{
|
|
|
|
| 65 |
{%- elif value is mapping -%}
|
| 66 |
{%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
|
| 67 |
properties:{
|
| 68 |
+
{{- format_parameters(value, value['required'] | default([]), filter_keys=true) -}}
|
| 69 |
}
|
| 70 |
{%- endif -%}
|
| 71 |
{%- if value['required'] -%}
|
|
|
|
| 178 |
{#- Handle System/Tool Definitions Block -#}
|
| 179 |
{%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
|
| 180 |
{{- '<|turn>system\n' -}}
|
|
|
|
| 181 |
{#- Inject Thinking token at the very top of the FIRST system turn -#}
|
| 182 |
{%- if enable_thinking is defined and enable_thinking -%}
|
| 183 |
{{- '<|think|>\n' -}}
|
| 184 |
{%- set ns.prev_message_type = 'think' -%}
|
| 185 |
{%- endif -%}
|
|
|
|
| 186 |
{%- if messages[0]['role'] in ['system', 'developer'] -%}
|
| 187 |
+
{%- if messages[0]['content'] is string -%}
|
| 188 |
+
{{- messages[0]['content'] | trim -}}
|
| 189 |
+
{%- elif messages[0]['content'] is sequence -%}
|
| 190 |
+
{%- for item in messages[0]['content'] -%}
|
| 191 |
+
{{- item['text'] | trim + ' '-}}
|
| 192 |
+
{%- endfor -%}
|
| 193 |
+
{%- endif -%}
|
| 194 |
{%- set loop_messages = messages[1:] -%}
|
| 195 |
{%- endif -%}
|
|
|
|
| 196 |
{%- if tools -%}
|
| 197 |
{%- for tool in tools %}
|
| 198 |
{{- '<|tool>' -}}
|
|
|
|
| 201 |
{%- endfor %}
|
| 202 |
{%- set ns.prev_message_type = 'tool' -%}
|
| 203 |
{%- endif -%}
|
|
|
|
| 204 |
{{- '<turn|>\n' -}}
|
| 205 |
{%- endif %}
|
| 206 |
|
|
|
|
| 304 |
{%- endfor -%}
|
| 305 |
{%- endif -%}
|
| 306 |
|
| 307 |
+
{%- set captured_content -%}
|
| 308 |
{%- if message['content'] is string -%}
|
| 309 |
{%- if role == 'model' -%}
|
| 310 |
{{- strip_thinking(message['content']) -}}
|
|
|
|
| 331 |
{%- endif -%}
|
| 332 |
{%- endfor -%}
|
| 333 |
{%- endif -%}
|
| 334 |
+
{%- endset -%}
|
| 335 |
+
|
| 336 |
+
{{- captured_content -}}
|
| 337 |
+
{%- set has_content = captured_content | trim | length > 0 -%}
|
| 338 |
|
| 339 |
{%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
|
| 340 |
{{- '<|tool_response>' -}}
|
| 341 |
+
{%- elif not (ns_tr_out.flag and not has_content) -%}
|
| 342 |
{{- '<turn|>\n' -}}
|
| 343 |
{%- endif -%}
|
| 344 |
{%- endif -%}
|
config.json
CHANGED
|
@@ -33,7 +33,7 @@
|
|
| 33 |
"hidden_size": 16,
|
| 34 |
"hidden_size_per_layer_input": 16,
|
| 35 |
"initializer_range": 0.02,
|
| 36 |
-
"intermediate_size":
|
| 37 |
"layer_types": [
|
| 38 |
"sliding_attention",
|
| 39 |
"full_attention"
|
|
@@ -70,7 +70,7 @@
|
|
| 70 |
"vocab_size_per_layer_input": 262144
|
| 71 |
},
|
| 72 |
"tie_word_embeddings": true,
|
| 73 |
-
"transformers_version": "5.
|
| 74 |
"video_token_id": 258884,
|
| 75 |
"vision_config": {
|
| 76 |
"_name_or_path": "",
|
|
@@ -78,7 +78,7 @@
|
|
| 78 |
"attention_bias": false,
|
| 79 |
"attention_dropout": 0.0,
|
| 80 |
"chunk_size_feed_forward": 0,
|
| 81 |
-
"default_output_length":
|
| 82 |
"dtype": "bfloat16",
|
| 83 |
"embed_dim": 64,
|
| 84 |
"global_head_dim": 64,
|
|
@@ -90,7 +90,7 @@
|
|
| 90 |
"1": "LABEL_1"
|
| 91 |
},
|
| 92 |
"initializer_range": 0.02,
|
| 93 |
-
"intermediate_size":
|
| 94 |
"is_encoder_decoder": false,
|
| 95 |
"label2id": {
|
| 96 |
"LABEL_0": 0,
|
|
@@ -105,7 +105,7 @@
|
|
| 105 |
"output_hidden_states": false,
|
| 106 |
"patch_size": 16,
|
| 107 |
"pooling_kernel_size": 3,
|
| 108 |
-
"position_embedding_size":
|
| 109 |
"problem_type": null,
|
| 110 |
"return_dict": true,
|
| 111 |
"rms_norm_eps": 1e-06,
|
|
|
|
| 33 |
"hidden_size": 16,
|
| 34 |
"hidden_size_per_layer_input": 16,
|
| 35 |
"initializer_range": 0.02,
|
| 36 |
+
"intermediate_size": 32,
|
| 37 |
"layer_types": [
|
| 38 |
"sliding_attention",
|
| 39 |
"full_attention"
|
|
|
|
| 70 |
"vocab_size_per_layer_input": 262144
|
| 71 |
},
|
| 72 |
"tie_word_embeddings": true,
|
| 73 |
+
"transformers_version": "5.6.0",
|
| 74 |
"video_token_id": 258884,
|
| 75 |
"vision_config": {
|
| 76 |
"_name_or_path": "",
|
|
|
|
| 78 |
"attention_bias": false,
|
| 79 |
"attention_dropout": 0.0,
|
| 80 |
"chunk_size_feed_forward": 0,
|
| 81 |
+
"default_output_length": 70,
|
| 82 |
"dtype": "bfloat16",
|
| 83 |
"embed_dim": 64,
|
| 84 |
"global_head_dim": 64,
|
|
|
|
| 90 |
"1": "LABEL_1"
|
| 91 |
},
|
| 92 |
"initializer_range": 0.02,
|
| 93 |
+
"intermediate_size": 32,
|
| 94 |
"is_encoder_decoder": false,
|
| 95 |
"label2id": {
|
| 96 |
"LABEL_0": 0,
|
|
|
|
| 105 |
"output_hidden_states": false,
|
| 106 |
"patch_size": 16,
|
| 107 |
"pooling_kernel_size": 3,
|
| 108 |
+
"position_embedding_size": 630,
|
| 109 |
"problem_type": null,
|
| 110 |
"return_dict": true,
|
| 111 |
"rms_norm_eps": 1e-06,
|
generation_config.json
CHANGED
|
@@ -10,5 +10,5 @@
|
|
| 10 |
"temperature": 1.0,
|
| 11 |
"top_k": 64,
|
| 12 |
"top_p": 0.95,
|
| 13 |
-
"transformers_version": "5.
|
| 14 |
}
|
|
|
|
| 10 |
"temperature": 1.0,
|
| 11 |
"top_k": 64,
|
| 12 |
"top_p": 0.95,
|
| 13 |
+
"transformers_version": "5.6.0"
|
| 14 |
}
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e867f4cc867e66065215e0e5dfa761b7e715cf3dfcf2c5938da29f395fbe7054
|
| 3 |
+
size 25415228
|
processor_config.json
CHANGED
|
@@ -33,19 +33,19 @@
|
|
| 33 |
0.0
|
| 34 |
],
|
| 35 |
"image_processor_type": "Gemma4ImageProcessor",
|
| 36 |
-
"image_seq_length":
|
| 37 |
"image_std": [
|
| 38 |
1.0,
|
| 39 |
1.0,
|
| 40 |
1.0
|
| 41 |
],
|
| 42 |
-
"max_soft_tokens":
|
| 43 |
"patch_size": 16,
|
| 44 |
"pooling_kernel_size": 3,
|
| 45 |
"resample": 3,
|
| 46 |
"rescale_factor": 0.00392156862745098
|
| 47 |
},
|
| 48 |
-
"image_seq_length":
|
| 49 |
"processor_class": "Gemma4Processor",
|
| 50 |
"video_processor": {
|
| 51 |
"do_convert_rgb": true,
|
|
|
|
| 33 |
0.0
|
| 34 |
],
|
| 35 |
"image_processor_type": "Gemma4ImageProcessor",
|
| 36 |
+
"image_seq_length": 70,
|
| 37 |
"image_std": [
|
| 38 |
1.0,
|
| 39 |
1.0,
|
| 40 |
1.0
|
| 41 |
],
|
| 42 |
+
"max_soft_tokens": 70,
|
| 43 |
"patch_size": 16,
|
| 44 |
"pooling_kernel_size": 3,
|
| 45 |
"resample": 3,
|
| 46 |
"rescale_factor": 0.00392156862745098
|
| 47 |
},
|
| 48 |
+
"image_seq_length": 70,
|
| 49 |
"processor_class": "Gemma4Processor",
|
| 50 |
"video_processor": {
|
| 51 |
"do_convert_rgb": true,
|
tokenizer.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a2619fe11b50dbed06ac443c51d757b354d0b62d64baa514404d4e84e6713519
|
| 3 |
+
size 32169780
|
tokenizer_config.json
CHANGED
|
@@ -16,9 +16,12 @@
|
|
| 16 |
"extra_special_tokens": [
|
| 17 |
"<|video|>"
|
| 18 |
],
|
|
|
|
| 19 |
"image_token": "<|image|>",
|
| 20 |
"is_local": false,
|
|
|
|
| 21 |
"mask_token": "<mask>",
|
|
|
|
| 22 |
"model_max_length": 1000000000000000019884624838656,
|
| 23 |
"model_specific_special_tokens": {
|
| 24 |
"audio_token": "<|audio|>",
|
|
|
|
| 16 |
"extra_special_tokens": [
|
| 17 |
"<|video|>"
|
| 18 |
],
|
| 19 |
+
"image_seq_length": 70,
|
| 20 |
"image_token": "<|image|>",
|
| 21 |
"is_local": false,
|
| 22 |
+
"local_files_only": false,
|
| 23 |
"mask_token": "<mask>",
|
| 24 |
+
"max_soft_tokens": 70,
|
| 25 |
"model_max_length": 1000000000000000019884624838656,
|
| 26 |
"model_specific_special_tokens": {
|
| 27 |
"audio_token": "<|audio|>",
|