Gemma 4 E2B-it (text only) for the Snapdragon 8 Gen 1 NPU — ExecuTorch + QNN
gemma-4-e2b-it-text-sm8450-npu-ctx4096.pte is
google/gemma-4-E2B-it compiled for the Hexagon
NPU of the Snapdragon 8 Gen 1 (SM8450, Hexagon v69) with ExecuTorch's Qualcomm AI Engine Direct
(QNN) backend. All 35 decoder layers and the lm_head run on the NPU. It was built for and measured
on a Samsung Galaxy S22 Ultra (SM-S908E).
Text only. The vision and audio towers are not included.
Thinking mode works: the model reasons in its <|channel>thought … <channel|> block and then
answers.
This file is compiled for one chip family. It will not run on other SoCs (the QNN context binaries inside target Hexagon v69), and it needs the patched runner in
runner/. Read "Limitations" before you spend 3 GB of download on it.
The easy way to run it: AutoDroid Studio
AutoDroid Studio is the Android app this model was built for and measured in. It
runs this .pte on the NPU of a Snapdragon 8 Gen 1 phone, exactly as published here. "Running it"
below is for people who want to drive it by hand.
Why use it:
- Nothing to set up. No runner to build, no
adb, no environment variables. The app sets up the Qualcomm runtime itself and finds and downloads models from Hugging Face in its own browser. - Chat on the phone, with the model's reasoning shown when you want it, and a benchmark to compare models and backends on your own hardware.
- A model server for your other devices. An OpenAI-compatible HTTP API, a web dashboard and an MCP endpoint on your local network, so existing tools, scripts and agents on your computer can use the phone as their model backend. A spare phone on a charger works well for this.
- Automation. A visual workflow builder with 70+ task types (AI steps, HTTP, RSS, PDF, OCR, SQLite, JavaScript), run on a schedule, from a webhook or as a Telegram or Discord bot.
- Your own documents. On-device embeddings, so the chat model can answer from your files.
- Private. No ads, no analytics, no account. Models run on the phone, and your data leaves it only when you send it somewhere yourself.
Get AutoDroid Studio on Google Play
At a glance
| Base model | google/gemma-4-E2B-it (text decoder only) |
| File | gemma-4-e2b-it-text-sm8450-npu-ctx4096.pte, 2.92 GB |
| SHA-256 | b7d430b531b821da8f28c32e462269b7ed490f8a10110f0c99d74c12d88e91a9 |
| Target | SM8450 / Snapdragon 8 Gen 1, Hexagon v69 HTP |
| On the NPU | all 35 decoder layers + lm_head, as QNN contexts |
| On the CPU | the two embedding lookups: token table (262144 × 1536) and the per-layer-embedding table (262144 × 8960, 2.3 B of the model's parameters), both 4-bit in groups of 32 |
| Context | 4096 tokens, shared by prompt and answer |
| Mode | KV ("kv"): one graph, one token per call, prompt included |
| Weights | linear layers 4-bit LPBQ (block 64) |
| Activations | 16-bit |
| KV cache | 8-bit (Hexagon v69 rejects a 16-bit second matmul input) |
| Exporter | ExecuTorch v1.5.1 static llama (examples/qualcomm/oss_scripts/llama, --decoder_model gemma4-e2b), with patches |
| QNN SDK | QAIRT 2.39.0 (compile time and run time) |
| Calibration | 4 thinking-mode conversations written by the float model itself, teacher-forced |
Measured on the phone (Galaxy S22 Ultra)
| Runner from a shell | Inside an Android app (backgrounded) | |
|---|---|---|
| Load | 2.3–2.6 s | ~8.7 s |
| Prompt processing | 9.1–10.1 tok/s | first token ~3.5 s on a follow-up turn |
| Generation | 9.0–9.8 tok/s | ~7 tok/s streamed |
Prompt processing runs at generation speed because the graph takes one token per call (see "Why KV mode only").
Quality
Single-turn evaluation, greedy, 9 prompts (a fact, letter counting, arithmetic, logic, code, a
two-turn memory test, Japanese, a no-thinking prompt): 8 of 9 clean. It answered Canberra,
18 pencils = $2.40, Carol, a correct is_prime function, remembered a cat's name and age across
turns, answered in Japanese (東京です。) and greeted in French with thinking off. Reasoning stays
in English, closes with <channel|> and leaks no template tokens.
Multi-turn evaluation through an Android app, temperature 0.7, thinking on, 6 conversations, 22 turns (facts carried across five turns, follow-ups on a previous answer, thinking toggled mid-chat, regenerate and edit, a stop followed by new questions, a new chat): 19 of 22 turns passed once the client handled the quirks below.
Known failures
- "How many r's are in strawberry?" never finishes thinking. It re-spells the word over and over until the budget runs out, greedy and sampled. The float model does not do this.
- Reasoning loops on easy questions, now and then. At temperature 0.7 the quantized model sometimes talks itself into "Wait, re-reading the prompt…" and repeats it. Seen on "Luna is 3 and Rex is 5 years older. How old is Rex?" and on "What is 17 × 23?", in both cases after it had already worked out the right answer. About 1 turn in 7 in the first multi-turn run. A client should detect the loop, stop, and close the thought channel (see "Client tips").
- Thinking off loses a reference to the previous answer. History "What is 17 * 23?" → "$17 \times 23 = 391$ …" → "Add 9 to that." gets "What number are you referring to?" from this file, greedy and sampled, every time. The float model answers 400 every time. With thinking on, the same chat is answered correctly (391 → 400 → 50).
- The thinking text is Gemma's own "Thinking Process: 1. Analyze the Request: …" outline, usually 500–2000 characters even for one-line answers.
Files
| File | What it is |
|---|---|
gemma-4-e2b-it-text-sm8450-npu-ctx4096.pte |
the model |
tokenizer.json, tokenizer_config.json |
the tokenizer of the base model |
special_tokens_map.json |
BOS <bos> and EOS `<turn |
chat_template.jinja |
the base model's chat template, for reference |
runner/qnn_llama_runner |
ExecuTorch v1.5.1 qnn_llama_runner for Android arm64, patched (see below) |
runner/libqnn_executorch_backend.so |
the QNN backend it links against |
runner/patch_runner.py |
the patch, so you can rebuild the runner yourself |
Not included: the Qualcomm runtime libraries. You need these from QAIRT 2.39.0
(lib/aarch64-android/ and lib/hexagon-v69/unsigned/): libQnnHtp.so, libQnnSystem.so,
libQnnHtpV69Stub.so, libQnnHtpV69Skel.so. They are Qualcomm's to distribute. A newer QAIRT
(2.48 was tried with a sibling model) made the DSP restart mid-generation; stay on 2.39.
Running it
Push everything into one folder on the phone (the tokenizer files into a tok/ subfolder), then:
cd /data/local/tmp/gemma4
export LD_LIBRARY_PATH=$PWD ADSP_LIBRARY_PATH=$PWD
./qnn_llama_runner \
--decoder_model_version gemma4 --raw_prompt \
--tokenizer_path tok \
--model_path gemma-4-e2b-it-text-sm8450-npu-ctx4096.pte \
--eval_mode 0 --seq_len 4096 --temperature 0 \
--prompt "$P"
$P is the fully rendered conversation, <bos> included:
<bos><|turn>system
<|think|>
<turn|>
<|turn>user
How many days are in a leap year?<turn|>
<|turn>model
Without thinking, drop the system turn (or leave <|think|> out of it):
<bos><|turn>user
Say hello in French.<turn|>
<|turn>model
The model's reply looks like <|channel>thought\n…reasoning…<channel|>The answer.<turn|>.
What matters here:
--decoder_model_version gemma4is required. It selects the shared-KV (YOCO) cache layout this model uses. An ExecuTorch v1.0.x runner cannot load the file at all.--raw_promptis required for thinking. The runner's built-in Gemma 4 template has no thinking switch, so the client renders the template and the runner passes it through.--raw_promptis added by the patch; the stock runner does not have it.- Write
<bos>yourself. In gemma4 mode the runner adds no BOS token (its own template carries it as text). Measured: 28 prompt tokens without it, 29 with. Results are worse without. --eval_mode 0: this is a KV-only export.- Tokenizer folder. Pass the folder, not
tokenizer.json. Given a folder, the runner reads BOS/EOS fromspecial_tokens_map.json; given a file, it guesses them from token names. - Temperature is a process flag. Changing it means restarting the runner.
Serve mode (what the patch adds)
The stock runner is one-shot and prints nothing until it finishes. The patched one streams, and
with --serve stays resident so the model loads once and the KV cache carries over between turns:
client -> runner GEN <nbytes>\n + nbytes of UTF-8 generate from this text
FEED <nbytes>\n + nbytes put text in the KV, no reply
REWIND <pos>\n forget the KV from token pos on
STOP\n (during a GEN) end it early
RESET\n new conversation
QUIT\n
runner -> client \x01READY stop rewind feed\n once, after loading
<echo of the prompt, then tokens> streamed
\x1eEND <chars> <secs> <pos>\n end of a GEN; pos = tokens in the KV
\x1eFED <tokens> <pos>\n
\x1eOK <pos>\n / \x1eOK\n
\x1eERR <why>\n
The runner stops on <turn|> without feeding it back, so a follow-up GEN must begin with
<turn|>\n to close the previous answer, unless you re-fed the answer yourself.
Measured on the phone: STOP ends a generation in about 0.1 s; after REWIND to where a reply
began and FEED of a replacement, the next turn answers from the replacement.
Client tips (these made multi-turn work)
- Drop the reasoning from history. Gemma 4's own chat template strips thought channels from
earlier turns. With a persistent KV cache that means: after a turn,
REWINDto where the reply began andFEEDthe answer plus<turn|>\n. A five-turn chat then holds ~110 tokens instead of over a thousand, and old reasoning cannot leak into later turns. - Catch reasoning loops. When the thought text repeats (the same sentence three times
running), send
STOP,REWINDto a little before the loop began, andGENthe text\n<channel|>. The model then answers from the reasoning it had. If the reasoning ran past ~1000 tokens before looping, rewind to the reply's start andGEN<|channel>thought\n<channel|>instead, so it answers without it. - After a stop, trim the turn to what the user saw (same
REWIND+FEED), so no unclosed thought stays in the cache.
With those three, a test run that had 3 empty answers and 4 runner restarts in 22 turns had none.
How it was built
Exported on a PC with 32 GB of RAM under WSL, 57 minutes, with ExecuTorch v1.5.1's static LLM flow and these changes, all needed for Hexagon v69:
- 8-bit KV cache. v69 does not accept a 16-bit second matmul input, so the K and V tensors are annotated 8-bit (the upstream recipe assumes v73+).
- LPBQ 4-bit weights (block 64) with 16-bit activations. v69 does support LPBQ; a plain 16a8w recipe is not needed and makes the file much larger.
- Embeddings on the CPU, 4-bit in groups of 32. Gemma 4 E2B's per-layer-embedding table alone is 2.3 B parameters. Quantizing it needed chunking to fit the PC's memory.
- Calibration on the model's own thinking-mode conversations, so the activation ranges cover the thought channel as well as answers.
Why KV mode only
QNN weight sharing between a prefill graph and a decode graph needs Hexagon v73 or newer. On v69 a hybrid file holds two full copies of the weights, and one process on this phone's cDSP can map only about 1.85 GB. So the file has a single one-token-per-call graph, and prompts are processed at generation speed.
Limitations
- Snapdragon 8 Gen 1 only. Other chips need their own export.
- It needs most of the phone's free memory. Loading maps the 2.9 GB file and copies it to the DSP, and an S22 Ultra has under 6 GB available to begin with. Close heavy apps first.
- 10 tok/s for prompts too. A 1000-token prompt takes over a minute and a half. Keep the KV cache between turns (serve mode) rather than re-sending history.
- Quantization costs quality in the ways listed under "Known failures". If you need the float model's reliability, this is not it.
- Text only; no tools or function calling were tested.
- The runner binaries are built from ExecuTorch (BSD-licensed) with the included patch and are provided as a convenience, with no warranty.
Licence and credits
The model weights derive from google/gemma-4-E2B-it and are under the same licence (Apache 2.0; see the Gemma 4 licence page linked above). Compiled with ExecuTorch and Qualcomm AI Engine Direct. This is an unofficial community build, not affiliated with Google, Meta or Qualcomm.