ONNX Runtime GenAI build (int4 weights, fp16 activations, DirectML execution provider) of the text component of google/gemma-3-4b-it.
Built for local, fully offline rewriting of dictated text (punctuation, filler-word removal, tone softening) in Celerando (Menterium IT Solutions GmbH); usable with any onnxruntime-genai client on DirectX-12-capable GPUs, within the 1024-token limit described below.
On DirectML, keep prompt + generated tokens ≤ 1024.
The DirectML kernel of GroupQueryAttention in ONNX Runtime does not apply the
local_window_size attribute (checked in v1.24.4, v1.31.0 and main). Gemma 3 uses a
1024-token sliding window in its local attention layers, 29 of the 34 layers of this
model. Beyond position 1024 these layers attend to tokens outside their window, and
the model falls into repetition loops or ends its answer early and silently drops
text. In an isolated operator test with 1026 tokens and a window of 1024, the CPU
kernel ignores a value outside the window (output 0.0), the DirectML kernel does not
(output 0.998).
What a client should do on DirectML:
max_length to at most 1024,The CPU execution provider applies the window correctly; the limit does not exist there. Other Gemma 3 based ONNX builds running on DirectML are affected in the same way.
Gemma3ForCausalLM, model type gemma3_text); the vision tower is not included.-p int4 -e dml, round-to-nearest int4 for all MatMuls including lm_head;
the embedding table stays fp16).full_attention) layers with theta 1e6 and linear scaling factor 8, local
sliding-window layers with theta 1e4 and no scaling. Model builder 0.15.2 applies
the factor 8 to the local layers as well, and the resulting model stops after
0–1 tokens. This build creates both caches with the values from config.json
(global factor 8, local factor 1) and was verified against them.genai_config.json ships with eos_token_id: [1, 106] so that
<end_of_turn> terminates generation (the stock config only stopped on <eos>),
and with do_sample: false, top_k: 1 (greedy decoding).Gemma requires the <bos> token at the start of the prompt — without it the
output degenerates. The tokenizer of onnxruntime-genai does not add it
automatically. Gemma has no system role; put instructions into the first user turn:
<bos><start_of_turn>user
Add punctuation to the text between <text> and </text>. Return only the text.
<text>can you send me the project tomorrow that would be great</text><end_of_turn>
<start_of_turn>model
All model files in this repository are modified versions of the files published in
google/gemma-3-4b-it: the text decoder
was extracted, converted to ONNX, quantized to int4 and given explicitly computed
rotary embedding caches; genai_config.json was adjusted as described above.
Gemma is provided under and subject to the Gemma Terms of Use found at
ai.google.dev/gemma/terms (see also NOTICE).
A copy of the Gemma Terms of Use and the Gemma Prohibited Use Policy is included as
GEMMA_TERMS_OF_USE.txt.
Use of this model is subject to the use restrictions of the
Gemma Prohibited Use Policy,
which apply to every downstream user and to every further redistribution.
This repository redistributes a quantized derivative of Gemma 3; all
rights in the underlying model remain with Google.
Have the files? Publish a torrent.
Publish a torrentHave the complete files and permission to share them? Replace the example folder path. The script checks the files, makes a torrent and submits its magnet and checksums. Keep your torrent client seeding. Get your community key from your settings, and read the script before running it.
curl -fsSL https://pirateface.co/package.sh | bash -s -- --repo Menterium/gemma-3-4b-it-onnx-int4-dml ./model-foldergoogle/gemma-3-4b-it