Instructions to use StationPC/Gemma4-E4B-RKNN3-RK1828 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use StationPC/Gemma4-E4B-RKNN3-RK1828 with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf StationPC/Gemma4-E4B-RKNN3-RK1828 # Run inference directly in the terminal: llama cli -hf StationPC/Gemma4-E4B-RKNN3-RK1828
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf StationPC/Gemma4-E4B-RKNN3-RK1828 # Run inference directly in the terminal: llama cli -hf StationPC/Gemma4-E4B-RKNN3-RK1828
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf StationPC/Gemma4-E4B-RKNN3-RK1828 # Run inference directly in the terminal: ./llama-cli -hf StationPC/Gemma4-E4B-RKNN3-RK1828
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf StationPC/Gemma4-E4B-RKNN3-RK1828 # Run inference directly in the terminal: ./build/bin/llama-cli -hf StationPC/Gemma4-E4B-RKNN3-RK1828
Use Docker
docker model run hf.co/StationPC/Gemma4-E4B-RKNN3-RK1828
- LM Studio
- Jan
- Ollama
How to use StationPC/Gemma4-E4B-RKNN3-RK1828 with Ollama:
ollama run hf.co/StationPC/Gemma4-E4B-RKNN3-RK1828
- Unsloth Desktop
- Pi
How to use StationPC/Gemma4-E4B-RKNN3-RK1828 with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf StationPC/Gemma4-E4B-RKNN3-RK1828
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "StationPC/Gemma4-E4B-RKNN3-RK1828" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use StationPC/Gemma4-E4B-RKNN3-RK1828 with Docker Model Runner:
docker model run hf.co/StationPC/Gemma4-E4B-RKNN3-RK1828
- Lemonade
How to use StationPC/Gemma4-E4B-RKNN3-RK1828 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull StationPC/Gemma4-E4B-RKNN3-RK1828
Run and chat with the model
lemonade run user.Gemma4-E4B-RKNN3-RK1828-{{QUANT_TAG}}List all available models
lemonade list
- Hermes Agent
How to use StationPC/Gemma4-E4B-RKNN3-RK1828 with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf StationPC/Gemma4-E4B-RKNN3-RK1828
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default StationPC/Gemma4-E4B-RKNN3-RK1828
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use StationPC/Gemma4-E4B-RKNN3-RK1828 with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf StationPC/Gemma4-E4B-RKNN3-RK1828
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "StationPC/Gemma4-E4B-RKNN3-RK1828" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Update Gemma4-E4B RKNN model files
Browse files- .gitattributes +34 -13
- llm_gemma-4-e4b-it.rknn → audio_gemma-4-e4b-it.rknn +2 -2
- audio_gemma-4-e4b-it.weight +3 -0
- chat_template.jinja +66 -40
- llm_gemma-4-e4b-it.safetensors → gemma-4-e4b-it.safetensors +1 -1
- gemma-4-e4b-it.tokenizer.gguf +2 -2
- llm_gemma-4-e4b-it-16384.rknn +3 -0
- llm_gemma-4-e4b-it.weight → llm_gemma-4-e4b-it-16384.weight +1 -1
- model.toml +2 -0
- tokenizer_config.json +46 -0
- vision_gemma-4-e4b-it-384.rknn +3 -0
- vision_gemma-4-e4b-it-384.weight +3 -0
.gitattributes
CHANGED
|
@@ -1,39 +1,60 @@
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 11 |
*.model filter=lfs diff=lfs merge=lfs -text
|
| 12 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
| 13 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 14 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 15 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 16 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
| 17 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 18 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 19 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 20 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 21 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 22 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 23 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 24 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.db* filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.ark* filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*.gguf* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.ggml filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.llamafile* filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.pt2 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 46 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 47 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
"/tokenizer.json" filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
"/vision_gemma-4-e4b-it-384.rknn" filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
"/audio_gemma-4-e4b-it.rknn" filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
"/llm_gemma-4-e4b-it-16384.rknn" filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
"/vision_gemma-4-e4b-it-384.weight" filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
"/audio_gemma-4-e4b-it.weight" filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
"/llm_gemma-4-e4b-it-16384.weight" filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
audio_gemma-4-e4b-it.rknn filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
audio_gemma-4-e4b-it.weight filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
llm_gemma-4-e4b-it-16384.rknn filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
llm_gemma-4-e4b-it-16384.weight filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
vision_gemma-4-e4b-it-384.rknn filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
vision_gemma-4-e4b-it-384.weight filter=lfs diff=lfs merge=lfs -text
|
llm_gemma-4-e4b-it.rknn → audio_gemma-4-e4b-it.rknn
RENAMED
|
@@ -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:680cfc353c2913311df897aa7ec0acb77e8ea20cd719ca414e4ce0a3fda1ca2f
|
| 3 |
+
size 10740816
|
audio_gemma-4-e4b-it.weight
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a81d880f372939d360b86e6b06af77c5fa8bf81894e1688bd600cba1880966c9
|
| 3 |
+
size 629950976
|
chat_template.jinja
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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) -%}
|
|
@@ -116,7 +122,9 @@
|
|
| 116 |
}
|
| 117 |
{%- endmacro -%}
|
| 118 |
{%- macro format_argument(argument, escape_keys=True) -%}
|
| 119 |
-
{%- if argument is
|
|
|
|
|
|
|
| 120 |
{{- '<|"|>' + argument + '<|"|>' -}}
|
| 121 |
{%- elif argument is boolean -%}
|
| 122 |
{{- 'true' if argument else 'false' -}}
|
|
@@ -172,18 +180,21 @@
|
|
| 172 |
{{- '<tool_response|>' -}}
|
| 173 |
{%- endmacro -%}
|
| 174 |
|
| 175 |
-
{
|
|
|
|
| 176 |
{%- set loop_messages = messages -%}
|
|
|
|
|
|
|
| 177 |
{{- bos_token -}}
|
| 178 |
{#- Handle System/Tool Definitions Block -#}
|
| 179 |
-
{%- if
|
| 180 |
{{- '<|turn>system\n' -}}
|
| 181 |
{#- Inject Thinking token at the very top of the FIRST system turn -#}
|
| 182 |
-
{%- if 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 -%}
|
|
@@ -217,31 +228,21 @@
|
|
| 217 |
{%- if message['role'] != 'tool' -%}
|
| 218 |
{%- set ns.prev_message_type = None -%}
|
| 219 |
{%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
|
| 220 |
-
{#- Detect continuation
|
| 221 |
-
{%- set
|
| 222 |
-
{%- if loop.index0 > 0 -%}
|
| 223 |
-
{%- for j in range(loop.index0 - 1, -1, -1) -%}
|
| 224 |
-
{%- if not prev_nt.found -%}
|
| 225 |
-
{%- if loop_messages[j]['role'] != 'tool' -%}
|
| 226 |
-
{%- set prev_nt.role = loop_messages[j]['role'] -%}
|
| 227 |
-
{%- set prev_nt.found = true -%}
|
| 228 |
-
{%- endif -%}
|
| 229 |
-
{%- endif -%}
|
| 230 |
-
{%- endfor -%}
|
| 231 |
-
{%- endif -%}
|
| 232 |
-
{%- set continue_same_model_turn = (role == 'model' and prev_nt.role == 'assistant') -%}
|
| 233 |
{%- if not continue_same_model_turn -%}
|
| 234 |
{{- '<|turn>' + role + '\n' }}
|
| 235 |
{%- endif -%}
|
| 236 |
|
| 237 |
{#- Render reasoning/reasoning_content as thinking channel -#}
|
| 238 |
{%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
|
| 239 |
-
{%-
|
|
|
|
| 240 |
{{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
|
| 241 |
{%- endif -%}
|
| 242 |
|
| 243 |
-
{%- if message
|
| 244 |
-
{%- for tool_call in message
|
| 245 |
{%- set function = tool_call['function'] -%}
|
| 246 |
{{- '<|tool_call>call:' + function['name'] + '{' -}}
|
| 247 |
{%- if function['arguments'] is mapping -%}
|
|
@@ -251,8 +252,13 @@
|
|
| 251 |
{%- set ns_args.found_first = true -%}
|
| 252 |
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
| 253 |
{%- endfor -%}
|
| 254 |
-
{%- elif function['arguments'] is
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
{%- endif -%}
|
| 257 |
{{- '}<tool_call|>' -}}
|
| 258 |
{%- endfor -%}
|
|
@@ -262,8 +268,8 @@
|
|
| 262 |
{%- set ns_tr_out = namespace(flag=false) -%}
|
| 263 |
{%- if message.get('tool_responses') -%}
|
| 264 |
{#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
|
| 265 |
-
{%- for tool_response in message
|
| 266 |
-
{{- format_tool_response_block(tool_response['name'] | default('unknown'), tool_response['response']) -}}
|
| 267 |
{%- set ns_tr_out.flag = true -%}
|
| 268 |
{%- set ns.prev_message_type = 'tool_response' -%}
|
| 269 |
{%- endfor -%}
|
|
@@ -277,8 +283,8 @@
|
|
| 277 |
{%- else -%}
|
| 278 |
{%- set follow = loop_messages[k] -%}
|
| 279 |
{#- Resolve tool_call_id to function name -#}
|
| 280 |
-
{%- set ns_tname = namespace(name=follow.get('name')
|
| 281 |
-
{%- for tc in message
|
| 282 |
{%- if tc.get('id') == follow.get('tool_call_id') -%}
|
| 283 |
{%- set ns_tname.name = tc['function']['name'] -%}
|
| 284 |
{%- endif -%}
|
|
@@ -296,9 +302,9 @@
|
|
| 296 |
{%- endfor -%}
|
| 297 |
{{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
|
| 298 |
{%- for part in tool_body -%}
|
| 299 |
-
{%- if part.get('type')
|
| 300 |
{{- '<|image|>' -}}
|
| 301 |
-
{%- elif part.get('type')
|
| 302 |
{{- '<|audio|>' -}}
|
| 303 |
{%- elif part.get('type') == 'video' -%}
|
| 304 |
{{- '<|video|>' -}}
|
|
@@ -314,29 +320,26 @@
|
|
| 314 |
{%- endif -%}
|
| 315 |
|
| 316 |
{%- set captured_content -%}
|
| 317 |
-
{%- if message
|
| 318 |
{%- if role == 'model' -%}
|
| 319 |
{{- strip_thinking(message['content']) -}}
|
| 320 |
{%- else -%}
|
| 321 |
{{- message['content'] | trim -}}
|
| 322 |
{%- endif -%}
|
| 323 |
-
{%- elif message
|
| 324 |
{%- for item in message['content'] -%}
|
| 325 |
-
{%- if item
|
| 326 |
{%- if role == 'model' -%}
|
| 327 |
{{- strip_thinking(item['text']) -}}
|
| 328 |
{%- else -%}
|
| 329 |
{{- item['text'] | trim -}}
|
| 330 |
{%- endif -%}
|
| 331 |
-
{%- elif item
|
| 332 |
{{- '<|image|>' -}}
|
| 333 |
-
|
| 334 |
-
{%- elif item['type'] == 'audio' -%}
|
| 335 |
{{- '<|audio|>' -}}
|
| 336 |
-
|
| 337 |
-
{%- elif item['type'] == 'video' -%}
|
| 338 |
{{- '<|video|>' -}}
|
| 339 |
-
{%- set ns.prev_message_type = 'video' -%}
|
| 340 |
{%- endif -%}
|
| 341 |
{%- endfor -%}
|
| 342 |
{%- endif -%}
|
|
@@ -345,16 +348,39 @@
|
|
| 345 |
{{- captured_content -}}
|
| 346 |
{%- set has_content = captured_content | trim | length > 0 -%}
|
| 347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
{%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
|
| 349 |
{{- '<|tool_response>' -}}
|
| 350 |
-
{%- elif
|
|
|
|
| 351 |
{{- '<turn|>\n' -}}
|
| 352 |
{%- endif -%}
|
|
|
|
|
|
|
|
|
|
| 353 |
{%- endif -%}
|
| 354 |
{%- endfor -%}
|
| 355 |
|
| 356 |
{%- if add_generation_prompt -%}
|
| 357 |
{%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
|
| 358 |
{{- '<|turn>model\n' -}}
|
|
|
|
|
|
|
| 359 |
{%- endif -%}
|
| 360 |
-
{%- endif -%}
|
|
|
|
| 1 |
+
{#
|
| 2 |
+
Template: Google Gemma 4 Canonical Chat Template
|
| 3 |
+
Author: Google Gemma Engineering Team
|
| 4 |
+
Published: 2026-07-09
|
| 5 |
+
Context: Fixed tool-calling loops, turn closures, and thinking content-ordering.
|
| 6 |
+
#}
|
| 7 |
{%- macro format_parameters(properties, required, filter_keys=false) -%}
|
| 8 |
{%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
|
| 9 |
{%- set ns = namespace(found_first=false) -%}
|
|
|
|
| 122 |
}
|
| 123 |
{%- endmacro -%}
|
| 124 |
{%- macro format_argument(argument, escape_keys=True) -%}
|
| 125 |
+
{%- if argument is none -%}
|
| 126 |
+
{{- 'null' -}}
|
| 127 |
+
{%- elif argument is string -%}
|
| 128 |
{{- '<|"|>' + argument + '<|"|>' -}}
|
| 129 |
{%- elif argument is boolean -%}
|
| 130 |
{{- 'true' if argument else 'false' -}}
|
|
|
|
| 180 |
{{- '<tool_response|>' -}}
|
| 181 |
{%- endmacro -%}
|
| 182 |
|
| 183 |
+
{#- ===== SETUP ===== -#}
|
| 184 |
+
{%- set ns = namespace(prev_message_type=None, prev_non_tool_role=None) -%}
|
| 185 |
{%- set loop_messages = messages -%}
|
| 186 |
+
{%- set enable_thinking = enable_thinking | default(false) -%}
|
| 187 |
+
{%- set preserve_thinking = preserve_thinking | default(false) -%}
|
| 188 |
{{- bos_token -}}
|
| 189 |
{#- Handle System/Tool Definitions Block -#}
|
| 190 |
+
{%- if enable_thinking or tools or (messages and messages[0]['role'] in ['system', 'developer']) -%}
|
| 191 |
{{- '<|turn>system\n' -}}
|
| 192 |
{#- Inject Thinking token at the very top of the FIRST system turn -#}
|
| 193 |
+
{%- if enable_thinking -%}
|
| 194 |
{{- '<|think|>\n' -}}
|
| 195 |
{%- set ns.prev_message_type = 'think' -%}
|
| 196 |
{%- endif -%}
|
| 197 |
+
{%- if messages and messages[0]['role'] in ['system', 'developer'] -%}
|
| 198 |
{%- if messages[0]['content'] is string -%}
|
| 199 |
{{- messages[0]['content'] | trim -}}
|
| 200 |
{%- elif messages[0]['content'] is sequence -%}
|
|
|
|
| 228 |
{%- if message['role'] != 'tool' -%}
|
| 229 |
{%- set ns.prev_message_type = None -%}
|
| 230 |
{%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
|
| 231 |
+
{#- Detect continuation using tracked state — O(1) instead of O(n) backward scan -#}
|
| 232 |
+
{%- set continue_same_model_turn = (role == 'model' and ns.prev_non_tool_role == 'assistant') -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
{%- if not continue_same_model_turn -%}
|
| 234 |
{{- '<|turn>' + role + '\n' }}
|
| 235 |
{%- endif -%}
|
| 236 |
|
| 237 |
{#- Render reasoning/reasoning_content as thinking channel -#}
|
| 238 |
{%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
|
| 239 |
+
{%- set thinking_gate = (loop.index0 > ns_turn.last_user_idx) or (preserve_thinking and message.get('tool_calls')) -%}
|
| 240 |
+
{%- if thinking_text and thinking_gate -%}
|
| 241 |
{{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
|
| 242 |
{%- endif -%}
|
| 243 |
|
| 244 |
+
{%- if message.get('tool_calls') -%}
|
| 245 |
+
{%- for tool_call in message.get('tool_calls') -%}
|
| 246 |
{%- set function = tool_call['function'] -%}
|
| 247 |
{{- '<|tool_call>call:' + function['name'] + '{' -}}
|
| 248 |
{%- if function['arguments'] is mapping -%}
|
|
|
|
| 252 |
{%- set ns_args.found_first = true -%}
|
| 253 |
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
| 254 |
{%- endfor -%}
|
| 255 |
+
{%- elif function['arguments'] is none -%}
|
| 256 |
+
{%- else -%}
|
| 257 |
+
{{- raise_exception(
|
| 258 |
+
"chat_template: tool_calls[].function.arguments must be a "
|
| 259 |
+
"JSON object (mapping), not a string. Deserialize arguments "
|
| 260 |
+
"before passing to the template."
|
| 261 |
+
) -}}
|
| 262 |
{%- endif -%}
|
| 263 |
{{- '}<tool_call|>' -}}
|
| 264 |
{%- endfor -%}
|
|
|
|
| 268 |
{%- set ns_tr_out = namespace(flag=false) -%}
|
| 269 |
{%- if message.get('tool_responses') -%}
|
| 270 |
{#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
|
| 271 |
+
{%- for tool_response in message.get('tool_responses') -%}
|
| 272 |
+
{{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}
|
| 273 |
{%- set ns_tr_out.flag = true -%}
|
| 274 |
{%- set ns.prev_message_type = 'tool_response' -%}
|
| 275 |
{%- endfor -%}
|
|
|
|
| 283 |
{%- else -%}
|
| 284 |
{%- set follow = loop_messages[k] -%}
|
| 285 |
{#- Resolve tool_call_id to function name -#}
|
| 286 |
+
{%- set ns_tname = namespace(name=follow.get('name') or 'unknown') -%}
|
| 287 |
+
{%- for tc in message.get('tool_calls') -%}
|
| 288 |
{%- if tc.get('id') == follow.get('tool_call_id') -%}
|
| 289 |
{%- set ns_tname.name = tc['function']['name'] -%}
|
| 290 |
{%- endif -%}
|
|
|
|
| 302 |
{%- endfor -%}
|
| 303 |
{{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
|
| 304 |
{%- for part in tool_body -%}
|
| 305 |
+
{%- if part.get('type') in ['image', 'image_url'] -%}
|
| 306 |
{{- '<|image|>' -}}
|
| 307 |
+
{%- elif part.get('type') in ['audio', 'input_audio'] -%}
|
| 308 |
{{- '<|audio|>' -}}
|
| 309 |
{%- elif part.get('type') == 'video' -%}
|
| 310 |
{{- '<|video|>' -}}
|
|
|
|
| 320 |
{%- endif -%}
|
| 321 |
|
| 322 |
{%- set captured_content -%}
|
| 323 |
+
{%- if message.get('content') is string -%}
|
| 324 |
{%- if role == 'model' -%}
|
| 325 |
{{- strip_thinking(message['content']) -}}
|
| 326 |
{%- else -%}
|
| 327 |
{{- message['content'] | trim -}}
|
| 328 |
{%- endif -%}
|
| 329 |
+
{%- elif message.get('content') is sequence -%}
|
| 330 |
{%- for item in message['content'] -%}
|
| 331 |
+
{%- if item.get('type') == 'text' -%}
|
| 332 |
{%- if role == 'model' -%}
|
| 333 |
{{- strip_thinking(item['text']) -}}
|
| 334 |
{%- else -%}
|
| 335 |
{{- item['text'] | trim -}}
|
| 336 |
{%- endif -%}
|
| 337 |
+
{%- elif item.get('type') in ['image', 'image_url'] -%}
|
| 338 |
{{- '<|image|>' -}}
|
| 339 |
+
{%- elif item.get('type') in ['audio', 'input_audio'] -%}
|
|
|
|
| 340 |
{{- '<|audio|>' -}}
|
| 341 |
+
{%- elif item.get('type') == 'video' -%}
|
|
|
|
| 342 |
{{- '<|video|>' -}}
|
|
|
|
| 343 |
{%- endif -%}
|
| 344 |
{%- endfor -%}
|
| 345 |
{%- endif -%}
|
|
|
|
| 348 |
{{- captured_content -}}
|
| 349 |
{%- set has_content = captured_content | trim | length > 0 -%}
|
| 350 |
|
| 351 |
+
{#- Forward-scan: find next non-tool message role for continuation detection -#}
|
| 352 |
+
{%- set next_nt = namespace(role=None, found=false) -%}
|
| 353 |
+
{%- for j in range(loop.index0 + 1, loop_messages | length) -%}
|
| 354 |
+
{%- if not next_nt.found -%}
|
| 355 |
+
{%- if loop_messages[j]['role'] != 'tool' -%}
|
| 356 |
+
{%- set next_nt.role = loop_messages[j]['role'] -%}
|
| 357 |
+
{%- set next_nt.found = true -%}
|
| 358 |
+
{%- endif -%}
|
| 359 |
+
{%- endif -%}
|
| 360 |
+
{%- endfor -%}
|
| 361 |
+
|
| 362 |
+
{%- set continues_into_next = (
|
| 363 |
+
role == 'model'
|
| 364 |
+
and next_nt.role == 'assistant'
|
| 365 |
+
and (not message.get('tool_calls') or ns_tr_out.flag)
|
| 366 |
+
) -%}
|
| 367 |
+
|
| 368 |
{%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
|
| 369 |
{{- '<|tool_response>' -}}
|
| 370 |
+
{%- elif continues_into_next -%}
|
| 371 |
+
{%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
|
| 372 |
{{- '<turn|>\n' -}}
|
| 373 |
{%- endif -%}
|
| 374 |
+
|
| 375 |
+
{#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
|
| 376 |
+
{%- set ns.prev_non_tool_role = message['role'] -%}
|
| 377 |
{%- endif -%}
|
| 378 |
{%- endfor -%}
|
| 379 |
|
| 380 |
{%- if add_generation_prompt -%}
|
| 381 |
{%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
|
| 382 |
{{- '<|turn>model\n' -}}
|
| 383 |
+
{%- elif ns.prev_message_type == 'tool_response' and enable_thinking -%}
|
| 384 |
+
{{- '<|channel>thought\n' -}}
|
| 385 |
{%- endif -%}
|
| 386 |
+
{%- endif -%}
|
llm_gemma-4-e4b-it.safetensors → gemma-4-e4b-it.safetensors
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 50332472
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ccc82ba892b55f577f760b5884a87e465a1958c19953d22b5e3fc0419cc01b6
|
| 3 |
size 50332472
|
gemma-4-e4b-it.tokenizer.gguf
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:b904ad542977e245604619ad7a3a4eacb4e3601242c1cc5fd016de211fb9937e
|
| 3 |
+
size 15782599
|
llm_gemma-4-e4b-it-16384.rknn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:edc057b9de842df7ce0f0ecb16763e1dec2b38a16b688f106c4519030b46d192
|
| 3 |
+
size 31688928
|
llm_gemma-4-e4b-it.weight → llm_gemma-4-e4b-it-16384.weight
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 3000512512
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:07343510be651d8c4d271241e771c5f2e4ab9729c1554eed3bf96dcf9944d64d
|
| 3 |
size 3000512512
|
model.toml
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
[model]
|
| 2 |
platform = "rknn3"
|
| 3 |
kind = "chat"
|
|
|
|
|
|
|
| 4 |
tool_call_parser_class = "gemma4"
|
| 5 |
|
| 6 |
[model.default_params]
|
|
|
|
| 1 |
[model]
|
| 2 |
platform = "rknn3"
|
| 3 |
kind = "chat"
|
| 4 |
+
chip_type = "rk1828"
|
| 5 |
+
quantized_dtype = "w4a16"
|
| 6 |
tool_call_parser_class = "gemma4"
|
| 7 |
|
| 8 |
[model.default_params]
|
tokenizer_config.json
CHANGED
|
@@ -63,6 +63,52 @@
|
|
| 63 |
},
|
| 64 |
"x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
|
| 65 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
"soc_token": "<|channel>",
|
| 67 |
"sot_token": "<|turn>",
|
| 68 |
"stc_token": "<|tool_call>",
|
|
|
|
| 63 |
},
|
| 64 |
"x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
|
| 65 |
},
|
| 66 |
+
"response_template": {
|
| 67 |
+
"defaults": {
|
| 68 |
+
"role": "assistant"
|
| 69 |
+
},
|
| 70 |
+
"fields": {
|
| 71 |
+
"content": {
|
| 72 |
+
"close": [
|
| 73 |
+
"<turn|>",
|
| 74 |
+
"<|tool_response>",
|
| 75 |
+
"<eos>"
|
| 76 |
+
],
|
| 77 |
+
"content": "text"
|
| 78 |
+
},
|
| 79 |
+
"thinking": {
|
| 80 |
+
"close": "<channel|>",
|
| 81 |
+
"content": "text",
|
| 82 |
+
"open": "<|channel>thought\n"
|
| 83 |
+
},
|
| 84 |
+
"tool_calls": {
|
| 85 |
+
"close": "<tool_call|>",
|
| 86 |
+
"content": "json",
|
| 87 |
+
"content_args": {
|
| 88 |
+
"string_delims": [
|
| 89 |
+
[
|
| 90 |
+
"<|\"|>",
|
| 91 |
+
"<|\"|>"
|
| 92 |
+
]
|
| 93 |
+
],
|
| 94 |
+
"unquoted_keys": true
|
| 95 |
+
},
|
| 96 |
+
"open_pattern": "<\\|tool_call>call:(?P<name>\\w+)",
|
| 97 |
+
"repeats": true,
|
| 98 |
+
"transform": {
|
| 99 |
+
"function": {
|
| 100 |
+
"arguments": "{content}",
|
| 101 |
+
"name": "{name}"
|
| 102 |
+
},
|
| 103 |
+
"type": "function"
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
},
|
| 107 |
+
"start_anchor": [
|
| 108 |
+
"<|turn>model\n",
|
| 109 |
+
"<tool_response|>"
|
| 110 |
+
]
|
| 111 |
+
},
|
| 112 |
"soc_token": "<|channel>",
|
| 113 |
"sot_token": "<|turn>",
|
| 114 |
"stc_token": "<|tool_call>",
|
vision_gemma-4-e4b-it-384.rknn
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:27d33de5f1a8b3f80191bf6005217cd449f5c1488909e8763ec5ae8910356439
|
| 3 |
+
size 5072816
|
vision_gemma-4-e4b-it-384.weight
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a42f7c6f47209374728553dbea05f3249a414f3d7f6b54eda172b8cab765264
|
| 3 |
+
size 91917312
|