Instructions to use litert-community/OvisOCR3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT-LM
How to use litert-community/OvisOCR3 with LiteRT-LM:
# LiteRT-LM runs on various platforms (Android, iOS, Windows, Linux, macOS, IoT, Web/WASM) # and supports many APIs (C++, Python, Kotlin, Swift, JavaScript, Flutter). # For platform-specific integration guides, please refer to the official developer website: # https://ai.google.dev/edge/litert-lm # To try LiteRT-LM, the easiest way is to use our CLI tool. # 1. Install the LiteRT-LM CLI tool: pip install -U litert-lm # 2. Download and run this model locally: # See: https://ai.google.dev/edge/litert-lm/cli # A single .litertlm file in the repo is picked automatically; otherwise the CLI asks which one to run # (or pass its name right after the repo id). litert-lm run \ --from-huggingface-repo=litert-community/OvisOCR3 \ --prompt="Write me a poem"
- LiteRT
How to use litert-community/OvisOCR3 with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
OvisOCR3 β LiteRT-LM (OCR)
This repository holds ATH-MaaS/OvisOCR3 as one file for Google's LiteRT-LM (.litertlm), to read pictures on the CPU of an Android phone. On a Snapdragon Galaxy S26 one request took 10.1β11.3 s for a paragraph and 13.2β13.4 s for a page, engine creation included (timed in a fresh process with the runtime's default cache, from engine creation to the end of the answer, 2026-11-29). Speed still being tuned (updates follow).
On the CPU of a Snapdragon Galaxy S26 and a Pixel 11 Pro, the answer passes our comparison with the original model's on 14 of our 18 test cases (17 pictures; one receipt photo with two prompts). It fails on a small receipt photo, a calligraphy sample, a page of dense equations and a handwritten derivation (see Correctness).
Run it on the CPU with python ocr_ovisocr3.py OvisOCR3_int8.litertlm <picture> (setup under How to use). Do not use the GPU: with LiteRT-LM 0.19.0, on the GPU of both phones 5 of the 18 cases fail the comparison, and on the Snapdragon Galaxy S26 a GPU request took 3.5β5.4 times as long as on the CPU; the Pixel 11 Pro's GPU was not timed (see Which backend).
OvisOCR3 (ATH-MaaS) is a 0.85B model for OCR and document understanding, built on Qwen3.5-0.8B: a 12-layer vision encoder and a Qwen3.5 hybrid text decoder (18 Gated DeltaNet + 6 attention layers). Its task prompts select what it does, and this file was checked with four of them: a page to Markdown (formulas as LaTeX, tables as HTML), plain text, formulas as LaTeX, and named fields as JSON. This file takes one picture of 768 Γ 1344 pixels (portrait) per request, as 1,008 image tokens.
| File | What is inside | Size | sha256 |
|---|---|---|---|
OvisOCR3_int8.litertlm |
text decoder with int8 weights in 145 fully connected layers (36 small Gated DeltaNet projections and 18 short-convolution filters stay float32), fp32 activations declared; int8 embedding table; vision encoder fp16 with fp16 activations declared; vision adapter int8 | 1.31 GB | 5f89306b58eb8c1e10abf6e426ea608a3e7d01a13276bc1553f78bcee3e252b0 |
Every run of this file reported on this page, on the phones and on a Mac, used these bytes (the sha256 above).
Which backend (LiteRT-LM 0.19.0 on both phones).
- On a Snapdragon Galaxy S26 one GPU request took 43.5β55.3 s against 10.1β13.4 s on the CPU, engine creation included: 3.5β5.4 times as long as a CPU request for the same picture. Creating the GPU engine and conversation took 37.8β49.1 s of that (see Known runtime issues).
- On the GPU of both phones the file fails the comparison with the original model on 5 of the 18 test cases: the CPU's 4 and the receipt photo read into fields (see Correctness).
- On a Pixel 11 Pro (Tensor G6) one CPU request took 19.4β24.5 s, engine creation included. Its GPU was not timed.
How to use
ocr_ovisocr3.py pads your picture and runs the file with litert-lm. It runs on a computer's Python (we ran it on a Mac); litert-lm 0.20.0 needs Python 3.10 or newer. The phone numbers on this page were measured on the phones with LiteRT-LM's Android Python wheel (litert-lm-api 0.19.0), not with this script.
pip install litert-lm==0.20.0 pillow huggingface_hub
hf download litert-community/OvisOCR3 --include "OvisOCR3_int8.litertlm" --include "samples/*" --local-dir ovisocr3
curl -LO https://raw.githubusercontent.com/john-rocky/hf-to-litertlm/main/ovisocr3_work/ocr_ovisocr3.py
python ocr_ovisocr3.py ovisocr3/OvisOCR3_int8.litertlm ovisocr3/samples/page_en.png
python ocr_ovisocr3.py ovisocr3/OvisOCR3_int8.litertlm ovisocr3/samples/table.png --task document_markdown
python ocr_ovisocr3.py ovisocr3/OvisOCR3_int8.litertlm ovisocr3/samples/receipt.png --task kie_fields --keys store_name,date,total
On a Mac's CPU we ran the three commands once with litert-lm 0.20.0 and once with 0.19.0 (six processes); both runtimes printed these answers, the same bytes. Both phones' CPUs wrote the same three answers. The page, cut after its first sentence:
# Regional Water Quality Survey 2025
The survey collected 1,284 samples from 37 rivers between April and September. β¦
The table:
<table border="1"><tr><td>Station</td><td>Samples</td><td>Nitrate (mg/L)</td><td>Phosphate (mg/L)</td></tr><tr><td>Kessel</td><td>212</td><td>3.1</td><td>0.42</td></tr><tr><td>Arden</td><td>185</td><td>2.7</td><td>0.38</td></tr><tr><td>Morrow</td><td>164</td><td>4.0</td><td>0.51</td></tr><tr><td>Lisle</td><td>143</td><td>1.9</td><td>0.29</td></tr></table>
The receipt:
{"store_name":"GREENLEAF MARKET","date":"2025-03-14","total":"17.60"}
The script keeps your picture's shape: it turns the picture upright (its EXIF orientation), centres it on the smallest white canvas of the file's 4:7 portrait shape that holds it, and resizes the canvas to 768 Γ 1344 before it calls the runtime. The pictures of our 18 test cases went in as exactly that padding's output.
--task picks one of the four prompts below (document_markdown is the default), and --prompt sends your own instead. --backend gpu puts the text decoder on the GPU, and --vision-backend sets the vision encoder's backend apart from it (default: the same as --backend). --threads sets the text decoder's CPU threads (default 4); in the source of LiteRT-LM 0.19.0 and 0.20.0, the vision encoder's CPU path sets 4 threads whatever it says (read, not measured). --cache-dir sets where the runtime writes its caches (default: beside the model file; the script makes the folder). --keep-picture saves, as a PNG, the 768 Γ 1344 picture the script sends to the runtime. On our 18 test cases a picture and its prompt took 1,077β1,207 of the 4,096 tokens the file holds, and the script lets an answer run to 2,880 tokens (--max-output-tokens).
--task |
The model's prompt file | Requested output |
|---|---|---|
document_markdown (default) |
prompts/document_markdown.txt |
one Markdown document in reading order: formulas as LaTeX, tables as HTML, charts and images as <img> tags with their box |
plain_ocr |
prompts/plain_ocr.txt |
plain text |
formula_recognition |
prompts/formula_recognition.txt |
LaTeX, each standalone or display expression in $$ ... $$ |
kie_fields with --keys a,b,β¦ |
prompts/kie_fields.txt, the keys put in as a JSON array |
a JSON object with exactly those keys |
The model's 14 other prompts were not tried with this file.
From your own code, pad the picture the same way (pad_to in the script), send it with the prompt in one user message, decode greedily (top-k 1, as the model card's temperature 0), and create one Engine per picture (see Known runtime issues).
We ran each case below with litert-lm 0.20.0 on a Mac. The script printed one line on stderr, its message, and exited with code 1, except for an option or argument it does not accept (an unknown --task, for example): there it printed the usage lines first and exited with code 2. The messages, with paths shortened to β¦:
| Case | Message |
|---|---|
| the model path does not exist | no such model file: 'β¦' |
| the picture path does not exist | cannot read the picture 'β¦': [Errno 2] No such file or directory: 'β¦' |
| the picture is not an image | cannot read the picture 'β¦': cannot identify image file 'β¦' |
the model path is a PNG, not a .litertlm file |
cannot load the model 'β¦': litert_lm_engine_create failed with status INVALID_ARGUMENT (3): INVALID_ARGUMENT: Unsupported or unknown file format. |
--task kie_fields without --keys |
--task kie_fields needs --keys, e.g. --keys store_name,date,total |
--threads 0 |
--threads must be 1 or more, got 0 |
a --cache-dir that cannot be made (/dev/null/cache) |
cannot make the cache dir 'β¦': [Errno 20] Not a directory: 'β¦' |
an option or argument the script does not accept, for example an unknown --task (exit code 2) |
ocr_ovisocr3.py: error: argument --task: invalid choice: 'layout' (choose from 'document_markdown', 'formula_recognition', 'plain_ocr', 'kie_fields') |
Correctness
The bar: for each test case, this file's answer is compared with what the original model writes from the same picture at its own size (Transformers, float32, greedy, the model card's picture settings). Each kind of case has its own measure. Text regions pass with a character error rate (CER: edits over the length of the original's answer, both texts normalized) of at most 0.02, and photo regions and pages with at most 0.05. A table passes with at least 90 % of its cells equal in the same row and column, a formula with the same LaTeX after normalization, and named fields with every requested JSON field equal. Every answer must also end with a stop token before the token limit. There are 18 test cases, each a picture sent with one of the four prompts above. 14 are regions: an English line, title and three paragraphs (one small, one tilted and blurred like a photo), a Chinese paragraph, a table, two formulas, a drawn receipt (read into three fields), a receipt photo (read as a document and as six fields), a calligraphy sample and a small receipt photo. Of these, the tilted paragraph, the receipt photo read as a document, the calligraphy and the small receipt photo are photo regions. 4 are pages: a drawn page, a page of dense equations, a handwritten derivation and a form photo. The receipt photo, the calligraphy, the equations and the derivation are example pictures of xiaomi-research/Xiaomi-OCR-0; the small receipt and the form come from huggingface/documentation-images; we drew the other 11.
| Device | Backend | Regions that pass (of 14) | Pages that pass (of 4) |
|---|---|---|---|
| Galaxy S26 (Snapdragon, SM8850) | CPU | 12 | 2 |
| Pixel 11 Pro (Tensor G6) | CPU | 12 | 2 |
| Galaxy S26 (Snapdragon, SM8850) | GPU | 11 | 2 |
| Pixel 11 Pro (Tensor G6) | GPU | 11 | 2 |
LiteRT-LM 0.19.0 on both phones (the Python API of its PyPI Android wheel), one process per test case, greedy (top-k 1), without the runtime's caches (2026-11-29). The two phones' CPUs wrote the same text on all 18 cases. We did not run the file through LiteRT-LM's Kotlin API.
- The four that fail on the phones' CPU. The ranges cover both phones and four processes of the same file on a Mac's CPU (Apple Silicon, LiteRT-LM 0.19.0, 4 threads), whose text varied between processes; with the text decoder on one CPU thread, two fresh processes wrote the same text on each of the four.
- The small receipt photo, read with the plain-text prompt: 77 of its 257 characters differ on both phones (CER 0.30), and the Mac's CER is 0.30β0.37; the bar allows 0.05. This file writes the item lines as a Markdown table where the original model writes lines of text; with the table marks and blanks removed from both, 9β12 of the original's 209 characters differ.
- The calligraphy sample: 2 of its 26 characters differ on both phones and 1β2 on the Mac; the bar allows 1.
- The page of dense equations: 19.0β19.5 % of its characters differ.
- The handwritten derivation: 9.0β17.9 % of its characters differ.
- On the GPU a fifth case fails. Read into six fields on the GPU of both phones, the receipt photo gets the mall's name, "CHERAS LEISURE MALL", as
seller_name, where the original model and the CPU give the shop's name at the top, "MR. D.I.Y. SDN BHD". The two GPUs wrote the same text. - The original model at this picture size. Given this file's 768 Γ 1344 picture and the plain 1-D token positions this file's decoder was exported with (in place of the model's M-RoPE positions), the original model itself (Transformers, float32) also differs from its answer at its own size on the same four cases: 77 of 257 characters on the small receipt (12 of 209 with the table marks and blanks removed), 2 of 26 on the calligraphy, 18.9 % on the equation page and 12.7 % on the derivation. At its own size it reads the derivation as 8,040 image tokens and the equation page as 2,296; this file reads every picture as 1,008.
Performance
One request = a fresh process with a new Engine: engine and conversation creation, the picture, prefill and decode, timed inside the process from engine creation to the end of the answer, less the time the process spent reading its own and the phone's memory use. LiteRT-LM 0.19.0 on the phones (the Python API of its PyPI Android wheel), with the runtime's default cache beside the model file; on the CPU the text decoder ran on 4 threads and the vision encoder on the CPU too. "Paragraph" = a drawn English paragraph (1,114 tokens in, 100 out). "Page" = a drawn English page (1,134 tokens in, 211 out). Three processes for each picture and backend; every range covers all three. On the CPU the first process wrote the runtime's caches and the next ones read them (on the Snapdragon Galaxy S26 those caches take about 1.12 GB); on the GPU, each later process failed to load some of the cached GPU contexts and rebuilt them (see Known runtime issues). Prefill and decode are the runtime's own BenchmarkInfo rates. Peak = the process's peak resident memory (VmHWM) in the phone's 1 s samples, in MiB. Each process started at thermal status 1 with no CPU clock cap, except the last GPU page request, which started with the CPU clock ceiling at 4,512,000 of 4,742,400 kHz; the first GPU request of each picture reached thermal status 2. In every request, a third to all of the phone's clock samples (one every 2β3 s) counted as CPU-capped: a CPU clock ceiling below its maximum, or on the Pixel 11 Pro a thermal-uclamp cooling device above 0.
| Galaxy S26 (Snapdragon, SM8850), Android 16 | Paragraph request (s) | Page request (s) | Engine and conversation creation (s) | Prefill (tok/s) | Decode (tok/s) | Peak (MiB) |
|---|---|---|---|---|---|---|
| CPU | 10.1β11.3 | 13.2β13.4 | 2.40β3.46 | 438β474 | 37.8β39.0 | 4,165β4,236 |
| GPU | 43.5β54.4 | 46.5β55.3 | 37.8β49.1 | 654β749 | 30.6β34.8 | 3,220β3,795 |
| Pixel 11 Pro (Tensor G6), Android 17 | Paragraph request (s) | Page request (s) | Engine and conversation creation (s) | Prefill (tok/s) | Decode (tok/s) | Peak (MiB) |
|---|---|---|---|---|---|---|
| CPU | 19.4β21.0 | 23.2β24.5 | 3.59β4.90 | 229β255 | 26.7β29.9 | 3,301β3,403 |
| GPU | not timed |
Timed from process start to exit, the Python interpreter's start included, the same requests took 11β14 s on the CPU and 47β60 s on the GPU of the Snapdragon Galaxy S26, and 21β26 s on the CPU of the Pixel 11 Pro.
LiteRT-LM's own benchmark on the CPU (litert_lm.Benchmark: the decoder alone on 1,024 prefill and 256 decode text tokens, context 2,048, three runs on one Engine in one process, 4 threads), runs 1 / 2 / 3:
- Galaxy S26 (Snapdragon, SM8850): prefill 565.24 / 481.88 / 394.09 tok/s, decode 45.811 / 36.393 / 35.217 tok/s.
- Pixel 11 Pro (Tensor G6): prefill 285.72 / 295.84 / 286.41 tok/s, decode 32.365 / 29.886 / 19.291 tok/s.
Both phones started the benchmark at thermal status 1 with no CPU clock cap. The CPU clock ceiling came down about 3 s after the process started on the Snapdragon Galaxy S26 and about 8 s after on the Pixel 11 Pro. Both phones decoded slower in runs 2 and 3 than in run 1.
Conversion notes
- Source: ATH-MaaS/OvisOCR3 at revision
5b252386: a Qwen3.5 text decoder of 24 layers (18 Gated DeltaNet linear-attention + 6 full-attention, hidden 1,024, a vocabulary of 248,320 with a tied output head) and a 12-layer vision encoder (hidden 768, patch 16) with a 2Γ2 merger to width 1,024. - Text decoder: 7 signatures (prefill 1024, 256, 64, 16, 4, 1 and decode), a 4,096-token KV budget on the 6 attention layers, the embedder outside the decoder for the
fast_vlmpath. Dynamic int8 on 145 fully connected layers and on the embedding; the 36 small Gated DeltaNet projections (in_proj_a/in_proj_b, 16 Γ 1024) and the 18 short-convolution filters stay float32; fp32 activations declared. Toolchain: a litert-torch checkout at commit 115a136 with the Qwen3.5 hybrid patch of hf-to-litertlm, litert-converter 0.3.0, ai-edge-quantizer 0.8.0, ai-edge-litert 2.1.6, transformers 5.14.1, torch 2.12.1. - Vision: the encoder and the merger exported for one fixed 768 Γ 1344 picture (84 rows of 48 patches) with litert-torch 0.9.3 and litert-converter 0.4.0. The encoder is fp16 with fp16 activations declared, and its LayerNorm inputs are scaled by powers of two; with the same LayerNorm arithmetic, the scaling left the float32 outputs of the 18 test cases unchanged. The adapter is int8 (ai-edge-quantizer 0.9.0).
- Template: the model's own chat template with three changes for LiteRT-LM: LiteRT-LM's image marker,
modelaccepted as the assistant's role name, and an empty message list handled. Thinking stays off unlessenable_thinkingis true; with it off, the prompt ends with an empty<think>\n\n</think>\n\nblock before the answer. This file was checked with thinking off only (enable_thinkingunset or false). For the 18 test cases and a two-turn conversation the template renders the same tokens as the model's processor. Stops<|im_end|>and<|endoftext|>, no start token, a 4,096-token limit; the tokenizer is the repository's owntokenizer.json. - Packing: litert-lm-builder 0.15.0 packed the sections; LiteRT-LM 0.18.1's
unpackandpackadded the ExecutorMetadata section, from which the runtime creates the decoder's 48 state buffers; LiteRT 2.3.0, LiteRT-LM 0.19.1 and litert-lm-builder 0.19.1 made the final file. - Machine-readable facts: litertlm_manifest.json.
Known runtime issues
- One Engine per picture. Before LiteRT-LM 0.20.0, on other files whose decoder carries a recurrent state, a new Conversation on an Engine that already served another one continued from the state the earlier conversation left (LiteRT-LM #3165). This file's decoder carries such a state; we have not run that case with it. So create one Engine per picture: the script does, and every picture request above ran in a fresh process (the benchmark's three runs share one Engine).
- The GPU rebuilds 5 of its 8 cached contexts. With LiteRT-LM 0.19.0 on the Snapdragon Galaxy S26, each later GPU process loaded 3 of the 8 serialized GPU contexts from the runtime's program cache and rebuilt the other 5, which failed to load with
DATA_LOSS(LiteRT-LM #4178). So engine and conversation creation took 38.2β49.1 s in the later processes against 37.8 s in the first, and the program cache file beside the model grew by about 223 MB per process (1,344 MB after 6 processes). Delete that file (OvisOCR3_int8.litertlm_β¦_mldrift_program_cache.bin), or pass a--cache-diryou clear. - Later turns. This file's decoder takes embeddings from its own embedder, so from the second turn of a conversation on, LiteRT-LM up to 0.19.1 puts the previous answer's stop token into the KV cache with a zero embedding. A later answer can then differ from the one the model gives to the same messages in a single prompt. We read this in the source of LiteRT-LM 0.16.0, 0.18.1 and 0.19.1 and measured it with 0.18.1 on WeVisOne-VL-2B and Qwen2.5-Coder-1.5B-Instruct, not on this file; the source of 0.20.0 looks the embedding up (read, not measured), and we have not read 0.19.2. Every picture check here sent one picture in one turn per conversation. One question per conversation avoids it, as does a new conversation, on a new Engine before LiteRT-LM 0.20.0, that starts with the earlier messages and the new question.
- 8 GB Android phones: not run. We have not run this file on an 8 GB phone; these numbers are from the 12 GB Snapdragon Galaxy S26 and the Pixel 11 Pro. With the runtime's cache, a CPU request peaked at up to 4,236 MiB on the Snapdragon Galaxy S26 and 3,403 MiB on the Pixel 11 Pro. Without it, over our 18 test cases, the CPU process peaked at up to 7,227 MiB on the Snapdragon Galaxy S26, whose available memory fell to 985 MiB, and at 6,855 MiB on the Pixel 11 Pro. Use the CPU backend on 8 GB Android phones and keep the runtime's cache.
- Where the GPU was run. On the Snapdragon Galaxy S26 (Adreno) and the Pixel 11 Pro (PowerVR), both through OpenCL, and once on a Mac through WebGPU. On both phones the decoder's 7 signatures and the vision encoder ran entirely on the GPU, in one partition each; the embedder and the vision adapter stayed on the CPU. No phone with an Arm Mali GPU was run, so the GPU path is not verified on Mali.
- Android GPU with LiteRT-LM v0.18.0 and v0.18.1. This file keeps some of its weights outside the model graph (LiteRT's external weights), and on a Pixel 8a the GPU backend of the v0.18.0 and v0.18.1 Android builds crashes (SIGSEGV) on a Qwen3-0.6B file with external weights (LiteRT-LM #3986).
- The CPU quantizes activations at run time. On the CPU, XNNPACK quantizes the float input of each int8 fully connected layer to int8 at run time (its dynamically quantized path, read in the source of the LiteRT versions that LiteRT-LM 0.19.0 and 0.20.0 build with, not measured with this file).
- Mac GPU, long outputs: not checked with this file. On macOS, LiteRT-LM 0.20.0's pip package runs
--backend gpuon WebGPU; there this file wrote the drawn sample page as the CPU did (one run). On a Mac's GPU (WebGPU), LiteRT-LM 0.19.0's default sampler path made the greedy answers of another Qwen3.5 model, Qwen3.5-4B-3D-Coder, differ from run to run and broke its long code answers; we have not checked 0.20.0 for it, nor this file's long answers there. - Tool calls were not tested. The template renders tool definitions, and this file's metadata carries no tool-call config.
- iPhone, iOS and NPUs: not verified. This file was not run on an iPhone, under iOS or on an NPU.
License and changes
Apache-2.0, inherited from ATH-MaaS/OvisOCR3. Changes from the original work: exported to the LiteRT-LM format for one fixed 768 Γ 1344 picture, with plain 1-D token positions in place of M-RoPE in the text decoder; the text decoder's 145 fully connected layers, the embedding and the vision adapter quantized to int8; the vision encoder cast to fp16, with its LayerNorm inputs scaled by powers of two; the chat template adapted to LiteRT-LM. The sample pictures in samples/ were drawn with the fixture script of hf-to-litertlm (text we wrote, DejaVu fonts). Problems with these files: open a discussion in this repo.
- Downloads last month
- -