请求加入做种队列,或现在用 pf download assassinshadow/Gemma-4-E4B-it-text-SM8450-LiteRT-LM-NPU 获取(CLI 指南)。
Google's quantization-aware-trained Gemma 4 E4B (litert-community/gemma-4-E4B-it-litert-lm, the bundle LiteRT-LM runs on a GPU), compiled for the Hexagon NPU of the Snapdragon 8 Gen 1 (SM8450, Hexagon v69). All 42 decoder layers and the lm_head run on the NPU.
| File | Context | Decode | Prompt speed | Size |
|---|---|---|---|---|
gemma4-e4b-qat_sm8450.litertlm |
4096 | 9–11 tok/s | ~390 tok/s | 5.39 GB |
gemma4-e4b-qat-ctx16384_sm8450.litertlm |
16384 | ~6.4 tok/s | ~360 tok/s | 5.39 GB |
gemma4-e4b-qat-ctx32768_sm8450.litertlm |
32768 | 5.5 tok/s; 8–14 tok/s with its drafter | ~190 tok/s | 5.58 GB |
gemma4-e4b-qat-ctx32768-c22-mtp-multimodal_sm8450.litertlm (text + image + audio) |
32768 | same NPU sections as the 32K file above | same | 5.92 GB |
gemma4-e4b-qat-ctx32768-c22-mtp_sm8350.litertlm (Snapdragon 888) |
32768 | 5.0 tok/s; 7–10 tok/s with its drafter | ~105 tok/s | 5.59 GB |
Measured on a Samsung Galaxy S22 Ultra (SM-S908E), LiteRT-LM CLI, big cores; the SM8350 file on a
Galaxy S21 Ultra (SM-G998U1). Every file is text only except the -multimodal one, which also
reads images and audio: see "The multimodal 32K file". Its speeds were not measured separately.
Where to use it: AutoDroid Studio on Google Play, an Android app that runs these bundles on the phone's NPU and serves them through an OpenAI-style endpoint, with the dispatch library and worker below already inside. To run them from a shell instead, see "Running it".
Which one? The smallest window the job needs: a longer window costs speed at any conversation length (see "Longer contexts").
The 32K file was replaced on 2026-10-10 by a faster build of the same model: its two decode
contexts are cut one layer earlier, and it carries Google's drafter for speculative decoding
(see "The 32K bundle"). It needs the dispatch library of the same date from runtime/.
The 4K and 16K files are unchanged.
This bundle does not load with a stock LiteRT. The E4B is 2.36 GB of weights on the NPU and one process on this chip can map about 1.85 GB of the DSP, so the bundle's three QNN contexts have to live in three processes. The dispatch library in
runtime/does that; with the stock one the second context fails withFailed to create QNN context: 1002. See "Running it".
Google's weights, not a re-quantization. The mobile E4B is quantization-aware trained: every linear layer has 2-, 4- or 8-bit weights between int8 activation grids, and those weights are not a rounding of google/gemma-4-E4B-it. This bundle carries Google's integer weight codes, scales and int8 grids exactly (344 linears: the lm_head 2-bit, 258 at 4 bits, 85 at 8 bits), with Google's embedding tables and SentencePiece tokenizer. The glue between the linears (norms, attention, residuals) is 16-bit, calibrated on 12 prompts; K/V caches are 8-bit at Google's scales.
Three QNN contexts, one process each:
| Context | Layers | Size | Process |
|---|---|---|---|
| decode, part 1 | 0–23 (every layer that writes K/V) | 1,144 MB | the client itself |
| decode, part 2 | 24–41 and the lm_head | 1,133 MB | worker 1 |
| prefill, 32 tokens per call | 0–23 | 1,095 MB | worker 2 |
The cut after layer 23 is the model's own seam: layers 24–41 produce no K/V and read only the caches of layers 22 and 23, and a prompt token needs nothing past layer 23. The sliding-window layers keep 512-slot ring buffers. (That is the 4K and 16K files; the 32K file is cut after layer 22, below.)
At 32K the cut after layer 23 turned out to be the wrong place. Layer 23 is a global layer, and layers 29, 35 and 41 attend over its K/V cache: with the cut after 23, the first context sliced that cache per head and handed the slices on, 67 MB written out of the DSP by one process and read back in by the next, on every token. Cut after layer 22, layer 23 and everything that reads its cache sit in one context and nothing cache-sized crosses: 5.0–5.1 → 6.1–6.6 tok/s on the plain bundle, same answers.
The file also carries what LiteRT-LM's speculative decoding needs: Google's MTP drafter (the
tf_lite_mtp_drafter section of their E4B bundle, converted to this bundle's cache layout; it
runs on the CPU and reads the last 2,048 slots of layer 23's cache) and a verify graph that
takes the last accepted token and three drafted ones in one NPU call. A four-token call costs the
NPU what a one-token call does, so decode runs on verify's QNN contexts and the file holds
the weights once:
| Context | Layers | Size | Process |
|---|---|---|---|
| verify / decode, part 1 | 0–22 | 1,096 MB | the client itself |
| verify / decode, part 2 | 23–41 and the lm_head | 1,187 MB | worker 1 |
| prefill, 32 tokens per call | 0–23 | 1,100 MB | worker 2 |
Measured on the S22 Ultra, one session, LiteRT-LM CLI on the big cores (260 tokens each):
| Story | Python function | |
|---|---|---|
| Drafter off | 5.5 tok/s | 5.7 tok/s |
Drafter on (--enable_speculative_decoding=true) |
8.3 tok/s | 14.2 tok/s |
| The previous 32K build with the same drafter, for comparison | 6.8 tok/s | 11.6 tok/s |
The gain follows how predictable the text is: about a third of the drafted tokens are accepted on prose, more in code. With the drafter on, two access codes hidden in a 3,292-token and in a 12,449-token prompt come back exact (12,449 tokens in 63–66 s). In an Android app, in the background on the little cores, through an OpenAI-style endpoint: 6.1–6.5 tok/s on a 1,500-token story, 9.7–10.9 tok/s on code, against 5.2 tok/s without drafting.
The drafter only works on unconstrained decoding. LiteRT-LM (v0.17.1 and main alike) falls back to one token per step whenever a decode step carries a constraint, and it turns a repetition penalty, a no-repeat-n-gram or suppress-tokens setting, a thinking budget and a tool-call grammar into one. Pass none of them, or the drafter sits idle and nothing says so.
gemma4-e4b-qat-ctx32768-c22-mtp-multimodal_sm8450.litertlm (added 2026-11-24) is the 32K bundle with
Google's vision and audio encoders packed beside it:
gemma4-e4b-qat-ctx32768_sm8450.litertlm. The packer
checks each section's hash.--backend=npu --vision_backend=gpu --audio_backend=cpu --enable_speculative_decoding=true.
In an app, pass a GPU vision backend and a CPU audio backend to the engine.Checked on the S22 Ultra with the LiteRT-LM CLI, drafter on, one prompt each, 15–19 s a run including the model load:
| Input | Answer |
|---|---|
| Picture with a red circle, a blue square and the code 7429 | shapes, sides and code all correct |
| Spoken sentence | transcribed exactly |
| The picture and the sentence in one prompt | code and sentence both correct |
It also answers pictures, sound, and both together inside an Android app on that phone. There is no benchmark of image or audio quality behind this.
gemma4-e4b-qat-ctx32768-c22-mtp_sm8350.litertlm (added 2026-11-02) is the 32K bundle above,
cut after layer 22 with the drafter, compiled for the Hexagon v68 of the Snapdragon 888
(SM8350). Same parts, same weights, same calibration: nothing was re-exported or re-quantized,
only compiled again for v68 (no op fell back from the NPU). All compute sits in the same three
QNN contexts (3,561 MB) over three processes, with the same dispatch library and worker from
runtime/ and LITERT_QNN_PROCESS_BUDGET_MB=1500.
Measured on a Galaxy S21 Ultra (SM-G998U1, 12 GB), LiteRT-LM CLI on the big cores, 32K window:
| Story | Python function | |
|---|---|---|
| Drafter off | 4.99 tok/s | 4.49 tok/s |
| Drafter on | 6.81 tok/s | 9.72 tok/s |
About 70–85% of the S22 Ultra. With the drafter on, the access codes hidden in a 3,292-token prompt (first token after 32 s) and in a 12,449-token one (118 s, ~106 tok/s) come back exact. It also runs inside an Android app on that phone.
On this chip use the v68 QAIRT 2.50 libraries: libQnnHtpV68Stub.so and
libQnnHtpV68Skel.so (from lib/hexagon-v68/unsigned/) in place of the V69 pair. The bundle
was compiled with 2.50.0.260828; an older v68 runtime does not load its context binaries. Keep
the process budget at 1500 MB: at 900 MB the contexts spread over more workers and the second
one cannot map its 1.19 GB context on this chip (Failed to create QNN context: 1002).
| E4B (this bundle) | E2B QAT 4K, for scale | |
|---|---|---|
| Decode, cool phone | 10–11 tok/s | 23–25 tok/s |
| Decode, after half an hour of runs | 8.5–9.2 tok/s | 20.6 tok/s |
| Prompt in, 3,292 tokens | 8.5 s (387 tok/s) | 2.2 s |
| Time to first token, short prompt | 0.3–0.6 s | 0.07 s |
| Load | 4.4–6.5 s | 1.3–2.3 s |
| Through an Android app's OpenAI-style endpoint | 8–8.5 tok/s | |
| RAM held while loaded (three processes) | ~3.7 GB | ~1.5 GB |
Checks:
There is no benchmark suite behind this. The 32-prompt comparison was run on the 4K bundle only.
The 16K and 32K bundles are the same model and the same three contexts with longer global caches; they were quantized with the 4K build's calibration (the float graphs differ only in the length of the four global caches). Measured in one session, phone otherwise idle:
| 4K | 16K | 32K (the build this file replaced) | |
|---|---|---|---|
| Decode | 8.3 tok/s | 6.3–6.4 tok/s | 4.3–4.7 tok/s |
| Long prompt in | 3,292 tokens: 8.5 s | 12,449 tokens: 34.5 s | 28,029 tokens: 148 s |
| Codes hidden in that prompt returned exactly | 2 of 2 | 2 of 2 | 3 of 3 (at tokens ~1.8K, ~14.2K, ~26.2K) |
| Load | 4.4–6.5 s | 5.4 s | 6.3 s |
The 32K column is the cut-after-23 build; the file now in this repository decodes faster (above) and has the same prefill graph, so its prompt speed is the same (~190 tok/s). The 28K-token prompt has not been repeated on it; the 12,449-token one has.
Every decode step reads the whole global caches, filled or not, and the E4B has four global K/V
layers of two heads each (256 MB of cache at 32K) with seven layers attending over them, so the
window costs more here than on the E2B. Use --max_num_tokens=16384 / 32768 with these files.
Besides the bundle you need:
QAIRT 2.50 runtime (Qualcomm's, not included), from lib/aarch64-android/ and
lib/hexagon-v69/unsigned/: libQnnHtp.so, libQnnSystem.so, libQnnHtpV69Stub.so,
libQnnHtpV69Skel.so. The context binaries were compiled with 2.50.0.260828.
The dispatch library and worker from runtime/:
libLiteRtDispatch_Qualcomm.so — LiteRT's Qualcomm dispatch library, patched. It must come
from the LiteRT commit your LiteRT-LM embeds, so there are two builds:
litert-9fe5be4_litert-lm-v0.17.1/ (LiteRT-LM v0.17.1, the litertlm-android AAR) and
litert-86112a3_litert-lm-main/ (LiteRT-LM main of 2026-10-02).libLiteRtQnnWorker.so — the worker executable (60 lines of C; named lib*.so because an
Android app may only execute files from its native library directory).The libraries were rebuilt on 2026-10-10: a worker now maps a context binary once however
many graphs use it, which the 32K file needs (its decode and verify share contexts). They
run the 4K and 16K files as before.
litert_lm_main / litert_lm_advanced_main from
LiteRT-LM, built for Android arm64, or the
litertlm-android AAR in an app.
From a shell, everything in one folder:
cd /data/local/tmp/litert
export LD_LIBRARY_PATH=$PWD ADSP_LIBRARY_PATH=$PWD
export LITERT_QNN_PROCESS_BUDGET_MB=1500
./litert_lm_advanced_main --backend=npu --model_path=$PWD/gemma4-e4b-qat_sm8450.litertlm \
--litert_dispatch_lib_dir=$PWD --use_session --async=false \
--max_num_tokens=4096 --input_prompt_file=$PWD/prompt.txt
For the 32K file add --enable_speculative_decoding=true (and --max_num_tokens=32768); without
the flag it decodes one token per step.
prompt.txt holds the fully rendered conversation (--use_session takes raw text):
<|turn>user
What is the capital of France?<turn|>
<|turn>model
Keep one libLiteRtDispatch_*.so under the dispatch folder: LiteRT searches it recursively
and takes the first it finds.
With LITERT_QNN_PROCESS_BUDGET_MB set, a context binary that would take the process past that
many MB of context binaries is created in a worker process instead (first worker with room, else
a new one). The worker dlopens the same dispatch library and serves a socket pair. The context
binary reaches it as a file descriptor and an offset into the bundle; graph inputs and outputs as
the FastRPC / DMA-BUF descriptors LiteRT allocated, registered with QNN in both processes, so
nothing is copied per token (an E2B forced over three processes decodes at 26.05 tok/s against
26.53 in one). A worker ends when its last context is released or when the client's socket
closes. Without the variable the library behaves like the stock one. LiteRT, LiteRT-LM and the
bundle format are untouched.
| Variable | Meaning |
|---|---|
LITERT_QNN_PROCESS_BUDGET_MB |
context-binary MB one process holds; unset = stock behaviour. 1500 for this bundle |
LITERT_QNN_WORKER |
path of the worker executable (default: libLiteRtQnnWorker.so in the dispatch folder) |
LITERT_QNN_WORKER_LIBRARY_PATH |
the worker's LD_LIBRARY_PATH, when it differs from the client's |
LITERT_QNN_PRELOAD |
colon-separated libraries the worker loads first |
The same library also reads the power settings described on the
E2B card
(LITERT_QNN_RPC_POLLING_US, LITERT_QNN_HTP_PERF_CTRL, ...).
Ship libLiteRtQnnWorker.so in jniLibs (with useLegacyPackaging, so it is extracted), put the
patched dispatch library where Backend.NPU is pointed, and set, before the engine is created
(Os.setenv): LITERT_QNN_PROCESS_BUDGET_MB=1500, LITERT_QNN_WORKER=<nativeLibraryDir>/libLiteRtQnnWorker.so
and LITERT_QNN_WORKER_LIBRARY_PATH=<QAIRT folder>:<nativeLibraryDir>:/system/lib64:/vendor/lib64.
Without /vendor/lib64 the worker's HTP backend fails with "Failed to create transport for
device, error: 4000". ADSP_LIBRARY_PATH must be in the process environment too; the worker
inherits it.
For the 32K file's drafter, set ExperimentalFlags.enableSpeculativeDecoding = true before the
Engine is created, and send no RepetitionPenaltyConfig and no thinking budget
(ThinkingConfig(enabled, 0) keeps the toggle without the budget): see "The drafter only works
on unconstrained decoding".
runtime/src: patch_dispatch_perf.py and patch_dispatch_remote.py (with
dispatch_remote.inc) patch litert/vendors/qualcomm of a LiteRT checkout,
build_dispatch_remote.sh builds the library with bazel and the worker (qnn_worker.c) with the
NDK. LiteRT is Apache-2.0; the binaries here are LiteRT's dispatch library with those two patches
and nothing else.
_sm8350 file is for the Snapdragon 888 (Hexagon v68) only.-multimodal_sm8450 file, which also takes images and audio.| File | SHA-256 |
|---|---|
gemma4-e4b-qat_sm8450.litertlm |
54b7da46251ee18f36fa1275e69413be80aaa14c1f2262890ae7864f9164f216 |
gemma4-e4b-qat-ctx16384_sm8450.litertlm |
f226ea1bec3bc4083f5ad263263874a3d69466698c46d5c2d409a283fbc1333f |
gemma4-e4b-qat-ctx32768_sm8450.litertlm |
dfea74b4cfbb3bf900a4775185045f22272fa37a282d65f5fa9f6fe1768511f3 |
gemma4-e4b-qat-ctx32768-c22-mtp-multimodal_sm8450.litertlm |
c0c4bd2c6ec13eccea1d8bc3b6364a9f45d534f038f9d623a9888eb5af37d050 |
gemma4-e4b-qat-ctx32768-c22-mtp_sm8350.litertlm |
81720e6bfd0fa1e8a7b28edd49da694d5b9ad5622f3a738dffc8ea7351139c34 |
The tokenizer, chat template and generation metadata are inside the .litertlm. The 32K file
until 2026-10-10 (91f7518b…, cut after layer 23, no drafter) is in this repository's history.
The model weights derive from google/gemma-4-E4B-it and Google's LiteRT-LM bundle of it, and are under the same licence (apache-2.0). Compiled with Google's LiteRT / LiteRT-LM tooling and Qualcomm AI Engine Direct. This is an unofficial community build, not affiliated with the authors of the base model, Google or Qualcomm.
有文件?提交种子。
发布种子google/gemma-4-E4B-it