Chandra OCR 2, ONNX (q4) for transformers.js

A 4-bit ONNX build of datalab-to/chandra-ocr-2 for running in a web browser on WebGPU. We use it in a volunteer OCR project, where people read pages of digitised library collections in their own browsers.

Not an official release of the original authors; all credit for the model goes to them. Report problems with this conversion here, not to them.

How it was made

Chandra OCR 2's weights (a Qwen3.5-4B fine-tune) swapped into onnx-community's Qwen3.5-4B ONNX graphs, quantized to 4-bit (MatMulNBits, block 32), with the fused com.microsoft.LinearAttention prefill. Decoder weights split over two data files. Prompt: Chandra's HTML OCR prompt; it answers in HTML.

The decoder returns logits for the last position only ([batch, 1, vocab]): a Slice sits in front of lm_head. Greedy generation only reads the last position anyway, and returning the whole prompt's logits (1.6โ€“3 GB with a 248k vocabulary) made WebGPU fail to download the buffer on large pages. Weights are unchanged.

Running it

const model = await AutoModelForImageTextToText.from_pretrained("tpendragon/chandra-ocr-2-ONNX", {
  device: "webgpu", dtype: "q4",
  use_external_data_format: { decoder_model_merged: 2, embed_tokens: 1, vision_encoder: 1 },
});

Size: ~3.3 GB download, ~11โ€“12 GB peak browser memory in our runs. Cap the page at ~2.6 MP: above that the vision encoder runs out of WebAssembly memory.

Licence

Licence. This is a Derivative of the Model under Datalab's modified AI PUBS OpenRAIL-M licence, included here as LICENSE, and is distributed under that same licence. Its use restrictions (Attachment A), including the commercial-use limits, apply to you, to anything you build on it, and to its output. Commercial licences: https://www.datalab.to/. Changes made: format conversion to ONNX and 4-bit weight quantization; no retraining.

Downloads last month
30
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for tpendragon/chandra-ocr-2-ONNX

Quantized
(48)
this model