2026-11-06 · Offline OCR vision models, run by llama.cpp’s own program

2026-11-06 · Offline OCR vision models, run by llama.cpp’s own program

Context

#105 asks for a second offline engine for Extract text: a small vision-language model trained for OCR, for the print Tesseract reads badly (degraded type, old newspapers in columns, mixed layouts, tables), still with no account, key, charge or upload. It named three candidates (PaddleOCR-VL, GLM-OCR, LightOnOCR) and four conditions: one copy of ggml, the existing paths (provider, catalogue, media, engine, cache, provenance), honesty about speed and invented text, and the three systems built in CI.

The checkpoint due before a third offline engine was held first, against the specification, the roadmap, AGENTS.md and the offline, core, media and engine crates.

Checkpoint findings

Decisions

llama.cpp as a separate program, not linked

whisper.cpp (through whisper-rs) already links one copy of ggml into the app. llama.cpp brings its own, of another version: linked statically beside it, the two would define the same symbols, which the linker either refuses or resolves to one copy for both, an ABI mismatch. Three ways out were weighed:

The program is llama-mtmd-cli, llama.cpp’s multimodal command line, given the page and the model’s fixed instruction once (-p "<__media__>grounding"), so it answers once and exits. llama-server was set aside: it would keep the model loaded, but opening a local port needs the network-server entitlement in the Mac App Store’s sandbox, and a server to start, watch and stop.

.github/workflows/llama.yml builds it from the source of the pinned release (b12110, which llama.cpp calls v0.9.0), checked against its SHA-256: one static executable per system, the C runtime included, without OpenMP or networking, for the same processors as Whisper (AVX2 with FMA and F16C on x64, armv8.2-a+dotprod+fp16 on ARM64, so cpu.rs checks both), and with Metal and its shaders built in on macOS. The archives are published as a GitHub release and pinned in scripts/llama.json, and scripts/fetch-llama.mjs installs them as FFmpeg’s are; the program is one more externalBin, signed to inherit the sandbox in the Mac App Store build. llama.cpp’s official builds were set aside because they ship as many libraries beside each program.

Models: LightOnOCR-3 1B and GLM-OCR

Q8_0 for both: at about a billion parameters a lower quantisation saves little and costs accuracy (#105 asked for Q4_K_M or better). Downloads: 1.1 GB for LightOnOCR-3, 1.4 GB for GLM-OCR.

Running them

One page at a time, each run given half the logical processors on x64 and all but one on ARM64, at most eight, as Whisper; every layer on the graphics processor where there is one. Pages larger than a model reads best are resized first (1540 pixels on the longest side for LightOnOCR, its makers’ advice; 1800 for GLM-OCR). The answer may run to 6,144 tokens, in a context of 10,240 with the image’s tokens read in one batch of 4,096 (llama.cpp would otherwise lower the image’s resolution to fit its default batch). A page that reaches the limit is marked cut short, and a line written over and over at its end is kept once.

Speed, measured rather than promised

The seconds each page took are kept per model in the models’ folder (speeds.json, a running average weighted to the latest pages). Settings and New job show them once the model has read a page on this computer, and before that say it has not been timed yet; the descriptions give the range (tens of seconds to over a minute a page on a processor, several times faster on a Mac’s graphics processor). The test page #105 suggested after installation was set aside for this: the first pages of a real job measure the same thing without a step of its own.

Benchmark: a first timing, error rates still to do

#105 asks for character error rates and seconds per page on real pages before choosing models. Running llama.cpp’s downloaded program on the development machine was not permitted in the session that built this, so the first numbers come from the workflow above, which times both models on the sample page (samples/bulletin-page.jpg, 992 × 1403 pixels, a typed page of French) on GitHub’s runners, with the app’s arguments:

Runner Threads LightOnOCR-3 1B GLM-OCR
Windows x64 (windows-latest) 2 161 s 153 s
Windows ARM64 (windows-11-arm) 3 135 s 121 s
macOS (macos-latest, a virtual machine) 2 769 s 440 s

Both read the page’s text correctly on all three. These runners are small virtual machines (two to four cores; the Mac’s has no usable graphics processor, so Metal could not help), so the numbers are an upper bound: a laptop with eight cores, or a real Mac’s graphics processor, should be several times faster, which Settings will measure. LightOnOCR’s first answers had no block positions: asked for grounding without the line break its chat template puts after the instruction, it wrote plain Markdown. The instruction now ends with one, and the workflow fails if LightOnOCR’s answer places no block. The benchmark on IWAC newspapers, typescripts and French and Arabic print remains to do before release, and may change which models are offered.

Consequences