2026-11-07 · Offline language models for analyses: Gemma 4 E4B and E2B

2026-11-07 · Offline language models for analyses: Gemma 4 E4B and E2B

Context

Analyses, tables of contents and corrections needed a cloud model: the specification said so outright. Researchers who cannot send their material anywhere (interviews, restricted archives, personal papers) could transcribe and extract it offline, then had nothing to analyse it with. Google’s Gemma 4 (Apache 2.0) has two small models built for laptops, E4B and E2B, that read texts and images in many languages; Google publishes them as GGUF files at the 4-bit quantisation they were trained for (QAT), which llama.cpp, already shipped for the OCR models, runs. Gemma 4 for text extraction was set aside: the OCR models of about a billion parameters are faster, smaller to download and less inclined to write text that is not on the page; a comparison on real pages may change that.

Checkpoint findings

The checkpoint due when a crate takes on a new task (offline answering in fields, not only reading pages and recordings) was held against the specification, the roadmap, AGENTS.md and the offline, core, providers, media and engine crates.

Decisions

Models: Gemma 4 E4B, and E2B for smaller computers

From Google’s own repositories (google/gemma-4-E4B-it-qat-q4_0-gguf, google/gemma-4-E2B-it-qat-q4_0-gguf), pinned by commit and SHA-256: the language model and its encoder (images and audio), downloaded together, 6.1 GB for E4B and 4.3 GB for E2B. Not gated, Apache 2.0. The 12B and larger models were left out: 7 GB and more to download and about 10 GB of free memory, too much for most researchers’ laptops.

Two programs: the text program for texts

llama-mtmd-cli, the OCR models’ program, answers once only when it is given an image, and takes the request on its command line, which Windows limits to about 32,000 characters, far less than a document. llama.cpp’s text program, llama-completion, reads the instructions (-sysf), the text (-f) and the answer’s schema (-jf) from files, applies the model’s own chat template for one turn (-cnv -st) with thinking off (--reasoning off; Gemma 4 E4B and E2B then write no thoughts) and prints only the answer (--no-display-prompt). A page image (a photographed letter, a page of an issue for a table of contents) goes to llama-mtmd-cli as for the OCR models, the image first as Gemma’s makers advise, with the largest of Gemma 4’s image budgets (1,120 tokens), the one they advise for reading text.

The text program is built beside each processor and Vulkan build in .github/workflows/llama.yml from the same pinned source (b12110), shipped as one more externalBin, and signed to inherit the sandbox in the Mac App Store build. The OpenCL build has none (below). scripts/llama.json records the programs its archives hold, so the workflow builds and publishes them again; until it has, fetch-llama.mjs stops the release builds.

The answer held to the schema as it is written

llama.cpp turns the analysis’s JSON schema into a grammar, so a small model cannot break the answer’s shape, only fill it badly; the answer is then checked against the fields as every provider’s is. An answer that reaches the output limit is refused without a retry, since greedy decoding would write it again. The limit is the catalogue’s max_output_tokens (8,192), which the engine passes like any model’s and provenance records; the provider keeps it between 512 and 8,192.

No thinking to choose

Gemma 4 can think before answering, but llama.cpp’s text program applies the schema’s grammar from the first token, which leaves no room for a thought block: only llama.cpp’s server knows where thinking ends and starts the grammar there. So the models have no reasoning levels in the catalogue, New job offers none, and thinking is off. Small models gain little from it, and on a processor it would add minutes to every document. Temperature (0), the context (32K) and the image budget are fixed, since the cache assumes the same request answers the same way.

What they read at once

A context of 32,768 tokens: the models take 128K, but reading that many on a processor takes far too long. A text over 66,000 characters (about 11,000 words) is refused before anything runs, with a message saying to split it or choose a cloud model; llama.cpp’s own refusal, for a script that needs more tokens per character, gets the same message. A whole PDF is not read: the media step says to extract its text first, then analyse the result.

The graphics processor wherever llama.cpp can use it

On a Mac the models run on Metal. On Windows they follow the OCR models’ Vulkan build and Settings choice, on any device it chooses, with -ngl auto --fit on: llama.cpp puts as many layers on the device as its memory holds beside the fixed context, the rest on the processor. A card with little memory of its own still speeds them up rather than being passed over or running out of memory; the OCR models, a fifth of the size, keep every layer there (-ngl 99). A failure on the graphics processor sends both engines back to the processor for the session.

Snapdragon’s Adreno is left to the processor for now: Vulkan read wrongly there for both OCR models (a wrong answer ends normally, so no fallback catches it), and the OpenCL build was measured only for GLM-OCR’s image encoder. llama.cpp’s OpenCL backend, with Qualcomm’s kernels, is written for 4-bit models like these, so it is the next thing to measure on a Snapdragon: building llama-completion-opencl and adding OpenCL to the models’ recipes is the whole change once it reads correctly.

Consequences