OpenFlowLM-Next icon indicating copy to clipboard operation
OpenFlowLM-Next copied to clipboard

Gemma 4 E2B and E4B text on the open kernels

Open Cyronius opened this issue 3 weeks ago • 0 comments

Part of #73: the text half of Gemma 4 E2B and E4B. Images and audio are not in scope here.

On main today, gemma4-it:e2b and gemma4-it:e4b run only on the closed gemma4e_npu engine. The support table in docs/docs/models/index.md says why: per-layer embeddings and KV sharing across layers have no open recipe. Gemma 4 12B already runs open since #232.

What E2B and E4B need on top of the 12B:

  • Per-layer inputs. Each layer adds a small per-token embedding to the residual through a gated projection.
  • KV sharing. The last layers (E4B 24-41, E2B 15-34) have no K or V projection. Each one reads the cache of the last earlier layer of the same kind.
  • Four layer kinds, not two: sliding or global, each with its own cache or a shared one.
  • E2B's shape. It has one KV head, and its shared layers have a double-width FFN.
  • GGUF install. Load straight from Google's QAT Q4_0 GGUF (google/gemma-4-E4B-it-qat-q4_0-gguf) through oflm-add.
  • Batched prefill, not one token at a time.

The open path is text only. It refuses images and audio with a 400, and those keep running on the closed engine from the official .q4nx container.

Working code for this exists on a branch from October (perf/gemma4-block-prefill). Through oflm serve at 6419 tokens it measured:

Model Prefill Decode
E4B 82.1 tok/s 6.9-7.1 tok/s
E2B 120-130 tok/s 8.8-11.0 tok/s

Its logits match the reference model (correlation >= 0.999, same top token). It predates #232, so it conflicts with main in 38 files, including the Gemma 4 recipe that #232 added for the 12B. A draft PR follows once it is ported.

Open question: that branch also has its own 12B path, with all layer kinds in one hardware context. The port keeps main's 12B unchanged unless we decide otherwise.

Cyronius avatar Nov 13 '26 13:11 Cyronius