image-text-to-text Β· document understanding Β· WebGPU Β· ~265 MB
Most doc models give you flat text. SmolDocling gives you structure: hand it a page image and it emits DocTags β a compact markup that tags every element with its type and bounding box β headings, paragraphs, tables (as OTSL cells) and formulas (as LaTeX). It's the 256M-parameter model behind IBM's Docling toolkit, running end-to-end on your GPU with nothing uploaded.
| Model | docling-project/SmolDocling-256M-preview |
|---|---|
| Task | image-text-to-text (document image β structured DocTags) |
| Architecture | Idefics3ForConditionalGeneration (idefics3) β a SmolVLM-family VLM: SigLIP vision encoder + SmolLM2 decoder, fine-tuned on synthetic document / table / formula / chart data |
| Output | DocTags: <text>, <section_header_level_1>, <otsl> tables (<ched>/<fcel> cells), <formula> (LaTeX), <picture>, <caption> β each with <loc_x> bounding-box coords |
| Params / dtype | 256M Β· q4 (4-bit) β the q4f16 / fp16 / int8 exports are degenerate for this model, so q4 is the honest runnable one |
| Transformers.js | v4.3.0, pinned locally in this model's worker (SmolDocling's ONNX doesn't load under the shared 3.7.5 pin β same version-pin pattern as the SAM2 demo) |
| Backend | WebGPU (required β needs a GPU adapter) |
| Download | ~265 MB, cached after first load |
| License | CDLA-Permissive-2.0 |
| Web APIs | WebGPU, Web Workers, FileReader, Canvas |
Not the same as the other document demos: Nougat outputs Markdown, Donut answers a question about a form, and TrOCR does line OCR. SmolDocling outputs a full structured document (layout + tables + formulas) in one pass.
Pick a sample, or drop your own page image:
Under the structured view above is a plain autoregressive VLM. The document image is split into
tiles, each turned into image tokens, and the decoder generates one long string of
DocTags β interleaving element tags (<text>,
<otsl>, <formula>) with <loc_n> coordinate
tokens. Below is the exact tag stream the model emits, token by token, plus the real input
tensor shape β so you can watch it lay out the page.
| pixel_values shape | β |
|---|---|
| prompt tokens (text + image tiles) | β |
A flat OCR dump loses the thing that makes a document useful: its structure. DocTags keep the table a table, the formula a formula, and the heading a heading β with coordinates β so a document becomes queryable, convertible, and re-flowable. And it happens on-device, privately, for free:
One page in, DocTags out β the plain documentβstructure loop, with the parsed elements shown.
Export the structure: turn the DocTags into clean Markdown you can copy β a private document converter.
Tables & formulas: extract a data table as rows and a printed equation as LaTeX.
SmolDocling reads the page β an on-device LLM summarises the structured document into a plain-language brief.
SmolDocling uses the standard vision-to-text classes. Build a chat message with the page image and the "Convert this page to docling." instruction, template it, run the processor, then generate β streaming the DocTags as they come. Note the v4 pin: its ONNX doesn't load under Transformers.js 3.x.
import { AutoProcessor, AutoModelForVision2Seq, load_image, TextStreamer }
from "@huggingface/transformers@4.3.0"; // v4 β 3.x can't load SmolDocling's ONNX
const processor = await AutoProcessor.from_pretrained("docling-project/SmolDocling-256M-preview");
const model = await AutoModelForVision2Seq.from_pretrained(
"docling-project/SmolDocling-256M-preview",
{ dtype: "q4", device: "webgpu" }, // q4 is the runnable export; q4f16/fp16/int8 are degenerate
);
const image = await load_image(pageURL);
const messages = [{ role: "user", content: [
{ type: "image" }, { type: "text", text: "Convert this page to docling." },
]}];
const text = processor.apply_chat_template(messages, { add_generation_prompt: true });
const inputs = await processor(text, [image]);
// inputs.pixel_values.dims === [1, numTiles, 3, H, W] β the split page
const streamer = new TextStreamer(processor.tokenizer,
{ skip_prompt: true, skip_special_tokens: false, callback_function: (t) => append(t) });
await model.generate({ ...inputs, max_new_tokens: 512, streamer });
// β "<doctag><section_header_level_1><loc_43>β¦Regional Sales Summary</section_header_level_1><otsl>β¦"
This page runs exactly that, in a Web Worker, and gates on a real WebGPU adapter first β if none exists it shows a labelled needs-WebGPU state instead of a fake answer.