Gemma 4 E2B with the odml.rope composite (LiteRT-LM #3913 test files)
This repository holds three test files for LiteRT-LM #3913, all exported from google/gemma-4-E2B-it (revision 3e22461f) with litert-torch's export_hf at 0a81bf6, for LiteRT-LM v0.18.0. They differ only in the two flags in the table. On an Apple M4 Max GPU (WebGPU delegate, Metal adapter) at the default fp16 activations, the two files exported with --use_rope_composite=True returned the 48-digit reference exactly in every case of the issue's copy sets that fits their caches (118 cases for the 8,192-token file, all 130 for the 32k file); the file exported without it first went wrong at token position 2,051 (2026-10-25).
| file | --use_rope_composite |
--cache_length (KV cache, tokens) |
bytes | sha256 |
|---|---|---|---|---|
gemma-4-E2B-it-ropecomposite.litertlm |
True |
8192 | 5,085,831,824 | 7b1e36f01371b0ec4cd75e83290cc142e2ef3d01796e36b414ad0af162db0302 |
gemma-4-E2B-it-ropecomposite-32k.litertlm |
True |
32768 | 5,085,930,128 | bd33140d429e67bd73ef50f642cc95256925ae8f6ab6b3c9613b20ee5740ef36 |
gemma-4-E2B-it-no-ropecomposite.litertlm |
not passed | 8192 | 5,082,964,624 | b0d12ee6d1afdcabe0822b5315e707b2fa99625646d596ad7666630bdd2e57ee |
no-ropecomposite is the control for the first file: the same command, run in the same session on 2026-10-18, without the flag (the run summary linked below calls it gemma-4-E2B-it-ltdefault.litertlm). The E4B file (the same command with the E4B model and two lower-memory conversion settings, described on its card) is in mlboydaisuke/gemma-4-E4B-it-litert-lm-rope-composite.
These are test files for that issue, not replacements for the stock file in litert-community/gemma-4-E2B-it-litert-lm. How they differ from the stock gemma-4-E2B-it.litertlm:
- Rotary embedding: the two
ropecompositefiles haveodml.ropecomposites (50 indecode, 29 in each ofprefill_128andprefill_1024) and no SIN / COS or INT32 → float cast of the position in the main graphs.no-ropecomposite, like the stock file, casts the position from INT32 to float in the graph and computes the angles from it. - KV cache: fixed at export (table). A prompt and its reply must fit in it.
- Weights: int8, the
export_hfdefault recipe (dynamic_wi8_afp32): 5.08 to 5.09 GB per file, against 2,588,147,712 bytes for the stock file. - Sections: text only (no vision or audio encoder) and no MTP drafter. The tokenizer is the source repo's
tokenizer.json, byte for byte. The chat template is the source repo's (Gemma 4 Canonical Chat Template, 2026-07-09), with its.get('…')lookups written as['…']. - Activations: no file sets
prefer_activation_type; LiteRT-LM v0.18.0 runs the GPU path at fp16 by default (engine log:System's default activation type for Text decoder is fp16). - Logits: the
decodegraph returns thelm_headoutput as the logits, without Gemma 4's final logit soft cap (30 * tanh(x / 30);final_logit_softcapping: 30.0in the source'sconfig.json), which transformers applies afterlm_head. The stock file has it (a TANH betweenlm_headand its logits output); these three files have none. litert-torch's Gemma 4 decode module at0a81bf6callslm_headwithout the cap (litert-torch#1382; litert-torch's main branch added the cap on 2026-10-30 in d1d1b40, after these files were exported; the latest release as of 2026-11-09, 0.10.0, does not include it). The cap does not change which logit is largest, so greedy decoding returns the same tokens with or without it, and the greedy runs below do not depend on it. On CPU and GPU, LiteRT-LM v0.18.0 samples with top-k 1 when neither the file nor the app sets a sampler, and these files set none. An app that sets top-k above 1 samples from the uncapped logits; #1382 shows how the cap changes the token probabilities ofgoogle/gemma-4-E4B-itin transformers. The effect on sampled text was not measured on these files.
Measured on a Mac
Apple M4 Max, macOS 27.0, the LiteRT-LM v0.18.0 Swift package (macOS library), 2026-10-25. Cases and runner are PowerBeef's, from research/issue-3913 in PowerBeef/agello-litert-lm at 39d5a014: greedy (topK 1, topP 1, temperature 0), maxOutputTokens 80, one runner process per case set (each cell of the table), maxNumTokens 8192 for the 8,192-token files and 32768 for the 32k file. Each case asks the model to copy a 48-digit number placed before a filler text (after it in the six late cases of baseline). Exact replies / cases:
| file | backend, activations | short (237–1,639 tok) |
baseline (1,705–2,592) |
long (2,094–3,983) |
cross4096 (3,983–4,449) |
xl t6000, t8000 (5,995–7,993) |
xl t12000–t30000 (11,990–29,960) |
|---|---|---|---|---|---|---|---|
ropecomposite |
GPU, fp16 (default) | 15/15 | 42/42 | 25/25 | 30/30 | 6/6 | does not fit |
ropecomposite-32k |
GPU, fp16 (default) | 15/15 | 42/42 | 25/25 | 30/30 | 6/6 | 12/12 |
ropecomposite-32k |
GPU, FLOAT32 | – | – | 25/25 | – | – | – |
ropecomposite-32k |
CPU (XNNPACK) | – | – | 25/25 | – | – | – |
no-ropecomposite |
GPU, fp16 (default) | 15/15 | 21/42 | 1/25 | 0/30 | 0/6 | does not fit |
GPU = the WebGPU delegate on the Metal adapter (engine log: Selected adapter: Apple M4 Max, arch=metal-3, vendor=apple, backend=Metal). In the failing replies of no-ropecomposite the first wrong digit sits at positions 2,051 to 7,998, and its 37 exact replies all end by position 2,638. The two composite files return the same text in all 112 cases of the first four sets. The three files give the same prompt token count for each case, and the counts equal those in PowerBeef's published runner records for the 100 case ids they share.
Runner-recorded speed, medians over the 118 cases that fit 8,192 tokens, prompt / decode tokens per second, MTP off (recorded by the runner, not a benchmark): ropecomposite 5,139 / 62.7, no-ropecomposite 5,126 / 62.3, ropecomposite-32k 1,985 / 25.8.
Earlier runs on the same Mac (2026-10-18) are in the run summary, with the raw replies and the engine logs: long at FLOAT32 and on the CPU, 25/25 for both 8,192-token files with the same text, and a 49-case copy suite of this author's, where on the GPU ropecomposite fails one case (a 129-token prompt; it returns the filler sentence after the REFERENCE: line instead of the date) and no-ropecomposite fails the same case.
Not measured: other GPUs (in particular the M1 Max loss below position 2,048 reported in #3913), iOS, Android.
Reproduce
python -m litert_torch.generative.export_hf --model=<google/gemma-4-E2B-it at 3e22461f> --output_dir=<dir> \
--task=text_generation --prefill_lengths=128,1024 --cache_length=8192 --externalize_embedder=True \
--export_vision_encoder=False --export_audio_encoder=False --bundle_litert_lm=True --use_rope_composite=True
ropecomposite-32k is the same command with --cache_length=32768; no-ropecomposite is the same command without --use_rope_composite=True.
Environment: macOS, Python 3.12, litert-torch 0.10.0 installed editable at 0a81bf6f3243a6f7c846d05d62afeff4008f2542, torch 2.12.0, transformers 5.19.0, ai-edge-litert-nightly 2.4.0.dev20261011, litert-converter 0.5.0, litert-lm-builder 0.18.0. At that revision model_ext/bonsai_flux2 imports tensorflow.lite.python.schema_py_generated; in place of TensorFlow, a stub tensorflow package on PYTHONPATH (three empty __init__.py files and one module) re-exported ai_edge_litert.schema_py_generated under that name. The 32k export took 191 s on this Mac and peaked at 62.6 GB of resident memory (/usr/bin/time -l).
Known runtime issues
With thinking off, from the second turn of a conversation on, LiteRT-LM puts the previous answer's stop token into the KV cache with a zero embedding, because these files hold the embedding table in its own section and the decoder takes embeddings, so later answers in a conversation can differ from the answer the model gives to the same messages in one prompt (read in the source of LiteRT-LM 0.16.0 to 0.18.1; measured with 0.18.1 on WeVisOne-VL-2B and Qwen2.5-Coder-1.5B-Instruct, not on these files). With thinking on, after an answer that carries its thought (<|channel>thought … <channel|>), the runtime rebuilds the cache from the re-rendered history at the next turn, so the second turn is free of it when the conversation opens with a user message; the same source shows a zero embedding at another token from the third turn on (not measured). One question per conversation avoids both, as does a new conversation that starts with the earlier messages and the new question.
On LiteRT-LM releases before 0.17.0 (read in the source of 0.10.1 to 0.16.1), an answer whose last punctuation mark is a token of its own, such as a . or ? after a word, arrives without that mark: these files carry stop sequences of <turn|> and a newline with each of 13 characters in front (12 punctuation marks and a space), so the runtime holds the mark back to see whether <turn|> and a newline follow, the answer ends on <turn|> alone, and the held mark is never written. LiteRT-LM 0.17.0 and later write the held mark (StopTokenStreamFilter in runtime/core/tasks.cc, read in the source of 0.17.0 to 0.18.1). Not measured on these files: this follows from the runtime's source read with these files' stop list and tokenizer; the drop itself was seen with LiteRT-LM 0.16.1 on a Galaxy S26, on another bundle whose stop sequences have the same form.
License
The weights are Gemma 4 E2B by Google DeepMind, licensed under the Apache License, Version 2.0 (the license of google/gemma-4-E2B-it). The files here are converted, int8-quantized copies of them: LICENSE holds the license text and NOTICE lists the changes.