Gemma 4 E2B-it (LiteRT-LM) — rotary-position fix for float16 activations
A modified copy of gemma-4-E2B-it.litertlm from
litert-community/gemma-4-E2B-it-litert-lm
at revision b3ca0d2f076785a8f4b2219ddbd2bdb99954eae1
(sha256 181938105e0eefd105961417e8da75903eacda102c4fce9ce90f50b97139a63c).
What changed
Weights are untouched. Only the rotary-position (RoPE) math in the graph is rewritten.
The stock graph casts the INT32 position to a float tensor before computing rotary angles.
With float16 activations (the GPU/Metal path) that tensor cannot represent large positions
exactly, so neighbouring tokens receive the same rotary phase. The visible symptom is
corrupted exact-copy sequences: digits, dates and short markers (1848 → 18848).
See LiteRT-LM #3913 and
#2814.
The patch (patch_rope.py --split, block-512 variant, from the research/3913 branch of
PowerBeef/LiteRT-LM) rewrites the position as 512·h + l: l (0–511) stays exact in
float16 and the phase of 512·h comes from small precomputed tables (positions up to
32 767), combined by angle addition. It is applied to every signature of
tf_lite_prefill_decode (decode, prefill_128, prefill_1024, verify) and to
tf_lite_mtp_drafter. The attention mask and KV-cache index paths are unchanged. In exact
arithmetic the outputs are identical to the original; on CPU at float32, logits are
bit-identical below position 2048.
| size (bytes) | sha256 | |
|---|---|---|
| original | 2 588 147 712 | 181938105e0eefd105961417e8da75903eacda102c4fce9ce90f50b97139a63c |
| this file | 2 589 310 976 | a963992d901da9f2436ffdcea69e90b8c610a7c72000094787d2a18a69040b17 |
Measured (iPhone 14 Pro, 6 GB, GPU backend, float16 activations, MTP on)
French numeric-fidelity probe, 30 turns: no digit duplication; every copied or recalled number that was given came back digit-exact. Decode 24.7 tok/s, memory plateau ~1.95 GB.
Licence
Apache 2.0, as the original. Gemma is provided under and subject to its original terms.